load FEN string, parse through chess.js and load correct orientaton etc

This commit is contained in:
2026-06-20 20:33:18 +02:00
parent 014ca0d18c
commit 42f8a88c61
2 changed files with 64 additions and 14 deletions
+34 -14
View File
@@ -3,21 +3,41 @@ import { Chess } from 'chess.js';
export const ChessBoard = {
mounted() {
this.chess = new Chess();
this.chess = new Chess();
this.ground = Chessground(this.el, {
fen: this.chess.fen(),
movable: {
color: 'white',
free: false,
dests: this.getValidDests()
},
events: {
move: (orig, dest, _metadata) => {
this.handleMove(orig, dest);
}
}
});
this.ground = Chessground(this.el, {
fen: this.chess.fen(),
movable: {
color: 'white',
free: false,
dests: this.getValidDests()
},
events: {
move: (orig, dest, _metadata) => {
this.handleMove(orig, dest);
}
}
});
this.handleEvent("set_fen", ({ fen }) => {
try {
this.chess.load(fen);
const currentTurnColor = this.chess.turn() === 'w' ? 'white' : 'black';
this.ground.set({
fen: fen,
turnColor: currentTurnColor,
movable: {
color: currentTurnColor,
dests: this.getValidDests()
}
});
} catch (error) {
console.error("Invalid FEN string submitted:", error);
alert("Invalid FEN configuration!");
}
});
},
getValidDests() {