Advance on components/game.js
[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
d44df0b0 5 gameid: undefined, //...yet
81bc1102
BA
6
7 conn: null,
8
baba6070 9 // TEMPORARY: DEBUG
baba6070
BA
10 mode: "analyze",
11 orientation: "w",
12 userColor: "w",
d44df0b0
BA
13
14 allowChat: false,
15 allowMovelist: false,
16 fen: V.GenRandInitFen(),
c794dbb8 17 },
d449ae46 18 created: function() {
b6487fb9 19 // TODO: navigation becomes a little more complex
d44df0b0
BA
20 this.setDisplay();
21
22
23 this.myid = "abcdefghij";
24//console.log(this.myid + " " + variant);
baba6070 25
d44df0b0 26 this.conn = new WebSocket(socketUrl + "/?sid=" + this.myid + "&page=" + variant.id);
81bc1102 27 const socketCloseListener = () => {
d44df0b0 28 this.conn = new WebSocket(socketUrl + "/?sid=" + this.myid + "&page=" + variant.id);
81bc1102
BA
29 }
30 this.conn.onclose = socketCloseListener;
31
d44df0b0
BA
32 window.onhashchange = this.setDisplay;
33 //this.vr = new VariantRules( V.GenRandInitFen() );
d449ae46 34 },
4ecf423b 35 methods: {
d44df0b0
BA
36 setDisplay: function() {
37
38//TODO: prevent set display if there is a running game
39
40 const page = (location.hash || "#room").substr(1);
41 this.display = page;
b6487fb9 42 // Close menu on small screens:
a5d56686
BA
43 let menuToggle = document.getElementById("drawer-control");
44 if (!!menuToggle)
45 menuToggle.checked = false;
e6dcb115 46 },
baba6070
BA
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 },
4ecf423b 68 },
f5d3e4f5 69});
81da2786 70
8d7e2786
BA
71//const continuation = (localStorage.getItem("variant") === variant.name);
72// if (continuation) //game VS human has priority
73// this.continueGame("human");
b6487fb9
BA
74
75// TODO:
76// si quand on arrive il y a une continuation "humaine" : display="game" et retour à la partie !