From dfec5327f950e18be935b2793b9545fa09f4e83a Mon Sep 17 00:00:00 2001 From: Benjamin Auder Date: Wed, 19 Dec 2018 00:27:36 +0100 Subject: [PATCH] Fix mycolor when resuming from game vs computer --- TODO | 2 -- public/javascripts/components/game.js | 13 +++++++------ 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/TODO b/TODO index 1cd762f4..244a7738 100644 --- a/TODO +++ b/TODO @@ -1,5 +1,3 @@ -setStorage, updateStorage in case of computer game: fix that -Implement chat (new mode ?! why not... still listen to oppid (dis)connect) Beautify styles Translations ? (probably not) Fill some puzzles: http://www.logicmazes.com/games/puz1to4.html diff --git a/public/javascripts/components/game.js b/public/javascripts/components/game.js index b78fe539..0189e314 100644 --- a/public/javascripts/components/game.js +++ b/public/javascripts/components/game.js @@ -250,7 +250,7 @@ Vue.component('my-game', { 'class': { 'game': true }, }, [_.range(sizeX).map(i => { - let ci = this.mycolor=='w' ? i : sizeX-i-1; + let ci = (this.mycolor=='w' ? i : sizeX-i-1); return h( 'div', { @@ -260,7 +260,7 @@ Vue.component('my-game', { style: { 'opacity': this.choices.length>0?"0.5":"1" }, }, _.range(sizeY).map(j => { - let cj = this.mycolor=='w' ? j : sizeY-j-1; + let cj = (this.mycolor=='w' ? j : sizeY-j-1); let elems = []; if (this.vr.board[ci][cj] != VariantRules.EMPTY) { @@ -1318,19 +1318,20 @@ Vue.component('my-game', { if (this.sound >= 1) new Audio("/sounds/newgame.mp3").play().catch(err => {}); document.getElementById("modal-newgame").checked = false; + this.setStorage(); //in case of interruptions } this.oppid = oppId; this.oppConnected = !continuation; this.mycolor = color; this.seek = false; - this.setStorage(); //in case of interruptions } else if (mode == "computer") { - this.setStorage(); //store game state this.compWorker.postMessage(["init",this.vr.getFen()]); - this.mycolor = Math.random() < 0.5 ? 'w' : 'b'; - if (this.mycolor == 'b') + this.mycolor = color || (Math.random() < 0.5 ? 'w' : 'b'); + if (!continuation) + this.setStorage(); //store game state + if (this.mycolor != this.vr.turn) this.playComputerMove(); } //else: against a (IRL) friend or problem solving: nothing more to do -- 2.44.0