more consistent leaderboard
This commit is contained in:
parent
23b890f4f0
commit
91c54e8cd4
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.use(express.static('./static'));
|
||||||
|
|
||||||
app.get('/leaderboard', async function (ws, req) {
|
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) {
|
app.ws('/', function (ws, req) {
|
||||||
|
|
|
@ -136,7 +136,7 @@ class Game extends GameBasic {
|
||||||
let that = this;
|
let that = this;
|
||||||
this.ws.close();
|
this.ws.close();
|
||||||
this.ws = new WebSocket(origin);
|
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) {
|
} else if (player.isMenu) {
|
||||||
player.r = Math.floor(Math.abs(player.rot / 1.2) % emojis.length);
|
player.r = Math.floor(Math.abs(player.rot / 1.2) % emojis.length);
|
||||||
player.isMenu = false;
|
player.isMenu = false;
|
||||||
|
@ -157,7 +157,7 @@ class Game extends GameBasic {
|
||||||
|
|
||||||
let p = player.legalProps.map(prop => player[prop]);
|
let p = player.legalProps.map(prop => player[prop]);
|
||||||
|
|
||||||
p.splice(0,0,'SYNC');
|
p.splice(0, 0, 'SYNC');
|
||||||
|
|
||||||
this.ws.send(JSON.stringify(p));
|
this.ws.send(JSON.stringify(p));
|
||||||
}
|
}
|
||||||
|
@ -236,15 +236,17 @@ class Game extends GameBasic {
|
||||||
|
|
||||||
this.ws = new WebSocket(origin);
|
this.ws = new WebSocket(origin);
|
||||||
|
|
||||||
this.ws.addEventListener('message', function (e) { that.recv(e) });
|
this.opener = function (that) {
|
||||||
|
|
||||||
this.ws.addEventListener('open', function () {
|
|
||||||
that.sync(true);
|
that.sync(true);
|
||||||
if (tok) {
|
if (tok) {
|
||||||
that.ws.send(JSON.stringify(["AUTH",tok]));
|
that.ws.send(JSON.stringify(["AUTH", tok]));
|
||||||
}
|
}
|
||||||
setInterval(function () { that.sync() }, 1000 / 5);
|
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);
|
setInterval(function () { that.render() }, 1000 / 60);
|
||||||
|
|
||||||
|
@ -259,7 +261,12 @@ class Game extends GameBasic {
|
||||||
scores[e.ip] += e.ko ** 2;
|
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');
|
document.querySelector('.lb').textContent = scores.map(x => `${x[0]}: ${x[1]}`).join('\n');
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue