X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fcomponents%2FBoard.vue;h=799185e46113be5d1e83b2eaa18f0b75fbf156f8;hb=d5af4af2ac7d86bed9166916eb1610736647df0a;hp=9e23fc5697f136760e6462678cf62c70747d889a;hpb=7c05a5f2297bea540c700ebceb0cc8b03a7f6775;p=vchess.git diff --git a/client/src/components/Board.vue b/client/src/components/Board.vue index 9e23fc56..799185e4 100644 --- a/client/src/components/Board.vue +++ b/client/src/components/Board.vue @@ -299,7 +299,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) { @@ -546,15 +547,20 @@ export default { } }, addArrow: function(arrow) { - this.arrows.push(arrow); - // Also add to DOM: - const boardElt = document.getElementById("gamePosition"); - const squareWidth = boardElt.offsetWidth / V.size.y; - const bPos = boardElt.getBoundingClientRect(); - const newArrow = - this.getSvgArrow(arrow, bPos.top, bPos.left, squareWidth); - document.getElementById("arrowCanvas") - .insertAdjacentElement("beforeend", newArrow); + const arrowIdx = this.arrows.findIndex(a => { + return ( + a.start[0] == arrow.start[0] && a.start[1] == arrow.start[1] && + a.end[0] == arrow.end[0] && a.end[1] == arrow.end[1] + ); + }); + if (arrowIdx >= 0) + // Erase the arrow + this.arrows.splice(arrowIdx, 1); + else + // Add to arrows vector: + this.arrows.push(arrow); + // NOTE: no need to draw here, will be re-draw + // by updated() hook callong re_setDrawings() }, getSvgArrow: function(arrow, top, left, squareWidth) { const aStart =