8 @input="adjustFenSize(); tryGotoFen()"
17 import BaseGame from "@/components/BaseGame.vue";
18 import { store } from "@/store";
24 // gameRef: to find the game in (potentially remote) storage
29 //given in URL (rid = remote ID)
34 players: [{ name: "Analyse" }, { name: "Analyse" }],
40 // NOTE: no watcher for $route change, because if fenStart doesn't change
41 // then it doesn't trigger BaseGame.re_init() and the result is weird.
43 this.gameRef.vname = this.$route.params["vname"];
44 const routeFen = this.$route.query["fen"];
45 if (!routeFen) this.alertAndQuit("Missing FEN");
47 this.gameRef.fen = routeFen.replace(/_/g, " ");
52 alertAndQuit: function(text, wrongVname) {
53 // Soon after component creation, st.tr might be uninitialized.
54 // Set a timeout to let a chance for the message to show translated.
55 const newUrl = "/variants" + (wrongVname ? "" : "/" + this.gameRef.vname);
57 alert(this.st.tr[text] || text);
58 this.$router.replace(newUrl);
61 initialize: async function() {
62 // Obtain VariantRules object
63 await import("@/variants/" + this.gameRef.vname + ".js")
65 window.V = vModule.VariantRules;
67 // Late check, in case the user tried to enter URL by hand
68 this.alertAndQuit("Analysis disabled for this variant");
71 .catch((err) => { this.alertAndQuit("Mispelled variant name", true); });
73 loadGame: function() {
74 // NOTE: no need to set score (~unused)
75 this.game.vname = this.gameRef.vname;
76 this.game.fen = this.gameRef.fen;
77 this.curFen = this.game.fen;
79 this.game.mycolor = V.ParseFen(this.gameRef.fen).turn;
80 this.$set(this.game, "fenStart", this.gameRef.fen);
82 // Triggered by "fenchange" emitted in BaseGame:
83 setFen: function(fen) {
87 adjustFenSize: function() {
88 let fenInput = document.getElementById("fen");
89 fenInput.style.width = this.curFen.length + "ch";
91 tryGotoFen: function() {
92 if (V.IsGoodFen(this.curFen))
94 this.gameRef.fen = this.curFen;