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
30 v-show="display=='rules'"
35 v-show="display=='computer'"
37 @game-stopped="gameStopped"
42 import ComputerGame from "@/components/ComputerGame.vue";
43 import { store } from "@/store";
44 import { getDiagram } from "@/utils/printDiagram";
45 import { CompgameStorage } from "@/utils/compgameStorage";
55 gameInProgress: false,
56 // variables passed to ComputerGame:
65 $route: function(newRoute) {
66 this.re_setVariant(newRoute.params["vname"]);
70 // NOTE: variant cannot be set before store is initialized
71 this.re_setVariant(this.$route.params["vname"]);
74 showAnalyzeBtn: function() {
75 return this.V && this.V.CanAnalyze;
78 if (!this.gameInfo.vname) return ""; //variant not set yet
79 // (AJAX) Request to get rules content (plain text, HTML)
82 "raw-loader!@/translations/rules/" +
83 this.gameInfo.vname + "/" +
86 // Next two lines fix a weird issue after last update (2019-11)
89 .replace('module.exports = "', "")
91 .replace(/(fen:)([^:]*):/g, this.replaceByDiag)
96 clickReadRules: function() {
97 if (this.display != "rules") this.display = "rules";
98 else if (this.gameInProgress) this.display = "computer";
101 const fenParts = fen.split(" ");
103 position: fenParts[0],
105 orientation: fenParts[2],
109 // Method to replace diagrams in loaded HTML
110 replaceByDiag: function(match, p1, p2) {
111 const args = this.parseFen(p2);
112 return getDiagram(args);
114 re_setVariant: async function(vname) {
115 await import("@/variants/" + vname + ".js")
117 this.V = window.V = vModule[vname + "Rules"];
118 this.gameInfo.vname = vname;
121 // Soon after component creation, st.tr might be uninitialized.
122 // Set a timeout to let a chance for the message to show translated.
123 const text = "Mispelled variant name";
125 alert(this.st.tr[text] || text);
126 this.$router.replace("/variants");
130 startGame: function(mode) {
131 if (this.gameInProgress) return;
132 this.gameInProgress = true;
133 this.display = "computer";
134 this.gameInfo.mode = mode;
135 if (this.gameInfo.mode == "versus") {
136 CompgameStorage.get(this.gameInfo.vname, (game) => {
137 // NOTE: game might be null
138 this.$refs["compgame"].launchGame(game);
141 this.$refs["compgame"].launchGame();
144 // user wants to stop the game:
145 stopGame: function() {
146 this.$refs["compgame"].gameOver("?", "Undetermined result");
148 // The game is effectively stopped:
149 gameStopped: function() {
150 this.gameInProgress = false;
151 if (this.gameInfo.mode == "versus")
152 CompgameStorage.remove(this.gameInfo.vname);
154 gotoAnalyze: function() {
156 "/analyse/" + this.gameInfo.vname +
157 "/?fen=" + V.GenRandInitFen(this.st.settings.randomness)
164 <!-- NOTE: not scoped here, because HTML is injected (TODO) -->
169 background-color: lightgrey
172 figure.diagram-container
173 margin: 15px 0 15px 0
186 margin-left: calc(10% - 20px)
188 @media screen and (max-width: 630px)
190 margin: 0 auto 10px auto
194 margin-right: calc(10% - 20px)
195 @media screen and (max-width: 630px)
205 background-color: #FFCC66
217 // To show (new) pieces, and/or there values...
218 figure.showPieces > img
221 figure.showPieces > figcaption
230 ol, ul:not(.browser-default)
233 ul:not(.browser-default)
236 ul:not(.browser-default) > li
237 list-style-type: disc