about summary refs log tree commit diff stats
path: root/linux/advent2020/vimrc.vim
Commit message (Expand)AuthorAgeFilesLines
* 7842 - new directory organizationKartik K. Agaram2021-03-031-0/+2
a id='n30' href='#n30'>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();
  };