diff options
author | Daniel Weipert <code@drogueronin.de> | 2023-08-30 22:04:15 +0200 |
---|---|---|
committer | Daniel Weipert <code@drogueronin.de> | 2023-08-30 22:04:15 +0200 |
commit | a5052fd596418f01544854c2da8d77d93ddee0be (patch) | |
tree | 4c33a309b7a4f524f85d58f9851966439c3a7f43 | |
parent | 5214cdfbf26bc0bdee5d669a237fb8aefffb78d5 (diff) |
backup save
-rw-r--r-- | resources/js/memory.js | 10 | ||||
-rw-r--r-- | resources/js/story.js | 34 | ||||
-rw-r--r-- | resources/js/ui.js | 2 |
3 files changed, 25 insertions, 21 deletions
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; } |