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