Avoid direct references to (Dark) variant name in BaseGame, Analyse and Board
[vchess.git] / client / src / views / Analyse.vue
1 <template lang="pug">
2 main
3 .row
4 .col-sm-12
5 .text-center
6 input#fen(
7 v-model="curFen"
8 @input="adjustFenSize()"
9 )
10 button(@click="gotoFen()") {{ st.tr["Go"] }}
11 BaseGame(
12 :game="game"
13 :vr="vr"
14 )
15 </template>
16
17 <script>
18 import BaseGame from "@/components/BaseGame.vue";
19 import { store } from "@/store";
20 export default {
21 name: "my-analyse",
22 components: {
23 BaseGame
24 },
25 // gameRef: to find the game in (potentially remote) storage
26 data: function() {
27 return {
28 st: store.state,
29 gameRef: {
30 //given in URL (rid = remote ID)
31 vname: "",
32 fen: ""
33 },
34 game: {
35 players: [{ name: "Analyse" }, { name: "Analyse" }],
36 mode: "analyze"
37 },
38 vr: null, //"variant rules" object initialized from FEN
39 curFen: ""
40 };
41 },
42 watch: {
43 // NOTE: no watcher for $route change, because if fenStart doesn't change
44 // then it doesn't trigger BaseGame.re_init() and the result is weird.
45 "vr.movesCount": function() {
46 this.curFen = this.vr.getFen();
47 this.adjustFenSize();
48 }
49 },
50 created: function() {
51 this.gameRef.vname = this.$route.params["vname"];
52 this.gameRef.fen = this.$route.query["fen"].replace(/_/g, " ");
53 this.initialize();
54 },
55 methods: {
56 initialize: async function() {
57 // Obtain VariantRules object
58 const vModule = await import("@/variants/" + this.gameRef.vname + ".js");
59 window.V = vModule.VariantRules;
60 this.loadGame();
61 },
62 loadGame: function() {
63 // NOTE: no need to set score (~unused)
64 this.game.vname = this.gameRef.vname;
65 this.game.fen = this.gameRef.fen;
66 this.curFen = this.game.fen;
67 this.adjustFenSize();
68 this.vr = new V(this.game.fen);
69 this.game.mycolor = this.vr.turn;
70 this.$set(this.game, "fenStart", this.gameRef.fen);
71 },
72 adjustFenSize: function() {
73 let fenInput = document.getElementById("fen");
74 fenInput.style.width = this.curFen.length + "ch";
75 },
76 gotoFen: function() {
77 this.gameRef.fen = this.curFen;
78 this.loadGame();
79 }
80 }
81 };
82 </script>