3 input#modalRules.modal(type="checkbox")
6 data-checkbox="modalRules"
9 label.modal-close(for="modalRules")
10 h4#variantNameInAnalyze(@click="gotoRules()") {{ game.vname }}
11 div(v-html="rulesContent")
17 @input="adjustFenSize(); tryGotoFen()"
27 import BaseGame from "@/components/BaseGame.vue";
28 import { processModalClick } from "@/utils/modalClick";
29 import { replaceByDiag } from "@/utils/printDiagram";
30 import { store } from "@/store";
33 // TODO: game import ==> require some adjustments, like
34 // the ability to analyse from a list of moves...
38 // gameRef: to find the game in (potentially remote) storage
48 players: [{ name: "Analyse" }, { name: "Analyse" }],
63 document.getElementById("rulesDiv")
64 .addEventListener("click", processModalClick);
67 alertAndQuit: function(text, wrongVname) {
68 // Soon after component creation, st.tr might be uninitialized.
69 // Set a timeout to let a chance for the message to show translated.
71 "/variants" + (wrongVname ? "" : "/" + this.gameRef.vname);
73 alert(this.st.tr[text] || text);
74 this.$router.replace(newUrl);
77 initFromUrl: function() {
78 this.gameRef.vname = this.$route.params["vname"];
79 const routeFen = this.$route.query["fen"];
80 if (!routeFen) this.alertAndQuit("Missing FEN");
82 this.gameRef.fen = routeFen.replace(/_/g, " ");
83 // orientation is optional: taken from FEN if missing.
84 // NOTE: currently no internal usage of 'side', but could be used by
85 // manually settings the URL (TODO?).
86 const orientation = this.$route.query["side"];
87 this.initialize(orientation);
90 initialize: async function(orientation) {
91 // Obtain VariantRules object
92 await import("@/variants/" + this.gameRef.vname + ".js")
94 window.V = vModule[this.gameRef.vname + "Rules"];
96 // Late check, in case the user tried to enter URL by hand
97 this.alertAndQuit("Analysis disabled for this variant");
98 else this.loadGame(orientation);
100 .catch((err) => { this.alertAndQuit("Mispelled variant name", true); });
103 "raw-loader!@/translations/rules/" +
104 this.gameRef.vname + "/" +
105 this.st.lang + ".pug"
107 // Next two lines fix a weird issue after last update (2019-11)
108 .replace(/\\n/g, " ")
109 .replace(/\\"/g, '"')
110 .replace('module.exports = "', "")
112 .replace(/(fen:)([^:]*):/g, replaceByDiag);
114 gotoRules: function() {
115 this.$router.push("/variants/" + this.gameRef.vname);
117 loadGame: function(orientation) {
118 this.game.vname = this.gameRef.vname;
119 this.game.fenStart = this.gameRef.fen;
120 this.game.fen = this.gameRef.fen;
121 this.game.score = "*"; //never change
122 this.curFen = this.game.fen;
123 this.adjustFenSize();
124 this.game.mycolor = orientation || V.ParseFen(this.gameRef.fen).turn;
125 this.$refs["basegame"].re_setVariables(this.game);
127 // Triggered by "fenchange" emitted in BaseGame:
128 setFen: function(fen) {
130 this.adjustFenSize();
132 adjustFenSize: function() {
133 let fenInput = document.getElementById("fen");
134 fenInput.style.width = (this.curFen.length+3) + "ch";
136 tryGotoFen: function() {
137 if (V.IsGoodFen(this.curFen)) {
138 this.gameRef.fen = this.curFen;
147 @import "@/styles/_board_squares_img.sass"
148 @import "@/styles/_rules.sass"
151 <style lang="sass" scoped>
152 h4#variantNameInAnalyze
155 text-decoration: underline
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"