From 7b1c251fcb085dc37de439ea1137373f1905d82e Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Wed, 23 Aug 2023 20:29:07 +0200 Subject: areas and capture and more --- resources/js/memory.js | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) (limited to 'resources/js/memory.js') 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(); -- cgit v1.2.3