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";
56 gameInProgress: false,
57 // variables passed to ComputerGame:
66 $route: function(newRoute) {
67 this.re_setVariant(newRoute.params["vname"]);
71 // NOTE: variant cannot be set before store is initialized
72 this.re_setVariant(this.$route.params["vname"]);
75 showAnalyzeBtn: function() {
76 return !!this.V && this.V.CanAnalyze;
79 if (!this.gameInfo.vname) return ""; //variant not set yet
80 // (AJAX) Request to get rules content (plain text, HTML)
83 "raw-loader!@/translations/rules/" +
84 this.gameInfo.vname + "/" +
87 .replace('export default "', "")
89 // Next two lines fix a weird issue after last update (2019-11)
92 .replace(/(fen:)([^:]*):/g, replaceByDiag)
97 clickReadRules: function() {
98 if (this.display != "rules") this.display = "rules";
99 else if (this.gameInProgress) this.display = "computer";
101 re_setVariant: async function(vname) {
102 const key = "rr_" + vname;
103 if (!localStorage.getItem(key))
104 // Mark rules as "read"
105 localStorage.setItem(key, '1');
106 await import("@/variants/" + vname + ".js")
108 this.V = window.V = vModule[vname + "Rules"];
109 this.gameInfo.vname = vname;
112 // Soon after component creation, st.tr might be uninitialized.
113 // Set a timeout to let a chance for the message to show translated.
114 const text = "Mispelled variant name";
116 alert(this.st.tr[text] || text);
117 this.$router.replace("/variants");
121 startGame: function(mode) {
122 if (this.gameInProgress) return;
123 this.gameInProgress = true;
124 this.display = "computer";
125 this.gameInfo.mode = mode;
126 if (this.gameInfo.mode == "versus") {
127 CompgameStorage.get(this.gameInfo.vname, (game) => {
128 // NOTE: game might be null
129 this.$refs["compgame"].launchGame(game);
132 this.$refs["compgame"].launchGame();
135 // The user wants to stop the game:
136 stopGame: function() {
137 this.$refs["compgame"].gameOver("?", "Undetermined result");
139 // The game is effectively stopped:
140 gameStopped: function() {
141 this.gameInProgress = false;
142 if (this.gameInfo.mode == "versus")
143 CompgameStorage.remove(this.gameInfo.vname);
145 gotoAnalyze: function() {
147 "/analyse/" + this.gameInfo.vname +
148 "/?fen=" + V.GenRandInitFen(this.st.settings.randomness)
155 <!-- NOTE: not scoped here, because HTML is injected -->
157 @import "@/styles/_board_squares_img.sass"
158 @import "@/styles/_rules.sass"
161 <style lang="sass" scoped>