X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fcomponents%2FBoard.vue;h=5b8b92206c7d202f21d0a9df01d8609b5c404b3b;hb=cfc1cf0d2dde4d7f69f107d8c7ec30c815812da0;hp=f20e7da6ef08423fdc6d28c5cd6d041f400e271a;hpb=2c33215f7c5ae03ab340f6a6e5555790d75762cf;p=vchess.git diff --git a/client/src/components/Board.vue b/client/src/components/Board.vue index f20e7da6..5b8b9220 100644 --- a/client/src/components/Board.vue +++ b/client/src/components/Board.vue @@ -31,6 +31,7 @@ export default { circles: {}, //object of squares' ID --> true (TODO: use a set?) click: "", clickTime: 0, + initialized: 0, settings: store.state.settings }; }, @@ -299,7 +300,8 @@ export default { (!myReserveTop && !!this.vr.reserve[playingColor]) ); // Center reserves, assuming same number of pieces for each side: - const nbReservePieces = myReservePiecesArray.length; + const nbReservePieces = + Math.max(myReservePiecesArray.length, oppReservePiecesArray.length); const marginLeft = ((100 - nbReservePieces * (100 / reserveSquareNb)) / 2) + "%"; if (hasReserveTop) { @@ -462,6 +464,8 @@ export default { } }; } + if (this.initialized == 1) this.$emit("rendered"); + if (this.initialized <= 1) this.initialized++; return ( h( "div", @@ -647,7 +651,6 @@ export default { document.getElementById("rootBoardElement").appendChild(arrowCanvas); }, mousedown: function(e) { - e.preventDefault(); if (!this.mobileBrowser && e.which != 3) // Cancel current drawing and circles, if any this.cancelResetArrows(); @@ -658,6 +661,7 @@ export default { document.getElementById("boardContainer").getBoundingClientRect(); // NOTE: classList[0] is enough: 'piece' is the first assigned class const withPiece = (e.target.classList[0] == "piece"); + if (withPiece) e.preventDefault(); // Show possible moves if current player allowed to play const startSquare = getSquareFromId(withPiece ? e.target.parentNode.id : e.target.id); @@ -701,6 +705,7 @@ export default { } else if (e.which == 3) { // Mouse right button + e.preventDefault(); this.containerPos = document.getElementById("gamePosition").getBoundingClientRect(); let elem = e.target; @@ -708,6 +713,7 @@ export default { while (elem.tagName == "IMG") elem = elem.parentNode; this.startArrow = getSquareFromId(elem.id); } + else e.preventDefault(); }, mousemove: function(e) { if (!this.selectedPiece && !this.startArrow) return; @@ -768,15 +774,17 @@ export default { } }, mouseup: function(e) { - e.preventDefault(); if (this.mobileBrowser || e.which == 1) { if (!this.selectedPiece) return; + e.preventDefault(); // Drag'n drop. Selected piece is no longer needed: this.selectedPiece.parentNode.removeChild(this.selectedPiece); delete this.selectedPiece; this.selectedPiece = null; this.processMoveAttempt(e); - } else if (e.which == 3) { + } + else if (e.which == 3) { + e.preventDefault(); if (!this.startArrow) return; // Mouse right button this.movingArrow = null;