MCPcopy Create free account
hub / github.com/esengine/esengine / getPreviewTiles

Method getPreviewTiles

packages/tilemap-editor/src/tools/FillTool.ts:26–75  ·  view source on GitHub ↗
(tileX: number, tileY: number, ctx: ToolContext)

Source from the content-addressed store, hash-verified

24 }
25
26 getPreviewTiles(tileX: number, tileY: number, ctx: ToolContext): { x: number; y: number }[] {
27 const { tilemap, editingCollision, currentLayer } = ctx;
28
29 if (tileX < 0 || tileX >= tilemap.width || tileY < 0 || tileY >= tilemap.height) {
30 return [];
31 }
32
33 const tiles: { x: number; y: number }[] = [];
34 const maxPreviewTiles = 500;
35
36 if (editingCollision) {
37 const targetCollision = tilemap.hasCollision(tileX, tileY);
38 const stack: [number, number][] = [[tileX, tileY]];
39 const visited = new Set<string>();
40
41 while (stack.length > 0 && tiles.length < maxPreviewTiles) {
42 const [x, y] = stack.pop()!;
43 const key = `${x},${y}`;
44
45 if (visited.has(key)) continue;
46 if (x < 0 || x >= tilemap.width || y < 0 || y >= tilemap.height) continue;
47 if (tilemap.hasCollision(x, y) !== targetCollision) continue;
48
49 visited.add(key);
50 tiles.push({ x, y });
51
52 stack.push([x + 1, y], [x - 1, y], [x, y + 1], [x, y - 1]);
53 }
54 } else {
55 const targetTile = tilemap.getTile(currentLayer, tileX, tileY);
56 const stack: [number, number][] = [[tileX, tileY]];
57 const visited = new Set<string>();
58
59 while (stack.length > 0 && tiles.length < maxPreviewTiles) {
60 const [x, y] = stack.pop()!;
61 const key = `${x},${y}`;
62
63 if (visited.has(key)) continue;
64 if (x < 0 || x >= tilemap.width || y < 0 || y >= tilemap.height) continue;
65 if (tilemap.getTile(currentLayer, x, y) !== targetTile) continue;
66
67 visited.add(key);
68 tiles.push({ x, y });
69
70 stack.push([x + 1, y], [x - 1, y], [x, y + 1], [x, y - 1]);
71 }
72 }
73
74 return tiles;
75 }
76
77 private floodFill(startX: number, startY: number, ctx: ToolContext): void {
78 const { tilemap, selectedTiles, editingCollision, currentLayer } = ctx;

Callers

nothing calls this directly

Calls 6

hasCollisionMethod · 0.80
popMethod · 0.80
getTileMethod · 0.80
hasMethod · 0.65
pushMethod · 0.65
addMethod · 0.45

Tested by

no test coverage detected