From: Benjamin Auder Date: Mon, 27 May 2019 18:40:25 +0000 (+0200) Subject: TODO: game storage init + get X-Git-Url: https://git.auder.net/%7B%7B%20asset%28%27mixstore/images/scripts/current/doc/%7B%7B%20targetUrl%20%7D%7D?a=commitdiff_plain;h=ce87ac6a12007a62a55a45e404f818df3eb90f64;p=vchess.git TODO: game storage init + get --- diff --git a/client/src/utils/storage.js b/client/src/utils/storage.js index bb7fdce7..ab459662 100644 --- a/client/src/utils/storage.js +++ b/client/src/utils/storage.js @@ -2,9 +2,11 @@ // 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); @@ -12,6 +14,21 @@ export const GameStorage = 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 ? diff --git a/client/src/views/Game.vue b/client/src/views/Game.vue index c60b17c7..7a99ef9b 100644 --- a/client/src/views/Game.vue +++ b/client/src/views/Game.vue @@ -48,6 +48,7 @@ export default { 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) }; @@ -242,7 +243,11 @@ export default { // - 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); @@ -260,6 +265,9 @@ export default { oppConnected: function(uid) { return this.opponents.some(o => o.id == uid && o.online); }, + processMove: function(move) { + // TODO: process some opponent's move + }, }, }; diff --git a/client/src/views/Hall.vue b/client/src/views/Hall.vue index 97df499a..9b891d75 100644 --- a/client/src/views/Hall.vue +++ b/client/src/views/Hall.vue @@ -584,6 +584,8 @@ export default { }, // 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);