X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fviews%2FGame.vue;h=67af3b9ff306d7ec4af666738b537035a97a2d7e;hb=3d55deea9a2011c38d8d0067bd57fc889958bec2;hp=2fdd2238290740950817002ca906520804aaaeef;hpb=22efa391c3f49ae7b91cd86ccf11da3af74523fe;p=vchess.git diff --git a/client/src/views/Game.vue b/client/src/views/Game.vue index 2fdd2238..67af3b9f 100644 --- a/client/src/views/Game.vue +++ b/client/src/views/Game.vue @@ -79,6 +79,12 @@ export default { } }, "game.clocks": function(newState) { + if (this.game.moves.length < 2) + { + // 1st move not completed yet: freeze time + this.virtualClocks = newState.map(s => ppt(s)); + return; + } const currentTurn = this.vr.turn; const colorIdx = ["w","b"].indexOf(currentTurn); let countdown = newState[colorIdx] - @@ -313,7 +319,12 @@ export default { // TODO: compute clocks + initime } const tc = extractTime(game.timeControl); - const myIdx = game.players.findIndex(p => p.sid == this.st.user.sid); + // TODO: this is not really beautiful (uid on corr players...) + if (gtype == "corr" && game.players[0].color == "b") + [ game.players[0], game.players[1] ] = [ game.players[1], game.players[0] ]; + const myIdx = game.players.findIndex(p => { + return p.sid == this.st.user.sid || p.uid == this.st.user.id; + }); if (game.clocks[0] < 0) //game unstarted { game.clocks = [tc.mainTime, tc.mainTime]; @@ -380,12 +391,15 @@ export default { return obj; }, {}); // Send move ("newmove" event) to opponent(s) (if ours) - let addTime = undefined; + let addTime = 0; if (move.color == this.game.mycolor) { - const elapsed = Date.now() - this.game.initime[colorIdx]; - // elapsed time is measured in milliseconds - addTime = this.game.increment - elapsed/1000; + if (this.game.moves.length >= 2) //after first move + { + const elapsed = Date.now() - this.game.initime[colorIdx]; + // elapsed time is measured in milliseconds + addTime = this.game.increment - elapsed/1000; + } this.st.conn.send(JSON.stringify({ code: "newmove", target: this.game.oppid,