X-Git-Url: https://git.auder.net/pieces/Cwda/n_white_knight.svg?a=blobdiff_plain;f=client%2Fsrc%2Fmain.js;h=c48985dddaf4f600765c7acb979ff763a2dc623c;hb=8d61fc4ab7373b4a576f3f9108cdf7768ae27096;hp=1fe69b2b5e4fdd282a8ecbdbc3bd8a964616e2fe;hpb=b644ef7f0302dcb024e5214600d13883906faed0;p=vchess.git diff --git a/client/src/main.js b/client/src/main.js index 1fe69b2b..c48985dd 100644 --- a/client/src/main.js +++ b/client/src/main.js @@ -12,9 +12,6 @@ new Vue({ render: function(h) { return h(App); }, -// data: { -// lang: "", -// }, watch: { $lang: async function(newLang) { // Fill modalWelcome, and import translations from "./translations/$lang.js" @@ -24,6 +21,10 @@ new Vue({ Vue.prototype.$tr = tModule.translations; //console.log(tModule.translations); }, + $route: function(newRoute) { + console.log(this.$route.params); + //TODO: conn.send("enter", newRoute) + }, }, created: function() { const supportedLangs = ["en","es","fr"]; @@ -31,20 +32,33 @@ new Vue({ supportedLangs.includes(navigator.language) ? navigator.language : "en"; - ajax("/variants", "GET", res => { - Vue.prototype.$variants = res.variantArray; - }); + ajax("/variants", "GET", res => { Vue.prototype.$variants = res.variantArray; }); Vue.prototype.$tr = {}; //to avoid a compiler error // TODO: if there is a socket ID in localStorage, it means a live game was interrupted (and should resume) const myid = localStorage["myid"] || util.getRandString(); // NOTE: in this version, we don't say on which page we are, yet // ==> we'll say "enter/leave" page XY (in fact juste "enter", seemingly) Vue.prototype.$conn = new WebSocket(params.socketUrl + "/?sid=" + myid); + // Settings initialized with values from localStorage + Vue.prototype.$settings = { + bcolor: localStorage["bcolor"] || "lichess", + sound: parseInt(localStorage["sound"]) || 2, + hints: parseInt(localStorage["hints"]) || 1, + coords: !!eval(localStorage["coords"]), + highlight: !!eval(localStorage["highlight"]), + sqSize: parseInt(localStorage["sqSize"]), + }; + const socketCloseListener = () => { + Vue.prototype.$conn = new WebSocket(params.socketUrl + "/?sid=" + myid); + } + Vue.prototype.$conn.onclose = socketCloseListener; //TODO: si une partie en cours dans storage, rediriger vers cette partie //(à condition que l'URL n'y corresponde pas déjà !) // TODO: à l'arrivée sur le site : set peerID (un identifiant unique // en tout cas...) si pas trouvé dans localStorage "myid" // (l'identifiant de l'utilisateur si connecté) +// if (!!localStorage["variant"]) +// location.hash = "#game?id=" + localStorage["gameId"]; }, // Later, for icons (if using feather): // mounted: function() { @@ -63,10 +77,8 @@ new Vue({ // game : aussi systématique // problems: on-demand // -// It works (to watch for route change), in a component: -//watch: { -// $route: function(newRoute) { -// console.log(this.$route.params); -// }, -//}, // See https://router.vuejs.org/guide/essentials/dynamic-matching.html#reacting-to-params-changes +// created: function() { +// window.onhashchange = this.setDisplay; +// }, +//});