projects
/
vchess.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
afc4260
)
Remove unused move.color, format moves corr --> live after retrieval
author
Benjamin Auder
<benjamin.auder@somewhere>
Fri, 6 Dec 2019 22:43:12 +0000
(23:43 +0100)
committer
Benjamin Auder
<benjamin.auder@somewhere>
Fri, 6 Dec 2019 22:43:12 +0000
(23:43 +0100)
client/src/components/BaseGame.vue
patch
|
blob
|
blame
|
history
client/src/utils/gameStorage.js
patch
|
blob
|
blame
|
history
client/src/views/Game.vue
patch
|
blob
|
blame
|
history
server/db/create.sql
patch
|
blob
|
blame
|
history
server/models/Game.js
patch
|
blob
|
blame
|
history
server/routes/games.js
patch
|
blob
|
blame
|
history
diff --git
a/client/src/components/BaseGame.vue
b/client/src/components/BaseGame.vue
index
19aaf15
..
e0bd937
100644
(file)
--- 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
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
#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);
},
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
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
0b3a7da
..
dc65379
100644
(file)
--- 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 => {
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
});
}
else //local game
diff --git
a/client/src/views/Game.vue
b/client/src/views/Game.vue
index
114b86b
..
cb00856
100644
(file)
--- 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.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 >= 3)
{
let addTime = [0, 0];
@@
-362,6
+363,18
@@
export default {
}
if (L >= 1)
game.initime[L%2] = game.moves[L-1].played;
}
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;
}
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,
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
},
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
0251c17
..
11c3574
100644
(file)
--- 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
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)
);
foreign key (gid) references Games(id)
);
diff --git
a/server/models/Game.js
b/server/models/Game.js
index
0e42292
..
786f1e7
100644
(file)
--- 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
* message: text
* played: datetime
* idx: integer
- * color: character
*/
const GameModel =
*/
const GameModel =
@@
-71,7
+70,7
@@
const GameModel =
if (!!err2)
return cb(err2);
query =
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) => {
"FROM Moves " +
"WHERE gid = " + id;
db.all(query, (err3,moves) => {
@@
-147,9
+146,9
@@
const GameModel =
{
const m = obj.move;
query =
{
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 +
"(" + id + ",'" + JSON.stringify(m.squares) + "','" + m.message +
- "'," + m.played + "," + m.idx + "
,'" + m.color + "'
)";
+ "'," + m.played + "," + m.idx + ")";
db.run(query);
}
});
db.run(query);
}
});
diff --git
a/server/routes/games.js
b/server/routes/games.js
index
128d9ee
..
9bd9a30
100644
(file)
--- 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", () => {
{
GameModel.getOne(gameId, (err,game) => {
access.checkRequest(res, err, game, "Game not found", () => {
-
res.json({game: game});
+ res.json({game: game});
});
});
}
});
});
}