Experimental in-page analyze + show rules from Game page
[vchess.git] / client / src / views / Rules.vue
index 2af53b4..c48feb0 100644 (file)
@@ -26,6 +26,7 @@ main
           | {{ st.tr["Analysis mode"] }}
   .row
     .col-sm-12.col-md-8.col-md-offset-2.col-lg-6.col-lg-offset-3
+      h4#variantName {{ gameInfo.vname }}
       div(
         v-show="display=='rules'"
         v-html="content"
@@ -41,7 +42,7 @@ main
 <script>
 import ComputerGame from "@/components/ComputerGame.vue";
 import { store } from "@/store";
-import { getDiagram } from "@/utils/printDiagram";
+import { replaceByDiag } from "@/utils/printDiagram";
 import { CompgameStorage } from "@/utils/compgameStorage";
 export default {
   name: "my-rules",
@@ -72,7 +73,7 @@ export default {
   },
   computed: {
     showAnalyzeBtn: function() {
-      return this.V && this.V.CanAnalyze;
+      return !!this.V && this.V.CanAnalyze;
     },
     content: function() {
       if (!this.gameInfo.vname) return ""; //variant not set yet
@@ -88,7 +89,7 @@ export default {
         .replace(/\\"/g, '"')
         .replace('module.exports = "', "")
         .replace(/"$/, "")
-        .replace(/(fen:)([^:]*):/g, this.replaceByDiag)
+        .replace(/(fen:)([^:]*):/g, replaceByDiag)
       );
     }
   },
@@ -97,20 +98,6 @@ export default {
       if (this.display != "rules") this.display = "rules";
       else if (this.gameInProgress) this.display = "computer";
     },
-    parseFen(fen) {
-      const fenParts = fen.split(" ");
-      return {
-        position: fenParts[0],
-        marks: fenParts[1],
-        orientation: fenParts[2],
-        shadow: fenParts[3]
-      };
-    },
-    // Method to replace diagrams in loaded HTML
-    replaceByDiag: function(match, p1, p2) {
-      const args = this.parseFen(p2);
-      return getDiagram(args);
-    },
     re_setVariant: async function(vname) {
       await import("@/variants/" + vname + ".js")
       .then((vModule) => {
@@ -163,10 +150,8 @@ export default {
 
 <!-- NOTE: not scoped here, because HTML is injected (TODO) -->
 <style lang="sass">
-.warn
-  padding: 3px
-  color: red
-  background-color: lightgrey
+h4#variantName
+  text-align: center
   font-weight: bold
 
 figure.diagram-container
@@ -235,4 +220,14 @@ ul:not(.browser-default)
 
 ul:not(.browser-default) > li
   list-style-type: disc
+
+table
+  margin: 15px auto
+
+.italic
+  font-style: italic
+
+img.img-center
+  display: block
+  margin: 0 auto 15px auto
 </style>