Allow to set also randomness against computer
[vchess.git] / client / src / components / Settings.vue
CommitLineData
98db2082
BA
1<template lang="pug">
2div
3 input#modalSettings.modal(type="checkbox")
910d631b
BA
4 div(
5 role="dialog"
6 data-checkbox="modalSettings"
7 )
5b3dc10e 8 .card
98db2082 9 label.modal-close(for="modalSettings")
5b3dc10e
BA
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)")
9a3049f3
BA
29 fieldset
30 label(for="setHints") {{ st.tr["Show possible moves?"] }}
910d631b
BA
31 input#setHints(
32 type="checkbox"
33 v-model="st.settings.hints"
34 )
9a3049f3
BA
35 fieldset
36 label(for="setHighlight")
37 | {{ st.tr["Highlight last move and checks?"] }}
910d631b
BA
38 input#setHighlight(
39 type="checkbox"
40 v-model="st.settings.highlight"
41 )
9a3049f3
BA
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
db1f1f9a 49 label(for="setSound")
3b959cfa 50 | {{ st.tr["Sound alert when game starts?"] }}
db1f1f9a
BA
51 input#setSound(
52 type="checkbox"
53 v-model="st.settings.sound"
54 )
f35b9960
BA
55 fieldset
56 label(for="setRandomness") {{ st.tr["Randomness against computer"] }}
57 select#setRandomness(v-model="st.settings.randomness")
58 option(value="0") {{ st.tr["Deterministic"] }}
59 option(value="1") {{ st.tr["Symmetric random"] }}
60 option(value="2") {{ st.tr["Asymmetric random"] }}
98db2082
BA
61</template>
62
63<script>
c66a829b 64import { store } from "@/store.js";
98db2082 65export default {
c66a829b
BA
66 name: "my-settings",
67 data: function() {
68 return {
6808d7a1 69 st: store.state
c66a829b 70 };
5701c228 71 },
5b3dc10e
BA
72 mounted: function() {
73 // NOTE: better style would be in pug directly, but how?
74 document.querySelectorAll("#langSelect > option").forEach(opt => {
75 if (opt.value == this.st.lang) opt.selected = true;
76 });
77 },
78 computed: {
79 flagImage: function() {
80 return `/images/flags/${this.st.lang}.svg`;
81 }
82 },
dac39588 83 methods: {
5b3dc10e
BA
84 setLanguage: function(e) {
85 localStorage["lang"] = e.target.value;
86 store.setLanguage(e.target.value);
87 },
98db2082 88 updateSettings: function(event) {
6808d7a1
BA
89 const propName = event.target.id
90 .substr(3)
91 .replace(/^\w/, c => c.toLowerCase());
f35b9960 92 const value = ["bcolor","randomness"].includes(propName)
602d6bef 93 ? event.target.value
6808d7a1 94 : event.target.checked;
dfeb96ea 95 store.updateSetting(propName, value);
6808d7a1
BA
96 }
97 }
98db2082
BA
98};
99</script>
9a3049f3
BA
100
101<style lang="sass" scoped>
102[type="checkbox"].modal+div .card
103 max-width: 767px
104 max-height: 100%
5b3dc10e
BA
105#flagContainer
106 display: inline-block
107 height: 100%
108 & > img
109 vertical-align: middle
110 padding: 0 0 0 10px
111 width: 36px
112 height: 27px
9a3049f3 113</style>