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, " "); | |
07052665 BA |
67 | // orientation is optional: taken from FEN if missing. |
68 | // NOTE: currently no internal usage of 'side', but could be used by | |
69 | // manually settings the URL (TODO?). | |
b1e46b33 BA |
70 | const orientation = this.$route.query["side"]; |
71 | this.initialize(orientation); | |
72 | } | |
73 | }, | |
7ba4a5bc | 74 | initialize: async function(orientation) { |
5157ce0b | 75 | // Obtain VariantRules object |
a97bdbda BA |
76 | await import("@/variants/" + this.gameRef.vname + ".js") |
77 | .then((vModule) => { | |
32f6285e | 78 | window.V = vModule[this.gameRef.vname + "Rules"]; |
a97bdbda BA |
79 | if (!V.CanAnalyze) |
80 | // Late check, in case the user tried to enter URL by hand | |
81 | this.alertAndQuit("Analysis disabled for this variant"); | |
7ba4a5bc | 82 | else this.loadGame(orientation); |
a97bdbda BA |
83 | }) |
84 | .catch((err) => { this.alertAndQuit("Mispelled variant name", true); }); | |
5157ce0b | 85 | }, |
7ba4a5bc | 86 | loadGame: function(orientation) { |
652f40de | 87 | this.game.vname = this.gameRef.vname; |
b1e46b33 | 88 | this.game.fenStart = this.gameRef.fen; |
652f40de | 89 | this.game.fen = this.gameRef.fen; |
0234201f | 90 | this.game.score = "*"; //never change |
5157ce0b BA |
91 | this.curFen = this.game.fen; |
92 | this.adjustFenSize(); | |
7ba4a5bc | 93 | this.game.mycolor = orientation || V.ParseFen(this.gameRef.fen).turn; |
b1e46b33 | 94 | this.$refs["basegame"].re_setVariables(this.game); |
7f3484bd | 95 | }, |
8055eabd BA |
96 | // Triggered by "fenchange" emitted in BaseGame: |
97 | setFen: function(fen) { | |
98 | this.curFen = fen; | |
99 | this.adjustFenSize(); | |
100 | }, | |
5157ce0b BA |
101 | adjustFenSize: function() { |
102 | let fenInput = document.getElementById("fen"); | |
d54f6261 | 103 | fenInput.style.width = (this.curFen.length+3) + "ch"; |
5157ce0b | 104 | }, |
725da57f | 105 | tryGotoFen: function() { |
3a2a7b5f | 106 | if (V.IsGoodFen(this.curFen)) { |
725da57f BA |
107 | this.gameRef.fen = this.curFen; |
108 | this.loadGame(); | |
109 | } | |
6808d7a1 BA |
110 | } |
111 | } | |
7f3484bd BA |
112 | }; |
113 | </script> | |
d54f6261 BA |
114 | |
115 | <style lang="sass" scoped=true> | |
116 | input#fen | |
117 | // Use a Monospace font for input FEN width adjustment | |
118 | font-family: "Fira Code" | |
119 | </style> |