Implement selected piece highlighting

Issue #3
This commit is contained in:
2021-12-13 20:14:53 +01:00
parent f9212a8291
commit 8d93acf950
2 changed files with 20 additions and 0 deletions

View File

@@ -31,6 +31,7 @@ class Chess {
this.canvas = new visuals.Canvas();
this.configVis = new visuals.ConfigVis(this.backend.getConfig());
this.configVis.draw(this.canvas);
this.activeSquares = new visuals.ActiveSquares();
this.moveSource = null;
this.canMoveTo = [];
document.onclick = (ev) => this.click(ev);
@@ -44,12 +45,14 @@ class Chess {
if (source === null) return;
let validMoves = this.backend.getAvailableMoves(source);
if (validMoves === null) return;
this.activeSquares.selectSquare(this.canvas, source);
this.moveSource = source;
}
finalizeMove(target) {
if (target !== null) {
this.backend.makeMove(this.moveSource, target);
}
this.activeSquares.unselectSquare(this.canvas);
this.syncBackend();
this.moveSource = null;
}