mirror of
https://github.com/doublespeakgames/adarkroom.git
synced 2026-05-28 08:11:54 +08:00
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:
@@ -33,8 +33,8 @@ Events.Global = [
|
||||
],
|
||||
onLoad: function() {
|
||||
$SM.set('game.thieves', 2);
|
||||
Engine.removeIncome('thieves');
|
||||
Engine.addStores($SM.get('game.stolen'));
|
||||
$SM.remove('income.thieves');
|
||||
$SM.addM('stores', $SM.get('game.stolen'));
|
||||
},
|
||||
buttons: {
|
||||
'leave': {
|
||||
@@ -50,8 +50,8 @@ Events.Global = [
|
||||
],
|
||||
onLoad: function() {
|
||||
$SM.set('game.thieves', 2);
|
||||
Engine.removeIncome('thieves');
|
||||
Engine.addPerk('stealthy');
|
||||
$SM.remove('income.thieves');
|
||||
$SM.addPerk('stealthy');
|
||||
},
|
||||
buttons: {
|
||||
'leave': {
|
||||
|
||||
+29
-29
@@ -5,7 +5,7 @@ Events.Room = [
|
||||
{ /* The Nomad -- Merchant */
|
||||
title: 'The Nomad',
|
||||
isAvailable: function() {
|
||||
return Engine.activeModule == Room && Engine.getStore('fur') > 0;
|
||||
return Engine.activeModule == Room && $SM.get('stores.fur', true) > 0;
|
||||
},
|
||||
scenes: {
|
||||
'start': {
|
||||
@@ -33,13 +33,13 @@ Events.Room = [
|
||||
},
|
||||
'buyCompass': {
|
||||
available: function() {
|
||||
return Engine.getStore('compass') < 1;
|
||||
return $SM.get('stores.compass', true) < 1;
|
||||
},
|
||||
text: 'buy compass',
|
||||
cost: { fur: 300, scales: 15, teeth: 5 },
|
||||
reward: { 'compass': 1 },
|
||||
notification: 'the old compass is dented and dusty, but it looks to work.',
|
||||
onChoose: Engine.openPath
|
||||
onChoose: Path.openPath
|
||||
},
|
||||
'goodbye': {
|
||||
text: 'say goodbye',
|
||||
@@ -51,7 +51,7 @@ Events.Room = [
|
||||
}, { /* Noises Outside -- gain wood/fur */
|
||||
title: 'Noises',
|
||||
isAvailable: function() {
|
||||
return Engine.activeModule == Room && Engine.storeAvailable('wood');
|
||||
return Engine.activeModule == Room && $SM.get('stores.wood');
|
||||
},
|
||||
scenes: {
|
||||
'start': {
|
||||
@@ -101,7 +101,7 @@ Events.Room = [
|
||||
{ /* Noises Inside -- trade wood for better good */
|
||||
title: 'Noises',
|
||||
isAvailable: function() {
|
||||
return Engine.activeModule == Room && Engine.storeAvailable('wood');
|
||||
return Engine.activeModule == Room && $SM.get('stores.wood');
|
||||
},
|
||||
scenes: {
|
||||
start: {
|
||||
@@ -127,12 +127,12 @@ Events.Room = [
|
||||
'the ground is littered with small scales'
|
||||
],
|
||||
onLoad: function() {
|
||||
var numWood = Engine.getStore('wood');
|
||||
var numWood = $SM.get('stores.wood', true);
|
||||
numWood = Math.floor(numWood * 0.1);
|
||||
if(numWood == 0) numWood = 1;
|
||||
var numScales = Math.floor(numWood / 5);
|
||||
if(numScales == 0) numScales = 1;
|
||||
Engine.addStores({wood: -numWood, scales: numScales});
|
||||
$SM.addM('stores', {'wood': -numWood, 'scales': numScales});
|
||||
},
|
||||
buttons: {
|
||||
'leave': {
|
||||
@@ -147,12 +147,12 @@ Events.Room = [
|
||||
'the ground is littered with small teeth'
|
||||
],
|
||||
onLoad: function() {
|
||||
var numWood = Engine.getStore('wood');
|
||||
var numWood = $SM.get('stores.wood', true);
|
||||
numWood = Math.floor(numWood * 0.1);
|
||||
if(numWood == 0) numWood = 1;
|
||||
var numTeeth = Math.floor(numWood / 5);
|
||||
if(numTeeth == 0) numTeeth = 1;
|
||||
Engine.addStores({wood: -numWood, teeth: numTeeth});
|
||||
$SM.addM('stores', {'wood': -numWood, 'teeth': numTeeth});
|
||||
},
|
||||
buttons: {
|
||||
'leave': {
|
||||
@@ -167,12 +167,12 @@ Events.Room = [
|
||||
'the ground is littered with scraps of cloth'
|
||||
],
|
||||
onLoad: function() {
|
||||
var numWood = Engine.getStore('wood');
|
||||
var numWood = $SM.get('stores.wood', true);
|
||||
numWood = Math.floor(numWood * 0.1);
|
||||
if(numWood == 0) numWood = 1;
|
||||
var numCloth = Math.floor(numWood / 5);
|
||||
if(numCloth == 0) numCloth = 1;
|
||||
Engine.addStores({wood: -numWood, cloth: numCloth});
|
||||
$SM.addM('stores', {'wood': -numWood, 'cloth': numCloth});
|
||||
},
|
||||
buttons: {
|
||||
'leave': {
|
||||
@@ -186,7 +186,7 @@ Events.Room = [
|
||||
{ /* The Beggar -- trade fur for better good */
|
||||
title: 'The Beggar',
|
||||
isAvailable: function() {
|
||||
return Engine.activeModule == Room && Engine.storeAvailable('fur');
|
||||
return Engine.activeModule == Room && $SM.get('stores.fur');
|
||||
},
|
||||
scenes: {
|
||||
start: {
|
||||
@@ -257,7 +257,7 @@ Events.Room = [
|
||||
{ /* Mysterious Wanderer -- wood gambling */
|
||||
title: 'The Mysterious Wanderer',
|
||||
isAvailable: function() {
|
||||
return Engine.activeModule == Room && Engine.storeAvailable('wood');
|
||||
return Engine.activeModule == Room && $SM.get('stores.wood');
|
||||
},
|
||||
scenes: {
|
||||
start: {
|
||||
@@ -290,7 +290,7 @@ Events.Room = [
|
||||
onLoad: function() {
|
||||
if(Math.random() < 0.5) {
|
||||
setTimeout(function() {
|
||||
Engine.addStore('wood', 300);
|
||||
$SM.add('stores.wood', 300);
|
||||
Notifications.notify(Room, 'the mysterious wanderer returns, cart piled high with wood.');
|
||||
}, 60 * 1000);
|
||||
}
|
||||
@@ -309,7 +309,7 @@ Events.Room = [
|
||||
onLoad: function() {
|
||||
if(Math.random() < 0.3) {
|
||||
setTimeout(function() {
|
||||
Engine.addStore('wood', 1500);
|
||||
$SM.add('stores.wood', 1500);
|
||||
Notifications.notify(Room, 'the mysterious wanderer returns, cart piled high with wood.');
|
||||
}, 60 * 1000);
|
||||
}
|
||||
@@ -327,7 +327,7 @@ Events.Room = [
|
||||
{ /* Mysterious Wanderer -- fur gambling */
|
||||
title: 'The Mysterious Wanderer',
|
||||
isAvailable: function() {
|
||||
return Engine.activeModule == Room && Engine.storeAvailable('fur');
|
||||
return Engine.activeModule == Room && $SM.get('stores.fur');
|
||||
},
|
||||
scenes: {
|
||||
start: {
|
||||
@@ -360,7 +360,7 @@ Events.Room = [
|
||||
onLoad: function() {
|
||||
if(Math.random() < 0.5) {
|
||||
setTimeout(function() {
|
||||
Engine.addStore('fur', 300);
|
||||
$SM.add('stores.fur', 300);
|
||||
Notifications.notify(Room, 'the mysterious wanderer returns, cart piled high with furs.');
|
||||
}, 60 * 1000);
|
||||
}
|
||||
@@ -379,7 +379,7 @@ Events.Room = [
|
||||
onLoad: function() {
|
||||
if(Math.random() < 0.3) {
|
||||
setTimeout(function() {
|
||||
Engine.addStore('fur', 1500);
|
||||
$SM.add('stores.fur', 1500);
|
||||
Notifications.notify(Room, 'the mysterious wanderer returns, cart piled high with furs.');
|
||||
}, 60 * 1000);
|
||||
}
|
||||
@@ -417,10 +417,10 @@ Events.Room = [
|
||||
text: 'learn scouting',
|
||||
cost: { 'fur': 1000, 'scales': 50, 'teeth': 20 },
|
||||
available: function() {
|
||||
return !Engine.hasPerk('scout');
|
||||
return !$SM.hasPerk('scout');
|
||||
},
|
||||
onChoose: function() {
|
||||
Engine.addPerk('scout');
|
||||
$SM.addPerk('scout');
|
||||
}
|
||||
},
|
||||
'leave': {
|
||||
@@ -468,30 +468,30 @@ Events.Room = [
|
||||
'evasion': {
|
||||
text: 'evasion',
|
||||
available: function() {
|
||||
return !Engine.hasPerk('evasive');
|
||||
return !$SM.hasPerk('evasive');
|
||||
},
|
||||
onChoose: function() {
|
||||
Engine.addPerk('evasive');
|
||||
$SM.addPerk('evasive');
|
||||
},
|
||||
nextScene: 'end'
|
||||
},
|
||||
'precision': {
|
||||
text: 'precision',
|
||||
available: function() {
|
||||
return !Engine.hasPerk('precise');
|
||||
return !$SM.hasPerk('precise');
|
||||
},
|
||||
onChoose: function() {
|
||||
Engine.addPerk('precise');
|
||||
$SM.addPerk('precise');
|
||||
},
|
||||
nextScene: 'end'
|
||||
},
|
||||
'force': {
|
||||
text: 'force',
|
||||
available: function() {
|
||||
return !Engine.hasPerk('barbarian');
|
||||
return !$SM.hasPerk('barbarian');
|
||||
},
|
||||
onChoose: function() {
|
||||
Engine.addPerk('barbarian');
|
||||
$SM.addPerk('barbarian');
|
||||
},
|
||||
nextScene: 'end'
|
||||
},
|
||||
@@ -536,7 +536,7 @@ Events.Room = [
|
||||
'some weird metal he picked up on his travels.'
|
||||
],
|
||||
onLoad: function() {
|
||||
Engine.addStore('alien alloy', 1);
|
||||
$SM.add('stores[\'alien alloy\']', 1);
|
||||
},
|
||||
buttons: {
|
||||
'bye': {
|
||||
@@ -552,7 +552,7 @@ Events.Room = [
|
||||
'some weird glowing boxes he picked up on his travels.'
|
||||
],
|
||||
onLoad: function() {
|
||||
Engine.addStore('energy cell', 3);
|
||||
$SM.add('stores[\'energy cell\']', 3);
|
||||
},
|
||||
buttons: {
|
||||
'bye': {
|
||||
@@ -568,7 +568,7 @@ Events.Room = [
|
||||
'all he has are some scales.'
|
||||
],
|
||||
onLoad: function() {
|
||||
Engine.addStore('scales', 5);
|
||||
$SM.add('stores.scales', 5);
|
||||
},
|
||||
buttons: {
|
||||
'bye': {
|
||||
|
||||
@@ -74,7 +74,7 @@ Events.Setpieces = {
|
||||
'his time here, now, is his penance.'
|
||||
],
|
||||
onLoad: function() {
|
||||
Engine.addPerk('gastronome');
|
||||
$SM.addPerk('gastronome');
|
||||
World.markVisited(World.curPos[0], World.curPos[1]);
|
||||
},
|
||||
buttons: {
|
||||
|
||||
Reference in New Issue
Block a user