Experimental update: preview corr move + allow deletion of any game
[vchess.git] / client / src / components / Settings.vue
1 <template lang="pug">
2 div
3 input#modalSettings.modal(type="checkbox")
4 div(
5 role="dialog"
6 data-checkbox="modalSettings"
7 )
8 .card
9 label.modal-close(for="modalSettings")
10 -
11 var langName = {
12 "en": "English",
13 "es": "Español",
14 "fr": "Français",
15 };
16 fieldset(@change="setLanguage($event)")
17 label(for="langSelect")
18 | {{ st.tr["Language"] }}
19 select#langSelect
20 each language,langCode in langName
21 option(value=langCode)
22 =language
23 #flagContainer
24 img(
25 v-if="!!st.lang"
26 :src="flagImage"
27 )
28 div(@change="updateSettings($event)")
29 fieldset
30 label(for="setHints") {{ st.tr["Show possible moves?"] }}
31 input#setHints(
32 type="checkbox"
33 v-model="st.settings.hints"
34 )
35 fieldset
36 label(for="setHighlight")
37 | {{ st.tr["Highlight last move and checks?"] }}
38 input#setHighlight(
39 type="checkbox"
40 v-model="st.settings.highlight"
41 )
42 fieldset
43 label(for="setBcolor") {{ st.tr["Board colors"] }}
44 select#setBcolor(v-model="st.settings.bcolor")
45 option(value="lichess") {{ st.tr["brown"] }}
46 option(value="chesscom") {{ st.tr["green"] }}
47 option(value="chesstempo") {{ st.tr["blue"] }}
48 fieldset
49 label(for="setSound")
50 | {{ st.tr["Sound alert when game starts?"] }}
51 input#setSound(
52 type="checkbox"
53 v-model="st.settings.sound"
54 )
55 fieldset
56 label(for="setGotonext")
57 | {{ st.tr["Show next game after move?"] }}
58 input#setGotonext(
59 type="checkbox"
60 v-model="st.settings.gotonext"
61 )
62 fieldset
63 label(for="setRandomness") {{ st.tr["Randomness against computer"] }}
64 select#setRandomness(v-model="st.settings.randomness")
65 option(value="0") {{ st.tr["Deterministic"] }}
66 option(value="1") {{ st.tr["Symmetric random"] }}
67 option(value="2") {{ st.tr["Asymmetric random"] }}
68 </template>
69
70 <script>
71 import { store } from "@/store.js";
72 export default {
73 name: "my-settings",
74 data: function() {
75 return {
76 st: store.state
77 };
78 },
79 mounted: function() {
80 // NOTE: better style would be in pug directly, but how?
81 document.querySelectorAll("#langSelect > option").forEach(opt => {
82 if (opt.value == this.st.lang) opt.selected = true;
83 });
84 },
85 computed: {
86 flagImage: function() {
87 return `/images/flags/${this.st.lang}.svg`;
88 }
89 },
90 methods: {
91 setLanguage: function(e) {
92 localStorage["lang"] = e.target.value;
93 store.setLanguage(e.target.value);
94 },
95 updateSettings: function(event) {
96 const propName = event.target.id
97 .substr(3)
98 .replace(/^\w/, c => c.toLowerCase());
99 const value = ["bcolor","randomness"].includes(propName)
100 ? event.target.value
101 : event.target.checked;
102 store.updateSetting(propName, value);
103 }
104 }
105 };
106 </script>
107
108 <style lang="sass" scoped>
109 [type="checkbox"].modal+div .card
110 max-width: 767px
111 max-height: 100%
112 #flagContainer
113 display: inline-block
114 height: 100%
115 & > img
116 vertical-align: middle
117 padding: 0 0 0 10px
118 width: 36px
119 height: 27px
120 </style>