mirror of
https://github.com/doublespeakgames/adarkroom.git
synced 2026-05-29 00:31:53 +08:00
lots of bugfixes
- bugfix Engine.startThieves call changed to $SM call
- bugfix $SM.remove not deleting state
- bugfix workaround for empty string when creating states
For some reason splitting "state.sub.sub2["sub3"]" will result in
empty strings whereas "state.sub.sub2[\'sub3\']" didn't. Maybe a
javascript regex quirk?
Had to add a loop to remove '' from the split string array.
- modified collectIncome so that only one update event fires for the
whole function, no event if no income was added.
- modified updateBuildButtons so that buttons would show up if the
building had already been built.
changed check to be wood != undefined
Also changed room to display store values of 0 instead of removing
the row. It was distracting to have the values shift up and down
when tightly managing a resource. If you haven't seen a resource
yet, it still doesn't show up.
This commit is contained in:
+1
-1
@@ -279,7 +279,7 @@ var Engine = {
|
||||
var diff = Math.abs(panelIndex - currentIndex);
|
||||
slider.animate({left: -(panelIndex * 700) + 'px'}, 300 * diff);
|
||||
|
||||
if($SM.get('stores.wood')) {
|
||||
if($SM.get('stores.wood') != undefined) {
|
||||
// FIXME Why does this work if there's an animation queue...?
|
||||
stores.animate({right: -(panelIndex * 700) + 'px'}, 300 * diff);
|
||||
}
|
||||
|
||||
+11
-5
@@ -777,7 +777,7 @@ var Room = {
|
||||
|
||||
// thieves?
|
||||
if(typeof $SM.get('game.thieves') == 'undefined' && num > 5000 && $SM.get('features.location.world')) {
|
||||
Engine.startThieves();
|
||||
$SM.startThieves();
|
||||
}
|
||||
|
||||
if(row.length == 0 && num > 0) {
|
||||
@@ -799,10 +799,8 @@ var Room = {
|
||||
row.insertAfter(location.find('#row_' + curPrev.replace(' ', '-')));
|
||||
}
|
||||
newRow = true;
|
||||
} else if(num> 0){
|
||||
} else if(num>= 0){
|
||||
$('div#' + row.attr('id') + ' > div.row_val', location).text(Math.floor(num));
|
||||
} else if(num == 0) {
|
||||
row.remove();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -949,6 +947,11 @@ var Room = {
|
||||
if(Room.needsWorkshop(craftable.type) && $SM.get('game.buildings["workshop"]', true) == 0) return false;
|
||||
var cost = craftable.cost();
|
||||
|
||||
//show button if one has already been built
|
||||
if($SM.get('game.buildings["'+thing+'"]') > 0){
|
||||
Room.buttons[thing] = true;
|
||||
return true;
|
||||
}
|
||||
// Show buttons if we have at least 1/2 the wood, and all other components have been seen.
|
||||
if($SM.get('stores.wood', true) < cost['wood'] * 0.5) {
|
||||
return false;
|
||||
@@ -960,7 +963,10 @@ var Room = {
|
||||
}
|
||||
|
||||
Room.buttons[thing] = true;
|
||||
Notifications.notify(Room, craftable.availableMsg);
|
||||
//don't notify if it has already been built before
|
||||
if(!$SM.get('game.buildings["'+thing+'"]')){
|
||||
Notifications.notify(Room, craftable.availableMsg);
|
||||
}
|
||||
return true;
|
||||
},
|
||||
|
||||
|
||||
+16
-4
@@ -48,6 +48,13 @@ var StateManager = {
|
||||
//create all parents and then set state
|
||||
createState: function(stateName, value) {
|
||||
var words = stateName.split(/[.\[\]'"]+/);
|
||||
//for some reason there are sometimes empty strings
|
||||
for (var i = 0; i < words.length; i++) {
|
||||
if (words[i] == '') {
|
||||
words.splice(i, 1);
|
||||
i--;
|
||||
}
|
||||
};
|
||||
var obj = State;
|
||||
var w = null;
|
||||
for(var i=0, len=words.length-1;i<len;i++){
|
||||
@@ -169,9 +176,9 @@ var StateManager = {
|
||||
},
|
||||
|
||||
remove: function(stateName, noEvent) {
|
||||
var whichState = $SM.buildPath(whichState);
|
||||
var whichState = $SM.buildPath(stateName);
|
||||
try{
|
||||
delete eval(whichState);
|
||||
eval('(delete '+whichState+')');
|
||||
} catch (e) {
|
||||
//it didn't exist in the first place
|
||||
Engine.log('WARNING: Tried to remove non-existant state \''+stateName+'\'.');
|
||||
@@ -301,7 +308,7 @@ var StateManager = {
|
||||
},
|
||||
|
||||
hasPerk: function(name) {
|
||||
return $SM.get('character.perks["'+name+'"]') == true;
|
||||
return $SM.get('character.perks["'+name+'"]');
|
||||
},
|
||||
|
||||
//INCOME
|
||||
@@ -322,6 +329,7 @@ var StateManager = {
|
||||
},
|
||||
|
||||
collectIncome: function() {
|
||||
var changed = false;
|
||||
if(typeof $SM.get('income') != 'undefined' && Engine.activeModule != Space) {
|
||||
for(var source in $SM.get('income')) {
|
||||
var income = $SM.get('income["'+source+'"]');
|
||||
@@ -334,13 +342,17 @@ var StateManager = {
|
||||
if(income.timeLeft <= 0) {
|
||||
Engine.log('collection income from ' + source);
|
||||
if(source == 'thieves') $SM.addStolen(income.stores);
|
||||
$SM.addM('stores', income.stores);
|
||||
$SM.addM('stores', income.stores, true);
|
||||
changed = true;
|
||||
if(typeof income.delay == 'number') {
|
||||
income.timeLeft = income.delay;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(changed){
|
||||
$SM.fireUpdate('income', true);
|
||||
};
|
||||
Engine._incomeTimeout = setTimeout($SM.collectIncome, 1000);
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user