From: Benjamin Auder Date: Tue, 18 Dec 2018 23:27:36 +0000 (+0100) Subject: Fix mycolor when resuming from game vs computer X-Git-Url: https://git.auder.net/variants/img/pieces/css/doc/html/%7B%7B?a=commitdiff_plain;h=dfec5327f950e18be935b2793b9545fa09f4e83a;p=vchess.git Fix mycolor when resuming from game vs computer --- 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