1 // TODO: general methods to access/retrieve from storage, to be generalized
2 // https://developer.mozilla.org/fr/docs/Web/API/API_IndexedDB
4 getStoragePrefix: function(mode
) {
6 if (mode
== "computer")
8 else if (mode
== "friend")
12 setStorage: function() {
13 if (this.mode
=="human")
15 localStorage
.setItem("myid", this.myid
);
16 localStorage
.setItem("oppid", this.oppid
);
17 localStorage
.setItem("gameId", this.gameId
);
19 const prefix
= this.getStoragePrefix(this.mode
);
20 localStorage
.setItem(prefix
+"variant", variant
);
21 localStorage
.setItem(prefix
+"mycolor", this.mycolor
);
22 localStorage
.setItem(prefix
+"fenStart", this.fenStart
);
23 localStorage
.setItem(prefix
+"moves", JSON
.stringify(this.vr
.moves
));
24 localStorage
.setItem(prefix
+"fen", this.vr
.getFen());
25 localStorage
.setItem(prefix
+"score", "*");
27 updateStorage: function() {
28 const prefix
= this.getStoragePrefix(this.mode
);
29 localStorage
.setItem(prefix
+"moves", JSON
.stringify(this.vr
.moves
));
30 localStorage
.setItem(prefix
+"fen", this.vr
.getFen());
31 if (this.score
!= "*")
32 localStorage
.setItem(prefix
+"score", this.score
);
34 // "computer mode" clearing is done through the menu
35 clearStorage: function() {
36 if (this.mode
== "human")
38 delete localStorage
["myid"];
39 delete localStorage
["oppid"];
40 delete localStorage
["gameId"];
42 const prefix
= this.getStoragePrefix(this.mode
);
43 delete localStorage
[prefix
+"variant"];
44 delete localStorage
[prefix
+"mycolor"];
45 delete localStorage
[prefix
+"fenStart"];
46 delete localStorage
[prefix
+"moves"];
47 delete localStorage
[prefix
+"fen"];
48 delete localStorage
[prefix
+"score"];
50 clearCurrentGame: function(e
) {
51 this.getRidOfTooltip(e
.currentTarget
);
53 location
.reload(); //to see clearing effects