refactor Engine.js for use with $SM

====functions removed====
//I just removed these because most were simpler or at least equal as
	direct $SM get/set/add calls, I realize the store ones are kind of
	subjective since calls were about equal, but oh well. If someone
	really 	feels we need the shortcut/named functions for manipulating
	stores specifically, it shouldn't be crazy to reimplement in $SM 
Engine.setStore >> $SM.set
Engine.setStores >> $SM.setM
Engine.addStore >> $SM.add
Engine.addStores >> $SM.addM
Engine.getStore >> $SM.get(requestZero = true)
Engine.storeAvailable >> $SM.get;
Engine.removeIncome >> $SM.remove //updates moved to handler


====functions moved====
//Any moved function I felt was more directly related to States or
	didn't belong where it was
Engine.addPerk > $SM.addPerk //kept function for now because of notify
	call inside, 'deep' state
Engine.hasPerk > $SM.hasPerk //kept function because of 'deep' state
	name
Engine.setIncome > $SM.setIncome //kept because it has internal logic
**Engine.getIncome > $SM.getIncome //**easily removable with
	Outside.updateVillageIncome refactor
Engine.openPath > Path.openPath //Since I'm refactoring anyways
Engine.addStolen > $SM.addStolen //internal logic
Engine.startThieves > $SM.startThieves //not sure $SM is a better place,
	but Engine should be nice and clean by the end of this, handling
	only engine mechanics
Engine.num > $SM.num //after Outside refacter, this is basically just a
	fancy $SM.get
Engine.upgradeState > $SM.updateOldState


====functions refactored====
$SM.addPerk; //updates moved to event handler, no check/create new perk
$SM.hasPerk; //don't need to check exist and ==true
$SM.collectIncome //removed changed check, update calls now handled by
	'stateUpdate' event listening
$SM.addStolen //fix to set stolen items in case a partial steal happens
$SM.startThieves //updates in handler
$SM.updateOldState //use $SM calls, add placeholder for updating to post
$SM state when more finalized 


====functions affected (by removed)====
Engine.init (Engine.getStore, Engine.storeAvailable)
Engine.collectIncome (Engine.addStores)
Engine.num (Engine.getStore)
Engine.travelTo (Engine.storeAvailable)

Room.init (Engine.getStore)
Room.unlockForest (Engine.setStore)
Room.lightFire (Engine.setStore, Engine.getStore, Engine.storeAvailable)
Room.stokeFire (Engine.setStore, Engine.getStore, Engine.storeAvailable)
Room.coolFire (Engine.setStore)
Room.buy (Engine.setStores, Engine.addStore, Engine.getStore)
Room.build (Engine.setStores, Engine.getStore)
Room.craftUnlocked (Engine.getStore, Engine.storeAvailable)
Room.buyUnlocked (Engine.storeAvailable)
Room.updateButton (Engine.storeAvailable)

Outside.gatherWood (Engine.addStores)
Outside.checkTraps (Engine.addStores, Engine.getStore)
Outside.updateVillage (Engine.getStore)

Path.embark (Engine.addStore)
Path.getCapacity (Engine.getStore)
Path.updateOutfitting (Engine.getStore)
Path.createOutfittingRow (Engine.getStore)
Path.increaseSupply (Engine.getStore)

World.goHome (Engine.addStore)
World.updateSupplies (Engine.getStore)
World.checkDanger (Engine.getStore)
World.getMaxHealth (Engine.getStore)
World.getMaxWater (Engine.getStore)

Ship.reinforceHull (Engine.addStore, Engine.getStore)
Ship.upgradeEngine (Engine.addStore, Engine.getStore)

Events.loadScene (Engine.addStores)
Events.updateButtons (Engine.getStore)
Events.buttonClick (Engine.getStore)

Events.Global (Engine.addStores, Engine.removeIncome)
Events.Room (Engine.addStore, Engine.addStores, Engine.getStore,
Engine.storeAvailable)
This commit is contained in:
LucidCrux
2013-07-24 17:41:36 -06:00
parent db4a346d21
commit dee7cbb9b3
12 changed files with 353 additions and 361 deletions
+13 -6
View File
@@ -100,11 +100,11 @@ var Ship = {
},
reinforceHull: function() {
if(Engine.getStore('alien alloy') < Ship.ALLOY_PER_HULL) {
if($SM.get('stores[\'alien alloy\']', true) < Ship.ALLOY_PER_HULL) {
Notifications.notify(Ship, "not enough alien alloy");
return false;
}
Engine.addStore('alien alloy', -Ship.ALLOY_PER_HULL);
$SM.add('stores[\'alien alloy\']', -Ship.ALLOY_PER_HULL);
$SM.add('game.spaceShip.hull', 1);
if($SM.get('game.spaceShip.hull') > 0) {
Button.setDisabled($('#liftoffButton', Ship.panel), false);
@@ -113,11 +113,11 @@ var Ship = {
},
upgradeEngine: function() {
if(Engine.getStore('alien alloy') < Ship.ALLOY_PER_THRUSTER) {
if($SM.get('stores[\'alien alloy\']', true) < Ship.ALLOY_PER_THRUSTER) {
Notifications.notify(Ship, "not enough alien alloy");
return false;
}
Engine.addStore('alien alloy', -Ship.ALLOY_PER_THRUSTER);
$SM.add('stores[\'alien alloy\']', -Ship.ALLOY_PER_THRUSTER);
$SM.add('game.spaceShip.thrusters', 1)
$('#engineRow .row_val', Ship.panel).text($SM.get('game.spaceShip.thrusters'));
},
@@ -164,5 +164,12 @@ var Ship = {
$('#outerSlider').animate({top: '700px'}, 300);
Space.onArrival();
Engine.activeModule = Space;
}
};
},
handleStateUpdates: function(e){
},
};
//listener for StateManager update events
$(Ship).on('stateUpdate', Ship.handleStateUpdates);