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 {{ 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 { getDiagram } 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 // Next two lines fix a weird issue after last update (2019-11)
90 .replace('module.exports = "', "")
92 .replace(/(fen:)([^:]*):/g, this.replaceByDiag)
97 clickReadRules: function() {
98 if (this.display != "rules") this.display = "rules";
99 else if (this.gameInProgress) this.display = "computer";
102 const fenParts = fen.split(" ");
104 position: fenParts[0],
106 orientation: fenParts[2],
110 // Method to replace diagrams in loaded HTML
111 replaceByDiag: function(match, p1, p2) {
112 const args = this.parseFen(p2);
113 return getDiagram(args);
115 re_setVariant: async function(vname) {
116 await import("@/variants/" + vname + ".js")
118 this.V = window.V = vModule[vname + "Rules"];
119 this.gameInfo.vname = vname;
122 // Soon after component creation, st.tr might be uninitialized.
123 // Set a timeout to let a chance for the message to show translated.
124 const text = "Mispelled variant name";
126 alert(this.st.tr[text] || text);
127 this.$router.replace("/variants");
131 startGame: function(mode) {
132 if (this.gameInProgress) return;
133 this.gameInProgress = true;
134 this.display = "computer";
135 this.gameInfo.mode = mode;
136 if (this.gameInfo.mode == "versus") {
137 CompgameStorage.get(this.gameInfo.vname, (game) => {
138 // NOTE: game might be null
139 this.$refs["compgame"].launchGame(game);
142 this.$refs["compgame"].launchGame();
145 // user wants to stop the game:
146 stopGame: function() {
147 this.$refs["compgame"].gameOver("?", "Undetermined result");
149 // The game is effectively stopped:
150 gameStopped: function() {
151 this.gameInProgress = false;
152 if (this.gameInfo.mode == "versus")
153 CompgameStorage.remove(this.gameInfo.vname);
155 gotoAnalyze: function() {
157 "/analyse/" + this.gameInfo.vname +
158 "/?fen=" + V.GenRandInitFen(this.st.settings.randomness)
165 <!-- NOTE: not scoped here, because HTML is injected (TODO) -->
170 background-color: lightgrey
177 figure.diagram-container
178 margin: 15px 0 15px 0
191 margin-left: calc(10% - 20px)
193 @media screen and (max-width: 630px)
195 margin: 0 auto 10px auto
199 margin-right: calc(10% - 20px)
200 @media screen and (max-width: 630px)
210 background-color: #FFCC66
222 // To show (new) pieces, and/or there values...
223 figure.showPieces > img
226 figure.showPieces > figcaption
235 ol, ul:not(.browser-default)
238 ul:not(.browser-default)
241 ul:not(.browser-default) > li
242 list-style-type: disc
252 margin: 0 auto 15px auto