Add Fanorona
[vchess.git] / client / src / components / Board.vue
index b8d0fad..b452808 100644 (file)
@@ -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)
@@ -659,30 +659,33 @@ export default {
             // Emit the click event which could be used by some variants
             const targetId =
               (withPiece ? e.target.parentNode.id : e.target.id);
-            this.$emit("click-square", getSquareFromId(targetId));
-            if (withPiece) {
+            const sq = getSquareFromId(targetId);
+            this.$emit("click-square", sq);
+            if (withPiece && !this.vr.onlyClick(sq)) {
               this.possibleMoves = this.vr.getPossibleMovesFrom(startSquare);
-              // 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);
+              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);
+              }
             }
           }
         }