button(@click="flip") Flip
button(@click="gotoBegin") GotoBegin
button(@click="gotoEnd") GotoEnd
+ #messageDiv.section-content {{ curMoveMessage() }}
#fenDiv.section-content(v-if="showFen && !!vr")
p#fenString.text-center {{ vr.getFen() }}
#pgnDiv.section-content
this.cursor = L-1;
this.lastMove = (L > 0 ? this.moves[L-1] : null);
},
+ // For corr games, potential message with each move sent
+ curMoveMessage: function() {
+ if (this.cursor < 0)
+ return "";
+ return this.game.moves[this.cursor].message || "";
+ },
download: function() {
const content = this.getPgn();
// Prepare and trigger download link
if (Number.isInteger(gameId) || !isNaN(parseInt(gameId)))
{
ajax("/games", "GET", {gid:gameId}, res => {
- callback(res.game);
+ let game = res.game;
+ game.moves.forEach(m => {
+ m.squares = JSON.parse(m.squares);
+ });
+ callback(game);
});
}
else //local game
game.clocks = [tc.mainTime, tc.mainTime];
game.initime = [0, 0];
const L = game.moves.length;
+ game.moves.sort((m1,m2) => m1.idx - m2.idx); //in case of
if (L >= 3)
{
let addTime = [0, 0];
}
if (L >= 1)
game.initime[L%2] = game.moves[L-1].played;
+ // Now that we used idx and played, re-format moves as for live games
+ game.moves = game.moves.map(m => {
+ const s = m.squares;
+ return
+ {
+ appear: s.appear,
+ vanish: s.vanish,
+ start: s.start,
+ end: s.end,
+ message: m.message,
+ };
+ });
}
const myIdx = game.players.findIndex(p => {
return p.sid == this.st.user.sid || p.uid == this.st.user.id;
message: this.corrMsg, //TODO
played: Date.now(), //TODO: on server?
idx: this.game.moves.length,
- color: move.color,
},
clocks: this.game.clocks.map((t,i) => i==colorIdx
? this.game.clocks[i] + addTime
message varchar,
played datetime, --when was this move played?
idx integer, --index of the move in the game
- color character, --required for e.g. Marseillais Chess
foreign key (gid) references Games(id)
);
* message: text
* played: datetime
* idx: integer
- * color: character
*/
const GameModel =
if (!!err2)
return cb(err2);
query =
- "SELECT squares, message, played, idx, color " +
+ "SELECT squares, message, played, idx " +
"FROM Moves " +
"WHERE gid = " + id;
db.all(query, (err3,moves) => {
{
const m = obj.move;
query =
- "INSERT INTO Moves (gid,squares,message,played,idx,color) VALUES " +
+ "INSERT INTO Moves (gid, squares, message, played, idx) VALUES " +
"(" + id + ",'" + JSON.stringify(m.squares) + "','" + m.message +
- "'," + m.played + "," + m.idx + ",'" + m.color + "')";
+ "'," + m.played + "," + m.idx + ")";
db.run(query);
}
});
{
GameModel.getOne(gameId, (err,game) => {
access.checkRequest(res, err, game, "Game not found", () => {
- res.json({game: game});
+ res.json({game: game});
});
});
}