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:
@@ -154,6 +154,12 @@ class PieceVis {
|
||||
}
|
||||
}
|
||||
|
||||
function pieceEqual(pieceA, pieceB) {
|
||||
return (
|
||||
pieceA.color === pieceB.color && pieceA.piece_type === pieceB.piece_type
|
||||
);
|
||||
}
|
||||
|
||||
export class ConfigVis {
|
||||
constructor(configuration) {
|
||||
this.configuration = configuration;
|
||||
@@ -162,7 +168,7 @@ export class ConfigVis {
|
||||
draw(canvas) {
|
||||
for (let [position, piece] of this.configuration) {
|
||||
if (this.piecesVis.has(position)) {
|
||||
if (this.piecesVis.get(position).piece == piece) {
|
||||
if (pieceEqual(this.piecesVis.get(position).piece, piece)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user