set metadata to null when there are no names or moves
This commit is contained in:
parent
2e324b180c
commit
f3ae25f16a
|
|
@ -391,17 +391,22 @@ $(function (){
|
||||||
const gameId = $('#cb_board').data('gameId');
|
const gameId = $('#cb_board').data('gameId');
|
||||||
const lightName = $('#cb_light_name').val();
|
const lightName = $('#cb_light_name').val();
|
||||||
const darkName = $('#cb_dark_name').val();
|
const darkName = $('#cb_dark_name').val();
|
||||||
|
const turns = currentGame.countTurns();
|
||||||
|
let meta = null;
|
||||||
|
if (lightName !== '' || darkName !== '' || turns !== 0) {
|
||||||
const winner = currentGame.winner;
|
const winner = currentGame.winner;
|
||||||
const lastMove = currentGame.lastMove || {};
|
const lastMove = currentGame.lastMove || {};
|
||||||
const lastMeta = lastMove.meta || {};
|
const lastMeta = lastMove.meta || {};
|
||||||
const status = !winner ? null : (lastMove.took === PS.KING) ? 'mate' : 'ended';
|
const status = !winner ? null : (lastMove.took === PS.KING) ? 'mate' : 'ended';
|
||||||
gun.get(PacoSakoUUID).get('meta').get(gameId).put({
|
meta = {
|
||||||
lightName: lightName,
|
lightName: lightName,
|
||||||
darkName: darkName,
|
darkName: darkName,
|
||||||
moves: currentGame.countTurns(),
|
moves: turns,
|
||||||
timestamp: lastMeta.timestamp || new Date(Gun.state()).getTime(),
|
timestamp: lastMeta.timestamp || new Date(Gun.state()).getTime(),
|
||||||
status: status,
|
status: status,
|
||||||
});
|
};
|
||||||
|
}
|
||||||
|
gun.get(PacoSakoUUID).get('meta').put({ [gameId]: meta });
|
||||||
}
|
}
|
||||||
|
|
||||||
function switchGameId(newId){
|
function switchGameId(newId){
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue