8 @input="adjustFenSize(); tryGotoFen()"
18 import BaseGame from "@/components/BaseGame.vue";
19 import { store } from "@/store";
25 // gameRef: to find the game in (potentially remote) storage
30 //given in URL (rid = remote ID)
35 players: [{ name: "Analyse" }, { name: "Analyse" }],
50 alertAndQuit: function(text, wrongVname) {
51 // Soon after component creation, st.tr might be uninitialized.
52 // Set a timeout to let a chance for the message to show translated.
54 "/variants" + (wrongVname ? "" : "/" + this.gameRef.vname);
56 alert(this.st.tr[text] || text);
57 this.$router.replace(newUrl);
60 initFromUrl: function() {
61 this.gameRef.vname = this.$route.params["vname"];
62 const routeFen = this.$route.query["fen"];
63 if (!routeFen) this.alertAndQuit("Missing FEN");
65 this.gameRef.fen = routeFen.replace(/_/g, " ");
66 // orientation is optional: taken from FEN if missing
67 const orientation = this.$route.query["side"];
68 this.initialize(orientation);
71 initialize: async function(orientation) {
72 // Obtain VariantRules object
73 await import("@/variants/" + this.gameRef.vname + ".js")
75 window.V = vModule[this.gameRef.vname + "Rules"];
77 // Late check, in case the user tried to enter URL by hand
78 this.alertAndQuit("Analysis disabled for this variant");
79 else this.loadGame(orientation);
81 .catch((err) => { this.alertAndQuit("Mispelled variant name", true); });
83 loadGame: function(orientation) {
84 this.game.vname = this.gameRef.vname;
85 this.game.fenStart = this.gameRef.fen;
86 this.game.fen = this.gameRef.fen;
87 this.game.score = "*"; //never change
88 this.curFen = this.game.fen;
90 this.game.mycolor = orientation || V.ParseFen(this.gameRef.fen).turn;
91 this.$refs["basegame"].re_setVariables(this.game);
93 // Triggered by "fenchange" emitted in BaseGame:
94 setFen: function(fen) {
98 adjustFenSize: function() {
99 let fenInput = document.getElementById("fen");
100 fenInput.style.width = (this.curFen.length+3) + "ch";
102 tryGotoFen: function() {
103 if (V.IsGoodFen(this.curFen)) {
104 this.gameRef.fen = this.curFen;
112 <style lang="sass" scoped=true>
114 // Use a Monospace font for input FEN width adjustment
115 font-family: "Fira Code"