my-board seems OK. Now TODO: test my-game (with sockets)
[vchess.git] / public / javascripts / variant.js
CommitLineData
f5d3e4f5 1new Vue({
b57dbd12 2 el: "#VueElement",
c794dbb8 3 data: {
baba6070 4 display: "undefined", //default to main hall; see "created()" function
298c42e6 5 gameid: "undefined", //...yet
baba6070
BA
6
7 // TEMPORARY: DEBUG
8 vr: null,
9 mode: "analyze",
10 orientation: "w",
11 userColor: "w",
12 gameOver: false,
c794dbb8 13 },
d449ae46 14 created: function() {
b6487fb9 15 // TODO: navigation becomes a little more complex
d449ae46
BA
16 const url = window.location.href;
17 const hashPos = url.indexOf("#");
baba6070
BA
18 const page = (hashPos >= 0 ? url.substr(hashPos+1) : "room");
19 this.setDisplay(page);
20
21 this.vr = new VariantRules( V.GenRandInitFen() );
d449ae46 22 },
4ecf423b 23 methods: {
e6dcb115
BA
24 setDisplay: function(elt) {
25 this.display = elt;
b6487fb9 26 // Close menu on small screens:
a5d56686
BA
27 let menuToggle = document.getElementById("drawer-control");
28 if (!!menuToggle)
29 menuToggle.checked = false;
e6dcb115 30 },
baba6070
BA
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 },
4ecf423b 52 },
f5d3e4f5 53});
81da2786 54
8d7e2786
BA
55//const continuation = (localStorage.getItem("variant") === variant.name);
56// if (continuation) //game VS human has priority
57// this.continueGame("human");
b6487fb9
BA
58
59// TODO:
60// si quand on arrive il y a une continuation "humaine" : display="game" et retour à la partie !