Fix moveList + progress on game navigation system
[vchess.git] / public / javascripts / utils / storage.js
CommitLineData
81da2786
BA
1 // TODO: general methods to access/retrieve from storage, to be generalized
2 // https://developer.mozilla.org/fr/docs/Web/API/API_IndexedDB
3 // https://dexie.org/
fd373b27
BA
4 setStorage: function(myid, oppid, gameId, variant, mycolor, fenStart) {
5 localStorage.setItem("myid", myid);
6 localStorage.setItem("oppid", oppid);
7 localStorage.setItem("gameId", gameId);
8 localStorage.setItem("variant", variant);
9 localStorage.setItem("mycolor", mycolor);
10 localStorage.setItem("fenStart", fenStart);
11 localStorage.setItem("moves", []);
81da2786 12 },
fd373b27
BA
13 updateStorage: function(move) {
14 let moves = JSON.parse(localStorage.getItem("moves"));
15 moves.push(move);
16 localStorage.setItem("moves", JSON.stringify(moves));
81da2786
BA
17 },
18 // "computer mode" clearing is done through the menu
19 clearStorage: function() {
fd373b27
BA
20 delete localStorage["myid"];
21 delete localStorage["oppid"];
22 delete localStorage["gameId"];
23 delete localStorage["variant"];
24 delete localStorage["mycolor"];
25 delete localStorage["fenStart"];
26 delete localStorage["moves"];
81da2786 27 },