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:
LucidCrux
2013-07-27 17:21:30 -06:00
parent 36011b5b15
commit 6561e88f9f
3 changed files with 28 additions and 10 deletions
+16 -4
View File
@@ -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);
},