X-Git-Url: https://git.auder.net/?p=vchess.git;a=blobdiff_plain;f=public%2Fjavascripts%2Fcomponents%2Fgame.js;fp=public%2Fjavascripts%2Fcomponents%2Fgame.js;h=8662028c909fd0117686760e7fe1e5afe9c27c47;hp=ef3855927b7fea90bbe44c64d1415ae53e949226;hb=60d9063fdfcd4b7628fbc0e0fc594f083bda8761;hpb=214dfe16b01836fb19291ebf209bb7035993bafe diff --git a/public/javascripts/components/game.js b/public/javascripts/components/game.js index ef385592..8662028c 100644 --- a/public/javascripts/components/game.js +++ b/public/javascripts/components/game.js @@ -35,11 +35,11 @@ Vue.component('my-game', { }; }, watch: { - fen: function(newFen) { + fen: function() { // (Security) No effect if a computer move is in progress: if (this.mode == "computer" && this.lockCompThink) return this.$emit("computer-think"); - this.newGameFromFen(newFen); + this.newGameFromFen(); }, gameId: function() { this.loadGame(); @@ -132,8 +132,10 @@ Vue.component('my-game', { // Send ping to server (answer pong if opponent is connected) if (true && !!this.conn) { - this.conn.send(JSON.stringify({ - code:"ping",oppid:this.oppid,gameId:this.gameId})); + this.conn.onopen = () => { + this.conn.send(JSON.stringify({ + code:"ping",oppid:this.oppid,gameId:this.gameId})); + }; } // TODO: also handle "draw accepted" (use opponents array?) // --> must give this info also when sending lastState... @@ -298,22 +300,22 @@ Vue.component('my-game', { this.endGame(this.mycolor=="w"?"0-1":"1-0"); }, translate: translate, - newGameFromFen: function(fen) { - this.vr = new VariantRules(fen); + newGameFromFen: function() { + this.vr = new VariantRules(this.fen); this.moves = []; this.cursor = -1; - this.fenStart = newFen; + this.fenStart = this.fen; this.score = "*"; if (this.mode == "analyze") { - this.mycolor = V.ParseFen(newFen).turn; + this.mycolor = V.ParseFen(this.fen).turn; this.orientation = this.mycolor; } else if (this.mode == "computer") //only other alternative (HH with gameId) { this.mycolor = (Math.random() < 0.5 ? "w" : "b"); this.orientation = this.mycolor; - this.compWorker.postMessage(["init",newFen]); + this.compWorker.postMessage(["init",this.fen]); if (this.mycolor != "w" || this.subMode == "auto") this.playComputerMove(); }