Toward game info simplification
[vchess.git] / client / src / views / Rules.vue
index 4edc428..74c4e84 100644 (file)
       button(v-show="gameInProgress" @click="stopGame")
         | Stop game
     .section-content(v-show="display=='rules'" v-html="content")
-    Game(v-show="display=='computer'" :gid-or-fen="fen"
-      :mode="mode" :sub-mode="subMode" :variant="variant"
+    ComputerGame(v-show="display=='computer'" :game-info="gameInfo"
       @computer-think="gameInProgress=false" @game-over="stopGame")
 </template>
 
 <script>
-import Game from "@/components/Game.vue";
+import ComputerGame from "@/components/ComputerGame.vue";
 import { store } from "@/store";
 import { getDiagram } from "@/utils/printDiagram";
+
 export default {
   name: 'my-rules',
   components: {
-    Game,
+    ComputerGame,
   },
   data: function() {
     return {
       st: store.state,
-      variant: {id: 0, name: "_unknown"}, //...yet
       content: "",
       display: "rules",
-      mode: "computer",
-      subMode: "", //'auto' for game CPU vs CPU
       gameInProgress: false,
-      mycolor: "w",
+      // variables passed to ComputerGame:
+      vname: "_unknown",
+      mode: "versus",
       fen: "",
     };
   },
+  computed: {
+    gameInfo: function() {
+      return {
+        fen: this.fen,
+        mode: this.mode,
+        vname: this.vname,
+      };
+    },
+  },
   watch: {
-    $route: function(newRoute) {
+    "$route": function(newRoute) {
       this.tryChangeVariant(newRoute.params["vname"]);
     },
   },
@@ -57,15 +65,9 @@ export default {
       };
     },
     tryChangeVariant: async function(vname) {
-      if (vname == "_unknown")
+      if (!vname || vname == "_unknown")
         return;
-      if (this.st.variants.length > 0)
-      {
-        const idxOfVar = this.st.variants.findIndex(e => e.name == vname);
-        this.variant = this.st.variants[idxOfVar];
-      }
-      else
-        this.variant.name = vname;
+      this.vname = vname;
       const vModule = await import("@/variants/" + vname + ".js");
       window.V = vModule.VariantRules;
       // Method to replace diagrams in loaded HTML
@@ -82,7 +84,6 @@ export default {
       if (this.gameInProgress)
         return;
       this.gameInProgress = true;
-      this.mode = "computer";
       this.display = "computer";
       this.fen = V.GenRandInitFen();
     },
@@ -91,11 +92,11 @@ export default {
       this.mode = "analyze";
     },
     playAgainstComputer: function() {
-      this.subMode = "";
+      this.mode = "versus";
       this.startGame();
     },
     watchComputerGame: function() {
-      this.subMode = "auto";
+      this.mode = "auto";
       this.startGame();
     },
   },