import { extractTime } from "@/utils/timeControl";
-import { shuffle } from "@/utils/alea";
// TODO: show game structure
//const newItem = [
// localStorage:
init: function(o)
{
- // NOTE: when >= 3 players, better use an array + shuffle for mycolor
- const mycolor = (Math.random() < 0.5 ? "w" : "b");
- // Shuffle players order (white then black then other colors).
- const players = shuffle(o.players);
// Extract times (in [milli]seconds), set clocks, store in localStorage
const tc = extractTime(o.timeControl);
{
gameId: o.gameId,
vname: o.vname,
- mycolor: mycolor,
fenStart: o.fenStart,
- players: players,
+ players: o.players,
timeControl: o.timeControl,
increment: tc.increment,
mode: "live", //function for live games only
// localStorage:
// TODO: also option to takeback a move ? Is fen included in move ?
// NOTE: for live games only (all on server for corr)
- update: function(fen, moves, clocks, started, score)
+ update: function(fen, move, clocks, started, score)
{
let gameState = JSON.parse(localStorage.getItem("gameState"));
if (!!fen)
{
- gameState.moves = moves;
+ gameState.moves.push(move);
gameState.fen = fen;
gameState.clocks = clocks;
}
// indexedDB:
// Since DB requests are asynchronous, require a callback using the result
// TODO: option for remote retrieval (third arg, or just "gameRef")
- getLocal: function(callback, gameId)
+ getLocal: function(gameId, callback)
{
let games = [];
dbOperation((db) => {
}
// Game is local and not running
- getLocal(callback, gid);
+ GameStorage.getLocal(gid, callback);
},
};