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" | |
8 | @input="adjustFenSize()" | |
9 | ) | |
9ddaf8da | 10 | button(@click="gotoFen()") {{ st.tr["Go"] }} |
910d631b BA |
11 | BaseGame( |
12 | :game="game" | |
13 | :vr="vr" | |
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", |
7f3484bd | 22 | components: { |
6808d7a1 | 23 | BaseGame |
7f3484bd BA |
24 | }, |
25 | // gameRef: to find the game in (potentially remote) storage | |
26 | data: function() { | |
27 | return { | |
28 | st: store.state, | |
6808d7a1 BA |
29 | gameRef: { |
30 | //given in URL (rid = remote ID) | |
652f40de BA |
31 | vname: "", |
32 | fen: "" | |
33 | }, | |
34 | game: { | |
6808d7a1 BA |
35 | players: [{ name: "Analyse" }, { name: "Analyse" }], |
36 | mode: "analyze" | |
7f3484bd | 37 | }, |
7f3484bd | 38 | vr: null, //"variant rules" object initialized from FEN |
6808d7a1 | 39 | curFen: "" |
652f40de | 40 | //people: [], //players + observers //TODO later: interactive analyze... |
7f3484bd BA |
41 | }; |
42 | }, | |
43 | watch: { | |
a0c41e7e BA |
44 | // NOTE: no watcher for $route change, because if fenStart doesn't change |
45 | // then it doesn't trigger BaseGame.re_init() and the result is weird. | |
6808d7a1 | 46 | "vr.movesCount": function() { |
5157ce0b BA |
47 | this.curFen = this.vr.getFen(); |
48 | this.adjustFenSize(); | |
6808d7a1 | 49 | } |
7f3484bd | 50 | }, |
7f3484bd | 51 | created: function() { |
652f40de | 52 | this.gameRef.vname = this.$route.params["vname"]; |
6808d7a1 | 53 | if (this.gameRef.vname == "Dark") { |
677fe285 | 54 | alert(this.st.tr["Analyse in Dark mode makes no sense!"]); |
0e16cb26 | 55 | history.back(); //or this.$router.go(-1) |
6808d7a1 | 56 | } else { |
a0c41e7e BA |
57 | this.gameRef.fen = this.$route.query["fen"].replace(/_/g, " "); |
58 | this.initialize(); | |
59 | } | |
7f3484bd BA |
60 | }, |
61 | methods: { | |
a0c41e7e | 62 | initialize: async function() { |
5157ce0b BA |
63 | // Obtain VariantRules object |
64 | const vModule = await import("@/variants/" + this.gameRef.vname + ".js"); | |
65 | window.V = vModule.VariantRules; | |
a0c41e7e | 66 | this.loadGame(); |
5157ce0b BA |
67 | }, |
68 | loadGame: function() { | |
0e16cb26 | 69 | // NOTE: no need to set score (~unused) |
652f40de BA |
70 | this.game.vname = this.gameRef.vname; |
71 | this.game.fen = this.gameRef.fen; | |
5157ce0b BA |
72 | this.curFen = this.game.fen; |
73 | this.adjustFenSize(); | |
652f40de | 74 | this.vr = new V(this.game.fen); |
d641bec1 | 75 | this.game.mycolor = this.vr.turn; |
77c50966 | 76 | this.$set(this.game, "fenStart", this.gameRef.fen); |
7f3484bd | 77 | }, |
5157ce0b BA |
78 | adjustFenSize: function() { |
79 | let fenInput = document.getElementById("fen"); | |
80 | fenInput.style.width = this.curFen.length + "ch"; | |
81 | }, | |
82 | gotoFen: function() { | |
83 | this.gameRef.fen = this.curFen; | |
84 | this.loadGame(); | |
6808d7a1 BA |
85 | } |
86 | } | |
7f3484bd BA |
87 | }; |
88 | </script> |