3 input#modalRules.modal(type="checkbox")
6 data-checkbox="modalRules"
9 label.modal-close(for="modalRules")
10 a#variantNameInAnalyze(:href="'/#/variants/'+game.vname")
12 div(v-html="rulesContent")
18 @input="adjustFenSize(); tryGotoFen()"
28 import BaseGame from "@/components/BaseGame.vue";
29 import { processModalClick } from "@/utils/modalClick";
30 import { replaceByDiag } from "@/utils/printDiagram";
31 import { store } from "@/store";
34 // TODO: game import ==> require some adjustments, like
35 // the ability to analyse from a list of moves...
39 // gameRef: to find the game in (potentially remote) storage
49 players: [{ name: "Analyse" }, { name: "Analyse" }],
64 document.getElementById("rulesDiv")
65 .addEventListener("click", processModalClick);
68 alertAndQuit: function(text, wrongVname) {
69 // Soon after component creation, st.tr might be uninitialized.
70 // Set a timeout to let a chance for the message to show translated.
72 "/variants" + (wrongVname ? "" : "/" + this.gameRef.vname);
74 alert(this.st.tr[text] || text);
75 this.$router.replace(newUrl);
78 initFromUrl: function() {
79 this.gameRef.vname = this.$route.params["vname"];
80 const routeFen = this.$route.query["fen"];
81 if (!routeFen) this.alertAndQuit("Missing FEN");
83 this.gameRef.fen = routeFen.replace(/_/g, " ");
84 // orientation is optional: taken from FEN if missing.
85 // NOTE: currently no internal usage of 'side', but could be used by
86 // manually settings the URL (TODO?).
87 const orientation = this.$route.query["side"];
88 this.initialize(orientation);
91 initialize: async function(orientation) {
92 // Obtain VariantRules object
93 await import("@/variants/" + this.gameRef.vname + ".js")
95 window.V = vModule[this.gameRef.vname + "Rules"];
97 // Late check, in case the user tried to enter URL by hand
98 this.alertAndQuit("Analysis disabled for this variant");
99 else this.loadGame(orientation);
101 .catch((err) => { this.alertAndQuit("Mispelled variant name", true); });
104 "raw-loader!@/translations/rules/" +
105 this.gameRef.vname + "/" +
106 this.st.lang + ".pug"
108 // Next two lines fix a weird issue after last update (2019-11)
109 .replace(/\\n/g, " ")
110 .replace(/\\"/g, '"')
111 .replace('module.exports = "', "")
113 .replace(/(fen:)([^:]*):/g, replaceByDiag);
115 loadGame: function(orientation) {
116 this.game.vname = this.gameRef.vname;
117 this.game.fenStart = this.gameRef.fen;
118 this.game.fen = this.gameRef.fen;
119 this.game.score = "*"; //never change
120 this.curFen = this.game.fen;
121 this.adjustFenSize();
122 this.game.mycolor = orientation || V.ParseFen(this.gameRef.fen).turn;
123 this.$refs["basegame"].re_setVariables(this.game);
125 // Triggered by "fenchange" emitted in BaseGame:
126 setFen: function(fen) {
128 this.adjustFenSize();
130 adjustFenSize: function() {
131 let fenInput = document.getElementById("fen");
132 fenInput.style.width = (this.curFen.length+3) + "ch";
134 tryGotoFen: function() {
135 if (V.IsGoodFen(this.curFen)) {
136 this.gameRef.fen = this.curFen;
145 @import "@/styles/_board_squares_img.sass"
146 @import "@/styles/_rules.sass"
149 <style lang="sass" scoped>
150 a#variantNameInAnalyze
151 color: var(--card-fore-color)
154 font-size: calc(1rem * var(--heading-ratio))
156 margin: calc(1.5 * var(--universal-margin))
162 @media screen and (max-width: 1500px)
164 @media screen and (max-width: 1024px)
166 @media screen and (max-width: 767px)
170 // Use a Monospace font for input FEN width adjustment
171 font-family: "Fira Code"