+ re_setClocks: function() {
+ if (this.game.moves.length < 2 || this.game.score != "*")
+ {
+ // 1st move not completed yet, or game over: freeze time
+ this.virtualClocks = this.game.clocks.map(s => ppt(s));
+ return;
+ }
+ const currentTurn = this.vr.turn;
+ const colorIdx = ["w","b"].indexOf(currentTurn);
+ let countdown = this.game.clocks[colorIdx] -
+ (Date.now() - this.game.initime[colorIdx])/1000;
+ this.virtualClocks = [0,1].map(i => {
+ const removeTime = i == colorIdx
+ ? (Date.now() - this.game.initime[colorIdx])/1000
+ : 0;
+ return ppt(this.game.clocks[i] - removeTime);
+ });
+ let clockUpdate = setInterval(() => {
+ if (countdown < 0 || this.vr.turn != currentTurn || this.game.score != "*")
+ {
+ clearInterval(clockUpdate);
+ if (countdown < 0)
+ this.gameOver(this.vr.turn=="w" ? "0-1" : "1-0", this.st.tr["Time"]);
+ }
+ else
+ this.$set(this.virtualClocks, colorIdx, ppt(Math.max(0, --countdown)));
+ }, 1000);
+ },