X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=public%2Fjavascripts%2Fvariant.js;h=606c1b9a2520cb7beff1ea44e93967dcbac65ae8;hb=582df3497b0f91dd4b645386a059eac9e98da1bb;hp=eac1ec0920790e3d719a9d76c693086ad3f6eb4c;hpb=8d7e2786f5a67a1b9a77c742d7951e0efbe8747d;p=vchess.git diff --git a/public/javascripts/variant.js b/public/javascripts/variant.js index eac1ec09..606c1b9a 100644 --- a/public/javascripts/variant.js +++ b/public/javascripts/variant.js @@ -1,19 +1,67 @@ new Vue({ - el: "#variantPage", + el: "#VueElement", data: { - display: "room", //default: main hall - gameid: "undefined", //...yet + 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() { - // TODO: navigation becomes a little more complex - 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: { - setDisplay: function(elt) { - this.display = elt; + 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() { + // 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) @@ -25,6 +73,3 @@ new Vue({ //const continuation = (localStorage.getItem("variant") === variant.name); // if (continuation) //game VS human has priority // this.continueGame("human"); - -// TODO: -// si quand on arrive il y a une continuation "humaine" : display="game" et retour à la partie !