- tryChangeVariant: async function(vname) {
- 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;
- const vModule = await import("@/variants/" + vname + ".js");
- window.V = vModule.VariantRules;
- // Method to replace diagrams in loaded HTML
- const replaceByDiag = (match, p1, p2) => {
- const args = this.parseFen(p2);
- return getDiagram(args);
- };
- // (AJAX) Request to get rules content (plain text, HTML)
- this.content =
- require("raw-loader!@/rules/" + vname + "/" + this.st.lang + ".pug")
- .replace(/(fen:)([^:]*):/g, replaceByDiag);
+ // Method to replace diagrams in loaded HTML
+ replaceByDiag: function(match, p1, p2) {
+ const args = this.parseFen(p2);
+ return getDiagram(args);
+ },
+ re_setVariant: async function(vname) {
+ await import("@/variants/" + vname + ".js")
+ .then((vModule) => {
+ this.V = window.V = vModule[vname + "Rules"];
+ this.gameInfo.vname = vname;
+ })
+ .catch((err) => {
+ // Soon after component creation, st.tr might be uninitialized.
+ // Set a timeout to let a chance for the message to show translated.
+ const text = "Mispelled variant name";
+ setTimeout(() => {
+ alert(this.st.tr[text] || text);
+ this.$router.replace("/variants");
+ }, 500);
+ });