diff options
author | elioat <elioat@tilde.institute> | 2024-12-01 15:00:37 -0500 |
---|---|---|
committer | elioat <elioat@tilde.institute> | 2024-12-01 15:00:37 -0500 |
commit | ecff6d35e51ee35dfb34df03acdc9ceb244f7204 (patch) | |
tree | fb4411e2ba51b30b728fa720964e673607ece91b /html/story-teller/js/state.js | |
parent | 1768e1fd0ddc4a059869caa8ff4b08b5734e3982 (diff) | |
download | tour-ecff6d35e51ee35dfb34df03acdc9ceb244f7204.tar.gz |
*
Diffstat (limited to 'html/story-teller/js/state.js')
-rw-r--r-- | html/story-teller/js/state.js | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/html/story-teller/js/state.js b/html/story-teller/js/state.js new file mode 100644 index 0000000..e6c4fe7 --- /dev/null +++ b/html/story-teller/js/state.js @@ -0,0 +1,43 @@ +export const createGameState = () => ({ + currentScene: 'start', + inventory: new Set(), + actionLog: [], + collectedItems: new Set(), + }); + + + +export const updateGameState = (state, updates) => ({ + ...state, + ...updates, +}); + +const STORAGE_KEY = 'gameState'; + +export const saveGameState = (state) => { + const stateToSave = { + currentScene: state.currentScene, + inventory: Array.from(state.inventory), + actionLog: state.actionLog, + }; + localStorage.setItem(STORAGE_KEY, JSON.stringify(stateToSave)); +}; + +export const loadGameState = () => { + const savedState = localStorage.getItem(STORAGE_KEY); + if (savedState) { + const parsedState = JSON.parse(savedState); + return { + currentScene: parsedState.currentScene, + inventory: new Set(parsedState.inventory), + actionLog: parsedState.actionLog, + }; + } + return createGameState(); +}; + +export const resetGameState = () => { + localStorage.removeItem(STORAGE_KEY); + return createGameState(); + }; + \ No newline at end of file |