1 // TODO: general methods to access/retrieve from storage, to be generalized
2 // https://developer.mozilla.org/fr/docs/Web/API/API_IndexedDB
5 function setStorage(myid
, oppid
, gameId
, variant
, mycolor
, fenStart
)
7 localStorage
.setItem("myid", myid
);
8 localStorage
.setItem("oppid", oppid
);
9 localStorage
.setItem("gameId", gameId
);
10 localStorage
.setItem("variant", variant
);
11 localStorage
.setItem("mycolor", mycolor
);
12 localStorage
.setItem("fenStart", fenStart
);
13 localStorage
.setItem("moves", []);
16 function updateStorage(move)
18 let moves
= JSON
.parse(localStorage
.getItem("moves"));
20 localStorage
.setItem("moves", JSON
.stringify(moves
));
23 // "computer mode" clearing is done through the menu
24 function clearStorage()
26 delete localStorage
["myid"];
27 delete localStorage
["oppid"];
28 delete localStorage
["gameId"];
29 delete localStorage
["variant"];
30 delete localStorage
["mycolor"];
31 delete localStorage
["fenStart"];
32 delete localStorage
["moves"];
35 function getGameFromStorage(gameId
)
38 if (localStorage
.getItem("gameId") === gameId
)
40 // Retrieve running game from localStorage
41 game
.score
= localStorage
.getItem("score");
42 game
.oppid
= localStorage
.getItem("oppid");
43 game
.oppname
= localStorage
.getItem("oppname");
44 game
.mycolor
= localStorage
.getItem("mycolor");
45 game
.fenStart
= localStorage
.getItem("fenStart");
46 game
.moves
= localStorage
.getItem("moves");
50 // Find the game in indexedDB: TODO