From 13cd3db387448444687dc270562c79ea281eeb62 Mon Sep 17 00:00:00 2001 From: biglyderv Date: Mon, 25 Nov 2024 14:14:20 -0500 Subject: [PATCH] better logging --- common/player.js | 5 ++--- index.js | 11 ++++++++--- static/js/index.js | 14 ++++++++++++-- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/common/player.js b/common/player.js index a1b5619..0a01ac8 100644 --- a/common/player.js +++ b/common/player.js @@ -34,7 +34,7 @@ class Player { ]; this.legalProps = [ - 'vel', 'dir', 'camera', 'ticks', 'isMenu', 'r' + 'vel', 'dir', 'camera', 'ticks', 'isMenu', 'r', 'ref' ]; } bump() { @@ -44,8 +44,6 @@ class Player { player.dir *= -1; } - console.log(player.ticks) - player.vel.x *= 0.3; player.vel.y *= 0.3; @@ -113,6 +111,7 @@ class Player { target.vel.y += (target.pos.y - ent.pos.y) * 0.1; if (target.health <= 0 && oldHealth > 0) { + console.log(`Player ${target.you} died to a player ${ent.you}`); ent.headCount++; } } diff --git a/index.js b/index.js index a2292be..7d1bffb 100644 --- a/index.js +++ b/index.js @@ -25,7 +25,7 @@ app.ws('/', function (ws, req) { ws.ent = player; // This will only work under NGINX. - console.log(`A player ${player.you} joined under IP ${req.headers["x-real-ip"]}`) + console.log(`Player ${player.you} joined under IP ${req.headers["x-real-ip"]}`) ws.on('message', function message(msg) { let data = {}; @@ -49,12 +49,17 @@ app.ws('/', function (ws, req) { let you2 = newEnt.you; if (you != you2) { - console.log(`A player ${you} now identifies as ${you2}`); + console.log(`Player ${you} now identifies as ${you2}`); + } + + if (newEnt.ref) { + console.log(`Player ${you2} discovered this game from ${newEnt.ref}`); + newEnt.ref = undefined; } }) ws.on('close', function () { - console.log(`A player ${game.entities[playerI].you} left`); + console.log(`Player ${game.entities[playerI].you} left`); ws.active = false; player.health = -1; }) diff --git a/static/js/index.js b/static/js/index.js index 7ec9674..ae6ac8e 100644 --- a/static/js/index.js +++ b/static/js/index.js @@ -135,9 +135,15 @@ class Game extends GameBasic { this.sync(); } } - sync() { + sync(first = false) { let { player } = this; + if (first) { + player.ref = new URL(window.location).searchParams.get('ref') || 'nobody'; + } else { + player.ref = false; + } + this.ws.send(JSON.stringify(player.legalProps.map(prop => player[prop]))); } recv({ data }) { @@ -215,8 +221,12 @@ class Game extends GameBasic { this.ws.addEventListener('message', function (e) { that.recv(e) }); + this.ws.addEventListener('open', function () { + that.sync(true); + setInterval(function () { that.sync() }, 1000 / 5); + }) + setInterval(function () { that.render() }, 1000 / 60); - setInterval(function () { that.sync() }, 1000 / 5); game.canvas.onclick = () => that.click(); }