summaryrefslogtreecommitdiff
path: root/resources/js/memory.js
diff options
context:
space:
mode:
authorDaniel Weipert <code@drogueronin.de>2023-08-30 22:04:15 +0200
committerDaniel Weipert <code@drogueronin.de>2023-08-30 22:04:15 +0200
commita5052fd596418f01544854c2da8d77d93ddee0be (patch)
tree4c33a309b7a4f524f85d58f9851966439c3a7f43 /resources/js/memory.js
parent5214cdfbf26bc0bdee5d669a237fb8aefffb78d5 (diff)
backup save
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;