about summary refs log tree commit diff stats
path: root/html/story-teller/js/state.js
diff options
context:
space:
mode:
authorelioat <elioat@tilde.institute>2024-12-01 15:00:37 -0500
committerelioat <elioat@tilde.institute>2024-12-01 15:00:37 -0500
commitecff6d35e51ee35dfb34df03acdc9ceb244f7204 (patch)
treefb4411e2ba51b30b728fa720964e673607ece91b /html/story-teller/js/state.js
parent1768e1fd0ddc4a059869caa8ff4b08b5734e3982 (diff)
downloadtour-ecff6d35e51ee35dfb34df03acdc9ceb244f7204.tar.gz
*
Diffstat (limited to 'html/story-teller/js/state.js')
-rw-r--r--html/story-teller/js/state.js43
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
ef='/akspecs/ranger/blame/test/tc_commandlist.py?h=v1.8.0&id=1f9a86d1515416a03721be261ae8fc937f129e9d'>^
11ff42af ^

0bc410c5 ^



11ff42af ^
0bc410c5 ^
11ff42af ^
d8ea8d5f ^
0bc410c5 ^

11ff42af ^
d8ea8d5f ^
0bc410c5 ^
698ba46a ^








ccd3f3c3 ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100