Show the full game and review it after an attempt

Closes #18
This commit is contained in:
2026-11-02 21:26:20 +01:00
parent 6d0d750ca7
commit 1e62b13d94
3 changed files with 472 additions and 34 deletions
+44
View File
@@ -6,11 +6,32 @@ export const ChessBoard = {
this.chess = new Chess();
this.ground = null;
this.playerColor = "white";
this.reviewing = false;
this.handleEvent("init_board", (payload) => {
this.reviewing = false;
this.initBoard(payload);
});
this.handleEvent("review_position", ({ fen }) => {
this.reviewing = true;
this.showReviewPosition(fen);
});
this.handleKeyDown = (event) => {
if (!this.reviewing) return;
if (event.key === "ArrowLeft") {
event.preventDefault();
this.pushEvent("review_prev", {});
} else if (event.key === "ArrowRight") {
event.preventDefault();
this.pushEvent("review_next", {});
}
};
window.addEventListener("keydown", this.handleKeyDown);
this.handleEvent("set_fen", ({ fen }) => {
try {
this.chess.load(fen);
@@ -53,6 +74,29 @@ export const ChessBoard = {
});
},
destroyed() {
window.removeEventListener("keydown", this.handleKeyDown);
},
showReviewPosition(fen) {
if (!this.ground) return;
try {
this.chess.load(fen);
} catch (error) {
console.error("Invalid review FEN from server:", fen, error);
return;
}
const turnColor = this.chess.turn() === "w" ? "white" : "black";
this.ground.set({
fen: this.chess.fen(),
turnColor,
movable: { color: null, dests: new Map() },
});
},
initBoard({ fen, orientation, player_color, blocked }) {
try {
this.chess.load(fen);