X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=public%2Fjavascripts%2Fvariant.js;h=74c4298c03ef00af6456afdf462dab06d65416d7;hb=4608eed94432356bd2df8c144d7d233913c6483c;hp=f9d23d8bf67a175c2d4ef706527b7d4262c33b82;hpb=f5d3e4f539355d166baf38bab97480582e90e4af;p=vchess.git diff --git a/public/javascripts/variant.js b/public/javascripts/variant.js index f9d23d8b..74c4298c 100644 --- a/public/javascripts/variant.js +++ b/public/javascripts/variant.js @@ -1,7 +1,76 @@ new Vue({ - el: "#variantPage", - data: { display: "" }, //do not show anything... - // TODO: listen event "show problem", avec le probleme stringifié en arg - // Alors: display=game, mode=friend, newGame(fen, turn, ...), - // et set Instructions+Soluce + el: "#VueElement", + data: { + 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 + this.setDisplay(); + window.onhashchange = 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; + + //this.vr = new VariantRules( V.GenRandInitFen() ); + }, + methods: { + setDisplay: function() { + +//TODO: prevent set display if there is a running game + + if (!location.hash) + location.hash = "#room"; //default + this.display = location.hash.substr(1); + // 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 !