+ if (["human","computer"].includes(this.mode))
+ {
+ const prefix = (this.mode=="computer" ? "comp-" : "");
+ localStorage.setItem(prefix+"score", score);
+ }
+ this.showScoreMsg();
+ if (this.mode == "human" && this.oppConnected)
+ {
+ // Send our nickname to opponent
+ this.conn.send(JSON.stringify({
+ code:"myname", name:this.myname, oppid:this.oppid}));
+ }
+ this.cursor = this.vr.moves.length; //to navigate in finished game
+ },
+ getStoragePrefix: function(mode) {
+ let prefix = "";
+ if (mode == "computer")
+ prefix = "comp-";
+ else if (mode == "friend")
+ prefix = "anlz-";
+ return prefix;
+ },
+ setStorage: function() {
+ if (this.mode=="human")
+ {
+ localStorage.setItem("myid", this.myid);
+ localStorage.setItem("oppid", this.oppid);
+ localStorage.setItem("gameId", this.gameId);
+ }
+ const prefix = this.getStoragePrefix(this.mode);
+ localStorage.setItem(prefix+"variant", variant);
+ localStorage.setItem(prefix+"mycolor", this.mycolor);
+ localStorage.setItem(prefix+"fenStart", this.fenStart);
+ localStorage.setItem(prefix+"moves", JSON.stringify(this.vr.moves));
+ localStorage.setItem(prefix+"fen", this.vr.getFen());
+ localStorage.setItem(prefix+"score", "*");
+ },
+ updateStorage: function() {
+ const prefix = this.getStoragePrefix(this.mode);
+ localStorage.setItem(prefix+"moves", JSON.stringify(this.vr.moves));
+ localStorage.setItem(prefix+"fen", this.vr.getFen());
+ if (this.score != "*")
+ localStorage.setItem(prefix+"score", this.score);
+ },
+ // "computer mode" clearing is done through the menu
+ clearStorage: function() {