// 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)
// 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);
// }
},
// 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)
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)
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;
}
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