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 lightName = $('#cb_light_name').val();
|
||||
const darkName = $('#cb_dark_name').val();
|
||||
const winner = currentGame.winner;
|
||||
const lastMove = currentGame.lastMove || {};
|
||||
const lastMeta = lastMove.meta || {};
|
||||
const status = !winner ? null : (lastMove.took === PS.KING) ? 'mate' : 'ended';
|
||||
gun.get(PacoSakoUUID).get('meta').get(gameId).put({
|
||||
lightName: lightName,
|
||||
darkName: darkName,
|
||||
moves: currentGame.countTurns(),
|
||||
timestamp: lastMeta.timestamp || new Date(Gun.state()).getTime(),
|
||||
status: status,
|
||||
});
|
||||
const turns = currentGame.countTurns();
|
||||
let meta = null;
|
||||
if (lightName !== '' || darkName !== '' || turns !== 0) {
|
||||
const winner = currentGame.winner;
|
||||
const lastMove = currentGame.lastMove || {};
|
||||
const lastMeta = lastMove.meta || {};
|
||||
const status = !winner ? null : (lastMove.took === PS.KING) ? 'mate' : 'ended';
|
||||
meta = {
|
||||
lightName: lightName,
|
||||
darkName: darkName,
|
||||
moves: turns,
|
||||
timestamp: lastMeta.timestamp || new Date(Gun.state()).getTime(),
|
||||
status: status,
|
||||
};
|
||||
}
|
||||
gun.get(PacoSakoUUID).get('meta').put({ [gameId]: meta });
|
||||
}
|
||||
|
||||
function switchGameId(newId){
|
||||
|
|
|
|||
Loading…
Reference in New Issue