3 .col-sm-12 col-md-10 col-md-offset-1 col-lg-8 col-lg-offset-2
5 button(@click="display='rules'") Read the rules
6 button(v-show="!gameInProgress" @click="watchComputerGame")
7 | Observe a sample game
8 button(v-show="!gameInProgress" @click="playAgainstComputer")
10 button(v-show="gameInProgress" @click="stopGame")
12 div(v-show="display=='rules'" v-html="content" class="section-content")
13 Game(v-show="display=='computer'" :gid-or-fen="fen"
14 :mode="mode" :sub-mode="subMode" :variant="variant"
15 @computer-think="gameInProgress=false" @game-over="stopGame")
19 import Game from "@/components/Game.vue";
20 import { store } from "@/store";
21 import { getDiagram } from "@/utils/printDiagram";
30 variant: {id: 0, name: "Unknown"}, //...yet
34 subMode: "", //'auto' for game CPU vs CPU
35 gameInProgress: false,
40 mounted: async function() {
41 // NOTE: variant cannot be set before store is initialized
42 const vname = this.$route.params["vname"];
43 //const idxOfVar = this.st.variants.indexOf(e => e.name == vname);
44 //this.variant = this.st.variants[idxOfVar]; //TODO: is it the right timing?!
45 this.variant.name = vname;
46 const vModule = await import("@/variants/" + vname + ".js");
47 window.V = vModule.VariantRules;
48 // Method to replace diagrams in loaded HTML
49 const replaceByDiag = (match, p1, p2) => {
50 const args = this.parseFen(p2);
51 return getDiagram(args);
53 // (AJAX) Request to get rules content (plain text, HTML)
55 // TODO: why doesn't this work? require("raw-loader!pug-plain-loader!@/rules/"...)
56 require("raw-loader!@/rules/" + vname + "/" + this.st.lang + ".pug")
57 .replace(/(fen:)([^:]*):/g, replaceByDiag);
61 const fenParts = fen.split(" ");
63 position: fenParts[0],
65 orientation: fenParts[2],
69 startGame: function() {
70 if (this.gameInProgress)
72 this.gameInProgress = true;
73 this.mode = "computer";
74 this.display = "computer";
75 this.fen = V.GenRandInitFen();
77 stopGame: function() {
78 this.gameInProgress = false;
79 this.mode = "analyze";
81 playAgainstComputer: function() {
85 watchComputerGame: function() {
86 this.subMode = "auto";