From 6561e88f9f9d0066e296b223dfb6207d61e692fb Mon Sep 17 00:00:00 2001 From: LucidCrux Date: Sat, 27 Jul 2013 17:21:30 -0600 Subject: [PATCH] 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. --- script/engine.js | 2 +- script/room.js | 16 +++++++++++----- script/state_manager.js | 20 ++++++++++++++++---- 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/script/engine.js b/script/engine.js index da24ec6..f28270b 100644 --- a/script/engine.js +++ b/script/engine.js @@ -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); } diff --git a/script/room.js b/script/room.js index 778201a..3bbe2ed 100644 --- a/script/room.js +++ b/script/room.js @@ -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; }, diff --git a/script/state_manager.js b/script/state_manager.js index 1befab2..0495e19 100644 --- a/script/state_manager.js +++ b/script/state_manager.js @@ -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