X-Git-Url: https://git.auder.net/variants/Dynamo/complete_rules.html?a=blobdiff_plain;f=public%2Fjavascripts%2Fvariant.js;h=453656cab7d3c84d8dbfa181c7af74e29f7cee25;hb=baba60703f661aab20f2327098c3a0af572f0704;hp=a7d182007cfce345367cbb9d4d65b985defcb052;hpb=4fefd0195b2dc8559284d3b3701a242a862cb70e;p=vchess.git diff --git a/public/javascripts/variant.js b/public/javascripts/variant.js index a7d18200..453656ca 100644 --- a/public/javascripts/variant.js +++ b/public/javascripts/variant.js @@ -1,25 +1,60 @@ 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 + + // TEMPORARY: DEBUG + vr: null, + mode: "analyze", + orientation: "w", + userColor: "w", + gameOver: false, }, 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)); + const page = (hashPos >= 0 ? url.substr(hashPos+1) : "room"); + this.setDisplay(page); + + this.vr = new VariantRules( V.GenRandInitFen() ); }, methods: { - showProblem: function(problemTxt) { - this.problem = JSON.parse(problemTxt); - this.display = "play"; - }, setDisplay: function(elt) { this.display = elt; + // 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 !