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