+ "game.clocks": function(newState) {
+ this.virtualClocks = newState.map(s => ppt(s));
+ const currentTurn = this.vr.turn;
+ const colorIdx = ["w","b"].indexOf(currentTurn);
+ let countdown = newState[colorIdx] -
+ (Date.now() - this.game.initime[colorIdx])/1000;
+ const myTurn = (currentTurn == this.game.mycolor);
+ let clockUpdate = setInterval(() => {
+ if (countdown <= 0 || this.vr.turn != currentTurn)
+ {
+ clearInterval(clockUpdate);
+ if (countdown <= 0 && myTurn)
+ {
+ this.$refs["basegame"].endGame(
+ this.game.mycolor=="w" ? "0-1" : "1-0", "Time");
+ this.st.conn.send(JSON.stringify({
+ code: "timeover",
+ target: this.game.oppid,
+ }));
+ }
+ }
+ else
+ {
+ // TODO: with Vue 3, just do this.virtualClocks[colorIdx] = ppt(--countdown)
+ this.$set(this.virtualClocks, colorIdx, ppt(Math.max(0, --countdown)));
+ }
+ }, 1000);
+ },