'update'
[vchess.git] / client / src / views / Analyze.vue
1 <template lang="pug">
2 main
3 .row
4 .col-sm-12
5 #fenDiv
6 input#fen(v-model="curFen" @input="adjustFenSize")
7 button(@click="gotoFen") Go
8 .row
9 .col-sm-12.col-md-10.col-md-offset-1
10 BaseGame(:game="game" :vr="vr" ref="basegame")
11 </template>
12
13 <script>
14 import BaseGame from "@/components/BaseGame.vue";
15 import { store } from "@/store";
16 import { ArrayFun } from "@/utils/array";
17
18 export default {
19 name: 'my-analyze',
20 components: {
21 BaseGame,
22 },
23 // gameRef: to find the game in (potentially remote) storage
24 data: function() {
25 return {
26 st: store.state,
27 gameRef: { //given in URL (rid = remote ID)
28 vname: "",
29 fen: ""
30 },
31 game: {
32 players:[{name:"Analyze"},{name:"Analyze"}],
33 mode: "analyze"
34 },
35 vr: null, //"variant rules" object initialized from FEN
36 curFen: "",
37 //people: [], //players + observers //TODO later: interactive analyze...
38 };
39 },
40 watch: {
41 "$route": function(to, from) {
42 this.gameRef.fen = to.query["fen"].replace(/_/g, " ");
43 this.gameRef.vname = to.params["vname"];
44 this.loadGame();
45 },
46 "vr.movesCount": function(fen) {
47 this.curFen = this.vr.getFen();
48 this.adjustFenSize();
49 },
50 },
51 created: function() {
52 this.gameRef.fen = this.$route.query["fen"].replace(/_/g, " ");
53 this.gameRef.vname = this.$route.params["vname"];
54 this.initialize(this.loadGame);
55 },
56 methods: {
57 initialize: async function(callback) {
58 // Obtain VariantRules object
59 const vModule = await import("@/variants/" + this.gameRef.vname + ".js");
60 window.V = vModule.VariantRules;
61 callback();
62 },
63 loadGame: function() {
64 this.game.vname = this.gameRef.vname;
65 this.game.fen = this.gameRef.fen;
66 this.curFen = this.game.fen;
67 this.adjustFenSize();
68 this.vr = new V(this.game.fen);
69 this.$set(this.game, "fenStart", this.gameRef.fen); //TODO: Vue3...
70 },
71 adjustFenSize: function() {
72 let fenInput = document.getElementById("fen");
73 fenInput.style.width = this.curFen.length + "ch";
74 },
75 gotoFen: function() {
76 this.gameRef.fen = this.curFen;
77 this.loadGame();
78 },
79 },
80 };
81 </script>
82
83 <style lang="sass" scoped>
84 #fenDiv
85 text-align: center
86 </style>