Commit | Line | Data |
---|---|---|
f5d3e4f5 | 1 | new Vue({ |
b57dbd12 | 2 | el: "#VueElement", |
c794dbb8 | 3 | data: { |
a3ab5fdb | 4 | display: "", //default to main hall; see "created()" function |
d44df0b0 | 5 | gameid: undefined, //...yet |
582df349 | 6 | queryHash: "", |
81bc1102 | 7 | conn: null, |
a3ab5fdb BA |
8 | mode: "analyze", |
9 | allowChat: false, | |
10 | allowMovelist: true, | |
582df349 BA |
11 | // Settings initialized with values from localStorage |
12 | settings: { | |
13 | bcolor: localStorage["bcolor"] || "lichess", | |
14 | sound: parseInt(localStorage["sound"]) || 2, | |
15 | hints: parseInt(localStorage["hints"]) || 1, | |
16 | coords: !!eval(localStorage["coords"]), | |
17 | highlight: !!eval(localStorage["highlight"]), | |
18 | sqSize: parseInt(localStorage["sqSize"]), | |
19 | }, | |
c794dbb8 | 20 | }, |
d449ae46 | 21 | created: function() { |
582df349 BA |
22 | if (!!localStorage["variant"]) |
23 | { | |
24 | location.hash = "#game?id=" + localStorage["gameId"]; | |
25 | this.display = location.hash.substr(1); | |
26 | } | |
27 | else | |
28 | this.setDisplay(); | |
4608eed9 | 29 | window.onhashchange = this.setDisplay; |
a3ab5fdb BA |
30 | // Our ID, always set (DB id if registered, collision-free random string otherwise) |
31 | this.myid = user.id || localStorage["myid"] || "anon-" + getRandString(); | |
d44df0b0 | 32 | this.conn = new WebSocket(socketUrl + "/?sid=" + this.myid + "&page=" + variant.id); |
81bc1102 | 33 | const socketCloseListener = () => { |
d44df0b0 | 34 | this.conn = new WebSocket(socketUrl + "/?sid=" + this.myid + "&page=" + variant.id); |
81bc1102 BA |
35 | } |
36 | this.conn.onclose = socketCloseListener; | |
d449ae46 | 37 | }, |
4ecf423b | 38 | methods: { |
582df349 BA |
39 | updateSettings: function(event) { |
40 | const propName = | |
41 | event.target.id.substr(3).replace(/^\w/, c => c.toLowerCase()) | |
42 | localStorage[propName] = ["highlight","coords"].includes(propName) | |
43 | ? event.target.checked | |
44 | : event.target.value; | |
45 | }, | |
a3ab5fdb BA |
46 | // Game is over, clear storage and put it in indexedDB |
47 | archiveGame: function() { | |
48 | // TODO: ... | |
49 | //clearStorage(); | |
50 | }, | |
d44df0b0 | 51 | setDisplay: function() { |
582df349 BA |
52 | // Prevent set display if there is a running game |
53 | if (!!localStorage["variant"]) | |
54 | return; | |
4608eed9 BA |
55 | if (!location.hash) |
56 | location.hash = "#room"; //default | |
582df349 BA |
57 | const hashParts = location.hash.substr(1).split("?"); |
58 | this.display = hashParts[0]; | |
59 | this.queryHash = hashParts[1]; //may be empty, undefined... | |
b6487fb9 | 60 | // Close menu on small screens: |
a5d56686 BA |
61 | let menuToggle = document.getElementById("drawer-control"); |
62 | if (!!menuToggle) | |
63 | menuToggle.checked = false; | |
e6dcb115 | 64 | }, |
4ecf423b | 65 | }, |
f5d3e4f5 | 66 | }); |