X-Git-Url: https://git.auder.net/img/rock_paper_scissors_lizard_spock.gif?a=blobdiff_plain;f=public%2Fjavascripts%2Fvariant.js;h=7d30d73102090b614f0167dfb7177c1f8c60df77;hb=81bc1102368a5a8b9358f58b77c241f82f3c2c4b;hp=510ea290e7cd8eb531f18ea5610c7b7e740750b7;hpb=81da2786f2f497b4416e0488c34a48fb794c28df;p=vchess.git diff --git a/public/javascripts/variant.js b/public/javascripts/variant.js index 510ea290..7d30d731 100644 --- a/public/javascripts/variant.js +++ b/public/javascripts/variant.js @@ -1,15 +1,30 @@ new Vue({ - el: "#variantPage", + el: "#VueElement", data: { - display: "room", //default: main hall + display: "undefined", //default to main hall; see "created()" function gameid: "undefined", //...yet + + conn: null, + + // TEMPORARY: DEBUG + mode: "analyze", + orientation: "w", + userColor: "w", }, 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.conn = new WebSocket(url + "/?sid=" + this.myid + "&page=" + variant._id); + const socketCloseListener = () => { + this.conn = new WebSocket(url + "/?sid=" + this.myid + "&page=" + variant._id); + } + this.conn.onclose = socketCloseListener; + + this.vr = new VariantRules( V.GenRandInitFen() ); }, methods: { setDisplay: function(elt) { @@ -19,12 +34,33 @@ 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); + }, }, }); -const continuation = (localStorage.getItem("variant") === variant); - if (continuation) //game VS human has priority - this.continueGame("human"); +//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 !