mirror of
https://github.com/doublespeakgames/adarkroom.git
synced 2026-05-28 00:01: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:
+15
-14
@@ -128,11 +128,12 @@ var World = {
|
||||
World.LANDMARKS[World.TILE.BATTLEFIELD] = {num: 5, minRadius: 18, maxRadius: World.RADIUS * 1.5, scene: 'battlefield', label: 'A Battlefield'};
|
||||
World.LANDMARKS[World.TILE.SWAMP] = {num: 1, minRadius: 15, maxRadius: World.RADIUS * 1.5, scene: 'swamp', label: 'A Murky Swamp'};
|
||||
|
||||
if(typeof State.world == 'undefined') {
|
||||
State.world = {
|
||||
if(typeof $SM.get('features.location.world') == 'undefined') {
|
||||
$SM.set('features.location.world', true);
|
||||
$SM.setM('game.world', {
|
||||
map: World.generateMap(),
|
||||
mask: World.newMask()
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
// Create the World panel
|
||||
@@ -440,9 +441,9 @@ var World = {
|
||||
Notifications.notify(World, 'starvation sets in')
|
||||
World.starvation = true;
|
||||
} else {
|
||||
State.starved = State.starved ? State.starved : 0;
|
||||
State.starved++;
|
||||
if(State.starved >= 10 && !Engine.hasPerk('slow metabolism')) {
|
||||
$SM.set('character.starved', $SM.get('character.starved', true));
|
||||
$SM.add('character.starved', 1);
|
||||
if($SM.get('character.starved') >= 10 && !Engine.hasPerk('slow metabolism')) {
|
||||
Engine.addPerk('slow metabolism');
|
||||
}
|
||||
World.die();
|
||||
@@ -469,9 +470,9 @@ var World = {
|
||||
Notifications.notify(World, 'the thirst becomes unbearable');
|
||||
World.thirst = true;
|
||||
} else {
|
||||
State.dehydrated = State.dehydrated ? State.dehydrated : 0;
|
||||
State.dehydrated++;
|
||||
if(State.dehydrated >= 10 && !Engine.hasPerk('desert rat')) {
|
||||
$SM.set('character.dehydrated', $SM.get('character.dehydrated', true));
|
||||
$SM.add('character.dehydrated', 1);
|
||||
if($SM.get('character.dehydrated') >= 10 && !Engine.hasPerk('desert rat')) {
|
||||
Engine.addPerk('desert rat');
|
||||
}
|
||||
World.die();
|
||||
@@ -604,7 +605,7 @@ var World = {
|
||||
applyMap: function() {
|
||||
var x = Math.floor(Math.random() * (World.RADIUS * 2) + 1);
|
||||
var y = Math.floor(Math.random() * (World.RADIUS * 2) + 1);
|
||||
World.uncoverMap(x, y, 5, State.world.mask);
|
||||
World.uncoverMap(x, y, 5, $SM.get('game.world.mask'));
|
||||
},
|
||||
|
||||
generateMap: function() {
|
||||
@@ -822,7 +823,7 @@ var World = {
|
||||
|
||||
goHome: function() {
|
||||
// Home safe! Commit the changes.
|
||||
State.world = World.state;
|
||||
$SM.setM('game.world', World.state);
|
||||
if(World.state.sulphurmine && Outside.numBuilding('sulphur mine') == 0) {
|
||||
Outside.addBuilding('sulphur mine', 1);
|
||||
Engine.event('progress', 'sulphur mine');
|
||||
@@ -835,7 +836,7 @@ var World = {
|
||||
Outside.addBuilding('coal mine', 1);
|
||||
Engine.event('progress', 'coal mine');
|
||||
}
|
||||
if(World.state.ship && !State.ship) {
|
||||
if(World.state.ship && !$SM.get('features.location.spaceShip')) {
|
||||
Ship.init();
|
||||
Engine.event('progress', 'ship');
|
||||
}
|
||||
@@ -904,7 +905,7 @@ var World = {
|
||||
Notifications.notify(null, 'water replenished');
|
||||
World.setWater(World.getMaxWater());
|
||||
// Save progress at outposts
|
||||
State.world = World.state;
|
||||
$SM.setM('game.world', World.state);
|
||||
// Mark this outpost as used
|
||||
World.usedOutposts[World.curPos[0] + ',' + World.curPos[1]] = true;
|
||||
},
|
||||
@@ -912,7 +913,7 @@ var World = {
|
||||
onArrival: function() {
|
||||
Engine.keyLock = false;
|
||||
// Explore in a temporary world-state. We'll commit the changes if you return home safe.
|
||||
World.state = $.extend(true, {}, State.world);
|
||||
World.state = $.extend(true, {}, $SM.get('game.world'));
|
||||
World.setWater(World.getMaxWater());
|
||||
World.setHp(World.getMaxHealth());
|
||||
World.foodMove = 0;
|
||||
|
||||
Reference in New Issue
Block a user