From b7db43abcaf8c9d9ccb4bcaff07c5416cb21ff62 Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Sat, 26 Aug 2023 19:00:03 +0200 Subject: auto-save to local storage --- resources/js/game.js | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'resources/js/game.js') 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(); }, -- cgit v1.2.3