Skip to content

Commit 6522cac

Browse files
committed
Allow to fill again
We need to mark the tile visited to avoid a circular function in this case: - Tiles occupied an area, I want to flip the tiles, so I pick the same tile, enable a flip mode, and click with the bucket, but the app freeze, so this changes fix it. And it also change the siimilar neighbors tiles.
1 parent df3b56c commit 6522cac

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

newIDE/app/src/InstancesEditor/index.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -953,15 +953,16 @@ export default class InstancesEditor extends Component<Props, State> {
953953
});
954954
const tileDefinition = editableTileMap.getTileDefinition(newTileId);
955955
if (!tileDefinition) return;
956-
if (targetTileId === newTileId) return;
957956

958957
// BFS flood fill over tiles matching the target tile (4-directional).
959958
const dimX = editableTileMap.getDimensionX();
960959
const dimY = editableTileMap.getDimensionY();
961960
const queue: Array<{| x: number, y: number |}> = [];
961+
const visited = new Set<string>();
962962

963963
if (clickX >= 0 && clickX < dimX && clickY >= 0 && clickY < dimY) {
964964
queue.push({ x: clickX, y: clickY });
965+
visited.add(`${clickX},${clickY}`);
965966
}
966967

967968
while (queue.length > 0) {
@@ -992,10 +993,21 @@ export default class InstancesEditor extends Component<Props, State> {
992993
tileMapTileSelection.flipVertically
993994
);
994995

995-
queue.push({ x: current.x - 1, y: current.y });
996-
queue.push({ x: current.x + 1, y: current.y });
997-
queue.push({ x: current.x, y: current.y - 1 });
998-
queue.push({ x: current.x, y: current.y + 1 });
996+
// Add neighbors if not already visited
997+
const neighbors = [
998+
{ x: current.x - 1, y: current.y },
999+
{ x: current.x + 1, y: current.y },
1000+
{ x: current.x, y: current.y - 1 },
1001+
{ x: current.x, y: current.y + 1 },
1002+
];
1003+
1004+
for (const neighbor of neighbors) {
1005+
const key = `${neighbor.x},${neighbor.y}`;
1006+
if (!visited.has(key)) {
1007+
visited.add(key);
1008+
queue.push(neighbor);
1009+
}
1010+
}
9991011
}
10001012
} else if (isTileMapPaintingSelection(tileMapTileSelection)) {
10011013
shouldTrimAfterOperations = editableTileMap.isEmpty();

0 commit comments

Comments
 (0)