X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fcomponents%2FBaseGame.vue;h=e04f5082e08e98f56ecf9bc98e8ae362a3d273af;hb=430a203855578f9bbf4c851165c6066a741ff1f8;hp=e880de5f4abde0246dc8bc1cca8e3e11d880fc81;hpb=603b8a8b4a854efb168953da70e7b43ae99b50d9;p=vchess.git diff --git a/client/src/components/BaseGame.vue b/client/src/components/BaseGame.vue index e880de5f..e04f5082 100644 --- a/client/src/components/BaseGame.vue +++ b/client/src/components/BaseGame.vue @@ -1,28 +1,28 @@ @@ -62,10 +62,6 @@ export default { "game.moveToPlay": function() { this.play(this.game.moveToPlay, "receive", this.game.vname=="Dark"); }, - "game.score": function(score) { - if (score != "*") - this.endGame(score, this.game.scoreMsg); - }, }, computed: { showMoves: function() { @@ -73,10 +69,10 @@ export default { //return window.innerWidth >= 768; }, showFen: function() { - return this.game.vname != "Dark" || this.score != "*"; + return this.game.vname != "Dark" || this.game.score != "*"; }, analyze: function() { - return this.game.mode == "analyze" || this.score != "*"; + return this.game.mode == "analyze" || this.game.score != "*"; }, }, created: function() { @@ -84,10 +80,35 @@ export default { this.re_setVariables(); }, methods: { + focusBg: function() { + // TODO: small blue border appears... + document.getElementById("baseGame").focus(); + }, + handleKeys: function(e) { + if ([32,37,38,39,40].includes(e.keyCode)) + e.preventDefault(); + switch (e.keyCode) + { + case 37: + this.undo(); + break; + case 39: + this.play(); + break; + case 38: + this.gotoBegin(); + break; + case 40: + this.gotoEnd(); + break; + case 32: + this.flip(); + break; + } + }, re_setVariables: function() { this.endgameMessage = ""; this.orientation = this.game.mycolor || "w"; //default orientation for observed games - this.score = this.game.score || "*"; //mutable (if initially "*") this.moves = JSON.parse(JSON.stringify(this.game.moves || [])); // Post-processing: decorate each move with color + current FEN: // (to be able to jump to any position quickly) @@ -100,13 +121,20 @@ export default { vr_tmp.play(move); move.fen = vr_tmp.getFen(); }); + if (this.game.fenStart.indexOf(" b ") >= 0 || + (this.moves.length > 0 && this.moves[0].color == "b")) + { + // 'end' is required for Board component to check lastMove for e.p. + this.moves.unshift({color: "w", notation: "...", end: {x:-1,y:-1}}); + } const L = this.moves.length; this.cursor = L-1; this.lastMove = (L > 0 ? this.moves[L-1] : null); }, gotoFenContent: function(event) { - this.$router.push("/analyze/" + this.game.vname + - "/?fen=" + event.target.innerText.replace(/ /g, "_")); + const newUrl = "#/analyze/" + this.game.vname + + "/?fen=" + event.target.innerText.replace(/ /g, "_"); + window.open(newUrl); //to open in a new tab }, download: function() { const content = this.getPgn(); @@ -124,7 +152,7 @@ export default { pgn += '[White "' + this.game.players[0].name + '"]\n'; pgn += '[Black "' + this.game.players[1].name + '"]\n'; pgn += '[Fen "' + this.game.fenStart + '"]\n'; - pgn += '[Result "' + this.score + '"]\n\n'; + pgn += '[Result "' + this.game.score + '"]\n\n'; let counter = 1; let i = 0; while (i < this.moves.length) @@ -166,13 +194,6 @@ export default { modalBox.checked = true; setTimeout(() => { modalBox.checked = false; }, 2000); }, - endGame: function(score, message) { - this.score = score; - if (!message) - message = this.getScoreMessage(score); - this.showEndgameMsg(score + " . " + message); - this.$emit("gameover", score); - }, animateMove: function(move) { let startSquare = document.getElementById(getSquareId(move.start)); let endSquare = document.getElementById(getSquareId(move.end)); @@ -236,7 +257,7 @@ export default { if (!navigate) { move.fen = this.vr.getFen(); - if (this.score == "*" || this.analyze) + if (this.game.score == "*" || this.analyze) { // Stack move on movesList at current cursor if (this.cursor == this.moves.length) @@ -252,14 +273,11 @@ export default { const score = this.vr.getCurrentScore(); if (score != "*") { + const message = this.getScoreMessage(score); if (!this.analyze) - this.endGame(score); - else - { - // Just show score on screen (allow undo) - const message = this.getScoreMessage(score); + this.$emit("gameover", score, message); + else //just show score on screen (allow undo) this.showEndgameMsg(score + " . " + message); - } } }, undo: function(move) { @@ -286,8 +304,16 @@ export default { }, gotoBegin: function() { this.vr.re_init(this.game.fenStart); - this.cursor = -1; - this.lastMove = null; + if (this.moves.length > 0 && this.moves[0].notation == "...") + { + this.cursor = 0; + this.lastMove = this.moves[0]; + } + else + { + this.cursor = -1; + this.lastMove = null; + } }, gotoEnd: function() { this.gotoMove(this.moves.length-1); @@ -298,3 +324,29 @@ export default { }, }; + +