Everything implemented. A lot still untested
[vchess.git] / client / src / views / Analyze.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")
602d6bef
BA
7 button(@click="gotoFen") {{ st.tr["Go"] }}
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
BA
14import { ArrayFun } from "@/utils/array";
15
16export default {
652f40de 17 name: 'my-analyze',
7f3484bd
BA
18 components: {
19 BaseGame,
7f3484bd
BA
20 },
21 // gameRef: to find the game in (potentially remote) storage
22 data: function() {
23 return {
24 st: store.state,
25 gameRef: { //given in URL (rid = remote ID)
652f40de
BA
26 vname: "",
27 fen: ""
28 },
29 game: {
30 players:[{name:"Analyze"},{name:"Analyze"}],
31 mode: "analyze"
7f3484bd 32 },
7f3484bd 33 vr: null, //"variant rules" object initialized from FEN
5157ce0b 34 curFen: "",
652f40de 35 //people: [], //players + observers //TODO later: interactive analyze...
7f3484bd
BA
36 };
37 },
38 watch: {
39 "$route": function(to, from) {
652f40de
BA
40 this.gameRef.fen = to.query["fen"].replace(/_/g, " ");
41 this.gameRef.vname = to.params["vname"];
7f3484bd
BA
42 this.loadGame();
43 },
5157ce0b
BA
44 "vr.movesCount": function(fen) {
45 this.curFen = this.vr.getFen();
46 this.adjustFenSize();
47 },
7f3484bd 48 },
7f3484bd 49 created: function() {
652f40de
BA
50 this.gameRef.fen = this.$route.query["fen"].replace(/_/g, " ");
51 this.gameRef.vname = this.$route.params["vname"];
0e16cb26
BA
52 if (this.gameRef.vname != "Dark")
53 this.initialize(this.loadGame);
54 else
55 {
602d6bef 56 alert(this.st.tr["Analyze in Dark mode makes no sense!"]);
0e16cb26
BA
57 history.back(); //or this.$router.go(-1)
58 }
7f3484bd
BA
59 },
60 methods: {
5157ce0b
BA
61 initialize: async function(callback) {
62 // Obtain VariantRules object
63 const vModule = await import("@/variants/" + this.gameRef.vname + ".js");
64 window.V = vModule.VariantRules;
65 callback();
66 },
67 loadGame: function() {
0e16cb26 68 // NOTE: no need to set score (~unused)
652f40de
BA
69 this.game.vname = this.gameRef.vname;
70 this.game.fen = this.gameRef.fen;
5157ce0b
BA
71 this.curFen = this.game.fen;
72 this.adjustFenSize();
652f40de 73 this.vr = new V(this.game.fen);
77c50966 74 this.$set(this.game, "fenStart", this.gameRef.fen);
7f3484bd 75 },
5157ce0b
BA
76 adjustFenSize: function() {
77 let fenInput = document.getElementById("fen");
78 fenInput.style.width = this.curFen.length + "ch";
79 },
80 gotoFen: function() {
81 this.gameRef.fen = this.curFen;
82 this.loadGame();
83 },
7f3484bd
BA
84 },
85};
86</script>
87
5157ce0b
BA
88<style lang="sass" scoped>
89#fenDiv
90 text-align: center
7f3484bd 91</style>