| 1 | new Vue({ |
| 2 | el: "#VueElement", |
| 3 | data: { |
| 4 | display: "undefined", //default to main hall; see "created()" function |
| 5 | gameid: undefined, //...yet |
| 6 | |
| 7 | conn: null, |
| 8 | |
| 9 | // TEMPORARY: DEBUG |
| 10 | mode: "analyze", |
| 11 | orientation: "w", |
| 12 | userColor: "w", |
| 13 | |
| 14 | allowChat: false, |
| 15 | allowMovelist: false, |
| 16 | fen: V.GenRandInitFen(), |
| 17 | }, |
| 18 | created: function() { |
| 19 | // TODO: navigation becomes a little more complex |
| 20 | this.setDisplay(); |
| 21 | window.onhashchange = this.setDisplay; |
| 22 | |
| 23 | this.myid = "abcdefghij"; |
| 24 | //console.log(this.myid + " " + variant); |
| 25 | |
| 26 | this.conn = new WebSocket(socketUrl + "/?sid=" + this.myid + "&page=" + variant.id); |
| 27 | const socketCloseListener = () => { |
| 28 | this.conn = new WebSocket(socketUrl + "/?sid=" + this.myid + "&page=" + variant.id); |
| 29 | } |
| 30 | this.conn.onclose = socketCloseListener; |
| 31 | |
| 32 | //this.vr = new VariantRules( V.GenRandInitFen() ); |
| 33 | }, |
| 34 | methods: { |
| 35 | setDisplay: function() { |
| 36 | |
| 37 | //TODO: prevent set display if there is a running game |
| 38 | |
| 39 | if (!location.hash) |
| 40 | location.hash = "#room"; //default |
| 41 | this.display = location.hash.substr(1); |
| 42 | // Close menu on small screens: |
| 43 | let menuToggle = document.getElementById("drawer-control"); |
| 44 | if (!!menuToggle) |
| 45 | menuToggle.checked = false; |
| 46 | }, |
| 47 | |
| 48 | // TEMPORARY: DEBUG (duplicate code) |
| 49 | play: function(move) { |
| 50 | // Not programmatic, or animation is over |
| 51 | if (!move.notation) |
| 52 | move.notation = this.vr.getNotation(move); |
| 53 | this.vr.play(move); |
| 54 | if (!move.fen) |
| 55 | move.fen = this.vr.getFen(); |
| 56 | if (this.sound == 2) |
| 57 | new Audio("/sounds/move.mp3").play().catch(err => {}); |
| 58 | // Is opponent in check? |
| 59 | this.incheck = this.vr.getCheckSquares(this.vr.turn); |
| 60 | const score = this.vr.getCurrentScore(); |
| 61 | }, |
| 62 | undo: function(move) { |
| 63 | this.vr.undo(move); |
| 64 | if (this.sound == 2) |
| 65 | new Audio("/sounds/undo.mp3").play().catch(err => {}); |
| 66 | this.incheck = this.vr.getCheckSquares(this.vr.turn); |
| 67 | }, |
| 68 | }, |
| 69 | }); |
| 70 | |
| 71 | //const continuation = (localStorage.getItem("variant") === variant.name); |
| 72 | // if (continuation) //game VS human has priority |
| 73 | // this.continueGame("human"); |
| 74 | |
| 75 | // TODO: |
| 76 | // si quand on arrive il y a une continuation "humaine" : display="game" et retour à la partie ! |