Commit | Line | Data |
---|---|---|
625022fd BA |
1 | import Vue from "vue"; |
2 | import App from "./App.vue"; | |
3 | import router from "./router"; | |
03470390 | 4 | import params from "./parameters"; //for socket connection |
625022fd | 5 | import { ajax } from "./utils/ajax"; |
98db2082 | 6 | import { util } from "./utils/misc"; |
625022fd BA |
7 | |
8 | Vue.config.productionTip = false; | |
9 | ||
10 | new Vue({ | |
11 | router, | |
12 | render: function(h) { | |
13 | return h(App); | |
98db2082 BA |
14 | }, |
15 | // data: { | |
16 | // lang: "", | |
17 | // }, | |
18 | watch: { | |
19 | $lang: async function(newLang) { | |
20 | // Fill modalWelcome, and import translations from "./translations/$lang.js" | |
21 | document.getElementById("modalWelcome").innerHTML = | |
22 | require("raw-loader!pug-plain-loader!./modals/welcome/" + newLang + ".pug"); | |
23 | const tModule = await import("./translations/" + newLang + ".js"); | |
24 | Vue.prototype.$tr = tModule.translations; | |
25 | //console.log(tModule.translations); | |
26 | }, | |
625022fd BA |
27 | }, |
28 | created: function() { | |
98db2082 BA |
29 | const supportedLangs = ["en","es","fr"]; |
30 | Vue.prototype.$lang = localStorage["lang"] || | |
31 | supportedLangs.includes(navigator.language) | |
32 | ? navigator.language | |
33 | : "en"; | |
03470390 BA |
34 | ajax("/variants", "GET", res => { |
35 | Vue.prototype.$variants = res.variantArray; | |
625022fd | 36 | }); |
98db2082 | 37 | Vue.prototype.$tr = {}; //to avoid a compiler error |
03470390 BA |
38 | const myid = localStorage["myid"] || util.getRandString(); |
39 | // NOTE: in this version, we don't say on which page we are, yet | |
40 | // ==> we'll say "enter/leave" page XY (in fact juste "enter", seemingly) | |
41 | Vue.prototype.$conn = new WebSocket(params.socketUrl + "/?sid=" + myid); | |
42 | //TODO: si une partie en cours dans storage, rediriger vers cette partie | |
43 | //(à condition que l'URL n'y corresponde pas déjà !) | |
44 | // TODO: à l'arrivée sur le site : set peerID (un identifiant unique | |
45 | // en tout cas...) si pas trouvé dans localStorage "myid" | |
46 | // (l'identifiant de l'utilisateur si connecté) | |
625022fd | 47 | }, |
03470390 BA |
48 | // Later, for icons (if using feather): |
49 | // mounted: function() { | |
50 | // feather.replace(); | |
51 | // }, | |
625022fd BA |
52 | }).$mount("#app"); |
53 | ||
54 | // TODO: get rules, dynamic import | |
55 | // Load a rules page (AJAX) | |
56 | // router.get("/rules/:vname([a-zA-Z0-9]+)", access.ajax, (req,res) => { | |
57 | // const lang = selectLanguage(req, res); | |
58 | // res.render("rules/" + req.params["vname"] + "/" + lang); | |
59 | // }); | |
03470390 BA |
60 | // |
61 | // board2, 3, 4 automatiquement, mais rules separement (les 3 pour une) | |
62 | // game : aussi systématique | |
63 | // problems: on-demand | |
64 | // | |
65 | // It works (to watch for route change), in a component: | |
66 | //watch: { | |
67 | // $route: function(newRoute) { | |
68 | // console.log(this.$route.params); | |
69 | // }, | |
70 | //}, | |
71 | // See https://router.vuejs.org/guide/essentials/dynamic-matching.html#reacting-to-params-changes |