more consistent leaderboard
This commit is contained in:
parent
59cf8f56e3
commit
6093ecb08c
2 changed files with 17 additions and 10 deletions
2
index.js
2
index.js
|
@ -21,7 +21,7 @@ app.use('/js', express.static('./common'));
|
|||
app.use(express.static('./static'));
|
||||
|
||||
app.get('/leaderboard', async function (ws, req) {
|
||||
req.send(JSON.stringify(await db.all('SELECT * from stats')));
|
||||
req.send(JSON.stringify(await db.all('SELECT * FROM stats ORDER BY ko DESC LIMIT 100')));
|
||||
})
|
||||
|
||||
app.ws('/', function (ws, req) {
|
||||
|
|
|
@ -136,7 +136,7 @@ class Game extends GameBasic {
|
|||
let that = this;
|
||||
this.ws.close();
|
||||
this.ws = new WebSocket(origin);
|
||||
this.ws.addEventListener('message', function (e) { that.recv(e) });
|
||||
this.ws.addEventListener('open', () => this.opener(that))
|
||||
} else if (player.isMenu) {
|
||||
player.r = Math.floor(Math.abs(player.rot / 1.2) % emojis.length);
|
||||
player.isMenu = false;
|
||||
|
@ -157,7 +157,7 @@ class Game extends GameBasic {
|
|||
|
||||
let p = player.legalProps.map(prop => player[prop]);
|
||||
|
||||
p.splice(0,0,'SYNC');
|
||||
p.splice(0, 0, 'SYNC');
|
||||
|
||||
this.ws.send(JSON.stringify(p));
|
||||
}
|
||||
|
@ -236,15 +236,17 @@ class Game extends GameBasic {
|
|||
|
||||
this.ws = new WebSocket(origin);
|
||||
|
||||
this.ws.addEventListener('message', function (e) { that.recv(e) });
|
||||
|
||||
this.ws.addEventListener('open', function () {
|
||||
this.opener = function (that) {
|
||||
that.sync(true);
|
||||
if (tok) {
|
||||
that.ws.send(JSON.stringify(["AUTH",tok]));
|
||||
}
|
||||
that.ws.send(JSON.stringify(["AUTH", tok]));
|
||||
}
|
||||
setInterval(function () { that.sync() }, 1000 / 5);
|
||||
})
|
||||
|
||||
that.ws.addEventListener('message', function (e) { that.recv(e) });
|
||||
};
|
||||
|
||||
this.ws.addEventListener('open', () => this.opener(that))
|
||||
|
||||
setInterval(function () { that.render() }, 1000 / 60);
|
||||
|
||||
|
@ -259,7 +261,12 @@ class Game extends GameBasic {
|
|||
scores[e.ip] += e.ko ** 2;
|
||||
}
|
||||
|
||||
scores = Object.entries(scores).sort((a,b) => b[1] - a[1]);
|
||||
for (let score in scores) {
|
||||
let s = scores[score];
|
||||
scores[score] = Math.round(Math.sqrt(s));
|
||||
}
|
||||
|
||||
scores = Object.entries(scores).sort((a, b) => b[1] - a[1]);
|
||||
|
||||
document.querySelector('.lb').textContent = scores.map(x => `${x[0]}: ${x[1]}`).join('\n');
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue