From: Benjamin Auder Date: Wed, 12 Jun 2019 14:35:49 +0000 (+0200) Subject: Fix moves sending. TODO: fix double opp move + clocks update X-Git-Url: https://git.auder.net/variants/Chakart/css/assets/current/doc/%7B%7B?a=commitdiff_plain;h=8a7452b520dc7ead6880a7e62e7c0e057db1ebda;p=vchess.git Fix moves sending. TODO: fix double opp move + clocks update --- diff --git a/client/src/utils/storage.js b/client/src/utils/storage.js index ecafe205..a30bb824 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), - initime: undefined, + initime: (o.initime ? Date.now() : undefined), score: "*", }; diff --git a/client/src/views/Game.vue b/client/src/views/Game.vue index 7aa7aa5f..8389bde1 100644 --- a/client/src/views/Game.vue +++ b/client/src/views/Game.vue @@ -250,8 +250,9 @@ export default { // Post-processing: decorate each move with current FEN: // (to be able to jump to any position quickly) game.moves.forEach(move => { + // TODO: this is doing manually what BaseGame.play() achieve... move.color = this.vr.turn; - vr.play(move); + this.vr.play(move); move.fen = this.vr.getFen(); }); this.vr.re_init(game.fen); @@ -281,7 +282,7 @@ export default { const filtered_move = Object.keys(move) .filter(key => allowed_fields.includes(key)) .reduce((obj, key) => { - obj[key] = raw[key]; + obj[key] = move[key]; return obj; }, {}); // Send move ("newmove" event) to opponent(s) (if ours) @@ -291,11 +292,11 @@ export default { const elapsed = Date.now() - GameStorage.getInitime(); this.game.players.forEach(p => { if (p.sid != this.st.user.sid) - this.st.conn.send("newmove", - { + this.st.conn.send(JSON.stringify({ + code: "newmove", target: p.sid, move: Object.assign({}, filtered_move, {elapsed: elapsed}), - }); + })); }); move.elapsed = elapsed; } diff --git a/client/src/views/Hall.vue b/client/src/views/Hall.vue index 563ecd30..dd4621b3 100644 --- a/client/src/views/Hall.vue +++ b/client/src/views/Hall.vue @@ -592,6 +592,7 @@ export default { fenStart: gameInfo.fen, players: gameInfo.players, timeControl: gameInfo.timeControl, + initime: (gameInfo.players[0].sid == this.st.user.sid), }); if (this.st.settings.sound >= 1) new Audio("/sounds/newgame.mp3").play().catch(err => {});