-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from vitalyiegorov/improve-ui
fix: refactor calculation logic, re-renders, timer speed up
- Loading branch information
Showing
14 changed files
with
149 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
// ts-prune-ignore-next | ||
export interface GameState { | ||
sudokuString: string; | ||
score: number; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { createAsyncThunk } from '@reduxjs/toolkit'; | ||
|
||
import { type RootState } from '../../../@app-root/store/app-root.store'; | ||
import { type HistoryRecordInterface } from '../../../history'; | ||
import { historySaveAction } from '../../../history/store/history.actions'; | ||
|
||
export const gameFinishedThunk = createAsyncThunk<boolean, HistoryRecordInterface, { state: RootState }>( | ||
'game/finish', | ||
(action, thunkAPI) => { | ||
const state = thunkAPI.getState(); | ||
|
||
const { difficulty, isWon } = action; | ||
|
||
const current = state.history.byDifficulty[difficulty]; | ||
const isBestScore = state.game.score > current.bestScore; | ||
|
||
thunkAPI.dispatch( | ||
historySaveAction({ | ||
difficulty, | ||
bestScore: isBestScore ? state.game.score : current.bestScore, | ||
bestTime: isBestScore ? state.game.elapsedTime : current.bestTime, | ||
gamesCompleted: current.gamesCompleted + 1, | ||
gamesLost: isWon ? current.gamesLost : current.gamesLost + 1, | ||
gamesWon: isWon ? current.gamesWon + 1 : current.gamesWon | ||
}) | ||
); | ||
|
||
return true; | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { createAsyncThunk } from '@reduxjs/toolkit'; | ||
|
||
import { type RootState } from '../../../@app-root/store/app-root.store'; | ||
import { type Sudoku } from '../../../@logic'; | ||
import { gameSaveAction } from '../game.actions'; | ||
|
||
export const gameMistakeThunk = createAsyncThunk<boolean, Sudoku, { state: RootState }>('game/save', (sudoku, thunkAPI) => { | ||
const state = thunkAPI.getState(); | ||
|
||
thunkAPI.dispatch( | ||
gameSaveAction({ | ||
sudokuString: sudoku.toString(), | ||
score: state.game.score, | ||
mistakes: state.game.mistakes + 1 | ||
}) | ||
); | ||
|
||
return true; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { createAsyncThunk } from '@reduxjs/toolkit'; | ||
|
||
import { type RootState } from '../../../@app-root/store/app-root.store'; | ||
import { type ScoredCellsInterface, type Sudoku } from '../../../@logic'; | ||
import { gameSaveAction } from '../game.actions'; | ||
|
||
interface GameSavePayloadInterface { | ||
sudoku: Sudoku; | ||
scoredCells: ScoredCellsInterface; | ||
} | ||
|
||
export const gameSaveThunk = createAsyncThunk<boolean, GameSavePayloadInterface, { state: RootState }>('game/save', (action, thunkAPI) => { | ||
const { sudoku } = action; | ||
|
||
const state = thunkAPI.getState(); | ||
|
||
thunkAPI.dispatch( | ||
gameSaveAction({ | ||
sudokuString: sudoku.toString(), | ||
score: state.game.score + sudoku.getScore(action.scoredCells, state.game.elapsedTime, state.game.mistakes), | ||
mistakes: state.game.mistakes | ||
}) | ||
); | ||
|
||
return true; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
import { type DifficultyEnum } from '../../@generic'; | ||
import { type GameState } from '../../game/store/game.state'; | ||
|
||
export interface HistoryRecordInterface extends Pick<GameState, 'elapsedTime' | 'score'> { | ||
export interface HistoryRecordInterface { | ||
isWon: boolean; | ||
difficulty: DifficultyEnum; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { historySlice } from './history.slice'; | ||
|
||
export const { save: historySaveAction } = historySlice.actions; |
Oops, something went wrong.