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";
32 import afterRawLoad from "@/utils/afterRawLoad";
35 // TODO: game import ==> require some adjustments, like
36 // the ability to analyse from a list of moves...
40 // gameRef: to find the game in (potentially remote) storage
50 players: [{ name: "Analyse" }, { name: "Analyse" }],
65 document.getElementById("rulesDiv")
66 .addEventListener("click", processModalClick);
69 alertAndQuit: function(text, wrongVname) {
70 // Soon after component creation, st.tr might be uninitialized.
71 // Set a timeout to let a chance for the message to show translated.
73 "/variants" + (wrongVname ? "" : "/" + this.gameRef.vname);
75 alert(this.st.tr[text] || text);
76 this.$router.replace(newUrl);
79 initFromUrl: function() {
80 this.gameRef.vname = this.$route.params["vname"];
81 const routeFen = this.$route.query["fen"];
82 if (!routeFen) this.alertAndQuit("Missing FEN");
84 this.gameRef.fen = routeFen.replace(/_/g, " ");
85 // orientation is optional: taken from FEN if missing.
86 // NOTE: currently no internal usage of 'side', but could be used by
87 // manually settings the URL (TODO?).
88 const orientation = this.$route.query["side"];
89 this.initialize(orientation);
92 initialize: async function(orientation) {
93 // Obtain VariantRules object
94 await import("@/variants/" + this.gameRef.vname + ".js")
96 window.V = vModule[this.gameRef.vname + "Rules"];
98 // Late check, in case the user tried to enter URL by hand
99 this.alertAndQuit("Analysis disabled for this variant");
100 else this.loadGame(orientation);
102 .catch((err) => { this.alertAndQuit("Mispelled variant name", true); });
106 "raw-loader!@/translations/rules/" +
107 this.gameRef.vname + "/" + this.st.lang + ".pug"
109 ).replace(/(fen:)([^:]*):/g, replaceByDiag);
111 loadGame: function(orientation) {
112 this.game.vname = this.gameRef.vname;
113 this.game.fenStart = this.gameRef.fen;
114 this.game.fen = this.gameRef.fen;
115 this.game.score = "*"; //never change
116 this.curFen = this.game.fen;
117 this.adjustFenSize();
118 this.game.mycolor = orientation || V.ParseFen(this.gameRef.fen).turn;
119 this.$refs["basegame"].re_setVariables(this.game);
121 // Triggered by "fenchange" emitted in BaseGame:
122 setFen: function(fen) {
124 this.adjustFenSize();
126 adjustFenSize: function() {
127 let fenInput = document.getElementById("fen");
128 fenInput.style.width = (this.curFen.length+3) + "ch";
130 tryGotoFen: function() {
131 if (V.IsGoodFen(this.curFen)) {
132 this.gameRef.fen = this.curFen;
141 @import "@/styles/_board_squares_img.sass"
142 @import "@/styles/_rules.sass"
145 <style lang="sass" scoped>
146 a#variantNameInAnalyze
147 color: var(--card-fore-color)
150 font-size: calc(1rem * var(--heading-ratio))
152 margin: calc(1.5 * var(--universal-margin))
158 @media screen and (max-width: 1500px)
160 @media screen and (max-width: 1024px)
162 @media screen and (max-width: 767px)
166 // Use a Monospace font for input FEN width adjustment
167 font-family: "Fira Code"