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
+1 -1
View File
@@ -279,7 +279,7 @@ var Engine = {
var diff = Math.abs(panelIndex - currentIndex); var diff = Math.abs(panelIndex - currentIndex);
slider.animate({left: -(panelIndex * 700) + 'px'}, 300 * diff); 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...? // FIXME Why does this work if there's an animation queue...?
stores.animate({right: -(panelIndex * 700) + 'px'}, 300 * diff); stores.animate({right: -(panelIndex * 700) + 'px'}, 300 * diff);
} }
+11 -5
View File
@@ -777,7 +777,7 @@ var Room = {
// thieves? // thieves?
if(typeof $SM.get('game.thieves') == 'undefined' && num > 5000 && $SM.get('features.location.world')) { if(typeof $SM.get('game.thieves') == 'undefined' && num > 5000 && $SM.get('features.location.world')) {
Engine.startThieves(); $SM.startThieves();
} }
if(row.length == 0 && num > 0) { if(row.length == 0 && num > 0) {
@@ -799,10 +799,8 @@ var Room = {
row.insertAfter(location.find('#row_' + curPrev.replace(' ', '-'))); row.insertAfter(location.find('#row_' + curPrev.replace(' ', '-')));
} }
newRow = true; newRow = true;
} else if(num> 0){ } else if(num>= 0){
$('div#' + row.attr('id') + ' > div.row_val', location).text(Math.floor(num)); $('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; if(Room.needsWorkshop(craftable.type) && $SM.get('game.buildings["workshop"]', true) == 0) return false;
var cost = craftable.cost(); 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. // 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) { if($SM.get('stores.wood', true) < cost['wood'] * 0.5) {
return false; return false;
@@ -960,7 +963,10 @@ var Room = {
} }
Room.buttons[thing] = true; 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; return true;
}, },
+16 -4
View File
@@ -48,6 +48,13 @@ var StateManager = {
//create all parents and then set state //create all parents and then set state
createState: function(stateName, value) { createState: function(stateName, value) {
var words = stateName.split(/[.\[\]'"]+/); 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 obj = State;
var w = null; var w = null;
for(var i=0, len=words.length-1;i<len;i++){ for(var i=0, len=words.length-1;i<len;i++){
@@ -169,9 +176,9 @@ var StateManager = {
}, },
remove: function(stateName, noEvent) { remove: function(stateName, noEvent) {
var whichState = $SM.buildPath(whichState); var whichState = $SM.buildPath(stateName);
try{ try{
delete eval(whichState); eval('(delete '+whichState+')');
} catch (e) { } catch (e) {
//it didn't exist in the first place //it didn't exist in the first place
Engine.log('WARNING: Tried to remove non-existant state \''+stateName+'\'.'); Engine.log('WARNING: Tried to remove non-existant state \''+stateName+'\'.');
@@ -301,7 +308,7 @@ var StateManager = {
}, },
hasPerk: function(name) { hasPerk: function(name) {
return $SM.get('character.perks["'+name+'"]') == true; return $SM.get('character.perks["'+name+'"]');
}, },
//INCOME //INCOME
@@ -322,6 +329,7 @@ var StateManager = {
}, },
collectIncome: function() { collectIncome: function() {
var changed = false;
if(typeof $SM.get('income') != 'undefined' && Engine.activeModule != Space) { if(typeof $SM.get('income') != 'undefined' && Engine.activeModule != Space) {
for(var source in $SM.get('income')) { for(var source in $SM.get('income')) {
var income = $SM.get('income["'+source+'"]'); var income = $SM.get('income["'+source+'"]');
@@ -334,13 +342,17 @@ var StateManager = {
if(income.timeLeft <= 0) { if(income.timeLeft <= 0) {
Engine.log('collection income from ' + source); Engine.log('collection income from ' + source);
if(source == 'thieves') $SM.addStolen(income.stores); 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') { if(typeof income.delay == 'number') {
income.timeLeft = income.delay; income.timeLeft = income.delay;
} }
} }
} }
} }
if(changed){
$SM.fireUpdate('income', true);
};
Engine._incomeTimeout = setTimeout($SM.collectIncome, 1000); Engine._incomeTimeout = setTimeout($SM.collectIncome, 1000);
}, },