diff options
author | Daniel Weipert <code@drogueronin.de> | 2023-08-23 20:29:07 +0200 |
---|---|---|
committer | Daniel Weipert <code@drogueronin.de> | 2023-08-23 20:29:07 +0200 |
commit | 7b1c251fcb085dc37de439ea1137373f1905d82e (patch) | |
tree | 32e3f2cd4367507726af6d0172e9621a37dff576 /resources/js/memory.js | |
parent | 4dd1a344c6474087a3f8782dd54f5c7b4acc67ed (diff) |
areas and capture and more
Diffstat (limited to 'resources/js/memory.js')
-rw-r--r-- | resources/js/memory.js | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/resources/js/memory.js b/resources/js/memory.js index 47cde88..40be4df 100644 --- a/resources/js/memory.js +++ b/resources/js/memory.js @@ -9,21 +9,39 @@ const Memory = { * @returns {string} */ save () { + const prepareSaveData = (saveData) => { + const prepareMonster = (monster) => { + if (monster.statusEffect && monster.statusEffect.slug === 'lifeleech') { + monster.statusEffect = null; + } + + return monster; + }; + + for (const idx in saveData.monsters) { + saveData.monsters[idx] = prepareMonster(saveData.monsters[idx]); + } + for (const idx in saveData.player.monsters) { + saveData.player.monsters[idx] = prepareMonster(saveData.player.monsters[idx]); + } + for (const idx in saveData.opponent.monsters) { + saveData.opponent.monsters[idx] = prepareMonster(saveData.opponent.monsters[idx]); + } + + return JSON.parse(JSON.stringify(saveData)); + }; + const saveMonster = (monsterData, monsterState) => { monsterData.level = monsterState.level; monsterData.hp = monsterState.hp; - if (monsterData.statusEffect && monsterData.statusEffect.slug === 'lifeleech') { - monsterData.statusEffect = null; - } - return monsterData; }; /** * @type {State} */ - const saveData = JSON.parse(JSON.stringify(Memory.state)); + const saveData = prepareSaveData(Object.assign({}, Memory.state)); // monsters for (const idx in saveData.monsters) { @@ -163,6 +181,7 @@ const Memory = { Memory.state.areaProgress[areaSlug] = await loadArea(areaData); } Memory.state.currentArea = await loadArea(loadedState.currentArea); + Memory.state.lastVisitedTown = loadedState.lastVisitedTown; Memory.state.turn = loadedState.turn; Memory.state.money = loadedState.money; @@ -179,7 +198,7 @@ const Memory = { Memory.state.activeTechnique = await loadTechnique(loadedState.activeTechnique); Memory.state.activeBall = await loadInventoryItem(loadedState.activeBall); - UI.drawArea(Memory.state.currentArea); + UI.drawArea(); UI.drawStatus(); UI.drawOpponentMonster(); UI.drawActiveMonster(); |