From 0493aa0c98d61206324910a410e7cbc1f3c285ec Mon Sep 17 00:00:00 2001 From: gocivici Date: Tue, 26 Sep 2023 19:03:59 +0300 Subject: [PATCH] updated debug function --- backend.js | 2 +- public/classes/Player.js | 14 +++++++++----- public/index.js | 6 +++--- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/backend.js b/backend.js index bc64d66..8e379b5 100644 --- a/backend.js +++ b/backend.js @@ -53,7 +53,7 @@ io.on('connection', (socket)=>{ socket.on('username',(username)=>{ bPlayers[socket.id].username = username - console.log("updated username for: "+bPlayers[socket.id]) + console.log("updated username for: "+bPlayers[socket.id].username) }) socket.on('message',(message)=>{ diff --git a/public/classes/Player.js b/public/classes/Player.js index a1aa8ee..58cff89 100644 --- a/public/classes/Player.js +++ b/public/classes/Player.js @@ -44,22 +44,26 @@ class Player extends Sprite { ctx.fillText("Click X&Y :"+[this.clickX,this.clickY], this.position.x, this.position.y-110); ctx.fillText("Position: "+[Math.round(this.position.x),Math.round(this.position.y)], this.position.x, this.position.y-98); ctx.fillText("Inc X&Y :"+[this.incrementX.toFixed(2),this.incrementY.toFixed(2)], this.position.x, this.position.y-85); - ctx.font = 'bold 18px sans-serif'; - ctx.fillStyle = 'white'; - ctx.fillText(this.message, this.position.x, this.position.y-65); + ctx.font = 'Normal 16px sans-serif'; ctx.textAlign = "center"; ctx.fillStyle = 'orange'; ctx.fillText("user ID: " + this.userId, this.position.x, this.position.y+35); - ctx.fillStyle = 'cyan'; - ctx.fillText(this.username, this.position.x, this.position.y+15); ctx.fill() } update(){ + ctx.textAlign = "center"; + ctx.font = 'bold 18px win98'; + ctx.fillStyle = 'cyan'; + ctx.fillText(this.username, this.position.x, this.position.y+15); + ctx.font = 'normal 15px sans-serif'; + ctx.fillStyle = 'white'; + ctx.fillText(this.message, this.position.x, this.position.y-65); + ctx.fill() // if((Math.sign(incrementX)==1&&fPlayer.xclickCoordinates[0])){fPlayer.x += incrementX;fPlayer.atPosition=false; socket.emit('clickPositionX',fPlayer.x)}else{fPlayer.atPosition=true} diff --git a/public/index.js b/public/index.js index 53d0f63..2db92e7 100644 --- a/public/index.js +++ b/public/index.js @@ -86,7 +86,7 @@ socket.on('updatePlayers', (bPlayers) =>{ fPlayers[id].clickY = bPlayer.clickY fPlayers[id].message = bPlayer.message fPlayers[id].username = bPlayer.username - + //update player position without animation if tab is inactive if (document.hidden) { fPlayers[id].position.x = bPlayer.x @@ -179,9 +179,9 @@ socket.emit('clickPosition',clickCoordinates) document.querySelector('#textInput').addEventListener('submit',(event)=>{ event.preventDefault() //do not refresh page whenform submited var inputValue = document.querySelector('#input').value - if(inputValue.includes("/name")){ + if(inputValue.includes("/name ")){ console.log('namechange') - fPlayers[socket.id].username = inputValue.replace("/name","") + fPlayers[socket.id].username = inputValue.replace("/name ","") socket.emit('username',fPlayers[socket.id].username) }else{ fPlayers[socket.id].message=document.querySelector('#input').value