X-Git-Url: https://git.auder.net/pieces/Checkered/cq.svg?a=blobdiff_plain;f=client%2Fsrc%2Futils%2Fstorage.js;h=e5978ae3e33f5f3d42ef48e56a1911b0c30a9623;hb=c4f91d3ff756bf1c8948433e0584e0e4235f3524;hp=f5c3b2534be63f44b9e374d783a3ca28583c0274;hpb=9d54ab8900b69876c3249b4ed1bfa355dccb7f97;p=vchess.git diff --git a/client/src/utils/storage.js b/client/src/utils/storage.js index f5c3b253..e5978ae3 100644 --- a/client/src/utils/storage.js +++ b/client/src/utils/storage.js @@ -99,7 +99,7 @@ export const GameStorage = fen: o.fenStart, moves: [], clocks: [...Array(o.players.length)].fill(tc.mainTime), - started: [...Array(o.players.length)].fill(false), + initime: (o.initime ? Date.now() : undefined), score: "*", }; @@ -116,14 +116,15 @@ export const GameStorage = // localStorage: // TODO: also option to takeback a move ? // NOTE: for live games only (all on server for corr) - update: function(o) //colorIdx, move, fen, elapsed, increment, initime, score + update: function(o) //colorIdx, move, fen, addTime, initime, score { let gameState = JSON.parse(localStorage.getItem("gameState")); if (!!o.move) { gameState.moves.push(o.move); gameState.fen = o.fen; - gameState.clocks[o.colorIdx] += (o.increment - o.elapsed); + if (!!o.addTime) //NaN if first move in game + gameState.clocks[o.colorIdx] += o.addTime; } if (!!o.initime) //just a flag (true) gameState.initime = Date.now(); @@ -168,7 +169,7 @@ export const GameStorage = callback({}); //everything's fine } transaction.onerror = function() { - callback({errmsg: "deleteGame failed: " + transaction.error}); + callback({errmsg: "game removal failed: " + transaction.error}); }; } transaction.objectStore("games").delete(gameId);