X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=public%2Fjavascripts%2Fvariant.js;h=e24dfc688433da348a93d5ccf1e245a3300599bb;hb=d44df0b01732d1948525daef5df62211ea6e1f64;hp=1ec4d89b16bf5dfaee41bee37a28bfdcf8968353;hpb=b57dbd126734b4398861292c611197c6991ed3eb;p=vchess.git diff --git a/public/javascripts/variant.js b/public/javascripts/variant.js index 1ec4d89b..e24dfc68 100644 --- a/public/javascripts/variant.js +++ b/public/javascripts/variant.js @@ -1,24 +1,70 @@ new Vue({ el: "#VueElement", data: { - display: "room", //default: main hall - gameid: "undefined", //...yet + display: "undefined", //default to main hall; see "created()" function + gameid: undefined, //...yet + + conn: null, + + // TEMPORARY: DEBUG + mode: "analyze", + orientation: "w", + userColor: "w", + + allowChat: false, + allowMovelist: false, + 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)); + this.setDisplay(); + + + this.myid = "abcdefghij"; +//console.log(this.myid + " " + variant); + + 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; + + window.onhashchange = this.setDisplay; + //this.vr = new VariantRules( V.GenRandInitFen() ); }, methods: { - setDisplay: function(elt) { - this.display = elt; + setDisplay: function() { + +//TODO: prevent set display if there is a running game + + const page = (location.hash || "#room").substr(1); + this.display = page; // 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); + }, }, });