'update'
[vchess.git] / client / src / views / Analyse.vue
CommitLineData
7f3484bd 1<template lang="pug">
7aa548e7 2main
63ca2b89
BA
3 .row
4 .col-sm-12
5157ce0b
BA
5 #fenDiv
6 input#fen(v-model="curFen" @input="adjustFenSize")
9ddaf8da 7 button(@click="gotoFen()") {{ st.tr["Go"] }}
602d6bef 8 BaseGame(:game="game" :vr="vr" ref="basegame")
7f3484bd
BA
9</template>
10
11<script>
12import BaseGame from "@/components/BaseGame.vue";
7f3484bd 13import { store } from "@/store";
7f3484bd 14import { ArrayFun } from "@/utils/array";
7f3484bd 15export default {
677fe285 16 name: 'my-analyse',
7f3484bd
BA
17 components: {
18 BaseGame,
7f3484bd
BA
19 },
20 // gameRef: to find the game in (potentially remote) storage
21 data: function() {
22 return {
23 st: store.state,
24 gameRef: { //given in URL (rid = remote ID)
652f40de
BA
25 vname: "",
26 fen: ""
27 },
28 game: {
677fe285 29 players:[{name:"Analyse"},{name:"Analyse"}],
652f40de 30 mode: "analyze"
7f3484bd 31 },
7f3484bd 32 vr: null, //"variant rules" object initialized from FEN
5157ce0b 33 curFen: "",
652f40de 34 //people: [], //players + observers //TODO later: interactive analyze...
7f3484bd
BA
35 };
36 },
37 watch: {
a0c41e7e
BA
38 // NOTE: no watcher for $route change, because if fenStart doesn't change
39 // then it doesn't trigger BaseGame.re_init() and the result is weird.
5157ce0b
BA
40 "vr.movesCount": function(fen) {
41 this.curFen = this.vr.getFen();
42 this.adjustFenSize();
43 },
7f3484bd 44 },
7f3484bd 45 created: function() {
652f40de 46 this.gameRef.vname = this.$route.params["vname"];
a0c41e7e 47 if (this.gameRef.vname == "Dark")
0e16cb26 48 {
677fe285 49 alert(this.st.tr["Analyse in Dark mode makes no sense!"]);
0e16cb26
BA
50 history.back(); //or this.$router.go(-1)
51 }
a0c41e7e
BA
52 else
53 {
54 this.gameRef.fen = this.$route.query["fen"].replace(/_/g, " ");
55 this.initialize();
56 }
7f3484bd
BA
57 },
58 methods: {
a0c41e7e 59 initialize: async function() {
5157ce0b
BA
60 // Obtain VariantRules object
61 const vModule = await import("@/variants/" + this.gameRef.vname + ".js");
62 window.V = vModule.VariantRules;
a0c41e7e 63 this.loadGame();
5157ce0b
BA
64 },
65 loadGame: function() {
0e16cb26 66 // NOTE: no need to set score (~unused)
652f40de
BA
67 this.game.vname = this.gameRef.vname;
68 this.game.fen = this.gameRef.fen;
5157ce0b
BA
69 this.curFen = this.game.fen;
70 this.adjustFenSize();
652f40de 71 this.vr = new V(this.game.fen);
d641bec1 72 this.game.mycolor = this.vr.turn;
77c50966 73 this.$set(this.game, "fenStart", this.gameRef.fen);
7f3484bd 74 },
5157ce0b
BA
75 adjustFenSize: function() {
76 let fenInput = document.getElementById("fen");
77 fenInput.style.width = this.curFen.length + "ch";
78 },
79 gotoFen: function() {
80 this.gameRef.fen = this.curFen;
81 this.loadGame();
82 },
7f3484bd
BA
83 },
84};
85</script>
86
5157ce0b
BA
87<style lang="sass" scoped>
88#fenDiv
89 text-align: center
7f3484bd 90</style>