summaryrefslogtreecommitdiff
path: root/resources/js/memory.js
diff options
context:
space:
mode:
Diffstat (limited to 'resources/js/memory.js')
-rw-r--r--resources/js/memory.js10
1 files changed, 8 insertions, 2 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;