Skip to content

Commit

Permalink
fix(game): add bonus game on clear
Browse files Browse the repository at this point in the history
  • Loading branch information
wolimst committed Apr 22, 2024
1 parent ee0072f commit 352525a
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/lib/wordle/game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,18 @@ export class Game {

if (this.#config.useSave) {
savedata.save(this.data)
if (isDailyBonusAvailable(this.data)) {
const bonusGameId = getDailyGameId(this.data.config)
if (bonusGameId !== this.data.id) {
savedata.save({
id: getDailyGameId(this.data.config),
config: this.data.config,
guesses: [],
status: 'playing',
wordleData: [],
})
}
}
}

if (this.status !== 'playing' && this.#config.useStatistics) {
Expand Down Expand Up @@ -304,13 +316,13 @@ function getDailyGameId(config: GameConfig): string {
}
}

export function isDailyBonusAvailable(latestGame: GameData | GameSaveData) {
export function isDailyBonusAvailable(currentGame: GameData | GameSaveData) {
return (
latestGame.config.mode === 'daily' &&
latestGame.status === 'win' &&
latestGame.guesses.length <=
DAILY_BONUS_GUESS_COUNTS[latestGame.config.nWordles][
latestGame.config.answerLength
currentGame.config.mode === 'daily' &&
currentGame.status === 'win' &&
currentGame.guesses.length <=
DAILY_BONUS_GUESS_COUNTS[currentGame.config.nWordles][
currentGame.config.answerLength
]
)
}

0 comments on commit 352525a

Please sign in to comment.