From 7f440a015e359a430b1a5ede986434c3e3d08250 Mon Sep 17 00:00:00 2001 From: "Felix W. Dekker" Date: Wed, 2 Sep 2020 20:47:01 +0200 Subject: [PATCH] Clean up score table, change score sorting --- package.json | 2 +- src/main/js/HighScores.ts | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 2476281..349caf1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "minesweeper", - "version": "0.82.0", + "version": "0.82.1", "description": "Just Minesweeper!", "author": "Felix W. Dekker", "browser": "dist/bundle.js", diff --git a/src/main/js/HighScores.ts b/src/main/js/HighScores.ts index fd63f10..3da8ffb 100644 --- a/src/main/js/HighScores.ts +++ b/src/main/js/HighScores.ts @@ -43,7 +43,11 @@ export class HighScores { addScore(difficulty: Difficulty, score: Score): void { const scores = this.storage.getArray(difficulty.name, []); scores.push(score); - scores.sort((a, b) => a.time - b.time); + scores.sort((a, b) => { + return Math.floor(a.time / 1000) !== Math.floor(b.time / 1000) + ? a.time - b.time + : a.deaths - b.deaths; + }); this.storage.setArray(difficulty.name, scores.slice(0, HighScores.scoresToStore)); } @@ -77,13 +81,15 @@ export class HighScores { report += "" + ` - + + `; for (let j = 0; j < highScores.length; j++) { const score = highScores[j]; report += "" + ` + `;
Time (seconds)Time Deaths
#${j} ${formatTime(Math.floor(score.time / 1000), true, false)} ${score.deaths}