// https://developer.mozilla.org/fr/docs/Web/API/API_IndexedDB
// https://dexie.org/
+import { storageState } from "@/store";
+
export const GameStorage =
{
- init: function(myid, oppid, gameId, variant, mycolor, fenStart)
+ init: function(myid, oppid, gameId, variant, mycolor, fenStart, mode)
{
localStorage.setItem("myid", myid);
localStorage.setItem("gameId", gameId);
localStorage.setItem("mycolor", mycolor);
localStorage.setItem("fenStart", fenStart);
localStorage.setItem("moves", []);
+
+
+
+ game.score = localStorage.getItem("score");
+ game.mycolor = localStorage.getItem("mycolor");
+ game.fenStart = localStorage.getItem("fenStart");
+ game.fen = localStorage.getItem("fen");
+ game.moves = JSON.parse(localStorage.getItem("moves"));
+ game.players = JSON.parse(localStorage.getItem("players"));
+ game.started = JSON.parse(localStorage.getItem("started"));
+ game.clocks = JSON.parse(localStorage.getItem("clocks"));
+ game.timeControl = localStorage.getItem("timeControl");
+ game.increment = localStorage.getItem("increment");
+ game.vname = localStorage.getItem("vname");
+ game.mode = "live";
},
// TODO: also option to takeback a move ?
gameInfo: {}, //passed to BaseGame
vr: null, //TODO
vname: "", //obtained from gameInfo (slightly redundant..)
+ mode: "analyze", //mutable
drawOfferSent: false, //did I just ask for draw? (TODO: draw variables?)
people: [], //potential observers (TODO)
};
// - from remote peer (one live game I don't play, finished or not)
loadGame: async function() {
this.gameInfo = GameStorage.get(this.gameRef);
+
+console.log(GameStorage.get(this.gameRef));
+
this.vname = this.gameInfo.vname;
+ this.mode = this.gameInfo.mode;
const vModule = await import("@/variants/" + this.vname + ".js");
window.V = vModule.VariantRules;
this.vr = new V(this.gameInfo.fen);
oppConnected: function(uid) {
return this.opponents.some(o => o.id == uid && o.online);
},
+ processMove: function(move) {
+ // TODO: process some opponent's move
+ },
},
};
</script>
},
// NOTE: for live games only (corr games are launched on server)
newGame: function(gameInfo) {
+ GameStorage.init(); //TODO here
+
localStorage["gid"] = getRandString();
// Extract times (in [milli]seconds), set clocks, store in localStorage
const tc = extractTime(gameInfo.timeControl);