TODO: modalSettings + finish game.js for other scenarios
[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,
7d9e99bc 15 allowMovelist: true,
d44df0b0 16 fen: V.GenRandInitFen(),
c794dbb8 17 },
d449ae46 18 created: function() {
b6487fb9 19 // TODO: navigation becomes a little more complex
d44df0b0 20 this.setDisplay();
4608eed9 21 window.onhashchange = this.setDisplay;
d44df0b0
BA
22
23 this.myid = "abcdefghij";
24//console.log(this.myid + " " + variant);
59d58d7d 25 //myid: localStorage.getItem("myid"), //our ID, always set
baba6070 26
d44df0b0 27 this.conn = new WebSocket(socketUrl + "/?sid=" + this.myid + "&page=" + variant.id);
81bc1102 28 const socketCloseListener = () => {
d44df0b0 29 this.conn = new WebSocket(socketUrl + "/?sid=" + this.myid + "&page=" + variant.id);
81bc1102
BA
30 }
31 this.conn.onclose = socketCloseListener;
32
d44df0b0 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
4608eed9
BA
40 if (!location.hash)
41 location.hash = "#room"; //default
42 this.display = location.hash.substr(1);
b6487fb9 43 // Close menu on small screens:
a5d56686
BA
44 let menuToggle = document.getElementById("drawer-control");
45 if (!!menuToggle)
46 menuToggle.checked = false;
e6dcb115 47 },
baba6070
BA
48
49 // TEMPORARY: DEBUG (duplicate code)
50 play: function(move) {
51 // Not programmatic, or animation is over
52 if (!move.notation)
53 move.notation = this.vr.getNotation(move);
54 this.vr.play(move);
55 if (!move.fen)
56 move.fen = this.vr.getFen();
57 if (this.sound == 2)
58 new Audio("/sounds/move.mp3").play().catch(err => {});
59 // Is opponent in check?
60 this.incheck = this.vr.getCheckSquares(this.vr.turn);
61 const score = this.vr.getCurrentScore();
62 },
63 undo: function(move) {
64 this.vr.undo(move);
65 if (this.sound == 2)
66 new Audio("/sounds/undo.mp3").play().catch(err => {});
67 this.incheck = this.vr.getCheckSquares(this.vr.turn);
68 },
4ecf423b 69 },
f5d3e4f5 70});
81da2786 71
8d7e2786
BA
72//const continuation = (localStorage.getItem("variant") === variant.name);
73// if (continuation) //game VS human has priority
74// this.continueGame("human");
b6487fb9
BA
75
76// TODO:
77// si quand on arrive il y a une continuation "humaine" : display="game" et retour à la partie !