projects
/
vchess.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fix moves sending. TODO: fix double opp move + clocks update
[vchess.git]
/
client
/
src
/
utils
/
storage.js
diff --git
a/client/src/utils/storage.js
b/client/src/utils/storage.js
index
8a7c526
..
a30bb82
100644
(file)
--- 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),
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: "*",
};
score: "*",
};
@@
-107,24
+107,31
@@
export const GameStorage =
localStorage.setItem("gameState", JSON.stringify(gameState));
},
localStorage.setItem("gameState", JSON.stringify(gameState));
},
+ getInitime: function()
+ {
+ const gameState = JSON.parse(localStorage.getItem("gameState"));
+ return gameState.initime;
+ },
+
// localStorage:
// localStorage:
- // TODO: also option to takeback a move ?
Is fen included in move ?
+ // TODO: also option to takeback a move ?
// NOTE: for live games only (all on server for corr)
// NOTE: for live games only (all on server for corr)
- update: function(
fen, move, clocks, started, score)
+ update: function(
o) //colorIdx, move, fen, elapsed, increment, initime, score
{
let gameState = JSON.parse(localStorage.getItem("gameState"));
{
let gameState = JSON.parse(localStorage.getItem("gameState"));
- if (!!
fen
)
+ if (!!
o.move
)
{
{
- gameState.moves.push(move);
- gameState.fen = fen;
- gameState.clocks = clocks;
+ gameState.moves.push(o.move);
+ gameState.fen = o.fen;
+ if (!!o.elapsed) //NaN if first move in game
+ gameState.clocks[o.colorIdx] += (o.increment - o.elapsed);
}
}
- if (!!
started
)
- gameState.
started = started
;
- if (!!score)
- gameState.score = score;
+ if (!!
o.initime) //just a flag (true
)
+ gameState.
initime = Date.now()
;
+ if (!!
o.
score)
+ gameState.score =
o.
score;
localStorage.setItem("gameState", JSON.stringify(gameState));
localStorage.setItem("gameState", JSON.stringify(gameState));
- if (!!
score &&
score != "*")
+ if (!!
o.score && o.
score != "*")
transferToDb(); //game is over
},
transferToDb(); //game is over
},
@@
-139,7
+146,7
@@
export const GameStorage =
let objectStore = db.transaction('games').objectStore('games');
objectStore.openCursor().onsuccess = function(event) {
var cursor = event.target.result;
let objectStore = db.transaction('games').objectStore('games');
objectStore.openCursor().onsuccess = function(event) {
var cursor = event.target.result;
- // if there is still another cursor to go, keep runing this code
+ // if there is still another cursor to go, keep run
n
ing this code
if (cursor)
{
games.push(cursor.value);
if (cursor)
{
games.push(cursor.value);
@@
-162,7
+169,7
@@
export const GameStorage =
callback({}); //everything's fine
}
transaction.onerror = function() {
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);
};
}
transaction.objectStore("games").delete(gameId);