Commit | Line | Data |
---|---|---|
59d58d7d 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/ | |
4 | ||
5 | function setStorage(myid, oppid, gameId, variant, mycolor, fenStart) | |
6 | { | |
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", []); | |
14 | } | |
15 | ||
16 | function updateStorage(move) | |
17 | { | |
18 | let moves = JSON.parse(localStorage.getItem("moves")); | |
19 | moves.push(move); | |
20 | localStorage.setItem("moves", JSON.stringify(moves)); | |
21 | } | |
22 | ||
23 | // "computer mode" clearing is done through the menu | |
24 | function clearStorage() | |
25 | { | |
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"]; | |
33 | } | |
34 | ||
35 | function getGameFromStorage(gameId) | |
36 | { | |
37 | let game = {}; | |
38 | if (localStorage.getItem("gameId") === gameId) | |
39 | { | |
40 | // Retrieve running game from localStorage | |
41 | game.score = localStorage.getItem("score"); | |
42 | game.oppid = localStorage.getItem("oppid"); | |
a3ab5fdb | 43 | game.oppname = localStorage.getItem("oppname"); |
59d58d7d BA |
44 | game.mycolor = localStorage.getItem("mycolor"); |
45 | game.fenStart = localStorage.getItem("fenStart"); | |
46 | game.moves = localStorage.getItem("moves"); | |
47 | } | |
48 | else | |
49 | { | |
50 | // Find the game in indexedDB: TODO | |
51 | } | |
52 | } |