Skip to content

Commit

Permalink
Kiosk: make sure exit condition for low score as best score is correc…
Browse files Browse the repository at this point in the history
…tly handled (#10059)

* make sure exit condition for low score as best score is correctly handled

* rename variable

* explicitly check that a selected game exists to forego optional chaining
  • Loading branch information
srietkerk committed Jul 31, 2024
1 parent f49349f commit 28acac4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions kiosk/src/Transforms/exitToEnterHighScore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import configData from "../config.json";
import { KioskState } from "../Types";
import { exitGame } from "./exitGame";

export function exitToEnterHighScore(): void {
export function exitToEnterHighScore(highScoreMode: string): void {
const { state } = stateAndDispatch();

if (!state.mostRecentScores?.length) {
Expand All @@ -20,11 +20,12 @@ export function exitToEnterHighScore(): void {
launchedGameHighs = launchedGameHighs || [];
const currentHighScore = state.mostRecentScores[0];
const lastScore = launchedGameHighs[launchedGameHighs.length - 1]?.score;
const scoreOutOfRange = highScoreMode === "lowscore" ? currentHighScore > lastScore : currentHighScore < lastScore;

if (
launchedGameHighs.length === configData.HighScoresToKeep &&
lastScore &&
currentHighScore < lastScore
scoreOutOfRange
) {
exitGame(KioskState.GameOver);
} else {
Expand Down
5 changes: 3 additions & 2 deletions kiosk/src/Transforms/gameOver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ export function gameOver(skipHighScore?: boolean): void {

if (
!skipHighScore &&
selectedGame?.highScoreMode !== "None" &&
selectedGame &&
selectedGame.highScoreMode !== "None" &&
state.mostRecentScores?.length
) {
exitToEnterHighScore();
exitToEnterHighScore(selectedGame.highScoreMode);
} else {
exitGame(KioskState.GameOver);
}
Expand Down

0 comments on commit 28acac4

Please sign in to comment.