bb7fdce7dd3aca1d0c372f8f284303aa24494431
1 // TODO: general methods to access/retrieve from storage, to be generalized
2 // https://developer.mozilla.org/fr/docs/Web/API/API_IndexedDB
5 export const GameStorage
=
7 init: function(myid
, oppid
, gameId
, variant
, mycolor
, fenStart
)
9 localStorage
.setItem("myid", myid
);
10 localStorage
.setItem("gameId", gameId
);
11 localStorage
.setItem("vname", variant
);
12 localStorage
.setItem("mycolor", mycolor
);
13 localStorage
.setItem("fenStart", fenStart
);
14 localStorage
.setItem("moves", []);
17 // TODO: also option to takeback a move ?
18 update: function(move)
20 let moves
= JSON
.parse(localStorage
.getItem("moves"));
22 localStorage
.setItem("moves", JSON
.stringify(moves
));
25 // "computer mode" clearing is done through the menu
28 // TODO: refresh, and implement "transfert" function (to indexedDB)
29 delete localStorage
["myid"];
30 delete localStorage
["oppid"];
31 delete localStorage
["gameId"];
32 delete localStorage
["variant"];
33 delete localStorage
["mycolor"];
34 delete localStorage
["fenStart"];
35 delete localStorage
["moves"];
38 // TODO: game or gameInfo ?!
39 get: function(gameRef
)
41 const gid
= gameRef
.id
;
42 const rid
= gameRef
.rid
; //may be blank
44 if (localStorage
.getItem("gameId") === gid
)
46 // Retrieve running game from localStorage
47 game
.score
= localStorage
.getItem("score");
48 game
.mycolor
= localStorage
.getItem("mycolor");
49 game
.fenStart
= localStorage
.getItem("fenStart");
50 game
.fen
= localStorage
.getItem("fen");
51 game
.moves
= JSON
.parse(localStorage
.getItem("moves"));
52 game
.players
= JSON
.parse(localStorage
.getItem("players"));
53 game
.started
= JSON
.parse(localStorage
.getItem("started"));
54 game
.clocks
= JSON
.parse(localStorage
.getItem("clocks"));
55 game
.timeControl
= localStorage
.getItem("timeControl");
56 game
.increment
= localStorage
.getItem("increment");
57 game
.vname
= localStorage
.getItem("vname");
62 // Find the game in indexedDB, on server or remotely: TODO