X-Git-Url: https://git.auder.net/?p=vchess.git;a=blobdiff_plain;f=public%2Fjavascripts%2Fvariant.js;fp=public%2Fjavascripts%2Fvariant.js;h=453656cab7d3c84d8dbfa181c7af74e29f7cee25;hp=1ec4d89b16bf5dfaee41bee37a28bfdcf8968353;hb=baba60703f661aab20f2327098c3a0af572f0704;hpb=fd08ab2c5b8931bb8c95cf7e9f2f95122647f991 diff --git a/public/javascripts/variant.js b/public/javascripts/variant.js index 1ec4d89b..453656ca 100644 --- a/public/javascripts/variant.js +++ b/public/javascripts/variant.js @@ -1,15 +1,24 @@ new Vue({ el: "#VueElement", data: { - display: "room", //default: main hall + 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: { setDisplay: function(elt) { @@ -19,6 +28,27 @@ new Vue({ 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); + }, }, });