Skip to content

Commit

Permalink
fix: optimize new game experience
Browse files Browse the repository at this point in the history
  • Loading branch information
CSharperMantle committed Jul 9, 2023
1 parent 9ca290f commit 7df1553
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/pages/autoplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const App = () => {
useEffect(() => {
viewModel.init()
return () => {
viewModel.reset()
viewModel.reset(true)
}
}, [])

Expand Down
2 changes: 1 addition & 1 deletion src/pages/game.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const App = () => {
viewModel.init()
return () => {
window.removeEventListener("keydown", onKeyDownThrottled)
viewModel.reset()
viewModel.reset(true)
}
}, [])

Expand Down
8 changes: 5 additions & 3 deletions src/viewmodel/GameViewModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,14 @@ export class GameViewModel {
}
}

public reset(): void {
public reset(clearSprites = true): void {
clearInterval(this._gameIntervalTimerHandle ?? undefined)
this._gameIntervalTimerHandle = null
clearInterval(this._gameStopwatchUpdateTimerHandle ?? undefined)
this._gameStopwatchUpdateTimerHandle = null
this.clearSprites()
if (clearSprites) {
this.clearSprites()
}
this.refreshGameStatus()
}

Expand Down Expand Up @@ -230,7 +232,7 @@ export class GameViewModel {
}

protected modelGameEndEventHandler(): void {
this.reset()
this.reset(false)
}

protected modelGameStartEventHandler(): void {
Expand Down

0 comments on commit 7df1553

Please sign in to comment.