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 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'resources/js/memory.js') 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; -- cgit v1.2.3