Commit | Line | Data |
---|---|---|
7f3484bd | 1 | <template lang="pug"> |
7aa548e7 | 2 | main |
63ca2b89 BA |
3 | .row |
4 | .col-sm-12 | |
9a3049f3 | 5 | .text-center |
910d631b BA |
6 | input#fen( |
7 | v-model="curFen" | |
725da57f | 8 | @input="adjustFenSize(); tryGotoFen()" |
910d631b | 9 | ) |
910d631b | 10 | BaseGame( |
b1e46b33 | 11 | ref="basegame" |
910d631b | 12 | :game="game" |
8055eabd | 13 | @fenchange="setFen" |
910d631b | 14 | ) |
7f3484bd BA |
15 | </template> |
16 | ||
17 | <script> | |
18 | import BaseGame from "@/components/BaseGame.vue"; | |
7f3484bd | 19 | import { store } from "@/store"; |
7f3484bd | 20 | export default { |
6808d7a1 | 21 | name: "my-analyse", |
5f918a27 BA |
22 | // TODO: game import ==> require some adjustments, like |
23 | // the ability to analyse from a list of moves... | |
7f3484bd | 24 | components: { |
6808d7a1 | 25 | BaseGame |
7f3484bd BA |
26 | }, |
27 | // gameRef: to find the game in (potentially remote) storage | |
28 | data: function() { | |
29 | return { | |
30 | st: store.state, | |
6808d7a1 | 31 | gameRef: { |
652f40de BA |
32 | vname: "", |
33 | fen: "" | |
34 | }, | |
35 | game: { | |
6808d7a1 BA |
36 | players: [{ name: "Analyse" }, { name: "Analyse" }], |
37 | mode: "analyze" | |
7f3484bd | 38 | }, |
6808d7a1 | 39 | curFen: "" |
7f3484bd BA |
40 | }; |
41 | }, | |
b1e46b33 BA |
42 | watch: { |
43 | $route: function() { | |
44 | this.initFromUrl(); | |
a97bdbda | 45 | } |
7f3484bd | 46 | }, |
b1e46b33 BA |
47 | created: function() { |
48 | this.initFromUrl(); | |
49 | }, | |
7f3484bd | 50 | methods: { |
a97bdbda BA |
51 | alertAndQuit: function(text, wrongVname) { |
52 | // Soon after component creation, st.tr might be uninitialized. | |
53 | // Set a timeout to let a chance for the message to show translated. | |
2c5d7b20 BA |
54 | const newUrl = |
55 | "/variants" + (wrongVname ? "" : "/" + this.gameRef.vname); | |
a97bdbda BA |
56 | setTimeout(() => { |
57 | alert(this.st.tr[text] || text); | |
58 | this.$router.replace(newUrl); | |
59 | }, 500); | |
60 | }, | |
b1e46b33 BA |
61 | initFromUrl: function() { |
62 | this.gameRef.vname = this.$route.params["vname"]; | |
63 | const routeFen = this.$route.query["fen"]; | |
64 | if (!routeFen) this.alertAndQuit("Missing FEN"); | |
65 | else { | |
66 | this.gameRef.fen = routeFen.replace(/_/g, " "); | |
67 | // orientation is optional: taken from FEN if missing | |
68 | const orientation = this.$route.query["side"]; | |
69 | this.initialize(orientation); | |
70 | } | |
71 | }, | |
7ba4a5bc | 72 | initialize: async function(orientation) { |
5157ce0b | 73 | // Obtain VariantRules object |
a97bdbda BA |
74 | await import("@/variants/" + this.gameRef.vname + ".js") |
75 | .then((vModule) => { | |
32f6285e | 76 | window.V = vModule[this.gameRef.vname + "Rules"]; |
a97bdbda BA |
77 | if (!V.CanAnalyze) |
78 | // Late check, in case the user tried to enter URL by hand | |
79 | this.alertAndQuit("Analysis disabled for this variant"); | |
7ba4a5bc | 80 | else this.loadGame(orientation); |
a97bdbda BA |
81 | }) |
82 | .catch((err) => { this.alertAndQuit("Mispelled variant name", true); }); | |
5157ce0b | 83 | }, |
7ba4a5bc | 84 | loadGame: function(orientation) { |
652f40de | 85 | this.game.vname = this.gameRef.vname; |
b1e46b33 | 86 | this.game.fenStart = this.gameRef.fen; |
652f40de | 87 | this.game.fen = this.gameRef.fen; |
0234201f | 88 | this.game.score = "*"; //never change |
5157ce0b BA |
89 | this.curFen = this.game.fen; |
90 | this.adjustFenSize(); | |
7ba4a5bc | 91 | this.game.mycolor = orientation || V.ParseFen(this.gameRef.fen).turn; |
b1e46b33 | 92 | this.$refs["basegame"].re_setVariables(this.game); |
7f3484bd | 93 | }, |
8055eabd BA |
94 | // Triggered by "fenchange" emitted in BaseGame: |
95 | setFen: function(fen) { | |
96 | this.curFen = fen; | |
97 | this.adjustFenSize(); | |
98 | }, | |
5157ce0b BA |
99 | adjustFenSize: function() { |
100 | let fenInput = document.getElementById("fen"); | |
d54f6261 | 101 | fenInput.style.width = (this.curFen.length+3) + "ch"; |
5157ce0b | 102 | }, |
725da57f | 103 | tryGotoFen: function() { |
3a2a7b5f | 104 | if (V.IsGoodFen(this.curFen)) { |
725da57f BA |
105 | this.gameRef.fen = this.curFen; |
106 | this.loadGame(); | |
107 | } | |
6808d7a1 BA |
108 | } |
109 | } | |
7f3484bd BA |
110 | }; |
111 | </script> | |
d54f6261 BA |
112 | |
113 | <style lang="sass" scoped=true> | |
114 | input#fen | |
115 | // Use a Monospace font for input FEN width adjustment | |
116 | font-family: "Fira Code" | |
117 | </style> |