show top scores on leaderboard

This commit is contained in:
biglyderv 2024-11-25 14:14:21 -05:00
parent ac25bedfc2
commit df2ed789f7
2 changed files with 10 additions and 4 deletions

12
game.js
View file

@ -15,7 +15,7 @@ class Game extends GameBasic {
this.ws = []; this.ws = [];
} }
async updateLeaderboard() { 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 || []; let scoresOld = this.scores || [];
@ -31,9 +31,15 @@ class Game extends GameBasic {
scores[score] = Math.round(Math.sqrt(s)); 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 = [...s];
s.length = Math.min(s.length,10); s.length = Math.min(s.length,10);

View file

@ -20,7 +20,7 @@ app.use(express.static('./static'));
app.get('/leaderboard', async function (ws, req) { app.get('/leaderboard', async function (ws, req) {
let scores = game.scores || []; 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) { app.ws('/', function (ws, req) {