+ if (this.mode == "human")
+ {
+ delete localStorage["myid"];
+ delete localStorage["oppid"];
+ delete localStorage["gameId"];
+ }
+ const prefix = this.getStoragePrefix(this.mode);
+ 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...
+ // NOTE: seems to work only in chrome/chromium. TODO...
+ 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;
+ },
+ clearCurrentGame: function(e) {
+ this.getRidOfTooltip(e.currentTarget);
+ this.clearStorage();
+ 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");
+ },
+ setBoardColor: function(e) {
+ this.bcolor = e.target.options[e.target.selectedIndex].value;
+ localStorage["bcolor"] = this.bcolor;
+ },
+ setSound: function(e) {
+ this.sound = parseInt(e.target.options[e.target.selectedIndex].value);
+ localStorage["sound"] = this.sound;
+ },
+ clickGameSeek: function(e) {
+ this.getRidOfTooltip(e.currentTarget);
+ if (this.mode == "human")
+ return; //no newgame while playing
+ if (this.seek)
+ {
+ this.conn.send(JSON.stringify({code:"cancelnewgame"}));
+ this.seek = false;
+ }
+ else
+ this.newGame("human");
+ },
+ clickComputerGame: function(e) {
+ this.getRidOfTooltip(e.currentTarget);
+ if (this.mode == "computer" && this.score == "*"
+ && this.vr.turn != this.mycolor)
+ {
+ // Wait for computer reply first (avoid potential "ghost move" bug)
+ return;
+ }
+ this.newGame("computer");
+ },
+ clickFriendGame: function(e) {
+ this.getRidOfTooltip(e.currentTarget);
+ document.getElementById("modal-fenedit").checked = true;
+ },
+ resign: function(e) {
+ this.getRidOfTooltip(e.currentTarget);
+ if (this.mode == "human" && this.oppConnected)
+ {
+ try {
+ this.conn.send(JSON.stringify({code: "resign", oppid: this.oppid}));
+ } catch (INVALID_STATE_ERR) {
+ return; //socket is not ready (and not yet reconnected)
+ }
+ }
+ this.endGame(this.mycolor=="w"?"0-1":"1-0");
+ },
+ newGame: function(mode, fenInit, color, oppId) {
+ const fen = "nrqkbrnb/pppppppp/8/8/8/8/PPPPPPPP/RKQBNRBN w 1111 -";//fenInit || VariantRules.GenRandInitFen();