From: Benjamin Auder Date: Wed, 12 Jun 2019 10:36:25 +0000 (+0200) Subject: 'update' X-Git-Url: https://git.auder.net/doc/html/index.html?a=commitdiff_plain;h=6ec161b904b068b0f07defce45dba936933f4a1b;p=vchess.git 'update' --- diff --git a/client/src/utils/storage.js b/client/src/utils/storage.js index f5c3b253..ecafe205 100644 --- a/client/src/utils/storage.js +++ b/client/src/utils/storage.js @@ -99,7 +99,7 @@ export const GameStorage = fen: o.fenStart, moves: [], clocks: [...Array(o.players.length)].fill(tc.mainTime), - started: [...Array(o.players.length)].fill(false), + initime: undefined, score: "*", }; @@ -123,7 +123,8 @@ export const GameStorage = { gameState.moves.push(o.move); gameState.fen = o.fen; - gameState.clocks[o.colorIdx] += (o.increment - o.elapsed); + if (!!o.elapsed) //NaN if first move in game + gameState.clocks[o.colorIdx] += (o.increment - o.elapsed); } if (!!o.initime) //just a flag (true) gameState.initime = Date.now(); @@ -168,7 +169,7 @@ export const GameStorage = callback({}); //everything's fine } transaction.onerror = function() { - callback({errmsg: "deleteGame failed: " + transaction.error}); + callback({errmsg: "game removal failed: " + transaction.error}); }; } transaction.objectStore("games").delete(gameId); diff --git a/client/src/views/Game.vue b/client/src/views/Game.vue index 920e9c84..7aa7aa5f 100644 --- a/client/src/views/Game.vue +++ b/client/src/views/Game.vue @@ -97,19 +97,8 @@ export default { // TODO: observer on dark games must see all board ? Or alternate ? (seems better) // ...or just see nothing as on buho21 this.$refs["basegame"].play( - data.move, this.game.vname!="Dark" ? "animate" : null); + data.move, this.game.vname!="Dark" ? "animate" : null); //TODO: arg to know if opponent move (or comp) in case of dark variant... this.processMove(data.move); - - - -// TODO: -// send filtered_move + elapsed time -// receive same. (update clock) + update (our) initime if it's my turn -// + update fen (using vr.getFen()) - - - - break; case "pong": //received if we sent a ping (game still alive on our side) if (this.gameRef.id != data.gameId) @@ -278,9 +267,9 @@ export default { // } }, // TODO: refactor this old "oppConnected" logic - oppConnected: function(uid) { - return this.opponents.some(o => o.id == uid && o.online); - }, +// oppConnected: function(uid) { +// return this.opponents.some(o => o.id == uid && o.online); +// }, // Post-process a move (which was just played) processMove: function(move) { if (!this.game.mycolor) @@ -316,7 +305,7 @@ export default { fen: move.fen, elapsed: move.elapsed, increment: this.game.increment, //redundant but faster - initime: (this.vr.turn == this.game.mycolor), //it's my turn + initime: (this.vr.turn == this.game.mycolor), //is it my turn? }); }, // NOTE: this update function should also work for corr games