From e795165cc48ec13b0df1185b8f47e53f7196993f Mon Sep 17 00:00:00 2001 From: 08draven Date: Mon, 4 Nov 2024 20:37:42 -0500 Subject: [PATCH] show top scores on leaderboard --- game.js | 12 +++++++++--- index.js | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/game.js b/game.js index fc15fe1..d05b098 100644 --- a/game.js +++ b/game.js @@ -15,7 +15,7 @@ class Game extends GameBasic { this.ws = []; } async updateLeaderboard() { - let jason = await db.all('SELECT * FROM stats ORDER BY CAST(ko AS REAL) DESC LIMIT 100'); + let jason = await db.all('SELECT * FROM stats ORDER BY CAST(ko AS REAL) DESC LIMIT 1000'); let scoresOld = this.scores || []; @@ -31,9 +31,15 @@ class Game extends GameBasic { scores[score] = Math.round(Math.sqrt(s)); } - this.scores = Object.entries(scores).sort((a, b) => b[1] - a[1]); + let s = Object.entries(scores).sort((a, b) => b[1] - a[1]); - let s = this.scores; + for (let x in s) { + let jk = jason.filter(y => y.ip == s[x][0]).map(y => y.ko).sort(); + + s[x].push(jk.join(', ')); + } + + this.scores = s; s = [...s]; s.length = Math.min(s.length,10); diff --git a/index.js b/index.js index feae123..2625459 100644 --- a/index.js +++ b/index.js @@ -20,7 +20,7 @@ app.use(express.static('./static')); app.get('/leaderboard', async function (ws, req) { let scores = game.scores || []; - req.send(scores.map((x,i) => `#${i+1}: ${x[0]} [${x[1]}]`).join('\n')); + req.send(scores.map((x,i) => `#${i+1}: ${x[0]} [${x[1]}: ${x[2]}]`).join('\n')); }) app.ws('/', function (ws, req) {