From a5052fd596418f01544854c2da8d77d93ddee0be Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Wed, 30 Aug 2023 22:04:15 +0200 Subject: backup save --- resources/js/memory.js | 10 ++++++++-- resources/js/story.js | 34 ++++++++++++++++------------------ resources/js/ui.js | 2 +- 3 files changed, 25 insertions(+), 21 deletions(-) (limited to 'resources') diff --git a/resources/js/memory.js b/resources/js/memory.js index b403037..972dac7 100644 --- a/resources/js/memory.js +++ b/resources/js/memory.js @@ -74,7 +74,13 @@ const Memory = { }, saveToLocalStorage () { + const lastWrite = new Date(localStorage.getItem('lastWrite')); + if (Math.abs(new Date() - lastWrite) / (1000 * 60 * 60 * 24) >= 1) { + localStorage.setItem(`state_${(new Date()).toLocaleDateString()}`, localStorage.getItem('state')); + } + localStorage.setItem('state', Memory.saveToString()); + localStorage.setItem('lastWrite', new Date()); }, /** @@ -198,8 +204,8 @@ const Memory = { } Memory.state.currentArea = await loadArea(loadedState.currentArea); Memory.state.lastVisitedTown = loadedState.lastVisitedTown; - Memory.state.storyProgress = loadedState.storyProgress; - Memory.state.currentStory = loadedState.currentStory; + Memory.state.storyProgress = loadedState.storyProgress || {}; // backwards compat: TODO: remove check later + Memory.state.currentStory = loadedState.currentStory || ''; // backwards compat: TODO: remove check later Memory.state.turn = loadedState.turn; Memory.state.money = loadedState.money; diff --git a/resources/js/story.js b/resources/js/story.js index c5f7add..bdec2e1 100644 --- a/resources/js/story.js +++ b/resources/js/story.js @@ -21,7 +21,11 @@ const Story = { 'grintot', 'ignibus', 'memnomnom', - ].map(async (monsterSlug) => await fetchMonster(monsterSlug)) + ].map(async (monsterSlug) => { + const monster = await fetchMonster(monsterSlug); + monster.level = 5; + return monster; + }) ); const monsterSelection = UI.openStarterMonsterSelection(possibleStarterMonsters, { title: translate('story:introduction:monster_selection:title', true) }); @@ -38,15 +42,9 @@ const Story = { // set rival monster Memory.state.rivalMonster = event.detail.monster.slug; - // initialize state variables + // set initial values Memory.state.money = 250; - Memory.state.opponent = new Trainer({ monsters: [] }); - await Memory.state.opponent.initialize(); - - Memory.state.player = new Trainer({ monsters: [] }); - await Memory.state.player.initialize(); - // go to starting area await Game.goToArea('paper-town'); @@ -66,7 +64,11 @@ const Story = { 'nut', 'agnite', 'rockitten', - ].map(async (monsterSlug) => await fetchMonster(monsterSlug)) + ].map(async (monsterSlug) => { + const monster = await fetchMonster(monsterSlug); + monster.level = 5; + return monster; + }) ); const monsterSelection = UI.openStarterMonsterSelection(possibleStarterMonsters, { title: translate('story:select_starter_monster:monster_selection:title', true) }); @@ -76,14 +78,8 @@ const Story = { return; } - Memory.state.player = new Trainer({ - monsters: [ - event.detail.monster, - ] - }); - await Memory.state.player.initialize(); - - Game.setActivePlayerMonster(Memory.state.player.monsters[0]); + Memory.state.player.monsters.push(event.detail.monster); + Game.setActivePlayerMonster(event.detail.monster); // go to starting area await Game.goToArea('paper-town'); @@ -101,7 +97,9 @@ const Story = { }, async battleRivalOne () { - Memory.state.opponent = new Trainer({ monsters: [ await fetchMonster(Memory.state.rivalMonster) ] }); + const rivalMonster = await fetchMonster(Memory.state.rivalMonster); + rivalMonster.level = 5; + Memory.state.opponent = new Trainer({ monsters: [ rivalMonster ] }); await Memory.state.opponent.initialize(); await UI.buildAndShowStoryPopup({ speaker: await fetchNpc('spyder_rivalbillie'), text: translate('spyder_papertown_firstfight', true) }); diff --git a/resources/js/ui.js b/resources/js/ui.js index 5626048..2d34a2a 100644 --- a/resources/js/ui.js +++ b/resources/js/ui.js @@ -453,7 +453,7 @@ const UI = { * @returns {void} */ drawActiveTechniques () { - if (!Memory.state.player) { // on starter selection screen only + if (!Memory.state.player.activeMonster) { // on starter selection screen only return; } -- cgit v1.2.3