main
.row
.col-sm-12
- #fenDiv
- input#fen(v-model="curFen" @input="adjustFenSize")
- button(@click="gotoFen()") {{ st.tr["Go"] }}
- BaseGame(:game="game" :vr="vr" ref="basegame")
+ .text-center
+ input#fen(
+ v-model="curFen"
+ @input="adjustFenSize(); tryGotoFen()"
+ )
+ BaseGame(
+ :game="game"
+ @fenchange="setFen"
+ )
</template>
<script>
import BaseGame from "@/components/BaseGame.vue";
import { store } from "@/store";
-import { ArrayFun } from "@/utils/array";
export default {
- name: 'my-analyse',
+ name: "my-analyse",
components: {
- BaseGame,
+ BaseGame
},
// gameRef: to find the game in (potentially remote) storage
data: function() {
return {
st: store.state,
- gameRef: { //given in URL (rid = remote ID)
+ gameRef: {
+ //given in URL (rid = remote ID)
vname: "",
fen: ""
},
game: {
- players:[{name:"Analyse"},{name:"Analyse"}],
+ players: [{ name: "Analyse" }, { name: "Analyse" }],
mode: "analyze"
},
- vr: null, //"variant rules" object initialized from FEN
- curFen: "",
- //people: [], //players + observers //TODO later: interactive analyze...
+ curFen: ""
};
},
- watch: {
- // NOTE: no watcher for $route change, because if fenStart doesn't change
- // then it doesn't trigger BaseGame.re_init() and the result is weird.
- "vr.movesCount": function(fen) {
- this.curFen = this.vr.getFen();
- this.adjustFenSize();
- },
- },
+ // NOTE: no watcher for $route change, because if fenStart doesn't change
+ // then it doesn't trigger BaseGame.re_init() and the result is weird.
created: function() {
this.gameRef.vname = this.$route.params["vname"];
- if (this.gameRef.vname == "Dark")
- {
- alert(this.st.tr["Analyse in Dark mode makes no sense!"]);
- history.back(); //or this.$router.go(-1)
- }
- else
- {
- this.gameRef.fen = this.$route.query["fen"].replace(/_/g, " ");
- this.initialize();
- }
+ this.gameRef.fen = this.$route.query["fen"].replace(/_/g, " ");
+ this.initialize();
},
methods: {
initialize: async function() {
this.game.fen = this.gameRef.fen;
this.curFen = this.game.fen;
this.adjustFenSize();
- this.vr = new V(this.game.fen);
- this.game.mycolor = this.vr.turn;
+ this.game.mycolor = V.ParseFen(this.gameRef.fen).turn;
this.$set(this.game, "fenStart", this.gameRef.fen);
},
+ // Triggered by "fenchange" emitted in BaseGame:
+ setFen: function(fen) {
+ this.curFen = fen;
+ this.adjustFenSize();
+ },
adjustFenSize: function() {
let fenInput = document.getElementById("fen");
fenInput.style.width = this.curFen.length + "ch";
},
- gotoFen: function() {
- this.gameRef.fen = this.curFen;
- this.loadGame();
- },
- },
+ tryGotoFen: function() {
+ if (V.IsGoodFen(this.curFen))
+ {
+ this.gameRef.fen = this.curFen;
+ this.loadGame();
+ }
+ }
+ }
};
</script>
-
-<style lang="sass" scoped>
-#fenDiv
- text-align: center
-</style>