X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=public%2Fjavascripts%2Fvariant.js;h=606c1b9a2520cb7beff1ea44e93967dcbac65ae8;hb=582df3497b0f91dd4b645386a059eac9e98da1bb;hp=819bf90fd10b6d8e9c4df595fe2fa09ee404346f;hpb=375ecdd1387e729f85ed114e82253469e4849869;p=vchess.git diff --git a/public/javascripts/variant.js b/public/javascripts/variant.js index 819bf90f..606c1b9a 100644 --- a/public/javascripts/variant.js +++ b/public/javascripts/variant.js @@ -1,28 +1,75 @@ new Vue({ - el: "#variantPage", + el: "#VueElement", data: { - display: "play", //default: play! - problem: undefined, //current problem in view + display: "undefined", //default to main hall; see "created()" function + gameid: undefined, //...yet + queryHash: "", + conn: null, + + // Settings initialized with values from localStorage + settings: { + bcolor: localStorage["bcolor"] || "lichess", + sound: parseInt(localStorage["sound"]) || 2, + hints: parseInt(localStorage["hints"]) || 1, + coords: !!eval(localStorage["coords"]), + highlight: !!eval(localStorage["highlight"]), + sqSize: parseInt(localStorage["sqSize"]), + }, + + // TEMPORARY: DEBUG + mode: "analyze", + orientation: "w", + userColor: "w", + allowChat: false, + allowMovelist: true, + fen: V.GenRandInitFen(), }, created: function() { - const url = window.location.href; - const hashPos = url.indexOf("#"); - if (hashPos >= 0) - this.setDisplay(url.substr(hashPos+1)); + if (!!localStorage["variant"]) + { + location.hash = "#game?id=" + localStorage["gameId"]; + this.display = location.hash.substr(1); + } + else + this.setDisplay(); + window.onhashchange = this.setDisplay; + this.myid = "abcdefghij"; +//console.log(this.myid + " " + variant); + //myid: localStorage.getItem("myid"), //our ID, always set + + this.conn = new WebSocket(socketUrl + "/?sid=" + this.myid + "&page=" + variant.id); + const socketCloseListener = () => { + this.conn = new WebSocket(socketUrl + "/?sid=" + this.myid + "&page=" + variant.id); + } + this.conn.onclose = socketCloseListener; + + //this.vr = new VariantRules( V.GenRandInitFen() ); }, methods: { - showProblem: function(problemTxt) { - this.problem = JSON.parse(problemTxt); - this.display = "play"; + updateSettings: function(event) { + const propName = + event.target.id.substr(3).replace(/^\w/, c => c.toLowerCase()) + localStorage[propName] = ["highlight","coords"].includes(propName) + ? event.target.checked + : event.target.value; }, - setDisplay: function(elt) { - this.display = elt; + setDisplay: function() { + // Prevent set display if there is a running game + if (!!localStorage["variant"]) + return; + if (!location.hash) + location.hash = "#room"; //default + const hashParts = location.hash.substr(1).split("?"); + this.display = hashParts[0]; + this.queryHash = hashParts[1]; //may be empty, undefined... + // Close menu on small screens: let menuToggle = document.getElementById("drawer-control"); if (!!menuToggle) menuToggle.checked = false; }, - notDark: function() { - return variant != "Dark"; - }, }, }); + +//const continuation = (localStorage.getItem("variant") === variant.name); +// if (continuation) //game VS human has priority +// this.continueGame("human");