Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix last move squares duplciating on dom changes #57

Merged
merged 1 commit into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "chessground",
"version": "7.11.1-pstrat3.4",
"version": "7.11.1-pstrat3.5",
"description": "playstrategy.org chess ui, forked from lichess.org",
"type": "module",
"module": "dist/chessground.js",
Expand Down
56 changes: 15 additions & 41 deletions src/variants/abalone/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,20 +108,20 @@ export const render = (s: State): void => {
// walk over all squares in current set, apply dom changes to moved squares
// or append new squares
for (const [sk, className] of squares) {
// if (!sameSquares.has(sk)) {
sMvdset = movedSquares.get(className);
sMvd = sMvdset && sMvdset.pop();
const translation = posToTranslate(s.key2pos(sk), orientation, s.dimensions, s.variant);
if (sMvd) {
sMvd.cgKey = sk;
translate(sMvd, translation);
} else {
const squareNode = createEl('square', className) as cg.SquareNode;
squareNode.cgKey = sk;
translate(squareNode, translation);
boardEl.insertBefore(squareNode, boardEl.firstChild);
if (!sameSquares.has(sk)) {
sMvdset = movedSquares.get(className);
sMvd = sMvdset && sMvdset.pop();
const translation = posToTranslate(s.key2pos(sk), orientation, s.dimensions, s.variant);
if (sMvd) {
sMvd.cgKey = sk;
translate(sMvd, translation);
} else {
const squareNode = createEl('square', className) as cg.SquareNode;
squareNode.cgKey = sk;
translate(squareNode, translation);
boardEl.insertBefore(squareNode, boardEl.firstChild);
}
}
// }
}

// walk over all pieces in current set, apply dom changes to moved pieces
Expand Down Expand Up @@ -174,7 +174,7 @@ export const render = (s: State): void => {

// remove any element that remains in the moved sets
for (const nodes of movedPieces.values()) removeNodes(s, nodes);
for (const nodes of movedSquares.values()) removeNodes(s, nodes); // do not compute movedSquares ???
for (const nodes of movedSquares.values()) removeNodes(s, nodes);
};

function pieceNameOf(piece: cg.Piece, myPlayerIndex: cg.PlayerIndex, orientation: cg.Orientation): string {
Expand All @@ -197,40 +197,14 @@ function addSquare(squares: SquareClasses, key: cg.Key, klass: string): void {
export function computeSquareClasses(s: State): SquareClasses {
const squares: SquareClasses = new Map();

if (s.lastMove && s.lastMove.length === 2) {
if (s.lastMove && s.lastMove.length === 2 && s.highlight.lastMove) {
const moveImpact = computeMoveVectorPostMove(s.pieces, s.lastMove[0], s.lastMove[1]);
const player = s.turnPlayerIndex;
moveImpact?.landingSquares.forEach(coordinates => {
addSquare(squares, coordinates, `last-move to ${player}${moveImpact.directionString}`);
});
}

if (s.lastMove && s.highlight.lastMove) {
// if (s.variants.abalone.lastMove) {
// for (const k of s.variants.abalone.lastMove.piecesMoving) {
// addSquare(squares, k, 'last-move from ww');
// }
// }
// let first = true;
// for (const k of s.lastMove) {
// if (k !== 'a0') {
// if (first) {
// console.log(s.variants);
// addSquare(squares, k, 'last-move from ww'); // + variantSpecificHighlightClass(s.variant, k, s.orientation));
// first = false;
// } else {
// addSquare(squares, k, 'last-move to ww'); // + variantSpecificHighlightClass(s.variant, k, s.orientation));
// }
// } else {
// first = false;
// }
// }
}
if (s.selectOnly) {
for (const key of s.selectedPieces.keys()) {
addSquare(squares, key, 'selected');
}
}
if (s.selected) {
addSquare(squares, s.selected, 'selected');
if (s.movable.showDests) {
Expand Down
Loading