set metadata to null when there are no names or moves

This commit is contained in:
Jesse D. McDonald 2020-03-29 00:27:38 -05:00
parent 2e324b180c
commit f3ae25f16a
1 changed files with 16 additions and 11 deletions

View File

@ -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 winner = currentGame.winner; const turns = currentGame.countTurns();
const lastMove = currentGame.lastMove || {}; let meta = null;
const lastMeta = lastMove.meta || {}; if (lightName !== '' || darkName !== '' || turns !== 0) {
const status = !winner ? null : (lastMove.took === PS.KING) ? 'mate' : 'ended'; const winner = currentGame.winner;
gun.get(PacoSakoUUID).get('meta').get(gameId).put({ const lastMove = currentGame.lastMove || {};
lightName: lightName, const lastMeta = lastMove.meta || {};
darkName: darkName, const status = !winner ? null : (lastMove.took === PS.KING) ? 'mate' : 'ended';
moves: currentGame.countTurns(), meta = {
timestamp: lastMeta.timestamp || new Date(Gun.state()).getTime(), lightName: lightName,
status: status, 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){ function switchGameId(newId){