+ if (["human","computer"].includes(this.mode))
+ {
+ const prefix = (this.mode=="computer" ? "comp-" : "");
+ localStorage.setItem(prefix+"score", score);
+ }
+ this.showScoreMsg();
+ // Variants may have special PGN structure (so next function isn't defined here)
+ this.pgnTxt = this.vr.getPGN(this.mycolor, this.score, this.fenStart, this.mode);
+ 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.mode = (this.mode=="human" ? "chat" : "idle");
+ this.cursor = this.vr.moves.length; //to navigate in finished game
+ },
+ setStorage: function() {
+ if (this.mode=="human")
+ {
+ localStorage.setItem("myid", this.myid);
+ localStorage.setItem("oppid", this.oppid);
+ localStorage.setItem("gameId", this.gameId);
+ }
+ // 'prefix' = "comp-" to resume games vs. computer
+ const prefix = (this.mode=="computer" ? "comp-" : "");
+ 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.mode=="computer" ? "comp-" : "");
+ 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() {
+ if (["human","chat"].includes(this.mode))
+ {
+ delete localStorage["myid"];
+ delete localStorage["oppid"];
+ delete localStorage["gameId"];
+ }
+ const prefix = (this.mode=="computer" ? "comp-" : "");
+ delete localStorage[prefix+"variant"];
+ delete localStorage[prefix+"mycolor"];
+ delete localStorage[prefix+"fenStart"];
+ delete localStorage[prefix+"moves"];
+ delete localStorage[prefix+"fen"];
+ delete localStorage[prefix+"score"];
+ },
+ // HACK because mini-css tooltips are persistent after click...
+ getRidOfTooltip: function(elt) {
+ elt.style.visibility = "hidden";
+ setTimeout(() => { elt.style.visibility="visible"; }, 100);
+ },
+ startChat: function(e) {
+ this.getRidOfTooltip(e.currentTarget);
+ document.getElementById("modal-chat").checked = true;
+ },
+ clearComputerGame: function(e) {
+ this.getRidOfTooltip(e.currentTarget);
+ this.clearStorage(); //this.mode=="computer" (already checked)
+ location.reload(); //to see clearing effects
+ },
+ showSettings: function(e) {
+ this.getRidOfTooltip(e.currentTarget);
+ document.getElementById("modal-settings").checked = true;
+ },
+ toggleHints: function() {
+ this.hints = !this.hints;
+ localStorage["hints"] = (this.hints ? "1" : "0");
+ },
+ setColor: function(e) {
+ this.color = e.target.options[e.target.selectedIndex].value;
+ localStorage["color"] = this.color;
+ },
+ setSound: function(e) {
+ this.sound = parseInt(e.target.options[e.target.selectedIndex].value);
+ localStorage["sound"] = this.sound;
+ },
+ clickGameSeek: function(e) {
+ this.getRidOfTooltip(e.currentTarget);