diff options
author | Daniel Weipert <code@drogueronin.de> | 2023-08-26 19:00:03 +0200 |
---|---|---|
committer | Daniel Weipert <code@drogueronin.de> | 2023-08-26 19:00:03 +0200 |
commit | b7db43abcaf8c9d9ccb4bcaff07c5416cb21ff62 (patch) | |
tree | 264f0e61fc2493c584519af218f4d28f3a58c55e /resources/js/game.js | |
parent | 7ffb5e01dcd87a29e3cb6a3d0bcef1b87bc94d44 (diff) |
auto-save to local storage
Diffstat (limited to 'resources/js/game.js')
-rw-r--r-- | resources/js/game.js | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/resources/js/game.js b/resources/js/game.js index 0ba5a8d..b628553 100644 --- a/resources/js/game.js +++ b/resources/js/game.js @@ -27,7 +27,6 @@ const Game = { playerIsChoosingNextMonster: false, doBattleAnimation: true, opponentActionTimeout: null, - isInBattle: false, didTechniqueHit: false, /* Battle */ @@ -110,7 +109,7 @@ const Game = { await Game.evolveMonster(Memory.state.player.activeMonster); } - Game.isInBattle = false; + Memory.state.Game.isInBattle = false; if (Memory.state.opponent.type === 'monster') { Memory.state.currentArea.monsterProgress++; @@ -128,6 +127,8 @@ const Game = { await Game.encounterNextTrainerMonster(); } } + + Memory.saveToLocalStorage(); } }, @@ -144,7 +145,7 @@ const Game = { // whole party defeated if (!Memory.state.player.monsters.some((monster) => monster.hp > 0)) { - Game.isInBattle = false; + Memory.state.Game.isInBattle = false; Memory.state.currentArea.monsterProgress = 0; // go to last visited town @@ -167,12 +168,15 @@ const Game = { Game.log(`Whited out!`); Game.log(`Payed ${formatPrice(totalHealingCenterPrice)} for full recovery at ${Memory.state.currentArea.name}!`); }); + + Memory.saveToLocalStorage(); } // party members still left else { Game.playerIsChoosingNextMonster = true; const monsterSelectionNode = UI.createPlayerDefeatedMonsterSelection(); + monsterSelectionNode.addEventListener('monster:selected', UI.createEventListener(() => Memory.saveToLocalStorage())); UI.openPlayerDefeatedMonsterSelection(monsterSelectionNode); } } @@ -602,7 +606,7 @@ const Game = { return; } - Game.isInBattle = true; + Memory.state.Game.isInBattle = true; UI.battleClickEvent = event; // player @@ -746,6 +750,7 @@ const Game = { UI.drawArea(); + Memory.saveToLocalStorage(); Game.isLoadingArea = false; }, @@ -833,6 +838,8 @@ const Game = { } } } + + Memory.saveToLocalStorage(); }, /** @@ -882,6 +889,9 @@ const Game = { Game.log(`Escape attempt ${attempts}: succeeded!`); Game.log(`${opposingMonster.name} broke free!`); + Memory.state.Game.isInBattle = true; + UI.drawStatus(); + Game.opponentTryUseTechnique(); return; // can't catch } @@ -903,6 +913,8 @@ const Game = { Game.log(`Caught ${caughtMonster.name}!`); await Game.encounterWildMonster(); + + Memory.saveToLocalStorage(); }, |