From: Benjamin Auder Date: Tue, 25 Jun 2019 20:10:15 +0000 (+0200) Subject: Fix clocks update X-Git-Url: https://git.auder.net/assets/%7B%7B%20asset%28%27mixstore/doc/html/current/gitweb.css?a=commitdiff_plain;h=27d18a24ff2f3b04a7bf26b9b95c7214f8e5076a;p=vchess.git Fix clocks update --- diff --git a/client/src/components/BaseGame.vue b/client/src/components/BaseGame.vue index 254741d5..9f4b6df8 100644 --- a/client/src/components/BaseGame.vue +++ b/client/src/components/BaseGame.vue @@ -85,13 +85,14 @@ export default { this.moves = JSON.parse(JSON.stringify(this.game.moves || [])); // Post-processing: decorate each move with color + current FEN: // (to be able to jump to any position quickly) + let vr_tmp = new V(this.game.fenStart); //vr is already at end of game this.moves.forEach(move => { // NOTE: this is doing manually what play() function below achieve, // but in a lighter "fast-forward" way - move.color = this.vr.turn; - move.notation = this.vr.getNotation(move); - this.vr.play(move); - move.fen = this.vr.getFen(); + move.color = vr_tmp.turn; + move.notation = vr_tmp.getNotation(move); + vr_tmp.play(move); + move.fen = vr_tmp.getFen(); }); const L = this.moves.length; this.cursor = L-1; diff --git a/client/src/views/Game.vue b/client/src/views/Game.vue index 9271f487..f8cf2a7a 100644 --- a/client/src/views/Game.vue +++ b/client/src/views/Game.vue @@ -66,22 +66,7 @@ export default { let countdown = newState[colorIdx] - (Date.now() - this.game.initime[colorIdx])/1000; const myTurn = (currentTurn == this.game.mycolor); - -console.log(this.vr.turn + " " + currentTurn + " " + this.vr.getFen()); - let clockUpdate = setInterval(() => { - - - - -console.log(countdown); - console.log(this.vr.turn +" " + currentTurn + " " + this.vr.getFen()); - -// TODO: incoherent state because vr is altered in BaseGame to replay game - // ==> should use a temporary vr ? - - - if (countdown <= 0 || this.vr.turn != currentTurn) { clearInterval(clockUpdate); @@ -392,7 +377,9 @@ console.log(countdown); // Also update current game object: this.game.moves.push(move); this.game.fen = move.fen; - this.game.clocks[colorIdx] += (!!addTime ? addTime : 0); + //TODO: just this.game.clocks[colorIdx] += (!!addTime ? addTime : 0); + this.$set(this.game.clocks, colorIdx, + this.game.clocks[colorIdx] + (!!addTime ? addTime : 0)); this.game.initime[nextIdx] = Date.now(); }, // TODO: this update function should also work for corr games