- if (!this.selectedPiece && e.target.classList.contains("piece"))
- {
- let parent = e.target.parentNode;
- // Next few lines to center the piece on mouse cursor
- let rect = parent.getBoundingClientRect();
- this.start = {
- x: rect.x + rect.width/2,
- y: rect.y + rect.width/2,
- id: parent.id
- };
- this.selectedPiece = e.target.cloneNode();
- let spStyle = this.selectedPiece.style
- spStyle.position = "absolute";
- spStyle.top = 0;
- spStyle.display = "inline-block";
- spStyle.zIndex = 3000;
- const startSquare = getSquareFromId(parent.id);
- this.possibleMoves = [];
- const color = (this.analyze ? this.vr.turn : this.userColor);
- if (this.vr.canIplay(color,startSquare))
- this.possibleMoves = this.vr.getPossibleMovesFrom(startSquare);
- // Next line add moving piece just after current image
- // (required for Crazyhouse reserve)
- parent.insertBefore(this.selectedPiece, e.target.nextSibling);
- }
+ let parent = e.target.parentNode; //the surrounding square
+ // Next few lines to center the piece on mouse cursor
+ let rect = parent.getBoundingClientRect();
+ this.start = {
+ x: rect.x + rect.width / 2,
+ y: rect.y + rect.width / 2,
+ id: parent.id
+ };
+ this.selectedPiece = e.target.cloneNode();
+ let spStyle = this.selectedPiece.style;
+ spStyle.position = "absolute";
+ spStyle.top = 0;
+ spStyle.display = "inline-block";
+ spStyle.zIndex = 3000;
+ const startSquare = getSquareFromId(parent.id);
+ this.possibleMoves = [];
+ const color = this.analyze ? this.vr.turn : this.userColor;
+ if (this.vr.canIplay(color, startSquare))
+ this.possibleMoves = this.vr.getPossibleMovesFrom(startSquare);
+ // Next line add moving piece just after current image
+ // (required for Crazyhouse reserve)
+ parent.insertBefore(this.selectedPiece, e.target.nextSibling);