remove extra console.log
[vchess.git] / client / src / views / Analyse.vue
CommitLineData
7f3484bd 1<template lang="pug">
7aa548e7 2main
63ca2b89
BA
3 .row
4 .col-sm-12
9a3049f3 5 .text-center
910d631b
BA
6 input#fen(
7 v-model="curFen"
725da57f 8 @input="adjustFenSize(); tryGotoFen()"
910d631b 9 )
910d631b
BA
10 BaseGame(
11 :game="game"
8055eabd 12 @fenchange="setFen"
910d631b 13 )
7f3484bd
BA
14</template>
15
16<script>
17import BaseGame from "@/components/BaseGame.vue";
7f3484bd 18import { store } from "@/store";
7f3484bd 19export default {
6808d7a1 20 name: "my-analyse",
7f3484bd 21 components: {
6808d7a1 22 BaseGame
7f3484bd
BA
23 },
24 // gameRef: to find the game in (potentially remote) storage
25 data: function() {
26 return {
27 st: store.state,
6808d7a1
BA
28 gameRef: {
29 //given in URL (rid = remote ID)
652f40de
BA
30 vname: "",
31 fen: ""
32 },
33 game: {
6808d7a1
BA
34 players: [{ name: "Analyse" }, { name: "Analyse" }],
35 mode: "analyze"
7f3484bd 36 },
6808d7a1 37 curFen: ""
7f3484bd
BA
38 };
39 },
8055eabd
BA
40 // NOTE: no watcher for $route change, because if fenStart doesn't change
41 // then it doesn't trigger BaseGame.re_init() and the result is weird.
7f3484bd 42 created: function() {
652f40de 43 this.gameRef.vname = this.$route.params["vname"];
20620465
BA
44 this.gameRef.fen = this.$route.query["fen"].replace(/_/g, " ");
45 this.initialize();
7f3484bd
BA
46 },
47 methods: {
a0c41e7e 48 initialize: async function() {
5157ce0b
BA
49 // Obtain VariantRules object
50 const vModule = await import("@/variants/" + this.gameRef.vname + ".js");
51 window.V = vModule.VariantRules;
a0c41e7e 52 this.loadGame();
5157ce0b
BA
53 },
54 loadGame: function() {
0e16cb26 55 // NOTE: no need to set score (~unused)
652f40de
BA
56 this.game.vname = this.gameRef.vname;
57 this.game.fen = this.gameRef.fen;
5157ce0b
BA
58 this.curFen = this.game.fen;
59 this.adjustFenSize();
8055eabd 60 this.game.mycolor = V.ParseFen(this.gameRef.fen).turn;
77c50966 61 this.$set(this.game, "fenStart", this.gameRef.fen);
7f3484bd 62 },
8055eabd
BA
63 // Triggered by "fenchange" emitted in BaseGame:
64 setFen: function(fen) {
65 this.curFen = fen;
66 this.adjustFenSize();
67 },
5157ce0b
BA
68 adjustFenSize: function() {
69 let fenInput = document.getElementById("fen");
70 fenInput.style.width = this.curFen.length + "ch";
71 },
725da57f
BA
72 tryGotoFen: function() {
73 if (V.IsGoodFen(this.curFen))
74 {
75 this.gameRef.fen = this.curFen;
76 this.loadGame();
77 }
6808d7a1
BA
78 }
79 }
7f3484bd
BA
80};
81</script>