3 input#modalOptions.modal(type="checkbox")
6 data-checkbox="modalOptions"
9 label.modal-close(for="modalOptions")
10 h3 {{ st.tr["Options"] }}
11 fieldset(v-if="!!V && V.Options")
12 div(v-for="select of V.Options.select || []")
13 label(:for="select.variable + '_opt'") {{ st.tr[select.label] }}
14 select(:id="select.variable + '_opt'")
16 v-for="o of select.options"
18 :selected="o.value == select.defaut"
20 | {{ st.tr[o.label] }}
21 div(v-for="check of V.Options.check || []")
22 label(:for="check.variable + '_opt'") {{ st.tr[check.label] }}
24 :id="check.variable + '_opt'"
26 :checked="check.defaut")
27 button(@click="setOptions()") {{ st.tr["Validate"] }}
29 .col-sm-12.col-md-10.col-md-offset-1.col-lg-8.col-lg-offset-2
31 button(@click="clickReadRules()") {{ st.tr["Rules"] }}
33 v-show="!gameInProgress"
34 @click="startGame('auto')"
36 | {{ st.tr["Example game"] }}
38 v-show="!gameInProgress"
39 @click="startGame('versus')"
41 | {{ st.tr["Practice"] }}
43 v-show="gameInProgress"
46 | {{ st.tr["Stop game"] }}
49 @click="gotoAnalyze()"
51 | {{ st.tr["Analysis mode"] }}
53 .col-sm-12.col-md-8.col-md-offset-2.col-lg-6.col-lg-offset-3
54 h4#variantName(v-show="display=='rules'") {{ getVariantDisplay }}
56 v-show="display=='rules'"
61 v-show="display=='computer'"
63 @game-stopped="gameStopped"
68 import ComputerGame from "@/components/ComputerGame.vue";
69 import { store } from "@/store";
70 import { replaceByDiag } from "@/utils/printDiagram";
71 import { CompgameStorage } from "@/utils/compgameStorage";
72 import { processModalClick } from "@/utils/modalClick";
73 import afterRawLoad from "@/utils/afterRawLoad";
83 gameInProgress: false,
84 // variables passed to ComputerGame:
93 $route: function(newRoute) {
94 this.re_setVariant(newRoute.params["vname"]);
98 // NOTE: variant cannot be set before store is initialized
99 this.re_setVariant(this.$route.params["vname"]);
101 mounted: function() {
102 document.getElementById("optionsDiv")
103 .addEventListener("click", processModalClick);
106 showAnalyzeBtn: function() {
107 return !!this.V && this.V.CanAnalyze;
109 getVariantDisplay: function() {
110 if (!this.gameInfo.vname) return ""; //variant not set yet
111 return this.st.variants.find(v => v.name == this.gameInfo.vname).display;
113 content: function() {
114 if (!this.gameInfo.vname) return ""; //variant not set yet
118 "raw-loader!@/translations/rules/" +
119 this.gameInfo.vname + "/" + this.st.lang + ".pug"
121 ).replace(/(fen:)([^:]*):/g, replaceByDiag)
126 clickReadRules: function() {
127 if (this.display != "rules") this.display = "rules";
128 else if (this.gameInProgress) this.display = "computer";
130 re_setVariant: async function(vname) {
131 const key = "rr_" + vname;
132 if (!localStorage.getItem(key))
133 // Mark rules as "read"
134 localStorage.setItem(key, '1');
135 await import("@/variants/" + vname + ".js")
137 this.V = window.V = vModule[vname + "Rules"];
138 this.gameInfo.vname = vname;
141 // Soon after component creation, st.tr might be uninitialized.
142 // Set a timeout to let a chance for the message to show translated.
143 const text = "Mispelled variant name";
145 alert(this.st.tr[text] || text);
146 this.$router.replace("/variants");
150 setOptions: function() {
152 // Get/set options variables / TODO: v-model?!
153 for (const check of this.V.Options.check || []) {
154 const elt = document.getElementById(check.variable + "_opt");
155 if (elt.checked) options[check.variable] = true;
157 for (const select of this.V.Options.select || []) {
158 const elt = document.getElementById(select.variable + "_opt");
159 options[select.variable] = parseInt(elt.value, 10) || elt.value;
161 if (!V.IsValidOptions(options)) {
162 alert(this.st.tr["Invalid options"]);
165 document.getElementById("modalOptions").checked = false;
166 if (this.whatNext == "analyze") this.gotoAnalyze(options);
167 else this.startGame(this.whatNext, options);
169 startGame: function(mode, options) {
170 if (this.gameInProgress) return;
171 const next = (game, options) => {
172 this.gameInProgress = true;
173 this.display = "computer";
174 this.gameInfo.mode = mode;
175 this.$refs["compgame"].launchGame(game, options);
181 const askOptions = () => {
182 this.whatNext = mode;
183 doClick("modalOptions");
185 if (mode == "versus") {
186 CompgameStorage.get(this.gameInfo.vname, (game) => {
187 // NOTE: game might be null (if none stored yet)
188 if (!!game && !V.IsGoodFen(game.fen)) {
189 // Some issues with stored game: delete
190 CompgameStorage.remove(game.vname);
193 if (!!game || !V.Options) next(game);
198 if (!V.Options) next();
202 // The user wants to stop the game:
203 stopGame: function() {
204 this.$refs["compgame"].gameOver("?", "Undetermined result");
206 // The game is effectively stopped:
207 gameStopped: function() {
208 this.gameInProgress = false;
209 if (this.gameInfo.mode == "versus")
210 CompgameStorage.remove(this.gameInfo.vname);
212 gotoAnalyze: function(options) {
213 if (!options && V.Options) {
214 this.whatNext = "analyze";
215 doClick("modalOptions");
219 "/analyse/" + this.gameInfo.vname +
220 "/?fen=" + V.GenRandInitFen(options)
228 <!-- NOTE: not scoped here, because HTML is injected -->
230 @import "@/styles/_board_squares_img.sass"
231 @import "@/styles/_rules.sass"
234 <style lang="sass" scoped>