mirror of
https://github.com/doublespeakgames/adarkroom.git
synced 2026-06-02 10:41:54 +08:00
create StateManager, change all State calls to managed calls
Introduced state_manager.js almost all State gets/sets are now run through the manager (alias $SM). For now it was a simple, mostly straightforward replacement of calls. This means that there are redundancies and a lot of now unneeded code for things the SM will handle. However, since I had trouble with making those changes as well as introducing the manager all at once my first attempt, I am taking the wiser approach and making "one change" at a time like I should have instead of being too sure of myself. At this point, it seems to work, but there may be bugs I didn't catch. There was also no attempt made to update old saves to work with this. In theory, it shouldn't be too hard. (included is a list of all state changes) TODO: Save Update. Refactor: a lot, many many redundancies now. Refactor: "location centric" to "global centric". Relocate all calls to different update functions to event listeners where possible. ====================================================== The changes to State are as follows: .room (exists) > features.location.room .room > game.room .room.builder > game.room.builder .room.temperature > game.room.temperature .room.fire > game.room.fire .room.buttons > game.room.buttons .outside (exists) > features.location.outside .outside > game.outside .outside.population > game.outside.population .outside.buildings > game.outside.buildings .outside.workers > game.outside.workers .outside.seenForest > game.outside.seenForest .world (exists) > features.location.world .world > game.world .world.map > game.world.map .world.mask > game.world.mask .starved > character.starved .dehydrated > character.dehydrated .ship (exists) > featuers.location.spaceShip .ship > game.spaceShip .ship.hull > game.spaceShip.hull .ship.thrusters > game.spaceShip.thrusters .ship.seenWarning > game.spaceShip.seenWarning .ship.seenShip > game.spaceShip.seenShip .punches > character.punches .perks > character.perks .thieves > game.thieves .stolen > game.stolen .cityCleared > game.cityCleared .stores > stores .income > income
This commit is contained in:
+17
-16
@@ -15,11 +15,12 @@ var Ship = {
|
||||
options
|
||||
);
|
||||
|
||||
if(!State.ship) {
|
||||
State.ship = {
|
||||
if(!$SM.get('features.location.spaceShip')) {
|
||||
$SM.set('features.location.spaceShip', true);
|
||||
$SM.setM('game.spaceShip', {
|
||||
hull: Ship.BASE_HULL,
|
||||
thrusters: Ship.BASE_THRUSTERS
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Create the Ship tab
|
||||
@@ -35,13 +36,13 @@ var Ship = {
|
||||
// Draw the hull label
|
||||
var hullRow = $('<div>').attr('id', 'hullRow').appendTo('div#shipPanel');
|
||||
$('<div>').addClass('row_key').text('hull:').appendTo(hullRow);
|
||||
$('<div>').addClass('row_val').text(State.ship.hull).appendTo(hullRow);
|
||||
$('<div>').addClass('row_val').text($SM.get('game.spaceShip.hull')).appendTo(hullRow);
|
||||
$('<div>').addClass('clear').appendTo(hullRow);
|
||||
|
||||
// Draw the thrusters label
|
||||
var engineRow = $('<div>').attr('id', 'engineRow').appendTo('div#shipPanel');
|
||||
$('<div>').addClass('row_key').text('engine:').appendTo(engineRow);
|
||||
$('<div>').addClass('row_val').text(State.ship.thrusters).appendTo(engineRow);
|
||||
$('<div>').addClass('row_val').text($SM.get('game.spaceShip.thrusters')).appendTo(engineRow);
|
||||
$('<div>').addClass('clear').appendTo(engineRow);
|
||||
|
||||
// Draw the reinforce button
|
||||
@@ -71,7 +72,7 @@ var Ship = {
|
||||
cooldown: Ship.LIFTOFF_COOLDOWN
|
||||
}).appendTo('div#shipPanel');
|
||||
|
||||
if(State.ship.hull <= 0) {
|
||||
if($SM.get('game.spaceShip.hull') <= 0) {
|
||||
Button.setDisabled(b, true);
|
||||
}
|
||||
|
||||
@@ -83,9 +84,9 @@ var Ship = {
|
||||
|
||||
onArrival: function(transition_diff) {
|
||||
Ship.setTitle();
|
||||
if(!State.seenShip) {
|
||||
if(!$SM.get('game.spaceShip.seenShip')) {
|
||||
Notifications.notify(Ship, 'somewhere above the debris cloud, the wanderer fleet hovers. been on this rock too long.');
|
||||
State.seenShip = true;
|
||||
$SM.set('game.spaceShip.seenShip', true);
|
||||
Engine.saveGame();
|
||||
}
|
||||
|
||||
@@ -104,11 +105,11 @@ var Ship = {
|
||||
return false;
|
||||
}
|
||||
Engine.addStore('alien alloy', -Ship.ALLOY_PER_HULL);
|
||||
State.ship.hull++;
|
||||
if(State.ship.hull > 0) {
|
||||
$SM.add('game.spaceShip.hull', 1);
|
||||
if($SM.get('game.spaceShip.hull') > 0) {
|
||||
Button.setDisabled($('#liftoffButton', Ship.panel), false);
|
||||
}
|
||||
$('#hullRow .row_val', Ship.panel).text(State.ship.hull);
|
||||
$('#hullRow .row_val', Ship.panel).text($SM.get('game.spaceShip.hull'));
|
||||
},
|
||||
|
||||
upgradeEngine: function() {
|
||||
@@ -117,16 +118,16 @@ var Ship = {
|
||||
return false;
|
||||
}
|
||||
Engine.addStore('alien alloy', -Ship.ALLOY_PER_THRUSTER);
|
||||
State.ship.thrusters++;
|
||||
$('#engineRow .row_val', Ship.panel).text(State.ship.thrusters);
|
||||
$SM.add('game.spaceShip.thrusters', 1)
|
||||
$('#engineRow .row_val', Ship.panel).text($SM.get('game.spaceShip.thrusters'));
|
||||
},
|
||||
|
||||
getMaxHull: function() {
|
||||
return State.ship.hull;
|
||||
return $SM.get('game.spaceShip.hull');
|
||||
},
|
||||
|
||||
checkLiftOff: function() {
|
||||
if(!State.ship.seenWarning) {
|
||||
if(!$SM.get('game.spaceShip.seenWarning')) {
|
||||
Events.startEvent({
|
||||
title: 'Ready to Leave?',
|
||||
scenes: {
|
||||
@@ -138,7 +139,7 @@ var Ship = {
|
||||
'fly': {
|
||||
text: 'lift off',
|
||||
onChoose: function() {
|
||||
State.ship.seenWarning = true;
|
||||
$SM.set('game.spaceShip.seenWarning', true);
|
||||
Ship.liftOff();
|
||||
},
|
||||
nextScene: 'end'
|
||||
|
||||
Reference in New Issue
Block a user