8 @input="adjustFenSize(); tryGotoFen()"
18 import BaseGame from "@/components/BaseGame.vue";
19 import { store } from "@/store";
22 // TODO: game import ==> require some adjustments, like
23 // the ability to analyse from a list of moves...
27 // gameRef: to find the game in (potentially remote) storage
36 players: [{ name: "Analyse" }, { name: "Analyse" }],
51 alertAndQuit: function(text, wrongVname) {
52 // Soon after component creation, st.tr might be uninitialized.
53 // Set a timeout to let a chance for the message to show translated.
55 "/variants" + (wrongVname ? "" : "/" + this.gameRef.vname);
57 alert(this.st.tr[text] || text);
58 this.$router.replace(newUrl);
61 initFromUrl: function() {
62 this.gameRef.vname = this.$route.params["vname"];
63 const routeFen = this.$route.query["fen"];
64 if (!routeFen) this.alertAndQuit("Missing FEN");
66 this.gameRef.fen = routeFen.replace(/_/g, " ");
67 // orientation is optional: taken from FEN if missing.
68 // NOTE: currently no internal usage of 'side', but could be used by
69 // manually settings the URL (TODO?).
70 const orientation = this.$route.query["side"];
71 this.initialize(orientation);
74 initialize: async function(orientation) {
75 // Obtain VariantRules object
76 await import("@/variants/" + this.gameRef.vname + ".js")
78 window.V = vModule[this.gameRef.vname + "Rules"];
80 // Late check, in case the user tried to enter URL by hand
81 this.alertAndQuit("Analysis disabled for this variant");
82 else this.loadGame(orientation);
84 .catch((err) => { this.alertAndQuit("Mispelled variant name", true); });
86 loadGame: function(orientation) {
87 this.game.vname = this.gameRef.vname;
88 this.game.fenStart = this.gameRef.fen;
89 this.game.fen = this.gameRef.fen;
90 this.game.score = "*"; //never change
91 this.curFen = this.game.fen;
93 this.game.mycolor = orientation || V.ParseFen(this.gameRef.fen).turn;
94 this.$refs["basegame"].re_setVariables(this.game);
96 // Triggered by "fenchange" emitted in BaseGame:
97 setFen: function(fen) {
101 adjustFenSize: function() {
102 let fenInput = document.getElementById("fen");
103 fenInput.style.width = (this.curFen.length+3) + "ch";
105 tryGotoFen: function() {
106 if (V.IsGoodFen(this.curFen)) {
107 this.gameRef.fen = this.curFen;
115 <style lang="sass" scoped=true>
117 // Use a Monospace font for input FEN width adjustment
118 font-family: "Fira Code"