+ setSound: function(e) {
+ this.sound = parseInt(e.target.options[e.target.selectedIndex].value);
+ localStorage["sound"] = this.sound;
+ },
+
+ // TODO: in another component
+ trySendChat: function(e) {
+ if (e.keyCode == 13) //'enter' key
+ this.sendChat();
+ },
+ sendChat: function() {
+ let chatInput = document.getElementById("input-chat");
+ const chatTxt = chatInput.value;
+ chatInput.value = "";
+ this.chats.push({msg:chatTxt, author:this.myid});
+ this.conn.send(JSON.stringify({
+ code:"newchat", oppid: this.oppid, msg: chatTxt}));
+ },
+ startChat: function(e) {
+ this.getRidOfTooltip(e.currentTarget);
+ document.getElementById("modal-chat").checked = true;
+ },
+
+ // TODO: in problems component
+ toggleShowSolution: function() {
+ let problemSolution = document.getElementById("problem-solution");
+ problemSolution.style.display =
+ !problemSolution.style.display || problemSolution.style.display == "none"
+ ? "block"
+ : "none";
+ },
+
+ download: function() {
+ // Variants may have special PGN structure (so next function isn't defined here)
+ const content = this.vr.getPGN(this.mycolor, this.score, this.fenStart, this.mode);
+ // Prepare and trigger download link
+ let downloadAnchor = document.getElementById("download");
+ downloadAnchor.setAttribute("download", "game.pgn");
+ downloadAnchor.href = "data:text/plain;charset=utf-8," + encodeURIComponent(content);
+ downloadAnchor.click();
+ },
+ showScoreMsg: function() {
+ let modalBox = document.getElementById("modal-eog");
+ modalBox.checked = true;
+ setTimeout(() => { modalBox.checked = false; }, 2000);
+ },
+ endGame: function(score) {
+ this.score = score;
+ if (["human","computer"].includes(this.mode))
+ {
+ const prefix = (this.mode=="computer" ? "comp-" : "");
+ localStorage.setItem(prefix+"score", score);
+ }
+ this.showScoreMsg();