Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Chessboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export class Chessboard {
const positionTo = new Position(fen)
if (positionFrom.getFen() !== positionTo.getFen()) {
this.state.position.setFen(fen)
this.view.visualMoveInput.positionChanged()
this.state.invokeExtensionPoints(EXTENSION_POINT.positionChanged)
}
return this.positionAnimationsQueue.enqueuePositionChange(positionFrom, this.state.position.clone(), animated)
Expand Down
14 changes: 13 additions & 1 deletion src/view/VisualMoveInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ export const MOVE_CANCELED_REASON = {
secondaryClick: "secondaryClick", // right click while moving
movedOutOfBoard: "movedOutOfBoard",
draggedBack: "draggedBack", // dragged to the start square
clickedAnotherPiece: "clickedAnotherPiece" // of the same color
clickedAnotherPiece: "clickedAnotherPiece", // of the same color
movedPieceChanged: "movedPieceChanged" // most likely got captured
}

const DRAG_THRESHOLD = 4
Expand All @@ -36,6 +37,7 @@ export class VisualMoveInput {
this.moveInputState = null
this.fromSquare = null
this.toSquare = null
this.movedPiece = null

this.setMoveInputState(MOVE_INPUT_STATE.waitForInputStart)
}
Expand Down Expand Up @@ -408,6 +410,16 @@ export class VisualMoveInput {
this.moveInputCanceledCallback(this.fromSquare, null, MOVE_CANCELED_REASON.secondaryClick)
}

positionChanged() {
if (this.fromSquare) {
const pieceName = this.chessboard.getPiece(this.fromSquare)
if (pieceName != this.movedPiece) {
this.setMoveInputState(MOVE_INPUT_STATE.reset)
this.moveInputCanceledCallback(this.fromSquare, null, MOVE_CANCELED_REASON.movedPieceChanged)
}
}
}

isDragging() {
return this.moveInputState === MOVE_INPUT_STATE.dragTo || this.moveInputState === MOVE_INPUT_STATE.clickDragTo
}
Expand Down