- localStorage.setItem("gameId", o.gameId);
- localStorage.setItem("vname", o.vname);
- // NOTE: when >= 3 players, better use an array + shuffle for mycolor
- const mycolor = (Math.random() < 0.5 ? "w" : "b");
- localStorage.setItem("mycolor", mycolor);
- localStorage.setItem("fenStart", o.fenStart);
- localStorage.setItem("fen", o.fenStart);
- localStorage.setItem("moves", JSON.stringify([]));
- // Shuffle players order (white then black then other colors).
- localStorage.setItem("players", JSON.stringify(shuffle(o.players)));
- // Extract times (in [milli]seconds), set clocks, store in localStorage
- const tc = extractTime(o.timeControl);
- localStorage.setItem("timeControl", o.timeControl);
- localStorage.setItem("clocks", JSON.stringify(
- [...Array(o.players.length)].fill(tc.mainTime)));
- localStorage.setItem("increment", tc.increment);
- localStorage.setItem("started", JSON.stringify(
- [...Array(o.players.length)].fill(false)));
- localStorage.setItem("score", "*");
- localStorage.setItem("started", JSON.stringify(
- [...Array(o.players.length)].fill(false)));
- localStorage.setItem("clocks", JSON.stringify(
- [...Array(o.players.length)].fill(0)));
- localStorage.setItem("mode", "live"); //function for live games only
-
-
- // TODO: refresh, and implement "transfert" function (to indexedDB)
- localStorage["myid"];
- localStorage["oppid"];
- delete localStorage["gameId"];
- delete localStorage["variant"];
- delete localStorage["mycolor"];
- delete localStorage["fenStart"];
- delete localStorage["moves"];
+ dbOperation((db) => {
+ let transaction = db.transaction(["games"], "readwrite");
+ if (callback)
+ {
+ transaction.oncomplete = function() {
+ callback({}); //everything's fine
+ }
+ transaction.onerror = function() {
+ callback({errmsg: "deleteGame failed: " + transaction.error});
+ };
+ }
+ transaction.objectStore("games").delete(gameId);
+ });