- tryChangeVariant: async function(vname) {
- if (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;
+ clickReadRules: function() {
+ if (this.display != "rules") this.display = "rules";
+ else if (this.gameInProgress) this.display = "computer";
+ },
+ parseFen(fen) {
+ const fenParts = fen.split(" ");
+ return {
+ position: fenParts[0],
+ marks: fenParts[1],
+ orientation: fenParts[2],
+ shadow: fenParts[3]
+ };
+ },
+ // 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.VariantRules;
+ 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);
+ });