show top scores on leaderboard
This commit is contained in:
parent
ac25bedfc2
commit
df2ed789f7
2 changed files with 10 additions and 4 deletions
12
game.js
12
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);
|
||||
|
|
2
index.js
2
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) {
|
||||
|
|
Loading…
Reference in a new issue