Fix flickering on board redraw

Turns out == operator can't be used to compare two JS objects. Implement
a custom method for determining piece equality.
This commit is contained in:
2021-12-14 21:57:26 +01:00
parent a1207f2404
commit 6bbcadddfd

View File

@@ -154,6 +154,12 @@ class PieceVis {
} }
} }
function pieceEqual(pieceA, pieceB) {
return (
pieceA.color === pieceB.color && pieceA.piece_type === pieceB.piece_type
);
}
export class ConfigVis { export class ConfigVis {
constructor(configuration) { constructor(configuration) {
this.configuration = configuration; this.configuration = configuration;
@@ -162,7 +168,7 @@ export class ConfigVis {
draw(canvas) { draw(canvas) {
for (let [position, piece] of this.configuration) { for (let [position, piece] of this.configuration) {
if (this.piecesVis.has(position)) { if (this.piecesVis.has(position)) {
if (this.piecesVis.get(position).piece == piece) { if (pieceEqual(this.piecesVis.get(position).piece, piece)) {
continue; continue;
} }
} }