Skip to content

Commit

Permalink
made saveAllScores take the scoring method (#1480)
Browse files Browse the repository at this point in the history
  • Loading branch information
srietkerk authored and abchatra committed Jul 22, 2024
1 parent fdfe364 commit 1c2be24
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
12 changes: 11 additions & 1 deletion libs/game/game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,15 @@ namespace game {
_gameOverImpl(true, player);
}

function _mapScoreTypeToString(scoreType: ScoringType): string {
switch (scoreType) {
case ScoringType.HighScore: return "highscore";
case ScoringType.LowScore: return "lowscore";
case ScoringType.None: return "none";
default: return "none";
}
}

function _gameOverImpl(win: boolean, winnerOverride?: number) {
init();
if (__isOver) return;
Expand All @@ -365,7 +374,8 @@ namespace game {
const scores = playersWithScores.map(player => new GameOverPlayerScore(player.number, player.impl.score(), player === winner));

// Save all scores. Dependency Note: this action triggers Kiosk to exit the simulator and show the high score screen.
info.saveAllScores();
const scoreTypeString = _mapScoreTypeToString(goc.scoringType);
info.saveAllScores(scoreTypeString);

// Save high score if this was a judged game and there was a winner (don't save in the LOSE case).
if (judged && winner) {
Expand Down
9 changes: 7 additions & 2 deletions libs/game/info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ namespace info {
return players ? players.filter(item => item.impl.hasScore()) : [];
}

export function saveAllScores() {
export function saveAllScores(scoringType: string) {
const allScoresKey = "all-scores";
let allScores: number[];
const pws = playersWithScores();
Expand All @@ -252,7 +252,12 @@ namespace info {
allScores = [];
}

settings.writeJSON(allScoresKey, allScores);
const scoresObj = {
"allScores": allScores,
"scoringType": allScores.length ? scoringType : "None"
}

settings.writeJSON(allScoresKey, scoresObj);
}

export function winningPlayer(): PlayerInfo {
Expand Down

0 comments on commit 1c2be24

Please sign in to comment.