Я использую cm-chessboard и пытаюсь позволить игроку перетаскивать свои фигуры, хотя сейчас не его ход. Я пытаюсь сделать это, чтобы разрешить premove. Предварительное перемещение означает, что мне разрешено «предварить» следующий ход во время моего противника. Проблема в том, что я не могу понять, как разрешить пользователю перетаскивать ходы, когда не его очередь.
const inputHandler = (event) => {
if (event.type === INPUT_EVENT_TYPE.movingOverSquare) {
return;
}
if (event.type !== INPUT_EVENT_TYPE.moveInputFinished) {
event.chessboard.removeLegalMovesMarkers()
}
if (event.type === INPUT_EVENT_TYPE.moveInputStarted) {
const moves = game.moves({square: event.squareFrom, verbose: true})
event.chessboard.addLegalMovesMarkers(moves)
return moves.length > 0
} else if (event.type === INPUT_EVENT_TYPE.validateMoveInput) {
const move = {from: event.squareFrom, to: event.squareTo, promotion: event.promotion}
const result = game.move(move)
if (result) {
event.chessboard.state.moveInputProcess.then(() => {
event.chessboard.setPosition(game.fen(), true)
})
return true;
} else {
let possibleMoves = game.moves({square: event.squareFrom, verbose: true})
for (const possibleMove of possibleMoves) {
if (possibleMove.promotion && possibleMove.to === event.squareTo) {
event.chessboard.showPromotionDialog(event.squareTo, COLOR.white, (result) => {
if (result.type === PROMOTION_DIALOG_RESULT_TYPE.pieceSelected) {
let pmove = game.move({from: event.squareFrom, to: event.squareTo, promotion: result.piece.charAt(1)})
event.chessboard.setPosition(game.fen(), true)
} else {
event.chessboard.setPosition(game.fen(), true)
}
})
return true
}
}
}
return result
}
}
Подробнее здесь: https://stackoverflow.com/questions/792 ... puthandler
Как включить Premove в InputHandler ⇐ Python
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Включить (включить) контроллер UART в пользовательском приложении в Linux.
Anonymous » » в форуме Linux - 0 Ответы
- 25 Просмотры
-
Последнее сообщение Anonymous
-