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 BA |
10 | BaseGame( |
11 | :game="game" | |
12 | :vr="vr" | |
13 | ) | |
7f3484bd BA |
14 | </template> |
15 | ||
16 | <script> | |
17 | import BaseGame from "@/components/BaseGame.vue"; | |
7f3484bd | 18 | import { store } from "@/store"; |
7f3484bd | 19 | export default { |
6808d7a1 | 20 | name: "my-analyse", |
7f3484bd | 21 | components: { |
6808d7a1 | 22 | BaseGame |
7f3484bd BA |
23 | }, |
24 | // gameRef: to find the game in (potentially remote) storage | |
25 | data: function() { | |
26 | return { | |
27 | st: store.state, | |
6808d7a1 BA |
28 | gameRef: { |
29 | //given in URL (rid = remote ID) | |
652f40de BA |
30 | vname: "", |
31 | fen: "" | |
32 | }, | |
33 | game: { | |
6808d7a1 BA |
34 | players: [{ name: "Analyse" }, { name: "Analyse" }], |
35 | mode: "analyze" | |
7f3484bd | 36 | }, |
7f3484bd | 37 | vr: null, //"variant rules" object initialized from FEN |
6808d7a1 | 38 | curFen: "" |
7f3484bd BA |
39 | }; |
40 | }, | |
41 | watch: { | |
a0c41e7e BA |
42 | // NOTE: no watcher for $route change, because if fenStart doesn't change |
43 | // then it doesn't trigger BaseGame.re_init() and the result is weird. | |
6808d7a1 | 44 | "vr.movesCount": function() { |
5157ce0b BA |
45 | this.curFen = this.vr.getFen(); |
46 | this.adjustFenSize(); | |
6808d7a1 | 47 | } |
7f3484bd | 48 | }, |
7f3484bd | 49 | created: function() { |
652f40de | 50 | this.gameRef.vname = this.$route.params["vname"]; |
20620465 BA |
51 | this.gameRef.fen = this.$route.query["fen"].replace(/_/g, " "); |
52 | this.initialize(); | |
7f3484bd BA |
53 | }, |
54 | methods: { | |
a0c41e7e | 55 | initialize: async function() { |
5157ce0b BA |
56 | // Obtain VariantRules object |
57 | const vModule = await import("@/variants/" + this.gameRef.vname + ".js"); | |
58 | window.V = vModule.VariantRules; | |
a0c41e7e | 59 | this.loadGame(); |
5157ce0b BA |
60 | }, |
61 | loadGame: function() { | |
0e16cb26 | 62 | // NOTE: no need to set score (~unused) |
652f40de BA |
63 | this.game.vname = this.gameRef.vname; |
64 | this.game.fen = this.gameRef.fen; | |
5157ce0b BA |
65 | this.curFen = this.game.fen; |
66 | this.adjustFenSize(); | |
652f40de | 67 | this.vr = new V(this.game.fen); |
d641bec1 | 68 | this.game.mycolor = this.vr.turn; |
77c50966 | 69 | this.$set(this.game, "fenStart", this.gameRef.fen); |
7f3484bd | 70 | }, |
5157ce0b BA |
71 | adjustFenSize: function() { |
72 | let fenInput = document.getElementById("fen"); | |
73 | fenInput.style.width = this.curFen.length + "ch"; | |
74 | }, | |
725da57f BA |
75 | tryGotoFen: function() { |
76 | if (V.IsGoodFen(this.curFen)) | |
77 | { | |
78 | this.gameRef.fen = this.curFen; | |
79 | this.loadGame(); | |
80 | } | |
6808d7a1 BA |
81 | } |
82 | } | |
7f3484bd BA |
83 | }; |
84 | </script> |