4 .col-sm-12.col-md-10.col-md-offset-1.col-lg-8.col-lg-offset-2
6 button(@click="clickReadRules") Rules
7 button(v-show="!gameInProgress" @click="() => startGame('auto')")
9 button(v-show="!gameInProgress" @click="() => startGame('versus')")
11 button(v-show="gameInProgress" @click="() => stopGame()")
13 button(v-if="gameInfo.vname!='Dark'" @click="gotoAnalyze")
14 | {{ st.tr["Analyze"] }}
15 .section-content(v-show="display=='rules'" v-html="content")
16 ComputerGame(v-show="display=='computer'" :game-info="gameInfo"
17 @game-over="stopGame" @game-stopped="gameStopped")
21 import ComputerGame from "@/components/ComputerGame.vue";
22 import { store } from "@/store";
23 import { getDiagram } from "@/utils/printDiagram";
35 gameInProgress: false,
36 // variables passed to ComputerGame:
46 "$route": function(newRoute) {
47 this.tryChangeVariant(newRoute.params["vname"]);
50 created: async function() {
51 // NOTE: variant cannot be set before store is initialized
52 this.tryChangeVariant(this.$route.params["vname"]);
55 clickReadRules: function() {
56 if (this.display != "rules")
57 this.display = "rules";
58 else if (this.gameInProgress)
59 this.display = "computer";
62 const fenParts = fen.split(" ");
64 position: fenParts[0],
66 orientation: fenParts[2],
70 tryChangeVariant: async function(vname) {
71 if (!vname || vname == "_unknown")
73 this.gameInfo.vname = vname;
74 const vModule = await import("@/variants/" + vname + ".js");
75 window.V = vModule.VariantRules;
76 // Method to replace diagrams in loaded HTML
77 const replaceByDiag = (match, p1, p2) => {
78 const args = this.parseFen(p2);
79 return getDiagram(args);
81 // (AJAX) Request to get rules content (plain text, HTML)
83 require("raw-loader!@/translations/rules/" + vname + "/" + this.st.lang + ".pug")
84 // Next two lines fix a weird issue after last update (2019-11)
85 .replace(/\\[n"]/g, " ")
86 .replace('module.exports = "', '').replace(/"$/, "")
87 .replace(/(fen:)([^:]*):/g, replaceByDiag);
89 startGame: function(mode) {
90 if (this.gameInProgress)
92 this.gameInProgress = true;
93 this.display = "computer";
94 this.gameInfo.mode = mode;
95 this.gameInfo.score = "*";
96 this.gameInfo.fen = V.GenRandInitFen();
98 // user is willing to stop the game:
99 stopGame: function(score) {
100 this.gameInfo.score = score || "?";
101 this.gameInfo.mode = "analyze";
103 // The game is effectively stopped:
104 gameStopped: function() {
105 this.gameInProgress = false;
107 gotoAnalyze: function() {
108 this.$router.push("/analyze/" + this.gameInfo.vname
109 + "/?fen=" + V.GenRandInitFen());
115 <style lang="sass" scoped>
119 // margin-right: auto
121 // figure.diagram-container
123 // @media screen and (max-width: 767px)
130 background-color: lightgrey
133 figure.diagram-container
134 margin: 15px 0 15px 0
146 margin-left: calc(10% - 20px)
148 @media screen and (max-width: 630px)
150 margin: 0 auto 10px auto
153 margin-right: calc(10% - 20px)
154 @media screen and (max-width: 630px)
164 background-color: #FFCC66
170 // To show (new) pieces, and/or there values...
171 figure.showPieces > img
174 figure.showPieces > figcaption
183 ol, ul:not(.browser-default)
186 ul:not(.browser-default)
189 ul:not(.browser-default) > li
190 list-style-type: disc
193 background-color: #e5e5ca
196 background-color: #6f8f57
198 // TODO: following is duplicated (Board.vue)
202 display: inline-block
207 padding-bottom: 12.5%
220 img.piece, img.mark-square
234 filter: brightness(50%)