// Game object: {
// // Static informations:
-// gameId: string
+// id: string
// vname: string,
// fenStart: string,
// players: array of sid+id+name,
alert("Error while loading database: " + event.target.errorCode);
};
// Create objectStore for vchess->games
- let objectStore = db.createObjectStore("games", { keyPath: "gameId" });
+ let objectStore = db.createObjectStore("games", { keyPath: "id" });
objectStore.createIndex("score", "score"); //to search by game result
}
}
},
// TODO: also option to takeback a move ?
- update: function(gameId, obj) //move, fen, clocks, score, initime, ...
+ // obj: chat, move, fen, clocks, score[Msg], initime, ...
+ update: function(gameId, obj)
{
if (Number.isInteger(gameId) || !isNaN(parseInt(gameId)))
{
gid: gameId,
newObj:
{
- // TODO: I think stringify isn't requuired here (see ajax() )
- move: JSON.stringify(obj.move), //may be undefined...
+ chat: obj.chat,
+ move: obj.move, //may be undefined...
fen: obj.fen,
score: obj.score,
+ scoreMsg: obj.scoreMsg,
+ drawOffer: obj.drawOffer,
}
}
);
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