From: Benjamin Auder Date: Fri, 6 Dec 2019 22:43:12 +0000 (+0100) Subject: Remove unused move.color, format moves corr --> live after retrieval X-Git-Url: https://git.auder.net/%7B%7B%20asset%28%27mixstore/css/static/img/assets/rpsls.css?a=commitdiff_plain;h=92b82defacccf9c4d3755924a71fcb584002ccc6;p=vchess.git Remove unused move.color, format moves corr --> live after retrieval --- diff --git a/client/src/components/BaseGame.vue b/client/src/components/BaseGame.vue index 19aaf154..e0bd9376 100644 --- a/client/src/components/BaseGame.vue +++ b/client/src/components/BaseGame.vue @@ -16,6 +16,7 @@ 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 @@ -98,6 +99,12 @@ export default { 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 diff --git a/client/src/utils/gameStorage.js b/client/src/utils/gameStorage.js index 0b3a7da6..dc653794 100644 --- a/client/src/utils/gameStorage.js +++ b/client/src/utils/gameStorage.js @@ -133,7 +133,11 @@ export const GameStorage = 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 diff --git a/client/src/views/Game.vue b/client/src/views/Game.vue index 114b86b4..cb00856d 100644 --- a/client/src/views/Game.vue +++ b/client/src/views/Game.vue @@ -349,6 +349,7 @@ export default { 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]; @@ -362,6 +363,18 @@ export default { } 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; @@ -453,7 +466,6 @@ export default { 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 diff --git a/server/db/create.sql b/server/db/create.sql index 0251c176..11c3574e 100644 --- a/server/db/create.sql +++ b/server/db/create.sql @@ -69,7 +69,6 @@ create table Moves ( 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) ); diff --git a/server/models/Game.js b/server/models/Game.js index 0e42292e..786f1e78 100644 --- a/server/models/Game.js +++ b/server/models/Game.js @@ -20,7 +20,6 @@ var db = require("../utils/database"); * message: text * played: datetime * idx: integer - * color: character */ const GameModel = @@ -71,7 +70,7 @@ 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) => { @@ -147,9 +146,9 @@ const GameModel = { 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); } }); diff --git a/server/routes/games.js b/server/routes/games.js index 128d9eeb..9bd9a30b 100644 --- a/server/routes/games.js +++ b/server/routes/games.js @@ -34,7 +34,7 @@ router.get("/games", access.ajax, (req,res) => { { GameModel.getOne(gameId, (err,game) => { access.checkRequest(res, err, game, "Game not found", () => { - res.json({game: game}); + res.json({game: game}); }); }); }