Commit | Line | Data |
---|---|---|
f5d3e4f5 | 1 | new Vue({ |
b57dbd12 | 2 | el: "#VueElement", |
c794dbb8 | 3 | data: { |
baba6070 | 4 | display: "undefined", //default to main hall; see "created()" function |
d44df0b0 | 5 | gameid: undefined, //...yet |
582df349 | 6 | queryHash: "", |
81bc1102 BA |
7 | conn: null, |
8 | ||
582df349 BA |
9 | // Settings initialized with values from localStorage |
10 | settings: { | |
11 | bcolor: localStorage["bcolor"] || "lichess", | |
12 | sound: parseInt(localStorage["sound"]) || 2, | |
13 | hints: parseInt(localStorage["hints"]) || 1, | |
14 | coords: !!eval(localStorage["coords"]), | |
15 | highlight: !!eval(localStorage["highlight"]), | |
16 | sqSize: parseInt(localStorage["sqSize"]), | |
17 | }, | |
18 | ||
baba6070 | 19 | // TEMPORARY: DEBUG |
baba6070 BA |
20 | mode: "analyze", |
21 | orientation: "w", | |
22 | userColor: "w", | |
d44df0b0 | 23 | allowChat: false, |
7d9e99bc | 24 | allowMovelist: true, |
d44df0b0 | 25 | fen: V.GenRandInitFen(), |
c794dbb8 | 26 | }, |
d449ae46 | 27 | created: function() { |
582df349 BA |
28 | if (!!localStorage["variant"]) |
29 | { | |
30 | location.hash = "#game?id=" + localStorage["gameId"]; | |
31 | this.display = location.hash.substr(1); | |
32 | } | |
33 | else | |
34 | this.setDisplay(); | |
4608eed9 | 35 | window.onhashchange = this.setDisplay; |
d44df0b0 BA |
36 | this.myid = "abcdefghij"; |
37 | //console.log(this.myid + " " + variant); | |
59d58d7d | 38 | //myid: localStorage.getItem("myid"), //our ID, always set |
baba6070 | 39 | |
d44df0b0 | 40 | this.conn = new WebSocket(socketUrl + "/?sid=" + this.myid + "&page=" + variant.id); |
81bc1102 | 41 | const socketCloseListener = () => { |
d44df0b0 | 42 | this.conn = new WebSocket(socketUrl + "/?sid=" + this.myid + "&page=" + variant.id); |
81bc1102 BA |
43 | } |
44 | this.conn.onclose = socketCloseListener; | |
45 | ||
d44df0b0 | 46 | //this.vr = new VariantRules( V.GenRandInitFen() ); |
d449ae46 | 47 | }, |
4ecf423b | 48 | methods: { |
582df349 BA |
49 | updateSettings: function(event) { |
50 | const propName = | |
51 | event.target.id.substr(3).replace(/^\w/, c => c.toLowerCase()) | |
52 | localStorage[propName] = ["highlight","coords"].includes(propName) | |
53 | ? event.target.checked | |
54 | : event.target.value; | |
55 | }, | |
d44df0b0 | 56 | setDisplay: function() { |
582df349 BA |
57 | // Prevent set display if there is a running game |
58 | if (!!localStorage["variant"]) | |
59 | return; | |
4608eed9 BA |
60 | if (!location.hash) |
61 | location.hash = "#room"; //default | |
582df349 BA |
62 | const hashParts = location.hash.substr(1).split("?"); |
63 | this.display = hashParts[0]; | |
64 | this.queryHash = hashParts[1]; //may be empty, undefined... | |
b6487fb9 | 65 | // Close menu on small screens: |
a5d56686 BA |
66 | let menuToggle = document.getElementById("drawer-control"); |
67 | if (!!menuToggle) | |
68 | menuToggle.checked = false; | |
e6dcb115 | 69 | }, |
4ecf423b | 70 | }, |
f5d3e4f5 | 71 | }); |
81da2786 | 72 | |
8d7e2786 BA |
73 | //const continuation = (localStorage.getItem("variant") === variant.name); |
74 | // if (continuation) //game VS human has priority | |
75 | // this.continueGame("human"); |