load FEN string, parse through chess.js and load correct orientaton etc
This commit is contained in:
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user