mirror of
https://github.com/doublespeakgames/adarkroom.git
synced 2026-05-28 00:01:54 +08:00
add $SM.setget, refactor Room to better use $SM
game.room.builder >> game.builder.level setget is mainly for use in local copies of states, useful for keeping code cleaner and less redundant while maintaining set/get of states by the $SM ====functions refactored==== Room.unlockForext //remove update calls Room.buy //remove update calls Room.build //remove update calls Room.cooFire //added locals to reduce gets Room.adjustTemp //added locals to reduce gets Room.updateBuilderState //added local to reduce gets Room.craftUnlocked //Room unlock is always going to be true, don't need to check parents to avoid errors anymore Room.buyUnlocked //Room unlock is always going to be true, don't need to check parents to avoid errors anymore
This commit is contained in:
@@ -5,7 +5,13 @@
|
|||||||
<projects>
|
<projects>
|
||||||
</projects>
|
</projects>
|
||||||
<buildSpec>
|
<buildSpec>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.wst.jsdt.core.javascriptValidator</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
</buildSpec>
|
</buildSpec>
|
||||||
<natures>
|
<natures>
|
||||||
|
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
|
||||||
</natures>
|
</natures>
|
||||||
</projectDescription>
|
</projectDescription>
|
||||||
|
|||||||
+43
-42
@@ -9,6 +9,10 @@ var Room = {
|
|||||||
_STOKE_COOLDOWN: 10, // cooldown to stoke the fire
|
_STOKE_COOLDOWN: 10, // cooldown to stoke the fire
|
||||||
_NEED_WOOD_DELAY: 15 * 1000, // from when the stranger shows up, to when you need wood
|
_NEED_WOOD_DELAY: 15 * 1000, // from when the stranger shows up, to when you need wood
|
||||||
|
|
||||||
|
fire:null,
|
||||||
|
temperature:null,
|
||||||
|
buttons:{},
|
||||||
|
|
||||||
Craftables: {
|
Craftables: {
|
||||||
'trap': {
|
'trap': {
|
||||||
button: null,
|
button: null,
|
||||||
@@ -445,14 +449,18 @@ var Room = {
|
|||||||
|
|
||||||
if(typeof $SM.get('features.location.room') == 'undefined') {
|
if(typeof $SM.get('features.location.room') == 'undefined') {
|
||||||
$SM.set('features.location.room', true);
|
$SM.set('features.location.room', true);
|
||||||
|
$SM.set('game.builder.level', -1);
|
||||||
$SM.set('game.room', {
|
$SM.set('game.room', {
|
||||||
temperature: this.TempEnum.Cold,
|
temperature: this.TempEnum.Cold,
|
||||||
fire: this.FireEnum.Dead,
|
fire: this.FireEnum.Dead,
|
||||||
buttons: {},
|
buttons: {},
|
||||||
builder: -1
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Room.temperature = this.TempEnum.Cold;
|
||||||
|
Room.fire = this.FireEnum.Dead;
|
||||||
|
|
||||||
|
|
||||||
// Create the room tab
|
// Create the room tab
|
||||||
this.tab = Header.addLocation("A Dark Room", "room", Room);
|
this.tab = Header.addLocation("A Dark Room", "room", Room);
|
||||||
|
|
||||||
@@ -506,10 +514,10 @@ var Room = {
|
|||||||
* 3 - Sleeping
|
* 3 - Sleeping
|
||||||
* 4 - Helping
|
* 4 - Helping
|
||||||
*/
|
*/
|
||||||
if($SM.get('game.room.builder') >= 0 && $SM.get('game.room.builder') < 3) {
|
if($SM.get('game.builder.level') >= 0 && $SM.get('game.builder.level') < 3) {
|
||||||
Room._builderTimer = setTimeout(Room.updateBuilderState, Room._BUILDER_STATE_DELAY);
|
Room._builderTimer = setTimeout(Room.updateBuilderState, Room._BUILDER_STATE_DELAY);
|
||||||
}
|
}
|
||||||
if($SM.get('game.room.builder') == 1 && $SM.get('stores.wood', true) < 0) {
|
if($SM.get('game.builder.level') == 1 && $SM.get('stores.wood', true) < 0) {
|
||||||
setTimeout(Room.unlockForest, Room._NEED_WOOD_DELAY);
|
setTimeout(Room.unlockForest, Room._NEED_WOOD_DELAY);
|
||||||
}
|
}
|
||||||
setTimeout($SM.collectIncome, 1000);
|
setTimeout($SM.collectIncome, 1000);
|
||||||
@@ -527,8 +535,8 @@ var Room = {
|
|||||||
Notifications.notify(Room, "the room is " + $SM.get('game.room.temperature.text'));
|
Notifications.notify(Room, "the room is " + $SM.get('game.room.temperature.text'));
|
||||||
Room.changed = false;
|
Room.changed = false;
|
||||||
}
|
}
|
||||||
if($SM.get('game.room.builder') == 3) {
|
if($SM.get('game.builder.level') == 3) {
|
||||||
$SM.add('game.room.builder', 1);
|
$SM.add('game.builder.level', 1);
|
||||||
$SM.setIncome('builder', {
|
$SM.setIncome('builder', {
|
||||||
delay: 10,
|
delay: 10,
|
||||||
stores: {'wood' : 2 }
|
stores: {'wood' : 2 }
|
||||||
@@ -642,8 +650,8 @@ var Room = {
|
|||||||
Room.changed = true;
|
Room.changed = true;
|
||||||
}
|
}
|
||||||
Notifications.notify(Room, "the fire is " + $SM.get('game.room.fire.text'), true);
|
Notifications.notify(Room, "the fire is " + $SM.get('game.room.fire.text'), true);
|
||||||
if($SM.get('game.room.fire.value') > 1 && $SM.get('game.room.builder') < 0) {
|
if($SM.get('game.room.fire.value') > 1 && $SM.get('game.builder.level') < 0) {
|
||||||
$SM.set('game.room.builder', 0);
|
$SM.set('game.builder.level', 0);
|
||||||
Notifications.notify(Room, "the light from the fire spills from the windows, out into the dark");
|
Notifications.notify(Room, "the light from the fire spills from the windows, out into the dark");
|
||||||
setTimeout(Room.updateBuilderState, Room._BUILDER_STATE_DELAY);
|
setTimeout(Room.updateBuilderState, Room._BUILDER_STATE_DELAY);
|
||||||
}
|
}
|
||||||
@@ -655,30 +663,33 @@ var Room = {
|
|||||||
|
|
||||||
coolFire: function() {
|
coolFire: function() {
|
||||||
var wood = $SM.get('stores.wood');
|
var wood = $SM.get('stores.wood');
|
||||||
if($SM.get('game.room.fire.value') <= Room.FireEnum.Flickering.value &&
|
var roomFire = $SM.get('game.room.fire');
|
||||||
$SM.get('game.room.builder') > 3 && wood > 0) {
|
if(roomFire.value <= Room.FireEnum.Flickering.value &&
|
||||||
|
$SM.get('game.builder.level') > 3 && wood > 0) {
|
||||||
Notifications.notify(Room, "builder stokes the fire", true);
|
Notifications.notify(Room, "builder stokes the fire", true);
|
||||||
$SM.set('stores.wood', wood - 1);
|
$SM.set('stores.wood', wood - 1);
|
||||||
$SM.set('game.room.fire', Room.FireEnum.fromInt($SM.get('game.room.fire.value') + 1));
|
roomFire = $SM.setget('game.room.fire', Room.FireEnum.fromInt(roomFire.value + 1));
|
||||||
}
|
}
|
||||||
if($SM.get('game.room.fire.value') > 0) {
|
if(roomFire.value > 0) {
|
||||||
$SM.set('game.room.fire', Room.FireEnum.fromInt($SM.get('game.room.fire.value') - 1));
|
$SM.set('game.room.fire', Room.FireEnum.fromInt(roomFire.value - 1));
|
||||||
Room._fireTimer = setTimeout(Room.coolFire, Room._FIRE_COOL_DELAY);
|
Room._fireTimer = setTimeout(Room.coolFire, Room._FIRE_COOL_DELAY);
|
||||||
Room.onFireChange();
|
Room.onFireChange();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
adjustTemp: function() {
|
adjustTemp: function() {
|
||||||
var old = $SM.get('game.room.temperature.value');
|
var roomTemp = $SM.get('game.room.temperature');
|
||||||
if($SM.get('game.room.temperature.value') > 0 && $SM.get('game.room.temperature.value') > $SM.get('game.room.fire.value')) {
|
var roomFire = $SM.get('game.room.fire');
|
||||||
$SM.set('game.room.temperature', Room.TempEnum.fromInt($SM.get('game.room.temperature.value') - 1));
|
var old = roomTemp.value;
|
||||||
Notifications.notify(Room, "the room is " + $SM.get('game.room.temperature.text'), true);
|
if(roomTemp.value > 0 && roomTemp.value > roomFire.value) {
|
||||||
|
roomTemp = $SM.setget('game.room.temperature', Room.TempEnum.fromInt(roomTemp.value - 1));
|
||||||
|
Notifications.notify(Room, "the room is " + roomTemp.text, true);
|
||||||
}
|
}
|
||||||
if($SM.get('game.room.temperature.value') < 4 && $SM.get('game.room.temperature.value') < $SM.get('game.room.fire.value')) {
|
if(roomTemp.value < 4 && roomTemp.value < roomFire.value) {
|
||||||
$SM.set('game.room.temperature', Room.TempEnum.fromInt($SM.get('game.room.temperature.value') + 1));
|
roomTemp = $SM.setget('game.room.temperature', Room.TempEnum.fromInt(roomTemp.value + 1));
|
||||||
Notifications.notify(Room, "the room is " + $SM.get('game.room.temperature.text'), true);
|
Notifications.notify(Room, "the room is " + roomTemp.text, true);
|
||||||
}
|
}
|
||||||
if($SM.get('game.room.temperature.value') != old) {
|
if(roomTemp.value != old) {
|
||||||
Room.changed = true;
|
Room.changed = true;
|
||||||
}
|
}
|
||||||
Room._tempTimer = setTimeout(Room.adjustTemp, Room._ROOM_WARM_DELAY);
|
Room._tempTimer = setTimeout(Room.adjustTemp, Room._ROOM_WARM_DELAY);
|
||||||
@@ -686,23 +697,22 @@ var Room = {
|
|||||||
|
|
||||||
unlockForest: function() {
|
unlockForest: function() {
|
||||||
$SM.set('stores.wood', 4);
|
$SM.set('stores.wood', 4);
|
||||||
Room.updateButton();
|
|
||||||
Outside.init();
|
Outside.init();
|
||||||
Room.updateStoresView();
|
|
||||||
Notifications.notify(Room, "the wind howls outside");
|
Notifications.notify(Room, "the wind howls outside");
|
||||||
Notifications.notify(Room, "the wood is running out");
|
Notifications.notify(Room, "the wood is running out");
|
||||||
Engine.event('progress', 'outside');
|
Engine.event('progress', 'outside');
|
||||||
},
|
},
|
||||||
|
|
||||||
updateBuilderState: function() {
|
updateBuilderState: function() {
|
||||||
if($SM.get('game.room.builder') == 0) {
|
var lBuilder = $SM.get('game.builder.level');
|
||||||
|
if(lBuilder == 0) {
|
||||||
Notifications.notify(Room, "a ragged stranger stumbles through the door and collapses in the corner");
|
Notifications.notify(Room, "a ragged stranger stumbles through the door and collapses in the corner");
|
||||||
$SM.set('game.room.builder', 1);
|
lBuilder = $SM.setget('game.builder.level', 1);
|
||||||
setTimeout(Room.unlockForest, Room._NEED_WOOD_DELAY);
|
setTimeout(Room.unlockForest, Room._NEED_WOOD_DELAY);
|
||||||
}
|
}
|
||||||
else if($SM.get('game.room.builder') < 3 && $SM.get('game.room.temperature.value') >= Room.TempEnum.Warm.value) {
|
else if(lBuilder < 3 && $SM.get('game.room.temperature.value') >= Room.TempEnum.Warm.value) {
|
||||||
var msg;
|
var msg;
|
||||||
switch($SM.get('game.room.builder')) {
|
switch(lBuilder) {
|
||||||
case 1:
|
case 1:
|
||||||
msg = "the stranger shivers, and mumbles quietly. her words are unintelligible.";
|
msg = "the stranger shivers, and mumbles quietly. her words are unintelligible.";
|
||||||
break;
|
break;
|
||||||
@@ -711,11 +721,11 @@ var Room = {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Notifications.notify(Room, msg);
|
Notifications.notify(Room, msg);
|
||||||
if($SM.get('game.room.builder') < 3) {
|
if(lBuilder < 3) {
|
||||||
$SM.add('game.room.builder', 1);
|
lBuilder = $SM.setget('game.builder.level', lBuilder + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if($SM.get('game.room.builder') < 3) {
|
if(lBuilder < 3) {
|
||||||
setTimeout(Room.updateBuilderState, Room._BUILDER_STATE_DELAY);
|
setTimeout(Room.updateBuilderState, Room._BUILDER_STATE_DELAY);
|
||||||
}
|
}
|
||||||
Engine.saveGame();
|
Engine.saveGame();
|
||||||
@@ -875,8 +885,6 @@ var Room = {
|
|||||||
|
|
||||||
$SM.add('stores[\''+thing+'\']', 1);
|
$SM.add('stores[\''+thing+'\']', 1);
|
||||||
|
|
||||||
Room.updateBuildButtons();
|
|
||||||
|
|
||||||
if(thing == 'compass') {
|
if(thing == 'compass') {
|
||||||
Path.openPath();
|
Path.openPath();
|
||||||
}
|
}
|
||||||
@@ -933,10 +941,7 @@ var Room = {
|
|||||||
case 'building':
|
case 'building':
|
||||||
Outside.addBuilding(thing, 1);
|
Outside.addBuilding(thing, 1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
Room.updateBuildButtons();
|
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
needsWorkshop: function(type) {
|
needsWorkshop: function(type) {
|
||||||
@@ -944,12 +949,10 @@ var Room = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
craftUnlocked: function(thing) {
|
craftUnlocked: function(thing) {
|
||||||
if(typeof $SM.get('features.location.room') != 'undefined' &&
|
if($SM.get('game.room.buttons[\''+thing+'\']')) {
|
||||||
typeof $SM.get('game.room.buttons') != 'undefined' &&
|
|
||||||
$SM.get('game.room.buttons[\''+thing+'\']')) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if($SM.get('game.room.builder') < 4) return false;
|
if($SM.get('game.builder.level') < 4) return false;
|
||||||
var craftable = Room.Craftables[thing];
|
var craftable = Room.Craftables[thing];
|
||||||
if(Room.needsWorkshop(craftable.type) && Outside.numBuilding('workshop') == 0) return false;
|
if(Room.needsWorkshop(craftable.type) && Outside.numBuilding('workshop') == 0) return false;
|
||||||
var cost = craftable.cost();
|
var cost = craftable.cost();
|
||||||
@@ -970,9 +973,7 @@ var Room = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
buyUnlocked: function(thing) {
|
buyUnlocked: function(thing) {
|
||||||
if(typeof $SM.get('features.location.room') != 'undefined' &&
|
if($SM.get('game.room.buttons[\''+thing+'\']')) {
|
||||||
typeof $SM.get('game.room.buttons') != 'undefined' &&
|
|
||||||
$SM.get('game.room.buttons[\''+thing+'\']')) {
|
|
||||||
return true;
|
return true;
|
||||||
} else if(Outside.numBuilding('trading post') > 0) {
|
} else if(Outside.numBuilding('trading post') > 0) {
|
||||||
if(thing == 'compass' || $SM.get('stores[\''+thing+'\']')) {
|
if(thing == 'compass' || $SM.get('stores[\''+thing+'\']')) {
|
||||||
|
|||||||
@@ -147,7 +147,7 @@ var StateManager = {
|
|||||||
//return state, undefined or 0
|
//return state, undefined or 0
|
||||||
get: function(stateName, requestZero) {
|
get: function(stateName, requestZero) {
|
||||||
var whichState = null;
|
var whichState = null;
|
||||||
var fullPath = $SM.buildPath(stateName, name);
|
var fullPath = $SM.buildPath(stateName);
|
||||||
|
|
||||||
//catch errors if parent of state doesn't exist
|
//catch errors if parent of state doesn't exist
|
||||||
try{
|
try{
|
||||||
@@ -161,6 +161,13 @@ var StateManager = {
|
|||||||
else return whichState;
|
else return whichState;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
//mainly for local copy use, add(M) can fail so we can't shortcut them
|
||||||
|
//since set does not fail, we know state exists and can simply return the object
|
||||||
|
setget: function(stateName, value, noEvent){
|
||||||
|
$SM.set(stateName, value, noEvent);
|
||||||
|
return eval('('+$SM.buildPath(stateName)+')');
|
||||||
|
},
|
||||||
|
|
||||||
remove: function(stateName, noEvent) {
|
remove: function(stateName, noEvent) {
|
||||||
var whichState = $SM.buildPath(whichState);
|
var whichState = $SM.buildPath(whichState);
|
||||||
try{
|
try{
|
||||||
|
|||||||
Reference in New Issue
Block a user