Fix. TODO: Vue reactivity on game.score and game. ...
[vchess.git] / client / src / views / Analyze.vue
1 <template lang="pug">
2 main
3 .row
4 .col-sm-12.col-md-10.col-md-offset-1
5 BaseGame(:game="game" :vr="vr" ref="basegame")
6 </template>
7
8 <script>
9 import BaseGame from "@/components/BaseGame.vue";
10 import { store } from "@/store";
11 import { ArrayFun } from "@/utils/array";
12
13 export default {
14 name: 'my-analyze',
15 components: {
16 BaseGame,
17 },
18 // gameRef: to find the game in (potentially remote) storage
19 data: function() {
20 return {
21 st: store.state,
22 gameRef: { //given in URL (rid = remote ID)
23 vname: "",
24 fen: ""
25 },
26 game: {
27 players:[{name:"Analyze"},{name:"Analyze"}],
28 mode: "analyze"
29 },
30 vr: null, //"variant rules" object initialized from FEN
31 //people: [], //players + observers //TODO later: interactive analyze...
32 };
33 },
34 watch: {
35 "$route": function(to, from) {
36 this.gameRef.fen = to.query["fen"].replace(/_/g, " ");
37 this.gameRef.vname = to.params["vname"];
38 this.loadGame();
39 },
40 },
41 created: function() {
42 this.gameRef.fen = this.$route.query["fen"].replace(/_/g, " ");
43 this.gameRef.vname = this.$route.params["vname"];
44 this.loadGame();
45 },
46 methods: {
47 loadGame: async function() {
48 this.game.vname = this.gameRef.vname;
49 this.game.fen = this.gameRef.fen;
50 const vModule = await import("@/variants/" + this.game.vname + ".js");
51 window.V = vModule.VariantRules;
52 this.vr = new V(this.game.fen);
53 // fenStart initialized in the end, after definition of V,
54 // because it triggers a reset on BaseGame component.
55 this.$set(this.game, "fenStart", this.gameRef.fen); //TODO: Vue3...
56 },
57 },
58 };
59 </script>
60
61 <style lang="sass">
62 // TODO
63 </style>