From 11bbe2eadb38e2406e1e88b4b2cb2d22fc13fadb Mon Sep 17 00:00:00 2001 From: Sarah Rietkerk <49178322+srietkerk@users.noreply.github.com> Date: Thu, 1 Aug 2024 11:31:41 -0700 Subject: [PATCH] Kiosk: make sure exit condition for low score as best score is correctly handled (#10059) (#10060) * 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 --- kiosk/src/Transforms/exitToEnterHighScore.ts | 5 +++-- kiosk/src/Transforms/gameOver.ts | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/kiosk/src/Transforms/exitToEnterHighScore.ts b/kiosk/src/Transforms/exitToEnterHighScore.ts index 32304991a477..daa5fe743c19 100644 --- a/kiosk/src/Transforms/exitToEnterHighScore.ts +++ b/kiosk/src/Transforms/exitToEnterHighScore.ts @@ -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) { @@ -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 { diff --git a/kiosk/src/Transforms/gameOver.ts b/kiosk/src/Transforms/gameOver.ts index dce8521628d5..a421f51e2785 100644 --- a/kiosk/src/Transforms/gameOver.ts +++ b/kiosk/src/Transforms/gameOver.ts @@ -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); }