Skip to content

Commit

Permalink
Merge pull request #467 from wyne/fix-game-initial-state
Browse files Browse the repository at this point in the history
Fix game initial state
  • Loading branch information
wyne authored Jul 19, 2024
2 parents 9a9e0ce + e3bbdd1 commit 393d6be
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/node.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ jobs:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm ci
- run: npx eslint .
- run: npm run lint
- run: npm test
12 changes: 7 additions & 5 deletions redux/GamesSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,16 @@ const gamesAdapter = createEntityAdapter({
});

const initialState = gamesAdapter.getInitialState({
});

const gameDefaults = {
roundCurrent: 0,
roundTotal: 1,
locked: false,
sortSelectorKey: SortSelectorKey.ByScore,
sortDirectionKey: SortDirectionKey.Normal,
palette: 'original',
});
};

const gamesSlice = createSlice({
name: 'games',
Expand Down Expand Up @@ -143,11 +146,10 @@ export const asyncRematchGame = createAsyncThunk(
});

dispatch(gameSave({
...gameDefaults,
id: newGameId,
title: game.title,
dateCreated: Date.now(),
roundCurrent: 0,
roundTotal: 1,
playerIds: playerIds,
}));

Expand Down Expand Up @@ -203,7 +205,7 @@ export const asyncCreateGame = createAsyncThunk(
playerIds.push(Crypto.randomUUID());
}

const paletteName = initialState.palette;
const paletteName = gameDefaults.palette;
const paletteColors = getPalette(paletteName);

playerIds.forEach((playerId, index) => {
Expand All @@ -217,7 +219,7 @@ export const asyncCreateGame = createAsyncThunk(
});

dispatch(gameSave({
...initialState,
...gameDefaults,
id: newGameId,
title: `Game ${gameCount + 1}`,
dateCreated: Date.now(),
Expand Down
2 changes: 1 addition & 1 deletion redux/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const gamesPersistConfig = {
key: 'games',
version: 0,
storage: AsyncStorage,
whitelist: ['entities', 'ids', 'sortSelectorKey'],
whitelist: ['entities', 'ids'],
};

const playersPersistConfig = {
Expand Down

0 comments on commit 393d6be

Please sign in to comment.