4 .col-sm-12.col-md-10.col-md-offset-1.col-lg-8.col-lg-offset-2
6 button(@click="clickReadRules()") {{ st.tr["Rules"] }}
8 v-show="!gameInProgress"
9 @click="startGame('auto')"
11 | {{ st.tr["Example game"] }}
13 v-show="!gameInProgress"
14 @click="startGame('versus')"
16 | {{ st.tr["Practice"] }}
18 v-show="gameInProgress"
21 | {{ st.tr["Stop game"] }}
24 @click="gotoAnalyze()"
26 | {{ st.tr["Analysis mode"] }}
28 .col-sm-12.col-md-8.col-md-offset-2.col-lg-6.col-lg-offset-3
29 h4#variantName(v-show="display=='rules'") {{ gameInfo.vname }}
31 v-show="display=='rules'"
36 v-show="display=='computer'"
38 @game-stopped="gameStopped"
43 import ComputerGame from "@/components/ComputerGame.vue";
44 import { store } from "@/store";
45 import { replaceByDiag } from "@/utils/printDiagram";
46 import { CompgameStorage } from "@/utils/compgameStorage";
47 import afterRawLoad from "@/utils/afterRawLoad";
57 gameInProgress: false,
58 // variables passed to ComputerGame:
67 $route: function(newRoute) {
68 this.re_setVariant(newRoute.params["vname"]);
72 // NOTE: variant cannot be set before store is initialized
73 this.re_setVariant(this.$route.params["vname"]);
76 showAnalyzeBtn: function() {
77 return !!this.V && this.V.CanAnalyze;
80 if (!this.gameInfo.vname) return ""; //variant not set yet
84 "raw-loader!@/translations/rules/" +
85 this.gameInfo.vname + "/" + this.st.lang + ".pug"
87 ).replace(/(fen:)([^:]*):/g, replaceByDiag)
92 clickReadRules: function() {
93 if (this.display != "rules") this.display = "rules";
94 else if (this.gameInProgress) this.display = "computer";
96 re_setVariant: async function(vname) {
97 const key = "rr_" + vname;
98 if (!localStorage.getItem(key))
99 // Mark rules as "read"
100 localStorage.setItem(key, '1');
101 await import("@/variants/" + vname + ".js")
103 this.V = window.V = vModule[vname + "Rules"];
104 this.gameInfo.vname = vname;
107 // Soon after component creation, st.tr might be uninitialized.
108 // Set a timeout to let a chance for the message to show translated.
109 const text = "Mispelled variant name";
111 alert(this.st.tr[text] || text);
112 this.$router.replace("/variants");
116 startGame: function(mode) {
117 if (this.gameInProgress) return;
118 this.gameInProgress = true;
119 this.display = "computer";
120 this.gameInfo.mode = mode;
121 if (this.gameInfo.mode == "versus") {
122 CompgameStorage.get(this.gameInfo.vname, (game) => {
123 // NOTE: game might be null
124 this.$refs["compgame"].launchGame(game);
127 this.$refs["compgame"].launchGame();
130 // The user wants to stop the game:
131 stopGame: function() {
132 this.$refs["compgame"].gameOver("?", "Undetermined result");
134 // The game is effectively stopped:
135 gameStopped: function() {
136 this.gameInProgress = false;
137 if (this.gameInfo.mode == "versus")
138 CompgameStorage.remove(this.gameInfo.vname);
140 gotoAnalyze: function() {
142 "/analyse/" + this.gameInfo.vname +
143 "/?fen=" + V.GenRandInitFen(this.st.settings.randomness)
150 <!-- NOTE: not scoped here, because HTML is injected -->
152 @import "@/styles/_board_squares_img.sass"
153 @import "@/styles/_rules.sass"
156 <style lang="sass" scoped>