blob: e6c4fe77f7e855a0614fd2592e654c6a915633d0 (
plain) (
tree)
|
|
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();
};
|