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
|
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();
};
|