Advance for rules page
[vchess.git] / client / src / views / Rules.vue
index 1702b50..fd26f16 100644 (file)
@@ -1,6 +1,6 @@
 <template lang="pug">
 .row
-  .col-sm-12 col-md-10 col-md-offset-1 col-lg-8 col-lg-offset-2
+  .col-sm-12.col-md-10.col-md-offset-1.col-lg-8.col-lg-offset-2
     .button-group
       button(@click="display='rules'") Read the rules
       button(v-show="!gameInProgress" @click="watchComputerGame")
@@ -10,7 +10,7 @@
       button(v-show="gameInProgress" @click="stopGame")
         | Stop game
     div(v-show="display=='rules'" v-html="content" class="section-content")
-    Game(v-show="display=='computer'" :mycolor="mycolor" :gid-or-fen="fen"
+    Game(v-show="display=='computer'" :gid-or-fen="fen"
       :mode="mode" :sub-mode="subMode" :variant="variant"
       @computer-think="gameInProgress=false" @game-over="stopGame")
 </template>
@@ -18,6 +18,7 @@
 <script>
 import Game from "@/components/Game.vue";
 import { store } from "@/store";
+import { getDiagram } from "@/utils/printDiagram";
 export default {
   name: 'my-rules',
   components: {
@@ -26,7 +27,7 @@ export default {
   data: function() {
     return {
       st: store.state,
-      variant: null,
+      variant: {id: 0, name: "Unknown"}, //...yet
       content: "",
       display: "rules",
       mode: "computer",
@@ -36,21 +37,26 @@ export default {
       fen: "",
     };
   },
-  created: function() {
+  mounted: async function() {
+    // NOTE: variant cannot be set before store is initialized
     const vname = this.$route.params["vname"];
-    const idxOfVar = this.st.variants.indexOf(e => e.name == vname);
-    this.variant = this.st.variants[idxOfVar];
-  },
-  mounted: function() {
+    //const idxOfVar = this.st.variants.indexOf(e => e.name == vname);
+    //this.variant = this.st.variants[idxOfVar]; //TODO: is it the right timing?!
+    this.variant.name = vname;
+    const vModule = await import("@/variants/" + vname + ".js");
+    window.V = vModule.VariantRules;
     // Method to replace diagrams in loaded HTML
     const replaceByDiag = (match, p1, p2) => {
       const args = this.parseFen(p2);
       return getDiagram(args);
     };
     // (AJAX) Request to get rules content (plain text, HTML)
+    // TODO: find a way to have Diagram(er) as a component,
+    // thus allowing images import through require(), handled by Webpack
+    // ==> the rules files should be less static
     this.content =
-      require("raw-loader!pug-plain-loader!@/rules/" +
-        this.$route.params["vname"] + "/" + this.st.lang + ".pug")
+      // TODO: why doesn't this work? require("raw-loader!pug-plain-loader!@/rules/"...)
+      require("raw-loader!@/rules/" + vname + "/" + this.st.lang + ".pug")
       .replace(/(fen:)([^:]*):/g, replaceByDiag);
   },
   methods: {