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"]);
},
},
};
},
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
if (this.gameInProgress)
return;
this.gameInProgress = true;
- this.mode = "computer";
this.display = "computer";
this.fen = V.GenRandInitFen();
},
this.mode = "analyze";
},
playAgainstComputer: function() {
- this.subMode = "";
+ this.mode = "versus";
this.startGame();
},
watchComputerGame: function() {
- this.subMode = "auto";
+ this.mode = "auto";
this.startGame();
},
},