X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fcomponents%2FBoard.vue;h=b45280821e91119e533e00ca046206780df93b79;hb=cdab566355412821c9187078ee0864ceb30545de;hp=313564d210cf7e84f3eaa6e65bf3b7e1458c6011;hpb=157a72c805261f68aa1adcd4776debf965d7e6cd;p=vchess.git diff --git a/client/src/components/Board.vue b/client/src/components/Board.vue index 313564d2..b4528082 100644 --- a/client/src/components/Board.vue +++ b/client/src/components/Board.vue @@ -365,7 +365,7 @@ export default { const squareWidth = boardElt.offsetWidth / sizeY; const offset = [boardElt.offsetTop, boardElt.offsetLeft]; const maxNbeltsPerRow = Math.min(this.choices.length, sizeY); - let topOffset = offset[0] + (sizeY / 2) * squareWidth - squareWidth / 2; + let topOffset = offset[0] + ((sizeX - 1) / 2) * squareWidth; let choicesHeight = squareWidth; if (this.choices.length >= sizeY) { // A second row is required (Eightpieces variant) @@ -402,10 +402,12 @@ export default { this.choices = []; this.play(m); }; + const stopPropagation = (e) => { e.stopPropagation(); } const onClick = this.mobileBrowser - ? { touchend: applyMove } - : { mouseup: applyMove }; + // Must cancel mousedown logic: + ? { touchstart: stopPropagation, touchend: applyMove } + : { mousedown: stopPropagation, mouseup: applyMove }; return h( "div", { @@ -423,7 +425,7 @@ export default { attrs: { src: "/images/pieces/" + - // orientation: extra arg useful for some variants: + // orientation: extra arg useful for some variants this.vr.getPPpath(m, this.orientation) + V.IMAGE_EXTENSION }, @@ -648,45 +650,48 @@ export default { document.getElementById("boardContainer").getBoundingClientRect(); // NOTE: classList[0] is enough: 'piece' is the first assigned class const withPiece = (e.target.classList[0] == "piece"); - // Emit the click event which could be used by some variants - this.$emit( - "click-square", - getSquareFromId(withPiece ? e.target.parentNode.id : e.target.id) - ); - // Start square must contain a piece. - if (!withPiece) return; - let parent = e.target.parentNode; //surrounding square // Show possible moves if current player allowed to play - const startSquare = getSquareFromId(parent.id); + const startSquare = + getSquareFromId(withPiece ? e.target.parentNode.id : e.target.id); this.possibleMoves = []; const color = this.analyze ? this.vr.turn : this.userColor; - if (this.vr.canIplay(color, startSquare)) - this.possibleMoves = this.vr.getPossibleMovesFrom(startSquare); - else return; - // For potential drag'n drop, remember start coordinates - // (to center the piece on mouse cursor) - const rect = parent.getBoundingClientRect(); - this.start = { - x: rect.x + rect.width / 2, - y: rect.y + rect.width / 2, - id: parent.id - }; - // Add the moving piece to the board, just after current image - this.selectedPiece = e.target.cloneNode(); - Object.assign( - this.selectedPiece.style, - { - position: "absolute", - top: 0, - display: "inline-block", - zIndex: 3000 + if (this.vr.canIplay(color, startSquare)) { + // Emit the click event which could be used by some variants + const targetId = + (withPiece ? e.target.parentNode.id : e.target.id); + const sq = getSquareFromId(targetId); + this.$emit("click-square", sq); + if (withPiece && !this.vr.onlyClick(sq)) { + this.possibleMoves = this.vr.getPossibleMovesFrom(startSquare); + if (this.possibleMoves.length > 0) { + // For potential drag'n drop, remember start coordinates + // (to center the piece on mouse cursor) + let parent = e.target.parentNode; //surrounding square + const rect = parent.getBoundingClientRect(); + this.start = { + x: rect.x + rect.width / 2, + y: rect.y + rect.width / 2, + id: parent.id + }; + // Add the moving piece to the board, just after current image + this.selectedPiece = e.target.cloneNode(); + Object.assign( + this.selectedPiece.style, + { + position: "absolute", + top: 0, + display: "inline-block", + zIndex: 3000 + } + ); + parent.insertBefore(this.selectedPiece, e.target.nextSibling); + } } - ); - parent.insertBefore(this.selectedPiece, e.target.nextSibling); - } else { - this.processMoveAttempt(e); + } } - } else if (e.which == 3) { + else this.processMoveAttempt(e); + } + else if (e.which == 3) { // Mouse right button this.containerPos = document.getElementById("gamePosition").getBoundingClientRect();