X-Git-Url: https://git.auder.net/?p=vchess.git;a=blobdiff_plain;f=public%2Fjavascripts%2Fvariant.js;h=606c1b9a2520cb7beff1ea44e93967dcbac65ae8;hp=c1ba85736dd39ad6b795fa12062f809956e9c01c;hb=582df3497b0f91dd4b645386a059eac9e98da1bb;hpb=59d58d7da742c937bca80c2102c2e72cc7d6e840 diff --git a/public/javascripts/variant.js b/public/javascripts/variant.js index c1ba8573..606c1b9a 100644 --- a/public/javascripts/variant.js +++ b/public/javascripts/variant.js @@ -3,23 +3,36 @@ new Vue({ data: { 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 - this.setDisplay(); + 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 @@ -33,45 +46,30 @@ new Vue({ //this.vr = new VariantRules( V.GenRandInitFen() ); }, methods: { + 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() { - -//TODO: prevent set display if there is a running game - + // Prevent set display if there is a running game + if (!!localStorage["variant"]) + return; if (!location.hash) location.hash = "#room"; //default - this.display = location.hash.substr(1); + 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; }, - - // TEMPORARY: DEBUG (duplicate code) - play: function(move) { - // Not programmatic, or animation is over - if (!move.notation) - move.notation = this.vr.getNotation(move); - this.vr.play(move); - if (!move.fen) - move.fen = this.vr.getFen(); - if (this.sound == 2) - new Audio("/sounds/move.mp3").play().catch(err => {}); - // Is opponent in check? - this.incheck = this.vr.getCheckSquares(this.vr.turn); - const score = this.vr.getCurrentScore(); - }, - undo: function(move) { - this.vr.undo(move); - if (this.sound == 2) - new Audio("/sounds/undo.mp3").play().catch(err => {}); - this.incheck = this.vr.getCheckSquares(this.vr.turn); - }, }, }); //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 !