use plain identifiers to initialize objects rather than strings

This commit is contained in:
Jesse D. McDonald 2020-03-14 13:07:10 -05:00
parent a77403484c
commit 67daeba99e
1 changed files with 18 additions and 18 deletions

View File

@ -8,7 +8,7 @@ var gun = Gun({
let initialBoard = (function (){ let initialBoard = (function (){
var init = JSON.stringify({ var init = JSON.stringify({
'light': [ light: [
'rnbqkbnr', 'rnbqkbnr',
'pppppppp', 'pppppppp',
' ', ' ',
@ -18,7 +18,7 @@ let initialBoard = (function (){
' ', ' ',
' ', ' ',
], ],
'dark': [ dark: [
' ', ' ',
' ', ' ',
' ', ' ',
@ -28,8 +28,8 @@ let initialBoard = (function (){
'pppppppp', 'pppppppp',
'rnbqkbnr', 'rnbqkbnr',
], ],
'player': 'light', player: 'light',
'timestamp': new Date().getTime(), timestamp: new Date().getTime(),
}); });
return function (){ return JSON.parse(init); } return function (){ return JSON.parse(init); }
})(); })();
@ -274,10 +274,10 @@ function movePiece(priorBoard, side, from, to){
board.timestamp = new Date().getTime(); board.timestamp = new Date().getTime();
board.move = { board.move = {
'side': normalizeSide(side), side: normalizeSide(side),
'type': type, type: type,
'from': from, from: from,
'to': to to: to
}; };
if (took !== ' ') { if (took !== ' ') {
board.move.took = took; board.move.took = took;
@ -340,7 +340,7 @@ function movePiece(priorBoard, side, from, to){
if (replaced === ' ') { if (replaced === ' ') {
board.player = otherSide(board.player); board.player = otherSide(board.player);
} else { } else {
board.phantom = { 'from': to, 'type': replaced + side[0] }; board.phantom = { from: to, type: replaced + side[0] };
} }
return board; return board;
@ -434,7 +434,7 @@ function placePiece(where, type, count){
var piece = $($('#' + piece_id)[0] || $('#cb_piece_' + type + ' img').clone()); var piece = $($('#' + piece_id)[0] || $('#cb_piece_' + type + ' img').clone());
piece.attr('style', ''); piece.attr('style', '');
piece.attr('id', piece_id); piece.attr('id', piece_id);
piece.data({ 'type': type, 'location': where }); piece.data({ type: type, location: where });
piece.appendTo('#cb_' + where); piece.appendTo('#cb_' + where);
piece.draggable({ piece.draggable({
disabled: true, disabled: true,
@ -561,7 +561,7 @@ function putState(board){
var game = gun.get(PacoSakoUUID).get('games').get(gameId); var game = gun.get(PacoSakoUUID).get('games').get(gameId);
var state = JSON.stringify(board); var state = JSON.stringify(board);
$('#cb_board').data('skip_notify', state); $('#cb_board').data('skip_notify', state);
game.put({ 'board': state }); game.put({ board: state });
putMeta(); putMeta();
} }
@ -573,12 +573,12 @@ function putMeta(){
var meta = gun.get(PacoSakoUUID).get('meta').get(gameId); var meta = gun.get(PacoSakoUUID).get('meta').get(gameId);
var stat = (board.move && board.move.took === 'k') ? 'mate' : null; var stat = (board.move && board.move.took === 'k') ? 'mate' : null;
meta.put({ meta.put({
'gameId': gameId, gameId: gameId,
'lightName': lightName, lightName: lightName,
'darkName': darkName, darkName: darkName,
'moves': countMoves(board), moves: countMoves(board),
'timestamp': board.timestamp || new Date().getTime(), timestamp: board.timestamp || new Date().getTime(),
'status': stat, status: stat,
}); });
} }
@ -799,7 +799,7 @@ $(function (){
if (!board.phantom) { if (!board.phantom) {
var newBoard = cloneJSON(board); var newBoard = cloneJSON(board);
newBoard.prior = board; newBoard.prior = board;
newBoard.move = { 'side': board.player, 'pass': true }; newBoard.move = { side: board.player, pass: true };
newBoard.player = otherSide(board.player); newBoard.player = otherSide(board.player);
newBoard.timestamp = new Date().getTime(); newBoard.timestamp = new Date().getTime();
putState(newBoard); putState(newBoard);