Clean up score table, change score sorting

This commit is contained in:
Florine W. Dekker 2020-09-02 20:47:01 +02:00
parent e64d20f3bd
commit 7f440a015e
Signed by: FWDekker
GPG Key ID: B1B567AF58D6EE0F
2 changed files with 9 additions and 3 deletions

View File

@ -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",

View File

@ -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 += "" +
`<table>
<tr>
<th>Time (seconds)</th>
<th></th>
<th>Time</th>
<th>Deaths</th>
</tr>`;
for (let j = 0; j < highScores.length; j++) {
const score = highScores[j];
report += "" +
`<tr>
<th>#${j}</th>
<td>${formatTime(Math.floor(score.time / 1000), true, false)}</td>
<td>${score.deaths}</td>
</tr>`;