mirror of
https://github.com/doublespeakgames/adarkroom.git
synced 2026-06-12 23:47:13 +08:00
Add fire and temperature to State.game
Adding fire and temperature to game state will allow persistence of the fire and temp on reloads.
This commit is contained in:
+29
-30
@@ -9,8 +9,6 @@ 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:{},
|
buttons:{},
|
||||||
|
|
||||||
Craftables: {
|
Craftables: {
|
||||||
@@ -476,9 +474,10 @@ var Room = {
|
|||||||
$SM.set('game.builder.level', -1);
|
$SM.set('game.builder.level', -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
Room.temperature = this.TempEnum.Cold;
|
// If this is the first time playing, the fire is dead and it's freezing.
|
||||||
Room.fire = this.FireEnum.Dead;
|
// Otherwise grab past save state temp and fire level.
|
||||||
|
$SM.set('game.temperature', $SM.get('game.temperature.value')==undefined?this.TempEnum.Freezing:$SM.get('game.temperature'));
|
||||||
|
$SM.set('game.fire', $SM.get('game.fire.value')==undefined?this.FireEnum.Dead:$SM.get('game.fire'));
|
||||||
|
|
||||||
// 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);
|
||||||
@@ -541,8 +540,8 @@ var Room = {
|
|||||||
}
|
}
|
||||||
setTimeout($SM.collectIncome, 1000);
|
setTimeout($SM.collectIncome, 1000);
|
||||||
|
|
||||||
Notifications.notify(Room, _("the room is {0}", Room.temperature.text));
|
Notifications.notify(Room, _("the room is {0}", $SM.get('game.temperature.text')));
|
||||||
Notifications.notify(Room, _("the fire is {0}", Room.fire.text));
|
Notifications.notify(Room, _("the fire is {0}", $SM.get('game.fire.text')));
|
||||||
},
|
},
|
||||||
|
|
||||||
options: {}, // Nothing for now
|
options: {}, // Nothing for now
|
||||||
@@ -550,8 +549,8 @@ var Room = {
|
|||||||
onArrival: function(transition_diff) {
|
onArrival: function(transition_diff) {
|
||||||
Room.setTitle();
|
Room.setTitle();
|
||||||
if(Room.changed) {
|
if(Room.changed) {
|
||||||
Notifications.notify(Room, _("the fire is {0}", Room.fire.text));
|
Notifications.notify(Room, _("the fire is {0}", $SM.get('game.temperature.text')));
|
||||||
Notifications.notify(Room, _("the room is {0}", Room.temperature.text));
|
Notifications.notify(Room, _("the room is {0}", $SM.get('game.temperature.text')));
|
||||||
Room.changed = false;
|
Room.changed = false;
|
||||||
}
|
}
|
||||||
if($SM.get('game.builder.level') == 3) {
|
if($SM.get('game.builder.level') == 3) {
|
||||||
@@ -600,7 +599,7 @@ var Room = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
setTitle: function() {
|
setTitle: function() {
|
||||||
var title = Room.fire.value < 2 ? _("A Dark Room") : _("A Firelit Room");
|
var title = $SM.get('game.fire.value') < 2 ? _("A Dark Room") : _("A Firelit Room");
|
||||||
if(Engine.activeModule == this) {
|
if(Engine.activeModule == this) {
|
||||||
document.title = title;
|
document.title = title;
|
||||||
}
|
}
|
||||||
@@ -610,7 +609,7 @@ var Room = {
|
|||||||
updateButton: function() {
|
updateButton: function() {
|
||||||
var light = $('#lightButton.button');
|
var light = $('#lightButton.button');
|
||||||
var stoke = $('#stokeButton.button');
|
var stoke = $('#stokeButton.button');
|
||||||
if(Room.fire.value == Room.FireEnum.Dead.value && stoke.css('display') != 'none') {
|
if($SM.get('game.fire.value') == Room.FireEnum.Dead.value && stoke.css('display') != 'none') {
|
||||||
stoke.hide();
|
stoke.hide();
|
||||||
light.show();
|
light.show();
|
||||||
if(stoke.hasClass('disabled')) {
|
if(stoke.hasClass('disabled')) {
|
||||||
@@ -644,7 +643,7 @@ var Room = {
|
|||||||
} else if(wood > 4) {
|
} else if(wood > 4) {
|
||||||
$SM.set('stores.wood', wood - 5);
|
$SM.set('stores.wood', wood - 5);
|
||||||
}
|
}
|
||||||
Room.fire = Room.FireEnum.Burning;
|
$SM.set('game.fire', Room.FireEnum.Burning);
|
||||||
Room.onFireChange();
|
Room.onFireChange();
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -658,8 +657,8 @@ var Room = {
|
|||||||
if(wood > 0) {
|
if(wood > 0) {
|
||||||
$SM.set('stores.wood', wood - 1);
|
$SM.set('stores.wood', wood - 1);
|
||||||
}
|
}
|
||||||
if(Room.fire.value < 4) {
|
if($SM.get('game.fire.value') < 4) {
|
||||||
Room.fire = Room.FireEnum.fromInt(Room.fire.value + 1);
|
$SM.set('game.fire', Room.FireEnum.fromInt($SM.get('game.fire.value') + 1));
|
||||||
}
|
}
|
||||||
Room.onFireChange();
|
Room.onFireChange();
|
||||||
},
|
},
|
||||||
@@ -668,8 +667,8 @@ var Room = {
|
|||||||
if(Engine.activeModule != Room) {
|
if(Engine.activeModule != Room) {
|
||||||
Room.changed = true;
|
Room.changed = true;
|
||||||
}
|
}
|
||||||
Notifications.notify(Room, _("the fire is {0}", Room.fire.text), true);
|
Notifications.notify(Room, _("the fire is {0}", $SM.get('game.fire.text')), true);
|
||||||
if(Room.fire.value > 1 && $SM.get('game.builder.level') < 0) {
|
if($SM.get('game.fire.value') > 1 && $SM.get('game.builder.level') < 0) {
|
||||||
$SM.set('game.builder.level', 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);
|
||||||
@@ -682,30 +681,30 @@ var Room = {
|
|||||||
|
|
||||||
coolFire: function() {
|
coolFire: function() {
|
||||||
var wood = $SM.get('stores.wood');
|
var wood = $SM.get('stores.wood');
|
||||||
if(Room.fire.value <= Room.FireEnum.Flickering.value &&
|
if($SM.get('game.fire.value') <= Room.FireEnum.Flickering.value &&
|
||||||
$SM.get('game.builder.level') > 3 && wood > 0) {
|
$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);
|
||||||
Room.fire = Room.FireEnum.fromInt(Room.fire.value + 1);
|
$SM.set('game.fire',Room.FireEnum.fromInt($SM.get('game.fire.value') + 1));
|
||||||
}
|
}
|
||||||
if(Room.fire.value > 0) {
|
if($SM.get('game.fire.value') > 0) {
|
||||||
Room.fire = Room.FireEnum.fromInt(Room.fire.value - 1);
|
$SM.set('game.fire',Room.FireEnum.fromInt($SM.get('game.fire.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 = Room.temperature.value;
|
var old = $SM.get('game.temperature.value');
|
||||||
if(Room.temperature.value > 0 && Room.temperature.value > Room.fire.value) {
|
if($SM.get('game.temperature.value') > 0 && $SM.get('game.temperature.value') > $SM.get('game.fire.value')) {
|
||||||
Room.temperature = Room.TempEnum.fromInt(Room.temperature.value - 1);
|
$SM.set('game.temperature',Room.TempEnum.fromInt($SM.get('game.temperature.value') - 1));
|
||||||
Notifications.notify(Room, _("the room is {0}" , Room.temperature.text), true);
|
Notifications.notify(Room, _("the room is {0}" , $SM.get('game.temperature.text')), true);
|
||||||
}
|
}
|
||||||
if(Room.temperature.value < 4 && Room.temperature.value < Room.fire.value) {
|
if($SM.get('game.temperature.value') < 4 && $SM.get('game.temperature.value') < $SM.get('game.fire.value')) {
|
||||||
Room.temperature = Room.TempEnum.fromInt(Room.temperature.value + 1);
|
$SM.set('game.temperature', Room.TempEnum.fromInt($SM.get('game.temperature.value') + 1));
|
||||||
Notifications.notify(Room, _("the room is {0}" , Room.temperature.text), true);
|
Notifications.notify(Room, _("the room is {0}" , $SM.get('game.temperature.text')), true);
|
||||||
}
|
}
|
||||||
if(Room.temperature.value != old) {
|
if($SM.get('game.temperature.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);
|
||||||
@@ -726,7 +725,7 @@ var Room = {
|
|||||||
lBuilder = $SM.setget('game.builder.level', 1);
|
lBuilder = $SM.setget('game.builder.level', 1);
|
||||||
setTimeout(Room.unlockForest, Room._NEED_WOOD_DELAY);
|
setTimeout(Room.unlockForest, Room._NEED_WOOD_DELAY);
|
||||||
}
|
}
|
||||||
else if(lBuilder < 3 && Room.temperature.value >= Room.TempEnum.Warm.value) {
|
else if(lBuilder < 3 && $SM.get('game.temperature.value') >= Room.TempEnum.Warm.value) {
|
||||||
var msg = "";
|
var msg = "";
|
||||||
switch(lBuilder) {
|
switch(lBuilder) {
|
||||||
case 1:
|
case 1:
|
||||||
@@ -906,7 +905,7 @@ var Room = {
|
|||||||
|
|
||||||
build: function(buildBtn) {
|
build: function(buildBtn) {
|
||||||
var thing = $(buildBtn).attr('buildThing');
|
var thing = $(buildBtn).attr('buildThing');
|
||||||
if(Room.temperature.value <= Room.TempEnum.Cold.value) {
|
if($SM.get('game.temperature.value') <= Room.TempEnum.Cold.value) {
|
||||||
Notifications.notify(Room, _("builder just shivers"));
|
Notifications.notify(Room, _("builder just shivers"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user