@codexo/exojs-tilemap 0.18.0 → 0.19.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +56 -34
- package/dist/esm/ChunkStreamer.d.ts.map +1 -1
- package/dist/esm/ChunkStreamer.js +28 -6
- package/dist/esm/ChunkStreamer.js.map +1 -1
- package/dist/esm/ImageLayer.d.ts +1 -1
- package/dist/esm/ImageLayer.d.ts.map +1 -1
- package/dist/esm/ImageLayerNode.d.ts.map +1 -1
- package/dist/esm/MapObject.d.ts +2 -2
- package/dist/esm/MapObject.d.ts.map +1 -1
- package/dist/esm/MapObject.js.map +1 -1
- package/dist/esm/MapObjectSpawner.d.ts.map +1 -1
- package/dist/esm/MapSpawnSession.d.ts.map +1 -1
- package/dist/esm/MapWorld.d.ts +8 -8
- package/dist/esm/MapWorld.d.ts.map +1 -1
- package/dist/esm/MapWorldRuntime.d.ts.map +1 -1
- package/dist/esm/ObjectLayer.d.ts +26 -10
- package/dist/esm/ObjectLayer.d.ts.map +1 -1
- package/dist/esm/ObjectLayer.js +28 -0
- package/dist/esm/ObjectLayer.js.map +1 -1
- package/dist/esm/SampledChunkSource.d.ts.map +1 -1
- package/dist/esm/TileAnimator.d.ts.map +1 -1
- package/dist/esm/TileChunk.d.ts.map +1 -1
- package/dist/esm/TileChunkNode.js +47 -10
- package/dist/esm/TileChunkNode.js.map +1 -1
- package/dist/esm/TileLayer.d.ts +11 -2
- package/dist/esm/TileLayer.d.ts.map +1 -1
- package/dist/esm/TileLayer.js +20 -10
- package/dist/esm/TileLayer.js.map +1 -1
- package/dist/esm/TileLayerNode.d.ts +6 -4
- package/dist/esm/TileLayerNode.d.ts.map +1 -1
- package/dist/esm/TileLayerNode.js +36 -21
- package/dist/esm/TileLayerNode.js.map +1 -1
- package/dist/esm/TileMap.d.ts +6 -2
- package/dist/esm/TileMap.d.ts.map +1 -1
- package/dist/esm/TileMap.js +13 -12
- package/dist/esm/TileMap.js.map +1 -1
- package/dist/esm/TileMapBand.d.ts.map +1 -1
- package/dist/esm/TileMapNode.d.ts.map +1 -1
- package/dist/esm/TileMapNode.js +4 -1
- package/dist/esm/TileMapNode.js.map +1 -1
- package/dist/esm/TileMapView.d.ts.map +1 -1
- package/dist/esm/TileProjection.d.ts +59 -0
- package/dist/esm/TileProjection.d.ts.map +1 -0
- package/dist/esm/TileProjection.js +106 -0
- package/dist/esm/TileProjection.js.map +1 -0
- package/dist/esm/TileSet.d.ts.map +1 -1
- package/dist/esm/WangSet.d.ts.map +1 -1
- package/dist/esm/WorkerSampledChunkSource.d.ts.map +1 -1
- package/dist/esm/autoTile.d.ts.map +1 -1
- package/dist/esm/chunkGeometry.js +78 -50
- package/dist/esm/chunkGeometry.js.map +1 -1
- package/dist/esm/index.js +2 -1
- package/dist/esm/projectObject.d.ts +4 -0
- package/dist/esm/projectObject.d.ts.map +1 -0
- package/dist/esm/projectObject.js +87 -0
- package/dist/esm/projectObject.js.map +1 -0
- package/dist/esm/public.d.ts +1 -0
- package/dist/esm/public.d.ts.map +1 -1
- package/dist/esm/tileCollision.d.ts +2 -2
- package/dist/esm/tileCollision.d.ts.map +1 -1
- package/dist/esm/tileCollision.js +48 -16
- package/dist/esm/tileCollision.js.map +1 -1
- package/dist/esm/tilemapSerializers.js +1 -1
- package/dist/esm/tilemapSerializers.js.map +1 -1
- package/dist/esm/types.d.ts +3 -3
- package/dist/esm/types.d.ts.map +1 -1
- package/dist/esm/webgl2/WebGl2TileChunkRenderer.js +5 -4
- package/dist/esm/webgl2/WebGl2TileChunkRenderer.js.map +1 -1
- package/dist/esm/webgl2/shaders/tile-chunk.vert.js +1 -1
- package/dist/esm/webgl2/shaders/tile-chunk.vert.js.map +1 -1
- package/dist/esm/webgpu/WebGpuTileChunkRenderer.js +63 -27
- package/dist/esm/webgpu/WebGpuTileChunkRenderer.js.map +1 -1
- package/dist/esm/webgpu/shaders/tile-chunk.wgsl.js +1 -1
- package/dist/esm/webgpu/shaders/tile-chunk.wgsl.js.map +1 -1
- package/package.json +4 -4
|
@@ -19,9 +19,9 @@ export interface TileLayerNodeOptions {
|
|
|
19
19
|
* A scene node that renders one generic {@link TileLayer} as a
|
|
20
20
|
* {@link Container} of per-chunk {@link TileChunkNode} drawables.
|
|
21
21
|
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
22
|
+
* Orthogonal chunks become one child each. Isometric chunks become diagonal
|
|
23
|
+
* slices ordered across storage boundaries, preserving painter order and
|
|
24
|
+
* texture runs. Each drawable has its own culling bounds. The layer's pixel
|
|
25
25
|
* `offset`, `visible` and `opacity` are all read live from the runtime layer on
|
|
26
26
|
* every frame (no rebuild required).
|
|
27
27
|
*
|
|
@@ -102,11 +102,13 @@ export declare class TileLayerNode extends Container {
|
|
|
102
102
|
destroy(): void;
|
|
103
103
|
private _buildChunkNodes;
|
|
104
104
|
/**
|
|
105
|
-
* Construct
|
|
105
|
+
* Construct the configured draw nodes for `chunk` - shared by
|
|
106
106
|
* the initial bulk build ({@link _buildChunkNodes}) and the incremental
|
|
107
107
|
* structural-listener handler, so a future constructor argument or
|
|
108
108
|
* per-node setting only needs to be added in one place.
|
|
109
109
|
*/
|
|
110
|
+
private _addChunkNodes;
|
|
111
|
+
private _sortChunks;
|
|
110
112
|
private _createChunkNode;
|
|
111
113
|
/**
|
|
112
114
|
* Compute and apply this layer's live tint (opacity as alpha, `tintColor`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TileLayerNode.d.ts","sourceRoot":"","sources":["../../src/TileLayerNode.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAE,aAAa,EAA0B,MAAM,4BAA4B,CAAC;AAMnF,OAAO,KAAK,EAAwB,SAAS,EAAE,MAAM,aAAa,CAAC;AAEnE;;;;GAIG;AACH,MAAM,W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WlC;IAEF,YAAmB,KAAK,EAAE,SAAS,EAAE,OAAO,CAAC,EAAE,oBAAoB,EAclE;IAED,2CAA2C;IAC3C,IAAW,KAAK,IAAI,SAAS,CAE5B;IAED;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,IAAW,aAAa,IAAI,aAAa,CAExC;IAED,IAAW,aAAa,CAAC,IAAI,EAAE,aAAa,EAW3C;IAED;;;;OAIG;IACI,OAAO,IAAI,IAAI,CAerB;IAOD;;;;OAIG;IACa,cAAc,IAAI,iBAAiB,CAiBlD;IAoDe,OAAO,IAAI,IAAI,CAY9B;IAED,OAAO,CAAC,gBAAgB;IAexB;;;;;OAKG;IACH,OAAO,CAAC,cAAc;IAWtB,OAAO,CAAC,WAAW;IAMnB,OAAO,CAAC,gBAAgB;IAYxB;;;;;;;OAOG;IACH,OAAO,CAAC,UAAU;IAQlB;;;;OAIG;IACH,OAAO,CAAC,SAAS;CAelB"}
|
|
@@ -9,9 +9,9 @@ import { Container } from "@codexo/exojs";
|
|
|
9
9
|
* A scene node that renders one generic {@link TileLayer} as a
|
|
10
10
|
* {@link Container} of per-chunk {@link TileChunkNode} drawables.
|
|
11
11
|
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
12
|
+
* Orthogonal chunks become one child each. Isometric chunks become diagonal
|
|
13
|
+
* slices ordered across storage boundaries, preserving painter order and
|
|
14
|
+
* texture runs. Each drawable has its own culling bounds. The layer's pixel
|
|
15
15
|
* `offset`, `visible` and `opacity` are all read live from the runtime layer on
|
|
16
16
|
* every frame (no rebuild required).
|
|
17
17
|
*
|
|
@@ -51,18 +51,16 @@ var TileLayerNode = class extends Container {
|
|
|
51
51
|
* revision-cached geometry survives untouched.
|
|
52
52
|
*/
|
|
53
53
|
_onStructuralChange = (event) => {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
this.
|
|
59
|
-
|
|
54
|
+
for (let i = this._chunkNodes.length - 1; i >= 0; i--) {
|
|
55
|
+
const node = this._chunkNodes[i];
|
|
56
|
+
if (!node) continue;
|
|
57
|
+
if (node.chunkX !== event.cx || node.chunkY !== event.cy) continue;
|
|
58
|
+
this._chunkNodes.splice(i, 1);
|
|
59
|
+
this.removeChild(node);
|
|
60
|
+
node.destroy();
|
|
60
61
|
}
|
|
61
|
-
if (event.chunk
|
|
62
|
-
|
|
63
|
-
this._chunkNodes.push(node);
|
|
64
|
-
this.addChild(node);
|
|
65
|
-
this._applyTint(node);
|
|
62
|
+
if (event.chunk !== null && !event.chunk.empty) this._addChunkNodes(event.chunk);
|
|
63
|
+
this._sortChunks();
|
|
66
64
|
};
|
|
67
65
|
constructor(layer, options) {
|
|
68
66
|
super();
|
|
@@ -134,7 +132,10 @@ var TileLayerNode = class extends Container {
|
|
|
134
132
|
getLocalBounds() {
|
|
135
133
|
const bounds = this._localBounds;
|
|
136
134
|
const { pixelHeight, pixelWidth } = this._layer;
|
|
137
|
-
if (
|
|
135
|
+
if (this._layer.projection.orientation === "isometric") {
|
|
136
|
+
bounds.set(0, 0, 0, 0);
|
|
137
|
+
aggregateChildLocalBounds(this._chunkNodes, bounds);
|
|
138
|
+
} else if (pixelWidth !== void 0 && pixelHeight !== void 0) bounds.set(this._layer.projection.originX, this._layer.projection.originY, pixelWidth, pixelHeight);
|
|
138
139
|
else if (this._chunkNodes.length > 0) aggregateChildLocalBounds(this._chunkNodes, bounds);
|
|
139
140
|
return bounds;
|
|
140
141
|
}
|
|
@@ -176,21 +177,35 @@ var TileLayerNode = class extends Container {
|
|
|
176
177
|
const layer = this._layer;
|
|
177
178
|
for (const chunk of layer.loadedChunks()) {
|
|
178
179
|
if (chunk.empty) continue;
|
|
179
|
-
|
|
180
|
-
this._chunkNodes.push(node);
|
|
181
|
-
this.addChild(node);
|
|
180
|
+
this._addChunkNodes(chunk);
|
|
182
181
|
}
|
|
182
|
+
this._sortChunks();
|
|
183
183
|
this._syncTint();
|
|
184
184
|
}
|
|
185
185
|
/**
|
|
186
|
-
* Construct
|
|
186
|
+
* Construct the configured draw nodes for `chunk` - shared by
|
|
187
187
|
* the initial bulk build ({@link _buildChunkNodes}) and the incremental
|
|
188
188
|
* structural-listener handler, so a future constructor argument or
|
|
189
189
|
* per-node setting only needs to be added in one place.
|
|
190
190
|
*/
|
|
191
|
-
|
|
191
|
+
_addChunkNodes(chunk) {
|
|
192
|
+
const iso = this._layer.projection.orientation === "isometric";
|
|
193
|
+
const count = iso ? chunk.width + chunk.height - 1 : 1;
|
|
194
|
+
for (let i = 0; i < count; i++) {
|
|
195
|
+
const node = this._createChunkNode(chunk, iso ? i : void 0);
|
|
196
|
+
this._chunkNodes.push(node);
|
|
197
|
+
this.addChild(node);
|
|
198
|
+
this._applyTint(node);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
_sortChunks() {
|
|
202
|
+
if (this._layer.projection.orientation !== "isometric") return;
|
|
203
|
+
this._chunkNodes.sort((a, b) => a.depth - b.depth || a.firstColumn - b.firstColumn);
|
|
204
|
+
for (const [index, node] of this._chunkNodes.entries()) this.setChildIndex(node, index);
|
|
205
|
+
}
|
|
206
|
+
_createChunkNode(chunk, diagonal) {
|
|
192
207
|
const layer = this._layer;
|
|
193
|
-
const node = new TileChunkNode(chunk, layer.tilesets, layer.tileWidth, layer.tileHeight, layer.chunkWidth, layer.chunkHeight);
|
|
208
|
+
const node = new TileChunkNode(chunk, layer.tilesets, layer.tileWidth, layer.tileHeight, layer.chunkWidth, layer.chunkHeight, layer.projection, diagonal);
|
|
194
209
|
node.cullable = this._cullChunks;
|
|
195
210
|
node.pixelSnapMode = this._pixelSnapMode;
|
|
196
211
|
return node;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TileLayerNode.js","names":[],"sources":["../../src/TileLayerNode.ts"],"sourcesContent":["import type { ReadonlyRectangle } from '@codexo/exojs';\nimport { Container } from '@codexo/exojs';\nimport { PixelSnapMode, type RenderPlanBuilder } from '@codexo/exojs/renderer-sdk';\n\nimport { aggregateChildLocalBounds } from './nodeBounds';\nimport { assertPixelSnapMode } from './pixelSnap';\nimport type { ReadonlyTileChunk } from './TileChunk';\nimport { TileChunkNode } from './TileChunkNode';\nimport type { ChunkStructuralEvent, TileLayer } from './TileLayer';\n\n/**\n * Options for a {@link TileLayerNode}. All optional; reserved for forward\n * compatibility.\n * @advanced\n */\nexport interface TileLayerNodeOptions {\n /**\n * Whether the layer's chunk nodes participate in per-chunk view culling.\n * Defaults to `true`. Disable only for tiny, always-on-screen layers where\n * the per-chunk bounds test is pure overhead.\n */\n readonly cullable?: boolean;\n}\n\n/**\n * A scene node that renders one generic {@link TileLayer} as a\n * {@link Container} of per-chunk {@link TileChunkNode} drawables.\n *\n * Each non-empty loaded chunk becomes one child positioned at its pixel\n * origin, so the engine's existing per-node culling drops individual chunks and\n * the render-plan optimiser batches them by tileset texture. The layer's pixel\n * `offset`, `visible` and `opacity` are all read live from the runtime layer on\n * every frame (no rebuild required).\n *\n * A `parallax` factor other than `1` makes this node's rendered position\n * camera-dependent, resolved per frame in {@link _collectContent} by patching\n * the node position against the camera centre, then restoring it - the cull\n * test runs before that patch, so a bounded layer with parallax would be\n * culled at its static base-offset bounds while actually rendering elsewhere.\n * Such a layer therefore opts out of view culling (`cullable = false`), same\n * as an unbounded layer (exactly like {@link import('./ImageLayerNode').ImageLayerNode}).\n *\n * The node references - but never owns - the {@link TileLayer}: destroying it\n * frees its chunk nodes and their cached geometry but leaves the layer, map,\n * and Loader-owned textures intact.\n *\n * Structural changes made via `_adoptChunk`/`_evictChunk` (chunk streaming)\n * are picked up incrementally as they happen, without a full rebuild.\n * {@link TileLayerNode.refresh} remains available for callers that mutate\n * chunk structure by other means (e.g. a bulk edit that bypasses\n * `_adoptChunk`/`_evictChunk`) and need a full resync. In-place tile edits to\n * existing chunks are picked up automatically via chunk revisions.\n *\n * @advanced\n */\nexport class TileLayerNode extends Container {\n private readonly _layer: TileLayer;\n private readonly _cullChunks: boolean;\n private readonly _chunkNodes: TileChunkNode[] = [];\n private _syncedOpacity = -1;\n private _syncedTint: number | null | undefined = undefined;\n private _pixelSnapMode: PixelSnapMode = PixelSnapMode.Geometry;\n\n /**\n * Bound once so `TileLayer._addStructuralListener`/`_removeStructuralListener`\n * add and remove the SAME function reference. Incrementally adds/removes\n * the `TileChunkNode` child for exactly the chunk that changed - never\n * triggers a full {@link refresh}, so every other chunk node's\n * revision-cached geometry survives untouched.\n */\n private readonly _onStructuralChange = (event: ChunkStructuralEvent): void => {\n const existingIndex = this._chunkNodes.findIndex(n => n.chunkX === event.cx && n.chunkY === event.cy);\n\n const existing = this._chunkNodes[existingIndex];\n\n if (existing) {\n this._chunkNodes.splice(existingIndex, 1);\n this.removeChild(existing);\n existing.destroy();\n }\n\n if (event.chunk === null || event.chunk.empty) {\n return;\n }\n\n const node = this._createChunkNode(event.chunk);\n\n this._chunkNodes.push(node);\n this.addChild(node);\n this._applyTint(node);\n };\n\n public constructor(layer: TileLayer, options?: TileLayerNodeOptions) {\n super();\n\n this._layer = layer;\n this._cullChunks = options?.cullable ?? true;\n\n this.setPosition(layer.offsetX, layer.offsetY);\n this._buildChunkNodes();\n\n if (!this._layer.bounded || layer.parallaxX !== 1 || layer.parallaxY !== 1 || layer.parallaxScale !== 1) {\n this.cullable = false;\n }\n\n this._layer._addStructuralListener(this._onStructuralChange);\n }\n\n /** The runtime layer this node renders. */\n public get layer(): TileLayer {\n return this._layer;\n }\n\n /**\n * Render-only pixel-snap mode applied to every chunk node in this layer (and\n * to chunks rebuilt later by {@link refresh}). Each chunk's rendered origin is\n * snapped to the active render target's device-pixel grid; because chunk\n * origins are integer multiples of the integer tile pitch from the same layer\n * origin, the whole grid stays exact and adjacent chunks cannot drift apart.\n *\n * Purely visual: tile data, the layer offset, chunk content revisions, and\n * culling bounds are never changed. `PixelSnapMode.Geometry` and `PixelSnapMode.Position` both resolve\n * to coherent origin snapping for tile chunks (chunk quads are already on the\n * integer pixel grid by construction). Setting the current value is a no-op;\n * an invalid value throws and leaves the prior mode unchanged.\n *\n * Defaults to `Geometry` because a tile grid is made of quads that share\n * their edges: left unsnapped, a boundary landing between two device pixels\n * is sampled across both, so the seams blur and shimmer as the view moves.\n * Set `None` to opt out.\n *\n * @default PixelSnapMode.Geometry\n * @stable\n */\n public get pixelSnapMode(): PixelSnapMode {\n return this._pixelSnapMode;\n }\n\n public set pixelSnapMode(mode: PixelSnapMode) {\n if (mode === this._pixelSnapMode) {\n return;\n }\n\n assertPixelSnapMode(mode);\n this._pixelSnapMode = mode;\n\n for (const chunk of this._chunkNodes) {\n chunk.pixelSnapMode = mode;\n }\n }\n\n /**\n * Rebuild the chunk-node children from the layer's current loaded chunks.\n * Call after structural mutation that creates or empties chunks. In-place\n * tile edits to existing chunks do not need a refresh.\n */\n public refresh(): this {\n const previous = [...this._chunkNodes];\n\n this.removeChildren();\n this._chunkNodes.length = 0;\n\n for (const child of previous) {\n child.destroy();\n }\n\n this._syncedOpacity = -1;\n this._syncedTint = undefined;\n this._buildChunkNodes();\n\n return this;\n }\n\n /** The chunk render nodes owned by this layer node, in build order. @internal */\n public get chunkNodes(): readonly TileChunkNode[] {\n return this._chunkNodes;\n }\n\n /**\n * Recomputed lazily on read, so it writes `_localBounds` directly rather than\n * going through `setLocalBounds`: an invalidating write inside a getter\n * would re-dirty the node on every read.\n */\n public override getLocalBounds(): ReadonlyRectangle {\n const bounds = this._localBounds;\n\n // Reading the pixel extents directly (rather than gating on `bounded`)\n // is what narrows them to numbers - `bounded` is a plain boolean getter.\n const { pixelHeight, pixelWidth } = this._layer;\n\n if (pixelWidth !== undefined && pixelHeight !== undefined) {\n bounds.set(0, 0, pixelWidth, pixelHeight);\n } else if (this._chunkNodes.length > 0) {\n aggregateChildLocalBounds(this._chunkNodes, bounds);\n }\n\n return bounds;\n }\n\n /** @internal */\n protected override _collectContent(builder: RenderPlanBuilder): void {\n if (!this._layer.visible) {\n return;\n }\n\n this._syncTint();\n\n const layer = this._layer;\n\n const patchesPosition = layer.parallaxX !== 1 || layer.parallaxY !== 1;\n const patchesScale = layer.parallaxScale !== 1;\n\n // `offsetX`/`offsetY` are live, mutable fields (`TileColliderStreamer` and\n // `pixelToTile` already read them per call) - re-read here every frame so a\n // runtime-moved layer's rendering follows its collision rather than freezing\n // at the position it had when this node was constructed.\n if (patchesPosition || patchesScale) {\n const camCenter = builder.view.center;\n const prevScaleX = this.scale.x;\n const prevScaleY = this.scale.y;\n\n if (patchesPosition) {\n this.x = layer.offsetX + camCenter.x * (1 - layer.parallaxX);\n this.y = layer.offsetY + camCenter.y * (1 - layer.parallaxY);\n } else {\n this.setPosition(layer.offsetX, layer.offsetY);\n }\n\n if (patchesScale) {\n this.setScale(prevScaleX * layer.parallaxScale, prevScaleY * layer.parallaxScale);\n }\n\n try {\n super._collectContent(builder);\n } finally {\n if (patchesPosition) {\n this.setPosition(layer.offsetX, layer.offsetY);\n }\n\n if (patchesScale) {\n this.setScale(prevScaleX, prevScaleY);\n }\n }\n } else {\n this.setPosition(layer.offsetX, layer.offsetY);\n super._collectContent(builder);\n }\n }\n\n public override destroy(): void {\n this._layer._removeStructuralListener(this._onStructuralChange);\n\n const children = [...this._chunkNodes];\n\n this._chunkNodes.length = 0;\n\n super.destroy();\n\n for (const child of children) {\n child.destroy();\n }\n }\n\n private _buildChunkNodes(): void {\n const layer = this._layer;\n\n for (const chunk of layer.loadedChunks()) {\n if (chunk.empty) {\n continue;\n }\n\n const node = this._createChunkNode(chunk);\n\n this._chunkNodes.push(node);\n this.addChild(node);\n }\n\n this._syncTint();\n }\n\n /**\n * Construct one configured {@link TileChunkNode} for `chunk` - shared by\n * the initial bulk build ({@link _buildChunkNodes}) and the incremental\n * structural-listener handler, so a future constructor argument or\n * per-node setting only needs to be added in one place.\n */\n private _createChunkNode(chunk: ReadonlyTileChunk): TileChunkNode {\n const layer = this._layer;\n const node = new TileChunkNode(chunk, layer.tilesets, layer.tileWidth, layer.tileHeight, layer.chunkWidth, layer.chunkHeight);\n\n node.cullable = this._cullChunks;\n // Unconditional: a chunk built after the layer was set to `None` has to\n // inherit that too, not just a non-default mode.\n node.pixelSnapMode = this._pixelSnapMode;\n\n return node;\n }\n\n /**\n * Compute and apply this layer's live tint (opacity as alpha, `tintColor`\n * as RGB multiply) to a single chunk node. Used both by {@link _syncTint}'s\n * bulk pass and by the structural-listener handler for a freshly-added\n * node - a node added between two \"nothing changed\" full syncs must still\n * receive the current tint, which a change-detection-guarded bulk pass\n * alone would skip.\n */\n private _applyTint(node: TileChunkNode): void {\n const tintColor = this._layer.tintColor;\n const r = tintColor === null ? 255 : (tintColor >> 16) & 0xff;\n const g = tintColor === null ? 255 : (tintColor >> 8) & 0xff;\n const b = tintColor === null ? 255 : tintColor & 0xff;\n node.tint.set(r, g, b, this._layer.opacity);\n }\n\n /**\n * Propagate the layer's live opacity and tint colour onto every chunk\n * render tint if either changed since the last call. Opacity drives the\n * tint alpha; `tintColor` (`0xRRGGBB`) multiplies the RGB (white = no tint).\n */\n private _syncTint(): void {\n const opacity = this._layer.opacity;\n const tintColor = this._layer.tintColor;\n\n if (opacity === this._syncedOpacity && tintColor === this._syncedTint) {\n return;\n }\n\n for (const child of this._chunkNodes) {\n this._applyTint(child);\n }\n\n this._syncedOpacity = opacity;\n this._syncedTint = tintColor;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuDA,IAAa,gBAAb,cAAmC,UAAU;CAC3C,AAAiB;CACjB,AAAiB;CACjB,AAAiB,cAA+B,CAAC;CACjD,AAAQ,iBAAiB;CACzB,AAAQ,cAAyC;CACjD,AAAQ,iBAAgC,cAAc;;;;;;;;CAStD,AAAiB,uBAAuB,UAAsC;EAC5E,MAAM,gBAAgB,KAAK,YAAY,WAAU,MAAK,EAAE,WAAW,MAAM,MAAM,EAAE,WAAW,MAAM,EAAE;EAEpG,MAAM,WAAW,KAAK,YAAY;EAElC,IAAI,UAAU;GACZ,KAAK,YAAY,OAAO,eAAe,CAAC;GACxC,KAAK,YAAY,Q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KAAK;GAExC,KAAK,YAAY,KAAK,IAAI;GAC1B,KAAK,SAAS,IAAI;EACpB;EAEA,KAAK,UAAU;CACjB;;;;;;;CAQA,AAAQ,iBAAiB,OAAyC;EAChE,MAAM,QAAQ,KAAK;EACnB,MAAM,OAAO,IAAI,cAAc,OAAO,MAAM,UAAU,MAAM,WAAW,MAAM,YAAY,MAAM,YAAY,MAAM,WAAW;EAE5H,KAAK,WAAW,KAAK;EAGrB,KAAK,gBAAgB,KAAK;EAE1B,OAAO;CACT;;;;;;;;;CAUA,AAAQ,WAAW,MAA2B;EAC5C,MAAM,YAAY,KAAK,OAAO;EAC9B,MAAM,IAAI,cAAc,OAAO,MAAO,aAAa,KAAM;EACzD,MAAM,IAAI,cAAc,OAAO,MAAO,aAAa,IAAK;EACxD,MAAM,IAAI,cAAc,OAAO,MAAM,YAAY;EACjD,KAAK,KAAK,IAAI,GAAG,GAAG,GAAG,KAAK,OAAO,OAAO;CAC5C;;;;;;CAOA,AAAQ,YAAkB;EACxB,MAAM,UAAU,KAAK,OAAO;EAC5B,MAAM,YAAY,KAAK,OAAO;EAE9B,IAAI,YAAY,KAAK,kBAAkB,cAAc,KAAK,aACxD;EAGF,KAAK,MAAM,SAAS,KAAK,aACvB,KAAK,WAAW,KAAK;EAGvB,KAAK,iBAAiB;EACtB,KAAK,cAAc;CACrB;AACF"}
|
|
1
|
+
{"version":3,"file":"TileLayerNode.js","names":[],"sources":["../../src/TileLayerNode.ts"],"sourcesContent":["import type { ReadonlyRectangle } from '@codexo/exojs';\nimport { Container } from '@codexo/exojs';\nimport { PixelSnapMode, type RenderPlanBuilder } from '@codexo/exojs/renderer-sdk';\n\nimport { aggregateChildLocalBounds } from './nodeBounds';\nimport { assertPixelSnapMode } from './pixelSnap';\nimport type { ReadonlyTileChunk } from './TileChunk';\nimport { TileChunkNode } from './TileChunkNode';\nimport type { ChunkStructuralEvent, TileLayer } from './TileLayer';\n\n/**\n * Options for a {@link TileLayerNode}. All optional; reserved for forward\n * compatibility.\n * @advanced\n */\nexport interface TileLayerNodeOptions {\n /**\n * Whether the layer's chunk nodes participate in per-chunk view culling.\n * Defaults to `true`. Disable only for tiny, always-on-screen layers where\n * the per-chunk bounds test is pure overhead.\n */\n readonly cullable?: boolean;\n}\n\n/**\n * A scene node that renders one generic {@link TileLayer} as a\n * {@link Container} of per-chunk {@link TileChunkNode} drawables.\n *\n * Orthogonal chunks become one child each. Isometric chunks become diagonal\n * slices ordered across storage boundaries, preserving painter order and\n * texture runs. Each drawable has its own culling bounds. The layer's pixel\n * `offset`, `visible` and `opacity` are all read live from the runtime layer on\n * every frame (no rebuild required).\n *\n * A `parallax` factor other than `1` makes this node's rendered position\n * camera-dependent, resolved per frame in {@link _collectContent} by patching\n * the node position against the camera centre, then restoring it - the cull\n * test runs before that patch, so a bounded layer with parallax would be\n * culled at its static base-offset bounds while actually rendering elsewhere.\n * Such a layer therefore opts out of view culling (`cullable = false`), same\n * as an unbounded layer (exactly like {@link import('./ImageLayerNode').ImageLayerNode}).\n *\n * The node references - but never owns - the {@link TileLayer}: destroying it\n * frees its chunk nodes and their cached geometry but leaves the layer, map,\n * and Loader-owned textures intact.\n *\n * Structural changes made via `_adoptChunk`/`_evictChunk` (chunk streaming)\n * are picked up incrementally as they happen, without a full rebuild.\n * {@link TileLayerNode.refresh} remains available for callers that mutate\n * chunk structure by other means (e.g. a bulk edit that bypasses\n * `_adoptChunk`/`_evictChunk`) and need a full resync. In-place tile edits to\n * existing chunks are picked up automatically via chunk revisions.\n *\n * @advanced\n */\nexport class TileLayerNode extends Container {\n private readonly _layer: TileLayer;\n private readonly _cullChunks: boolean;\n private readonly _chunkNodes: TileChunkNode[] = [];\n private _syncedOpacity = -1;\n private _syncedTint: number | null | undefined = undefined;\n private _pixelSnapMode: PixelSnapMode = PixelSnapMode.Geometry;\n\n /**\n * Bound once so `TileLayer._addStructuralListener`/`_removeStructuralListener`\n * add and remove the SAME function reference. Incrementally adds/removes\n * the `TileChunkNode` child for exactly the chunk that changed - never\n * triggers a full {@link refresh}, so every other chunk node's\n * revision-cached geometry survives untouched.\n */\n private readonly _onStructuralChange = (event: ChunkStructuralEvent): void => {\n for (let i = this._chunkNodes.length - 1; i >= 0; i--) {\n const node = this._chunkNodes[i];\n if (!node) continue;\n if (node.chunkX !== event.cx || node.chunkY !== event.cy) continue;\n this._chunkNodes.splice(i, 1);\n this.removeChild(node);\n node.destroy();\n }\n if (event.chunk !== null && !event.chunk.empty) this._addChunkNodes(event.chunk);\n this._sortChunks();\n };\n\n public constructor(layer: TileLayer, options?: TileLayerNodeOptions) {\n super();\n\n this._layer = layer;\n this._cullChunks = options?.cullable ?? true;\n\n this.setPosition(layer.offsetX, layer.offsetY);\n this._buildChunkNodes();\n\n if (!this._layer.bounded || layer.parallaxX !== 1 || layer.parallaxY !== 1 || layer.parallaxScale !== 1) {\n this.cullable = false;\n }\n\n this._layer._addStructuralListener(this._onStructuralChange);\n }\n\n /** The runtime layer this node renders. */\n public get layer(): TileLayer {\n return this._layer;\n }\n\n /**\n * Render-only pixel-snap mode applied to every chunk node in this layer (and\n * to chunks rebuilt later by {@link refresh}). Each chunk's rendered origin is\n * snapped to the active render target's device-pixel grid; because chunk\n * origins are integer multiples of the integer tile pitch from the same layer\n * origin, the whole grid stays exact and adjacent chunks cannot drift apart.\n *\n * Purely visual: tile data, the layer offset, chunk content revisions, and\n * culling bounds are never changed. `PixelSnapMode.Geometry` and `PixelSnapMode.Position` both resolve\n * to coherent origin snapping for tile chunks (chunk quads are already on the\n * integer pixel grid by construction). Setting the current value is a no-op;\n * an invalid value throws and leaves the prior mode unchanged.\n *\n * Defaults to `Geometry` because a tile grid is made of quads that share\n * their edges: left unsnapped, a boundary landing between two device pixels\n * is sampled across both, so the seams blur and shimmer as the view moves.\n * Set `None` to opt out.\n *\n * @default PixelSnapMode.Geometry\n * @stable\n */\n public get pixelSnapMode(): PixelSnapMode {\n return this._pixelSnapMode;\n }\n\n public set pixelSnapMode(mode: PixelSnapMode) {\n if (mode === this._pixelSnapMode) {\n return;\n }\n\n assertPixelSnapMode(mode);\n this._pixelSnapMode = mode;\n\n for (const chunk of this._chunkNodes) {\n chunk.pixelSnapMode = mode;\n }\n }\n\n /**\n * Rebuild the chunk-node children from the layer's current loaded chunks.\n * Call after structural mutation that creates or empties chunks. In-place\n * tile edits to existing chunks do not need a refresh.\n */\n public refresh(): this {\n const previous = [...this._chunkNodes];\n\n this.removeChildren();\n this._chunkNodes.length = 0;\n\n for (const child of previous) {\n child.destroy();\n }\n\n this._syncedOpacity = -1;\n this._syncedTint = undefined;\n this._buildChunkNodes();\n\n return this;\n }\n\n /** The chunk render nodes owned by this layer node, in build order. @internal */\n public get chunkNodes(): readonly TileChunkNode[] {\n return this._chunkNodes;\n }\n\n /**\n * Recomputed lazily on read, so it writes `_localBounds` directly rather than\n * going through `setLocalBounds`: an invalidating write inside a getter\n * would re-dirty the node on every read.\n */\n public override getLocalBounds(): ReadonlyRectangle {\n const bounds = this._localBounds;\n\n // Reading the pixel extents directly (rather than gating on `bounded`)\n // is what narrows them to numbers - `bounded` is a plain boolean getter.\n const { pixelHeight, pixelWidth } = this._layer;\n\n if (this._layer.projection.orientation === 'isometric') {\n bounds.set(0, 0, 0, 0);\n aggregateChildLocalBounds(this._chunkNodes, bounds);\n } else if (pixelWidth !== undefined && pixelHeight !== undefined) {\n bounds.set(this._layer.projection.originX, this._layer.projection.originY, pixelWidth, pixelHeight);\n } else if (this._chunkNodes.length > 0) {\n aggregateChildLocalBounds(this._chunkNodes, bounds);\n }\n\n return bounds;\n }\n\n /** @internal */\n protected override _collectContent(builder: RenderPlanBuilder): void {\n if (!this._layer.visible) {\n return;\n }\n\n this._syncTint();\n\n const layer = this._layer;\n\n const patchesPosition = layer.parallaxX !== 1 || layer.parallaxY !== 1;\n const patchesScale = layer.parallaxScale !== 1;\n\n // `offsetX`/`offsetY` are live, mutable fields (`TileColliderStreamer` and\n // `pixelToTile` already read them per call) - re-read here every frame so a\n // runtime-moved layer's rendering follows its collision rather than freezing\n // at the position it had when this node was constructed.\n if (patchesPosition || patchesScale) {\n const camCenter = builder.view.center;\n const prevScaleX = this.scale.x;\n const prevScaleY = this.scale.y;\n\n if (patchesPosition) {\n this.x = layer.offsetX + camCenter.x * (1 - layer.parallaxX);\n this.y = layer.offsetY + camCenter.y * (1 - layer.parallaxY);\n } else {\n this.setPosition(layer.offsetX, layer.offsetY);\n }\n\n if (patchesScale) {\n this.setScale(prevScaleX * layer.parallaxScale, prevScaleY * layer.parallaxScale);\n }\n\n try {\n super._collectContent(builder);\n } finally {\n if (patchesPosition) {\n this.setPosition(layer.offsetX, layer.offsetY);\n }\n\n if (patchesScale) {\n this.setScale(prevScaleX, prevScaleY);\n }\n }\n } else {\n this.setPosition(layer.offsetX, layer.offsetY);\n super._collectContent(builder);\n }\n }\n\n public override destroy(): void {\n this._layer._removeStructuralListener(this._onStructuralChange);\n\n const children = [...this._chunkNodes];\n\n this._chunkNodes.length = 0;\n\n super.destroy();\n\n for (const child of children) {\n child.destroy();\n }\n }\n\n private _buildChunkNodes(): void {\n const layer = this._layer;\n\n for (const chunk of layer.loadedChunks()) {\n if (chunk.empty) {\n continue;\n }\n\n this._addChunkNodes(chunk);\n }\n\n this._sortChunks();\n this._syncTint();\n }\n\n /**\n * Construct the configured draw nodes for `chunk` - shared by\n * the initial bulk build ({@link _buildChunkNodes}) and the incremental\n * structural-listener handler, so a future constructor argument or\n * per-node setting only needs to be added in one place.\n */\n private _addChunkNodes(chunk: ReadonlyTileChunk): void {\n const iso = this._layer.projection.orientation === 'isometric';\n const count = iso ? chunk.width + chunk.height - 1 : 1;\n for (let i = 0; i < count; i++) {\n const node = this._createChunkNode(chunk, iso ? i : undefined);\n this._chunkNodes.push(node);\n this.addChild(node);\n this._applyTint(node);\n }\n }\n\n private _sortChunks(): void {\n if (this._layer.projection.orientation !== 'isometric') return;\n this._chunkNodes.sort((a, b) => a.depth - b.depth || a.firstColumn - b.firstColumn);\n for (const [index, node] of this._chunkNodes.entries()) this.setChildIndex(node, index);\n }\n\n private _createChunkNode(chunk: ReadonlyTileChunk, diagonal?: number): TileChunkNode {\n const layer = this._layer;\n const node = new TileChunkNode(chunk, layer.tilesets, layer.tileWidth, layer.tileHeight, layer.chunkWidth, layer.chunkHeight, layer.projection, diagonal);\n\n node.cullable = this._cullChunks;\n // Unconditional: a chunk built after the layer was set to `None` has to\n // inherit that too, not just a non-default mode.\n node.pixelSnapMode = this._pixelSnapMode;\n\n return node;\n }\n\n /**\n * Compute and apply this layer's live tint (opacity as alpha, `tintColor`\n * as RGB multiply) to a single chunk node. Used both by {@link _syncTint}'s\n * bulk pass and by the structural-listener handler for a freshly-added\n * node - a node added between two \"nothing changed\" full syncs must still\n * receive the current tint, which a change-detection-guarded bulk pass\n * alone would skip.\n */\n private _applyTint(node: TileChunkNode): void {\n const tintColor = this._layer.tintColor;\n const r = tintColor === null ? 255 : (tintColor >> 16) & 0xff;\n const g = tintColor === null ? 255 : (tintColor >> 8) & 0xff;\n const b = tintColor === null ? 255 : tintColor & 0xff;\n node.tint.set(r, g, b, this._layer.opacity);\n }\n\n /**\n * Propagate the layer's live opacity and tint colour onto every chunk\n * render tint if either changed since the last call. Opacity drives the\n * tint alpha; `tintColor` (`0xRRGGBB`) multiplies the RGB (white = no tint).\n */\n private _syncTint(): void {\n const opacity = this._layer.opacity;\n const tintColor = this._layer.tintColor;\n\n if (opacity === this._syncedOpacity && tintColor === this._syncedTint) {\n return;\n }\n\n for (const child of this._chunkNodes) {\n this._applyTint(child);\n }\n\n this._syncedOpacity = opacity;\n this._syncedTint = tintColor;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuDA,IAAa,gBAAb,cAAmC,UAAU;CAC3C,AAAiB;CACjB,AAAiB;CACjB,AAAiB,cAA+B,CAAC;CACjD,AAAQ,iBAAiB;CACzB,AAAQ,cAAyC;CACjD,AAAQ,iBAAgC,cAAc;;;;;;;;CAStD,AAAiB,uBAAuB,U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C,MAAM,YAAY,KAAK,OAAO;EAC9B,MAAM,IAAI,cAAc,OAAO,MAAO,aAAa,KAAM;EACzD,MAAM,IAAI,cAAc,OAAO,MAAO,aAAa,IAAK;EACxD,MAAM,IAAI,cAAc,OAAO,MAAM,YAAY;EACjD,KAAK,KAAK,IAAI,GAAG,GAAG,GAAG,KAAK,OAAO,OAAO;CAC5C;;;;;;CAOA,AAAQ,YAAkB;EACxB,MAAM,UAAU,KAAK,OAAO;EAC5B,MAAM,YAAY,KAAK,OAAO;EAE9B,IAAI,YAAY,KAAK,kBAAkB,cAAc,KAAK,aACxD;EAGF,KAAK,MAAM,SAAS,KAAK,aACvB,KAAK,WAAW,KAAK;EAGvB,KAAK,iBAAiB;EACtB,KAAK,cAAc;CACrB;AACF"}
|
package/dist/esm/TileMap.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type { ObjectLayer, ObjectSchema } from './ObjectLayer';
|
|
|
3
3
|
import { type TileLayer } from './TileLayer';
|
|
4
4
|
import type { TileMapViewOptions } from './TileMapView';
|
|
5
5
|
import { TileMapView } from './TileMapView';
|
|
6
|
+
import { TileProjection } from './TileProjection';
|
|
6
7
|
import { type TileSet } from './TileSet';
|
|
7
8
|
import type { ResolvedTile, TileProperties } from './types';
|
|
8
9
|
/**
|
|
@@ -10,6 +11,8 @@ import type { ResolvedTile, TileProperties } from './types';
|
|
|
10
11
|
* @advanced
|
|
11
12
|
*/
|
|
12
13
|
export interface TileMapOptions {
|
|
14
|
+
/** Shared projection; defaults to an orthogonal grid of the supplied tile size. */
|
|
15
|
+
readonly projection?: TileProjection;
|
|
13
16
|
/** Map name (for debugging). */
|
|
14
17
|
readonly name?: string;
|
|
15
18
|
/**
|
|
@@ -92,6 +95,7 @@ export interface TileMapOptions {
|
|
|
92
95
|
* @advanced
|
|
93
96
|
*/
|
|
94
97
|
export declare class TileMap {
|
|
98
|
+
readonly projection: TileProjection;
|
|
95
99
|
/** Map name (debug). */
|
|
96
100
|
readonly name: string;
|
|
97
101
|
/** Map width in tiles, or `undefined` if unbounded. */
|
|
@@ -277,7 +281,7 @@ export declare class TileMap {
|
|
|
277
281
|
*/
|
|
278
282
|
clearTileAt(layerId: number, tx: number, ty: number): void;
|
|
279
283
|
/**
|
|
280
|
-
* Convert a
|
|
284
|
+
* Convert a grid vertex to display pixels (the top diamond vertex for isometric cells)
|
|
281
285
|
* in map-local space (ignoring layer offsets).
|
|
282
286
|
*/
|
|
283
287
|
tileToPixel(tx: number, ty: number): {
|
|
@@ -285,7 +289,7 @@ export declare class TileMap {
|
|
|
285
289
|
y: number;
|
|
286
290
|
};
|
|
287
291
|
/**
|
|
288
|
-
* Convert a
|
|
292
|
+
* Convert a display position in map-local space to the tile coordinate
|
|
289
293
|
* that contains it. Uses `floor`. May return coordinates outside map bounds.
|
|
290
294
|
*/
|
|
291
295
|
pixelToTile(px: number, py: number): {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TileMap.d.ts","sourceRoot":"","sources":["../../src/TileMap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC/D,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAG5D;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B,gCAAgC;IAChC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB;;;;OAIG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,kEAAkE;IACl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AC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAE,CAEnE;IAED;;;OAGG;IACI,WAAW,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAA;KAAE,CAErE;IAID;;;;;OAKG;IACH,IAAW,QAAQ,IAAI,MAAM,CAE5B;IAED,0CAA0C;IAC1C,IAAW,SAAS,IAAI,OAAO,CAE9B;IAED,OAAO,CAAC,eAAe;IAMvB;;;;;OAKG;IACI,OAAO,IAAI,IAAI,CAYrB;CACF"}
|
package/dist/esm/TileMap.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { validatePairedDimensions, validatePositiveInteger } from "./types.js";
|
|
2
|
+
import { TileProjection } from "./TileProjection.js";
|
|
2
3
|
import { TileMapView } from "./TileMapView.js";
|
|
3
4
|
|
|
4
5
|
//#region src/TileMap.ts
|
|
@@ -18,6 +19,7 @@ import { TileMapView } from "./TileMapView.js";
|
|
|
18
19
|
* @advanced
|
|
19
20
|
*/
|
|
20
21
|
var TileMap = class {
|
|
22
|
+
projection;
|
|
21
23
|
/** Map name (debug). */
|
|
22
24
|
name;
|
|
23
25
|
/** Map width in tiles, or `undefined` if unbounded. */
|
|
@@ -30,11 +32,11 @@ var TileMap = class {
|
|
|
30
32
|
tileHeight;
|
|
31
33
|
/** Pixel width, or `undefined` if unbounded. */
|
|
32
34
|
get pixelWidth() {
|
|
33
|
-
return this.width === void 0 ? void 0 : this.
|
|
35
|
+
return this.width === void 0 || this.height === void 0 ? void 0 : this.projection.getBounds(0, 0, this.width, this.height).width;
|
|
34
36
|
}
|
|
35
37
|
/** Pixel height, or `undefined` if unbounded. */
|
|
36
38
|
get pixelHeight() {
|
|
37
|
-
return this.height === void 0 ? void 0 : this.
|
|
39
|
+
return this.width === void 0 || this.height === void 0 ? void 0 : this.projection.getBounds(0, 0, this.width, this.height).height;
|
|
38
40
|
}
|
|
39
41
|
/** `true` if this map has a fixed width/height; `false` if unbounded. */
|
|
40
42
|
get bounded() {
|
|
@@ -76,6 +78,11 @@ var TileMap = class {
|
|
|
76
78
|
this.height = options.height;
|
|
77
79
|
this.tileWidth = options.tileWidth;
|
|
78
80
|
this.tileHeight = options.tileHeight;
|
|
81
|
+
this.projection = options.projection ?? new TileProjection({
|
|
82
|
+
tileWidth: options.tileWidth,
|
|
83
|
+
tileHeight: options.tileHeight
|
|
84
|
+
});
|
|
85
|
+
if (this.projection.tileWidth !== this.tileWidth || this.projection.tileHeight !== this.tileHeight) throw new Error("Projection tile dimensions must match the layer or map.");
|
|
79
86
|
this.chunkWidth = chunkWidth;
|
|
80
87
|
this.chunkHeight = chunkHeight;
|
|
81
88
|
this.class = options.class ?? "";
|
|
@@ -346,24 +353,18 @@ var TileMap = class {
|
|
|
346
353
|
layer.clearTileAt(tx, ty);
|
|
347
354
|
}
|
|
348
355
|
/**
|
|
349
|
-
* Convert a
|
|
356
|
+
* Convert a grid vertex to display pixels (the top diamond vertex for isometric cells)
|
|
350
357
|
* in map-local space (ignoring layer offsets).
|
|
351
358
|
*/
|
|
352
359
|
tileToPixel(tx, ty) {
|
|
353
|
-
return
|
|
354
|
-
x: tx * this.tileWidth,
|
|
355
|
-
y: ty * this.tileHeight
|
|
356
|
-
};
|
|
360
|
+
return this.projection.tileToPixel(tx, ty);
|
|
357
361
|
}
|
|
358
362
|
/**
|
|
359
|
-
* Convert a
|
|
363
|
+
* Convert a display position in map-local space to the tile coordinate
|
|
360
364
|
* that contains it. Uses `floor`. May return coordinates outside map bounds.
|
|
361
365
|
*/
|
|
362
366
|
pixelToTile(px, py) {
|
|
363
|
-
return
|
|
364
|
-
tx: Math.floor(px / this.tileWidth),
|
|
365
|
-
ty: Math.floor(py / this.tileHeight)
|
|
366
|
-
};
|
|
367
|
+
return this.projection.pixelToTile(px, py);
|
|
367
368
|
}
|
|
368
369
|
/**
|
|
369
370
|
* Monotonic map revision counter. Increments on structural changes only
|
package/dist/esm/TileMap.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TileMap.js","names":[],"sources":["../../src/TileMap.ts"],"sourcesContent":["import { type ImageLayer } from './ImageLayer';\nimport type { ObjectLayer, ObjectSchema } from './ObjectLayer';\nimport { type TileLayer } from './TileLayer';\nimport type { TileMapViewOptions } from './TileMapView';\nimport { TileMapView } from './TileMapView';\nimport { type TileSet } from './TileSet';\nimport type { ResolvedTile, TileProperties } from './types';\nimport { validatePairedDimensions, validatePositiveInteger } from './types';\n\n/**\n * Options for constructing a {@link TileMap}.\n * @advanced\n */\nexport interface TileMapOptions {\n /** Map name (for debugging). */\n readonly name?: string;\n /**\n * Map width in tiles. Omit together with {@link height} for an unbounded\n * map - layers you add are then free to be unbounded too (this option\n * does not constrain per-layer dimensions either way).\n */\n readonly width?: number;\n /** Map height in tiles. Must be provided iff {@link width} is. */\n readonly height?: number;\n /** Width of each tile in pixels. */\n readonly tileWidth: number;\n /** Height of each tile in pixels. */\n readonly tileHeight: number;\n /** Tilesets available to this map. */\n readonly tilesets?: readonly TileSet[];\n /** Layers (constructed externally and owned by the map after construction). */\n readonly layers?: readonly TileLayer[];\n /** Object layers (data-only; spawn points, triggers, collision regions). */\n readonly objectLayers?: readonly ObjectLayer[];\n /** Image layers (data-only; background/foreground images from Tiled image layers). */\n readonly imageLayers?: readonly ImageLayer[];\n /** Chunk width for layers (default 32). */\n readonly chunkWidth?: number;\n /** Chunk height for layers (default 32). */\n readonly chunkHeight?: number;\n /** Map class/type string (Tiled `class`). Defaults to `''`. */\n readonly class?: string;\n /**\n * Map background colour as a `0xRRGGBB` integer, or `null` (Tiled\n * `backgroundcolor`). Informational - the renderer does not auto-clear to it.\n * Default `null`.\n */\n readonly backgroundColor?: number | null;\n /** Tile draw order (Tiled `renderorder`), informational. Default `'right-down'`. */\n readonly renderOrder?: string;\n /** Map-level properties (copied and frozen). */\n readonly properties?: TileProperties;\n /**\n * Combined document order across tile and image layers, as an ordered list\n * of layer ids - exposed via {@link TileMap.renderableLayers}. Every tile\n * and image layer passed to this map (via {@link layers} / {@link\n * imageLayers}) must appear exactly once; an id that belongs to neither\n * kind, or is listed more than once, throws. The list's length must also\n * equal the total number of tile/image layer instances - nothing enforces\n * unique ids across image layers, so two image layers sharing an id would\n * otherwise both satisfy the id-based checks while one silently drops out\n * of {@link TileMap.renderableLayers}; that mismatch throws too.\n *\n * A tile layer and an image layer sharing the same id makes the order\n * ambiguous - that combination throws when `documentOrder` is provided.\n * It is NOT rejected when this option is omitted: the fallback order below\n * is unambiguous by construction (tile layers are always listed before\n * image layers), so hand-built maps that predate this option are\n * unaffected even if such an id collision exists.\n *\n * Omit to fall back to all tile layers in insertion order, followed by all\n * image layers in insertion order - the map's implicit ordering before\n * this option existed.\n *\n * Named `documentOrder` rather than `renderOrder` to avoid colliding with\n * the unrelated {@link renderOrder} option above (Tiled's tile-draw-\n * direction string, e.g. `'right-down'`).\n */\n readonly documentOrder?: readonly number[];\n}\n\n/**\n * A generic, format-independent tile map.\n *\n * Owns a finite grid of {@link TileLayer}s and a shared set of {@link TileSet}s.\n * Tile data is stored in compact chunked arrays - no per-tile heap objects.\n *\n * The map does NOT own tileset textures (those are Loader-owned) and does\n * NOT own SceneNode children - see {@link import('./TileMapNode').TileMapNode},\n * which owns those.\n *\n * Multiple tilesets are supported: each cell stores a packed tileset index\n * and local tile ID, so different tilesets may have different tile dimensions.\n *\n * @advanced\n */\nexport class TileMap {\n /** Map name (debug). */\n public readonly name: string;\n\n /** Map width in tiles, or `undefined` if unbounded. */\n public readonly width: number | undefined;\n /** Map height in tiles, or `undefined` if unbounded. */\n public readonly height: number | undefined;\n\n /** Tile width in pixels. */\n public readonly tileWidth: number;\n /** Tile height in pixels. */\n public readonly tileHeight: number;\n\n /** Pixel width, or `undefined` if unbounded. */\n public get pixelWidth(): number | undefined {\n return this.width === undefined ? undefined : this.width * this.tileWidth;\n }\n /** Pixel height, or `undefined` if unbounded. */\n public get pixelHeight(): number | undefined {\n return this.height === undefined ? undefined : this.height * this.tileHeight;\n }\n /** `true` if this map has a fixed width/height; `false` if unbounded. */\n public get bounded(): boolean {\n return this.width !== undefined && this.height !== undefined;\n }\n\n /** Default chunk width for layers. */\n public readonly chunkWidth: number;\n /** Default chunk height for layers. */\n public readonly chunkHeight: number;\n\n /** Map class/type string (Tiled `class`; may be empty). */\n public readonly class: string;\n /** Map background colour as `0xRRGGBB`, or `null`. Informational. */\n public readonly backgroundColor: number | null;\n /** Tile draw order (Tiled `renderorder`). Informational. */\n public readonly renderOrder: string;\n\n /** Map-level properties (immutable). */\n public readonly properties: TileProperties;\n\n private readonly _tilesets: TileSet[];\n private readonly _layers: TileLayer[] = [];\n private readonly _layerById = new Map<number, TileLayer>();\n private readonly _objectLayers: ObjectLayer[] = [];\n private readonly _imageLayers: ImageLayer[] = [];\n private readonly _documentOrder: Array<TileLayer | ImageLayer> = [];\n\n private _revision = 0;\n private _destroyed = false;\n\n /**\n * @throws When dimensions or other options are invalid.\n */\n public constructor(options: TileMapOptions) {\n validatePairedDimensions(options.width, options.height, 'TileMap', 'map');\n validatePositiveInteger(options.tileWidth, 'map.tileWidth');\n validatePositiveInteger(options.tileHeight, 'map.tileHeight');\n\n const chunkWidth = options.chunkWidth ?? 32;\n const chunkHeight = options.chunkHeight ?? 32;\n validatePositiveInteger(chunkWidth, 'chunkWidth');\n validatePositiveInteger(chunkHeight, 'chunkHeight');\n\n this.name = options.name ?? 'TileMap';\n this.width = options.width;\n this.height = options.height;\n this.tileWidth = options.tileWidth;\n this.tileHeight = options.tileHeight;\n this.chunkWidth = chunkWidth;\n this.chunkHeight = chunkHeight;\n this.class = options.class ?? '';\n this.backgroundColor = options.backgroundColor ?? null;\n this.renderOrder = options.renderOrder ?? 'right-down';\n\n this._tilesets = options.tilesets ? [...options.tilesets] : [];\n this.properties = options.properties ? Object.freeze({ ...options.properties }) : Object.freeze({});\n\n if (options.layers) {\n for (const layer of options.layers) {\n this._addLayer(layer);\n }\n }\n\n if (options.objectLayers) {\n this._objectLayers.push(...options.objectLayers);\n }\n\n if (options.imageLayers) {\n for (const layer of options.imageLayers) {\n this._addImageLayer(layer);\n }\n }\n\n this._documentOrder.push(...this._buildDocumentOrder(options.documentOrder));\n }\n\n /**\n * Validate an explicit `documentOrder` option against current tile/image\n * layer membership and resolve it to layer instances, or compute the\n * fallback order (tile layers in insertion order, then image layers) when\n * omitted. The order stores instance references - not ids - so a\n * cross-kind id collision in a fallback map can never resolve to the\n * wrong layer.\n * @throws Per the validation rules documented on {@link\n * TileMapOptions.documentOrder}.\n */\n private _buildDocumentOrder(documentOrder: readonly number[] | undefined): Array<TileLayer | ImageLayer> {\n if (!documentOrder) {\n return [...this._layers, ...this._imageLayers];\n }\n\n const tileIds = new Set(this._layers.map(l => l.id));\n const imageIds = new Set(this._imageLayers.map(l => l.id));\n\n for (const id of tileIds) {\n if (imageIds.has(id)) {\n throw new Error(`Layer ID ${id} exists as both a tile layer and an image layer in map \"${this.name}\"; documentOrder cannot disambiguate them.`);\n }\n }\n\n const seen = new Set<number>();\n for (const id of documentOrder) {\n if (!tileIds.has(id) && !imageIds.has(id)) {\n throw new Error(`documentOrder references unknown layer ID ${id} in map \"${this.name}\".`);\n }\n if (seen.has(id)) {\n throw new Error(`documentOrder lists layer ID ${id} more than once in map \"${this.name}\".`);\n }\n seen.add(id);\n }\n\n const totalLayers = tileIds.size + imageIds.size;\n if (seen.size !== totalLayers) {\n for (const id of [...tileIds, ...imageIds]) {\n if (!seen.has(id)) {\n throw new Error(`documentOrder is missing layer ID ${id} in map \"${this.name}\".`);\n }\n }\n }\n\n // The checks above are id-SET based, so they can't see a duplicate\n // image-layer id (nothing enforces image-layer id uniqueness): two\n // image layers sharing an id collapse to one entry in `imageIds`,\n // letting a documentOrder that covers every distinct id still be one\n // instance short. Compare against the actual instance counts so that\n // case throws instead of silently dropping an instance from\n // renderableLayers.\n const instanceCount = this._layers.length + this._imageLayers.length;\n if (documentOrder.length !== instanceCount) {\n throw new Error(\n `documentOrder has ${documentOrder.length} entries but map \"${this.name}\" has ${instanceCount} tile/image layer instances; check for a duplicate image-layer ID.`,\n );\n }\n\n // Ids are unique across kinds here (the cross-kind check above threw\n // otherwise), so resolving each id to an instance is unambiguous. The\n // count check above does not guarantee the ids themselves match, so an\n // unresolvable one is reported rather than left as a hole in the list.\n return documentOrder.map(id => {\n const layer = this._layerById.get(id) ?? this._imageLayers.find(imageLayer => imageLayer.id === id);\n\n if (!layer) {\n throw new Error(`documentOrder references layer id ${id}, but map \"${this.name}\" has no tile or image layer with that id.`);\n }\n\n return layer;\n });\n }\n\n // ── Tilesets ──────────────────────────────────────────────────────────\n\n /** Immutable list of tilesets available to this map. */\n public get tilesets(): readonly TileSet[] {\n return this._tilesets;\n }\n\n /**\n * Add a tileset. Tilesets must have unique names.\n * @throws If a tileset with the same name already exists, or the map is destroyed.\n */\n public addTileset(tileset: TileSet): void {\n this._checkDestroyed();\n if (this._tilesets.some(ts => ts.name === tileset.name)) {\n throw new Error(`Tileset \"${tileset.name}\" already exists in map \"${this.name}\".`);\n }\n this._tilesets.push(tileset);\n this._revision++;\n }\n\n /**\n * Get a tileset by name, or undefined.\n */\n public getTileset(name: string): TileSet | undefined {\n return this._tilesets.find(ts => ts.name === name);\n }\n\n // ── Layers ────────────────────────────────────────────────────────────\n\n /** Immutable snapshot of layers (ordered). */\n public get layers(): readonly TileLayer[] {\n return this._layers;\n }\n\n private _addLayer(layer: TileLayer): void {\n if (this._layerById.has(layer.id)) {\n throw new Error(`Layer ID ${layer.id} already exists in map \"${this.name}\".`);\n }\n this._layerById.set(layer.id, layer);\n this._layers.push(layer);\n }\n\n /**\n * Add a layer after construction. Appended to the end of {@link\n * renderableLayers}'s document order.\n * @throws If a layer with the same ID already exists.\n */\n public addLayer(layer: TileLayer): void {\n this._checkDestroyed();\n this._addLayer(layer);\n this._documentOrder.push(layer);\n this._revision++;\n }\n\n /**\n * Get a tile layer by ID.\n */\n public getTileLayerById(id: number): TileLayer | undefined {\n return this._layerById.get(id);\n }\n\n /**\n * Get a tile layer by name. Returns the first match in insertion order.\n */\n public getTileLayer(name: string): TileLayer | undefined {\n return this._layers.find(l => l.name === name);\n }\n\n /**\n * Remove a layer by ID. The layer is destroyed and spliced out of {@link\n * renderableLayers}'s document order.\n * @returns true if the layer was found and removed.\n */\n public removeLayer(id: number): boolean {\n this._checkDestroyed();\n const layer = this._layerById.get(id);\n if (!layer) return false;\n this._layers.splice(this._layers.indexOf(layer), 1);\n this._layerById.delete(id);\n const orderIndex = this._documentOrder.indexOf(layer);\n if (orderIndex !== -1) this._documentOrder.splice(orderIndex, 1);\n layer.destroy();\n this._revision++;\n return true;\n }\n\n // ── Object layers (data-only) ─────────────────────────────────────────\n\n /** Immutable snapshot of object layers (insertion order). */\n public get objectLayers(): readonly ObjectLayer[] {\n return this._objectLayers;\n }\n\n /**\n * Add an object layer after construction.\n * @throws If the map is destroyed.\n */\n public addObjectLayer(layer: ObjectLayer): void {\n this._checkDestroyed();\n this._objectLayers.push(layer);\n this._revision++;\n }\n\n /**\n * Get an object layer by name (first match in insertion order), or undefined.\n *\n * Supply an {@link ObjectSchema} type argument `S` to obtain a typed view of\n * the layer - `getObjectLayer<LevelObjects>('Entities')` returns an\n * `ObjectLayer<LevelObjects>` whose {@link ObjectLayer.byType} / {@link\n * ObjectLayer.where} accessors narrow `properties`. The schema is a static\n * developer promise only; no runtime validation is performed and the call\n * remains fully back-compatible when omitted.\n */\n public getObjectLayer<S extends ObjectSchema = ObjectSchema>(name: string): ObjectLayer<S> | undefined {\n return this._objectLayers.find(layer => layer.name === name) as ObjectLayer<S> | undefined;\n }\n\n /**\n * Get an object layer by ID.\n *\n * Supply an {@link ObjectSchema} type argument `S` to obtain a typed view of\n * the layer, as with {@link getObjectLayer}.\n */\n public getObjectLayerById<S extends ObjectSchema = ObjectSchema>(id: number): ObjectLayer<S> | undefined {\n return this._objectLayers.find(layer => layer.id === id) as ObjectLayer<S> | undefined;\n }\n\n /**\n * Remove an object layer by ID.\n * @returns true if the layer was found and removed.\n */\n public removeObjectLayer(id: number): boolean {\n this._checkDestroyed();\n const index = this._objectLayers.findIndex(layer => layer.id === id);\n if (index === -1) return false;\n this._objectLayers.splice(index, 1);\n this._revision++;\n return true;\n }\n\n // ── Image layers (data-only) ──────────────────────────────────────────\n\n /** Immutable snapshot of image layers (insertion order). */\n public get imageLayers(): readonly ImageLayer[] {\n return this._imageLayers;\n }\n\n /**\n * Add an image layer after construction. Appended to both {@link\n * imageLayers} and the end of {@link renderableLayers}'s document order.\n * @throws If an image layer with the same ID already exists. An ID shared\n * with a *tile* layer is permitted - the two kinds keep separate ID\n * spaces, and all internal bookkeeping is instance-based.\n */\n public addImageLayer(layer: ImageLayer): void {\n this._checkDestroyed();\n this._addImageLayer(layer);\n this._documentOrder.push(layer);\n this._revision++;\n }\n\n /** Shared by the constructor and {@link addImageLayer}: enforce ID uniqueness within the image-layer kind. */\n private _addImageLayer(layer: ImageLayer): void {\n if (this._imageLayers.some(existing => existing.id === layer.id)) {\n throw new Error(`Image layer ID ${layer.id} already exists in map \"${this.name}\".`);\n }\n this._imageLayers.push(layer);\n }\n\n /**\n * Get an image layer by name (first match in insertion order), or undefined.\n */\n public getImageLayer(name: string): ImageLayer | undefined {\n return this._imageLayers.find(layer => layer.name === name);\n }\n\n /**\n * Get an image layer by ID.\n */\n public getImageLayerById(id: number): ImageLayer | undefined {\n return this._imageLayers.find(layer => layer.id === id);\n }\n\n /**\n * Remove an image layer by ID. Spliced out of {@link renderableLayers}'s\n * document order.\n * @returns true if the layer was found and removed.\n */\n public removeImageLayer(id: number): boolean {\n this._checkDestroyed();\n const layer = this._imageLayers.find(l => l.id === id);\n if (!layer) return false;\n this._imageLayers.splice(this._imageLayers.indexOf(layer), 1);\n const orderIndex = this._documentOrder.indexOf(layer);\n if (orderIndex !== -1) this._documentOrder.splice(orderIndex, 1);\n this._revision++;\n return true;\n }\n\n // ── Combined render order ─────────────────────────────────────────────\n\n /**\n * Tile and image layers combined into a single document order (see {@link\n * TileMapOptions.documentOrder}), maintained live as membership changes.\n * Reflects `addLayer` / `addImageLayer` / `removeLayer` /\n * `removeImageLayer` calls made after construction. Holds instance\n * references, so entries stay correct even when a tile layer and an image\n * layer share an id in a fallback-ordered map. Object layers are\n * data-only and never appear here.\n */\n public get renderableLayers(): ReadonlyArray<TileLayer | ImageLayer> {\n return this._documentOrder;\n }\n\n // ── Scene composition ─────────────────────────────────────────────────\n\n /**\n * Create a new {@link TileMapView} that groups this map's layers into\n * independently placeable band / layer scene nodes for interleaving\n * application actors between tile layers.\n *\n * Each call returns a fresh, independent view - the map does **not** cache a\n * single global view, so multiple coexisting views of the same map are\n * allowed. The view references this map but never owns it: destroying the\n * view frees only its generated layer/band nodes - never the map, its layers,\n * tileset textures, or any application actors.\n *\n * @advanced\n */\n public createView(options?: TileMapViewOptions): TileMapView {\n return new TileMapView(this, options);\n }\n\n // ── Queries ───────────────────────────────────────────────────────────\n\n /**\n * Get a resolved tile from a given layer at tile coordinates.\n * Convenience for `map.getTileLayerById(id)?.getTileAt(tx, ty)`.\n * Returns null for an empty cell, out-of-bounds, or missing layer.\n */\n public getTileAt(layerId: number, tx: number, ty: number): ResolvedTile | null {\n const layer = this._layerById.get(layerId);\n if (!layer) return null;\n return layer.getTileAt(tx, ty);\n }\n\n /**\n * Set a tile on a given layer at tile coordinates.\n * Convenience for `map.getTileLayerById(id)?.setTileAt(tx, ty, tile)`.\n * @throws If the layer does not exist, coordinates are out of bounds,\n * or the tile reference is invalid.\n */\n public setTileAt(layerId: number, tx: number, ty: number, tile: ResolvedTile): void {\n const layer = this._layerById.get(layerId);\n if (!layer) throw new Error(`Layer ${layerId} not found in map \"${this.name}\".`);\n layer.setTileAt(tx, ty, tile);\n }\n\n /**\n * Clear a tile on a given layer at tile coordinates.\n * Convenience for `map.getTileLayerById(id)?.clearTileAt(tx, ty)`.\n * @throws If the layer does not exist or coordinates are out of bounds.\n */\n public clearTileAt(layerId: number, tx: number, ty: number): void {\n const layer = this._layerById.get(layerId);\n if (!layer) throw new Error(`Layer ${layerId} not found in map \"${this.name}\".`);\n layer.clearTileAt(tx, ty);\n }\n\n // ── Coordinate conversion (base layer) ────────────────────────────────\n\n /**\n * Convert a tile coordinate to the pixel position of its top-left corner\n * in map-local space (ignoring layer offsets).\n */\n public tileToPixel(tx: number, ty: number): { x: number; y: number } {\n return {\n x: tx * this.tileWidth,\n y: ty * this.tileHeight,\n };\n }\n\n /**\n * Convert a pixel position in map-local space to the tile coordinate\n * that contains it. Uses `floor`. May return coordinates outside map bounds.\n */\n public pixelToTile(px: number, py: number): { tx: number; ty: number } {\n return {\n tx: Math.floor(px / this.tileWidth),\n ty: Math.floor(py / this.tileHeight),\n };\n }\n\n // ── Revision / lifecycle ──────────────────────────────────────────────\n\n /**\n * Monotonic map revision counter. Increments on structural changes only\n * (add/remove layer, add tileset). Cell mutations are tracked per-chunk\n * and per-layer; the renderer reads chunk-level revisions directly.\n * @advanced\n */\n public get revision(): number {\n return this._revision;\n }\n\n /** Whether the map has been destroyed. */\n public get destroyed(): boolean {\n return this._destroyed;\n }\n\n private _checkDestroyed(): void {\n if (this._destroyed) {\n throw new Error(`TileMap \"${this.name}\" has been destroyed.`);\n }\n }\n\n /**\n * Destroy the map and all owned layers and chunk storage.\n *\n * Is idempotent. Does NOT destroy tileset textures (Loader-owned) or\n * any SceneNodes (those do not exist yet in this slice).\n */\n public destroy(): void {\n if (this._destroyed) return;\n this._destroyed = true;\n for (const layer of this._layers) {\n layer.destroy();\n }\n this._layers.length = 0;\n this._layerById.clear();\n this._objectLayers.length = 0;\n this._imageLayers.length = 0;\n this._documentOrder.length = 0;\n this._tilesets.length = 0;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAgGA,IAAa,UAAb,MAAqB;;CAEnB,AAAgB;;CAGhB,AAAgB;;CAEhB,AAAgB;;CAGhB,AAAgB;;CAEhB,AAAgB;;CAGhB,IAAW,aAAiC;EAC1C,OAAO,KAA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AO,MAAM,IAAI,MAAM,SAAS,QAAQ,qBAAqB,KAAK,KAAK,GAAG;EAC/E,MAAM,YAAY,IAAI,EAAE;CAC1B;;;;;CAQA,AAAO,YAAY,IAAY,IAAsC;EACnE,OAAO;GACL,GAAG,KAAK,KAAK;GACb,GAAG,KAAK,KAAK;EACf;CACF;;;;;CAMA,AAAO,YAAY,IAAY,IAAwC;EACrE,OAAO;GACL,IAAI,KAAK,MAAM,KAAK,KAAK,SAAS;GAClC,IAAI,KAAK,MAAM,KAAK,KAAK,UAAU;EACrC;CACF;;;;;;;CAUA,IAAW,WAAmB;EAC5B,OAAO,KAAK;CACd;;CAGA,IAAW,YAAqB;EAC9B,OAAO,KAAK;CACd;CAEA,AAAQ,kBAAwB;EAC9B,IAAI,KAAK,YACP,MAAM,IAAI,MAAM,YAAY,KAAK,KAAK,sBAAsB;CAEhE;;;;;;;CAQA,AAAO,UAAgB;EACrB,IAAI,KAAK,YAAY;EACrB,KAAK,aAAa;EAClB,KAAK,MAAM,SAAS,KAAK,SACvB,MAAM,QAAQ;EAEhB,KAAK,QAAQ,SAAS;EACtB,KAAK,WAAW,MAAM;EACtB,KAAK,cAAc,SAAS;EAC5B,KAAK,aAAa,SAAS;EAC3B,KAAK,eAAe,SAAS;EAC7B,KAAK,UAAU,SAAS;CAC1B;AACF"}
|
|
1
|
+
{"version":3,"file":"TileMap.js","names":[],"sources":["../../src/TileMap.ts"],"sourcesContent":["import { type ImageLayer } from './ImageLayer';\nimport type { ObjectLayer, ObjectSchema } from './ObjectLayer';\nimport { type TileLayer } from './TileLayer';\nimport type { TileMapViewOptions } from './TileMapView';\nimport { TileMapView } from './TileMapView';\nimport { TileProjection } from './TileProjection';\nimport { type TileSet } from './TileSet';\nimport type { ResolvedTile, TileProperties } from './types';\nimport { validatePairedDimensions, validatePositiveInteger } from './types';\n\n/**\n * Options for constructing a {@link TileMap}.\n * @advanced\n */\nexport interface TileMapOptions {\n /** Shared projection; defaults to an orthogonal grid of the supplied tile size. */\n readonly projection?: TileProjection;\n /** Map name (for debugging). */\n readonly name?: string;\n /**\n * Map width in tiles. Omit together with {@link height} for an unbounded\n * map - layers you add are then free to be unbounded too (this option\n * does not constrain per-layer dimensions either way).\n */\n readonly width?: number;\n /** Map height in tiles. Must be provided iff {@link width} is. */\n readonly height?: number;\n /** Width of each tile in pixels. */\n readonly tileWidth: number;\n /** Height of each tile in pixels. */\n readonly tileHeight: number;\n /** Tilesets available to this map. */\n readonly tilesets?: readonly TileSet[];\n /** Layers (constructed externally and owned by the map after construction). */\n readonly layers?: readonly TileLayer[];\n /** Object layers (data-only; spawn points, triggers, collision regions). */\n readonly objectLayers?: readonly ObjectLayer[];\n /** Image layers (data-only; background/foreground images from Tiled image layers). */\n readonly imageLayers?: readonly ImageLayer[];\n /** Chunk width for layers (default 32). */\n readonly chunkWidth?: number;\n /** Chunk height for layers (default 32). */\n readonly chunkHeight?: number;\n /** Map class/type string (Tiled `class`). Defaults to `''`. */\n readonly class?: string;\n /**\n * Map background colour as a `0xRRGGBB` integer, or `null` (Tiled\n * `backgroundcolor`). Informational - the renderer does not auto-clear to it.\n * Default `null`.\n */\n readonly backgroundColor?: number | null;\n /** Tile draw order (Tiled `renderorder`), informational. Default `'right-down'`. */\n readonly renderOrder?: string;\n /** Map-level properties (copied and frozen). */\n readonly properties?: TileProperties;\n /**\n * Combined document order across tile and image layers, as an ordered list\n * of layer ids - exposed via {@link TileMap.renderableLayers}. Every tile\n * and image layer passed to this map (via {@link layers} / {@link\n * imageLayers}) must appear exactly once; an id that belongs to neither\n * kind, or is listed more than once, throws. The list's length must also\n * equal the total number of tile/image layer instances - nothing enforces\n * unique ids across image layers, so two image layers sharing an id would\n * otherwise both satisfy the id-based checks while one silently drops out\n * of {@link TileMap.renderableLayers}; that mismatch throws too.\n *\n * A tile layer and an image layer sharing the same id makes the order\n * ambiguous - that combination throws when `documentOrder` is provided.\n * It is NOT rejected when this option is omitted: the fallback order below\n * is unambiguous by construction (tile layers are always listed before\n * image layers), so hand-built maps that predate this option are\n * unaffected even if such an id collision exists.\n *\n * Omit to fall back to all tile layers in insertion order, followed by all\n * image layers in insertion order - the map's implicit ordering before\n * this option existed.\n *\n * Named `documentOrder` rather than `renderOrder` to avoid colliding with\n * the unrelated {@link renderOrder} option above (Tiled's tile-draw-\n * direction string, e.g. `'right-down'`).\n */\n readonly documentOrder?: readonly number[];\n}\n\n/**\n * A generic, format-independent tile map.\n *\n * Owns a finite grid of {@link TileLayer}s and a shared set of {@link TileSet}s.\n * Tile data is stored in compact chunked arrays - no per-tile heap objects.\n *\n * The map does NOT own tileset textures (those are Loader-owned) and does\n * NOT own SceneNode children - see {@link import('./TileMapNode').TileMapNode},\n * which owns those.\n *\n * Multiple tilesets are supported: each cell stores a packed tileset index\n * and local tile ID, so different tilesets may have different tile dimensions.\n *\n * @advanced\n */\nexport class TileMap {\n public readonly projection: TileProjection;\n /** Map name (debug). */\n public readonly name: string;\n\n /** Map width in tiles, or `undefined` if unbounded. */\n public readonly width: number | undefined;\n /** Map height in tiles, or `undefined` if unbounded. */\n public readonly height: number | undefined;\n\n /** Tile width in pixels. */\n public readonly tileWidth: number;\n /** Tile height in pixels. */\n public readonly tileHeight: number;\n\n /** Pixel width, or `undefined` if unbounded. */\n public get pixelWidth(): number | undefined {\n return this.width === undefined || this.height === undefined ? undefined : this.projection.getBounds(0, 0, this.width, this.height).width;\n }\n /** Pixel height, or `undefined` if unbounded. */\n public get pixelHeight(): number | undefined {\n return this.width === undefined || this.height === undefined ? undefined : this.projection.getBounds(0, 0, this.width, this.height).height;\n }\n /** `true` if this map has a fixed width/height; `false` if unbounded. */\n public get bounded(): boolean {\n return this.width !== undefined && this.height !== undefined;\n }\n\n /** Default chunk width for layers. */\n public readonly chunkWidth: number;\n /** Default chunk height for layers. */\n public readonly chunkHeight: number;\n\n /** Map class/type string (Tiled `class`; may be empty). */\n public readonly class: string;\n /** Map background colour as `0xRRGGBB`, or `null`. Informational. */\n public readonly backgroundColor: number | null;\n /** Tile draw order (Tiled `renderorder`). Informational. */\n public readonly renderOrder: string;\n\n /** Map-level properties (immutable). */\n public readonly properties: TileProperties;\n\n private readonly _tilesets: TileSet[];\n private readonly _layers: TileLayer[] = [];\n private readonly _layerById = new Map<number, TileLayer>();\n private readonly _objectLayers: ObjectLayer[] = [];\n private readonly _imageLayers: ImageLayer[] = [];\n private readonly _documentOrder: Array<TileLayer | ImageLayer> = [];\n\n private _revision = 0;\n private _destroyed = false;\n\n /**\n * @throws When dimensions or other options are invalid.\n */\n public constructor(options: TileMapOptions) {\n validatePairedDimensions(options.width, options.height, 'TileMap', 'map');\n validatePositiveInteger(options.tileWidth, 'map.tileWidth');\n validatePositiveInteger(options.tileHeight, 'map.tileHeight');\n\n const chunkWidth = options.chunkWidth ?? 32;\n const chunkHeight = options.chunkHeight ?? 32;\n validatePositiveInteger(chunkWidth, 'chunkWidth');\n validatePositiveInteger(chunkHeight, 'chunkHeight');\n\n this.name = options.name ?? 'TileMap';\n this.width = options.width;\n this.height = options.height;\n this.tileWidth = options.tileWidth;\n this.tileHeight = options.tileHeight;\n this.projection = options.projection ?? new TileProjection({ tileWidth: options.tileWidth, tileHeight: options.tileHeight });\n if (this.projection.tileWidth !== this.tileWidth || this.projection.tileHeight !== this.tileHeight) {\n throw new Error('Projection tile dimensions must match the layer or map.');\n }\n this.chunkWidth = chunkWidth;\n this.chunkHeight = chunkHeight;\n this.class = options.class ?? '';\n this.backgroundColor = options.backgroundColor ?? null;\n this.renderOrder = options.renderOrder ?? 'right-down';\n\n this._tilesets = options.tilesets ? [...options.tilesets] : [];\n this.properties = options.properties ? Object.freeze({ ...options.properties }) : Object.freeze({});\n\n if (options.layers) {\n for (const layer of options.layers) {\n this._addLayer(layer);\n }\n }\n\n if (options.objectLayers) {\n this._objectLayers.push(...options.objectLayers);\n }\n\n if (options.imageLayers) {\n for (const layer of options.imageLayers) {\n this._addImageLayer(layer);\n }\n }\n\n this._documentOrder.push(...this._buildDocumentOrder(options.documentOrder));\n }\n\n /**\n * Validate an explicit `documentOrder` option against current tile/image\n * layer membership and resolve it to layer instances, or compute the\n * fallback order (tile layers in insertion order, then image layers) when\n * omitted. The order stores instance references - not ids - so a\n * cross-kind id collision in a fallback map can never resolve to the\n * wrong layer.\n * @throws Per the validation rules documented on {@link\n * TileMapOptions.documentOrder}.\n */\n private _buildDocumentOrder(documentOrder: readonly number[] | undefined): Array<TileLayer | ImageLayer> {\n if (!documentOrder) {\n return [...this._layers, ...this._imageLayers];\n }\n\n const tileIds = new Set(this._layers.map(l => l.id));\n const imageIds = new Set(this._imageLayers.map(l => l.id));\n\n for (const id of tileIds) {\n if (imageIds.has(id)) {\n throw new Error(`Layer ID ${id} exists as both a tile layer and an image layer in map \"${this.name}\"; documentOrder cannot disambiguate them.`);\n }\n }\n\n const seen = new Set<number>();\n for (const id of documentOrder) {\n if (!tileIds.has(id) && !imageIds.has(id)) {\n throw new Error(`documentOrder references unknown layer ID ${id} in map \"${this.name}\".`);\n }\n if (seen.has(id)) {\n throw new Error(`documentOrder lists layer ID ${id} more than once in map \"${this.name}\".`);\n }\n seen.add(id);\n }\n\n const totalLayers = tileIds.size + imageIds.size;\n if (seen.size !== totalLayers) {\n for (const id of [...tileIds, ...imageIds]) {\n if (!seen.has(id)) {\n throw new Error(`documentOrder is missing layer ID ${id} in map \"${this.name}\".`);\n }\n }\n }\n\n // The checks above are id-SET based, so they can't see a duplicate\n // image-layer id (nothing enforces image-layer id uniqueness): two\n // image layers sharing an id collapse to one entry in `imageIds`,\n // letting a documentOrder that covers every distinct id still be one\n // instance short. Compare against the actual instance counts so that\n // case throws instead of silently dropping an instance from\n // renderableLayers.\n const instanceCount = this._layers.length + this._imageLayers.length;\n if (documentOrder.length !== instanceCount) {\n throw new Error(\n `documentOrder has ${documentOrder.length} entries but map \"${this.name}\" has ${instanceCount} tile/image layer instances; check for a duplicate image-layer ID.`,\n );\n }\n\n // Ids are unique across kinds here (the cross-kind check above threw\n // otherwise), so resolving each id to an instance is unambiguous. The\n // count check above does not guarantee the ids themselves match, so an\n // unresolvable one is reported rather than left as a hole in the list.\n return documentOrder.map(id => {\n const layer = this._layerById.get(id) ?? this._imageLayers.find(imageLayer => imageLayer.id === id);\n\n if (!layer) {\n throw new Error(`documentOrder references layer id ${id}, but map \"${this.name}\" has no tile or image layer with that id.`);\n }\n\n return layer;\n });\n }\n\n // ── Tilesets ──────────────────────────────────────────────────────────\n\n /** Immutable list of tilesets available to this map. */\n public get tilesets(): readonly TileSet[] {\n return this._tilesets;\n }\n\n /**\n * Add a tileset. Tilesets must have unique names.\n * @throws If a tileset with the same name already exists, or the map is destroyed.\n */\n public addTileset(tileset: TileSet): void {\n this._checkDestroyed();\n if (this._tilesets.some(ts => ts.name === tileset.name)) {\n throw new Error(`Tileset \"${tileset.name}\" already exists in map \"${this.name}\".`);\n }\n this._tilesets.push(tileset);\n this._revision++;\n }\n\n /**\n * Get a tileset by name, or undefined.\n */\n public getTileset(name: string): TileSet | undefined {\n return this._tilesets.find(ts => ts.name === name);\n }\n\n // ── Layers ────────────────────────────────────────────────────────────\n\n /** Immutable snapshot of layers (ordered). */\n public get layers(): readonly TileLayer[] {\n return this._layers;\n }\n\n private _addLayer(layer: TileLayer): void {\n if (this._layerById.has(layer.id)) {\n throw new Error(`Layer ID ${layer.id} already exists in map \"${this.name}\".`);\n }\n this._layerById.set(layer.id, layer);\n this._layers.push(layer);\n }\n\n /**\n * Add a layer after construction. Appended to the end of {@link\n * renderableLayers}'s document order.\n * @throws If a layer with the same ID already exists.\n */\n public addLayer(layer: TileLayer): void {\n this._checkDestroyed();\n this._addLayer(layer);\n this._documentOrder.push(layer);\n this._revision++;\n }\n\n /**\n * Get a tile layer by ID.\n */\n public getTileLayerById(id: number): TileLayer | undefined {\n return this._layerById.get(id);\n }\n\n /**\n * Get a tile layer by name. Returns the first match in insertion order.\n */\n public getTileLayer(name: string): TileLayer | undefined {\n return this._layers.find(l => l.name === name);\n }\n\n /**\n * Remove a layer by ID. The layer is destroyed and spliced out of {@link\n * renderableLayers}'s document order.\n * @returns true if the layer was found and removed.\n */\n public removeLayer(id: number): boolean {\n this._checkDestroyed();\n const layer = this._layerById.get(id);\n if (!layer) return false;\n this._layers.splice(this._layers.indexOf(layer), 1);\n this._layerById.delete(id);\n const orderIndex = this._documentOrder.indexOf(layer);\n if (orderIndex !== -1) this._documentOrder.splice(orderIndex, 1);\n layer.destroy();\n this._revision++;\n return true;\n }\n\n // ── Object layers (data-only) ─────────────────────────────────────────\n\n /** Immutable snapshot of object layers (insertion order). */\n public get objectLayers(): readonly ObjectLayer[] {\n return this._objectLayers;\n }\n\n /**\n * Add an object layer after construction.\n * @throws If the map is destroyed.\n */\n public addObjectLayer(layer: ObjectLayer): void {\n this._checkDestroyed();\n this._objectLayers.push(layer);\n this._revision++;\n }\n\n /**\n * Get an object layer by name (first match in insertion order), or undefined.\n *\n * Supply an {@link ObjectSchema} type argument `S` to obtain a typed view of\n * the layer - `getObjectLayer<LevelObjects>('Entities')` returns an\n * `ObjectLayer<LevelObjects>` whose {@link ObjectLayer.byType} / {@link\n * ObjectLayer.where} accessors narrow `properties`. The schema is a static\n * developer promise only; no runtime validation is performed and the call\n * remains fully back-compatible when omitted.\n */\n public getObjectLayer<S extends ObjectSchema = ObjectSchema>(name: string): ObjectLayer<S> | undefined {\n return this._objectLayers.find(layer => layer.name === name) as ObjectLayer<S> | undefined;\n }\n\n /**\n * Get an object layer by ID.\n *\n * Supply an {@link ObjectSchema} type argument `S` to obtain a typed view of\n * the layer, as with {@link getObjectLayer}.\n */\n public getObjectLayerById<S extends ObjectSchema = ObjectSchema>(id: number): ObjectLayer<S> | undefined {\n return this._objectLayers.find(layer => layer.id === id) as ObjectLayer<S> | undefined;\n }\n\n /**\n * Remove an object layer by ID.\n * @returns true if the layer was found and removed.\n */\n public removeObjectLayer(id: number): boolean {\n this._checkDestroyed();\n const index = this._objectLayers.findIndex(layer => layer.id === id);\n if (index === -1) return false;\n this._objectLayers.splice(index, 1);\n this._revision++;\n return true;\n }\n\n // ── Image layers (data-only) ──────────────────────────────────────────\n\n /** Immutable snapshot of image layers (insertion order). */\n public get imageLayers(): readonly ImageLayer[] {\n return this._imageLayers;\n }\n\n /**\n * Add an image layer after construction. Appended to both {@link\n * imageLayers} and the end of {@link renderableLayers}'s document order.\n * @throws If an image layer with the same ID already exists. An ID shared\n * with a *tile* layer is permitted - the two kinds keep separate ID\n * spaces, and all internal bookkeeping is instance-based.\n */\n public addImageLayer(layer: ImageLayer): void {\n this._checkDestroyed();\n this._addImageLayer(layer);\n this._documentOrder.push(layer);\n this._revision++;\n }\n\n /** Shared by the constructor and {@link addImageLayer}: enforce ID uniqueness within the image-layer kind. */\n private _addImageLayer(layer: ImageLayer): void {\n if (this._imageLayers.some(existing => existing.id === layer.id)) {\n throw new Error(`Image layer ID ${layer.id} already exists in map \"${this.name}\".`);\n }\n this._imageLayers.push(layer);\n }\n\n /**\n * Get an image layer by name (first match in insertion order), or undefined.\n */\n public getImageLayer(name: string): ImageLayer | undefined {\n return this._imageLayers.find(layer => layer.name === name);\n }\n\n /**\n * Get an image layer by ID.\n */\n public getImageLayerById(id: number): ImageLayer | undefined {\n return this._imageLayers.find(layer => layer.id === id);\n }\n\n /**\n * Remove an image layer by ID. Spliced out of {@link renderableLayers}'s\n * document order.\n * @returns true if the layer was found and removed.\n */\n public removeImageLayer(id: number): boolean {\n this._checkDestroyed();\n const layer = this._imageLayers.find(l => l.id === id);\n if (!layer) return false;\n this._imageLayers.splice(this._imageLayers.indexOf(layer), 1);\n const orderIndex = this._documentOrder.indexOf(layer);\n if (orderIndex !== -1) this._documentOrder.splice(orderIndex, 1);\n this._revision++;\n return true;\n }\n\n // ── Combined render order ─────────────────────────────────────────────\n\n /**\n * Tile and image layers combined into a single document order (see {@link\n * TileMapOptions.documentOrder}), maintained live as membership changes.\n * Reflects `addLayer` / `addImageLayer` / `removeLayer` /\n * `removeImageLayer` calls made after construction. Holds instance\n * references, so entries stay correct even when a tile layer and an image\n * layer share an id in a fallback-ordered map. Object layers are\n * data-only and never appear here.\n */\n public get renderableLayers(): ReadonlyArray<TileLayer | ImageLayer> {\n return this._documentOrder;\n }\n\n // ── Scene composition ─────────────────────────────────────────────────\n\n /**\n * Create a new {@link TileMapView} that groups this map's layers into\n * independently placeable band / layer scene nodes for interleaving\n * application actors between tile layers.\n *\n * Each call returns a fresh, independent view - the map does **not** cache a\n * single global view, so multiple coexisting views of the same map are\n * allowed. The view references this map but never owns it: destroying the\n * view frees only its generated layer/band nodes - never the map, its layers,\n * tileset textures, or any application actors.\n *\n * @advanced\n */\n public createView(options?: TileMapViewOptions): TileMapView {\n return new TileMapView(this, options);\n }\n\n // ── Queries ───────────────────────────────────────────────────────────\n\n /**\n * Get a resolved tile from a given layer at tile coordinates.\n * Convenience for `map.getTileLayerById(id)?.getTileAt(tx, ty)`.\n * Returns null for an empty cell, out-of-bounds, or missing layer.\n */\n public getTileAt(layerId: number, tx: number, ty: number): ResolvedTile | null {\n const layer = this._layerById.get(layerId);\n if (!layer) return null;\n return layer.getTileAt(tx, ty);\n }\n\n /**\n * Set a tile on a given layer at tile coordinates.\n * Convenience for `map.getTileLayerById(id)?.setTileAt(tx, ty, tile)`.\n * @throws If the layer does not exist, coordinates are out of bounds,\n * or the tile reference is invalid.\n */\n public setTileAt(layerId: number, tx: number, ty: number, tile: ResolvedTile): void {\n const layer = this._layerById.get(layerId);\n if (!layer) throw new Error(`Layer ${layerId} not found in map \"${this.name}\".`);\n layer.setTileAt(tx, ty, tile);\n }\n\n /**\n * Clear a tile on a given layer at tile coordinates.\n * Convenience for `map.getTileLayerById(id)?.clearTileAt(tx, ty)`.\n * @throws If the layer does not exist or coordinates are out of bounds.\n */\n public clearTileAt(layerId: number, tx: number, ty: number): void {\n const layer = this._layerById.get(layerId);\n if (!layer) throw new Error(`Layer ${layerId} not found in map \"${this.name}\".`);\n layer.clearTileAt(tx, ty);\n }\n\n // ── Coordinate conversion (base layer) ────────────────────────────────\n\n /**\n * Convert a grid vertex to display pixels (the top diamond vertex for isometric cells)\n * in map-local space (ignoring layer offsets).\n */\n public tileToPixel(tx: number, ty: number): { x: number; y: number } {\n return this.projection.tileToPixel(tx, ty);\n }\n\n /**\n * Convert a display position in map-local space to the tile coordinate\n * that contains it. Uses `floor`. May return coordinates outside map bounds.\n */\n public pixelToTile(px: number, py: number): { tx: number; ty: number } {\n return this.projection.pixelToTile(px, py);\n }\n\n // ── Revision / lifecycle ──────────────────────────────────────────────\n\n /**\n * Monotonic map revision counter. Increments on structural changes only\n * (add/remove layer, add tileset). Cell mutations are tracked per-chunk\n * and per-layer; the renderer reads chunk-level revisions directly.\n * @advanced\n */\n public get revision(): number {\n return this._revision;\n }\n\n /** Whether the map has been destroyed. */\n public get destroyed(): boolean {\n return this._destroyed;\n }\n\n private _checkDestroyed(): void {\n if (this._destroyed) {\n throw new Error(`TileMap \"${this.name}\" has been destroyed.`);\n }\n }\n\n /**\n * Destroy the map and all owned layers and chunk storage.\n *\n * Is idempotent. Does NOT destroy tileset textures (Loader-owned) or\n * any SceneNodes (those do not exist yet in this slice).\n */\n public destroy(): void {\n if (this._destroyed) return;\n this._destroyed = true;\n for (const layer of this._layers) {\n layer.destroy();\n }\n this._layers.length = 0;\n this._layerById.clear();\n this._objectLayers.length = 0;\n this._imageLayers.length = 0;\n this._documentOrder.length = 0;\n this._tilesets.length = 0;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAmGA,IAAa,UAAb,MAAqB;CACnB,AAAgB;;CAEhB,AAAgB;;CAGhB,AAAgB;;CAEhB,AAAgB;;CAGhB,AAAgB;;CAEhB,AAAgB;;CAGhB,IAAW,aAAiC;EAC1C,OAAO,KAAK,UAAU,UAAa,KAAK,WAAW,SAAY,SAAY,KAAK,WAAW,UAAU,GAAG,GAAG,KAAK,OAAO,KAAK,MAAM,CAAC,CAAC;CACtI;;CAEA,IAAW,cAAkC;EAC3C,OAAO,KAAK,UAAU,UAAa,KAAK,WAAW,SAAY,SAAY,KAAK,WAAW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xC;;;;OAIG;IACa,IAAI,SAAM;IAE1B,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAwC;IACpE,OAAO,CAAC,UAAU,CAAS;IAmB3B;;;;;OAKG;IACH,IAAW,UAAU,IAAI,aAAa,CAAC,aAAa,GAAG,cAAc,CAAC,CAErE;IAED;;;OAGG;IACI,gBAAgB,CAAC,EAAE,EAAE,MAAM,GAAG,aAAa,GAAG,cAAc,GAAG,SAAS;
|
|
1
|
+
{"version":3,"file":"TileMapBand.d.ts","sourceRoot":"","sources":["../../src/TileMapBand.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAG1C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAEvD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAErD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,qBAAa,WAAY,SAAQ,SAAS;IACxC;;;;OAIG;IACa,IAAI,SAAM;IAE1B,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAwC;IACpE,OAAO,CAAC,UAAU,CAAS;IAmB3B;;;;;OAKG;IACH,IAAW,UAAU,IAAI,aAAa,CAAC,aAAa,GAAG,cAAc,CAAC,CAErE;IAED;;;OAGG;IACI,gBAAgB,CAAC,EAAE,EAAE,MAAM,GAAG,aAAa,GAAG,cAAc,GAAG,SAAS,CAE9E;IAED,uDAAuD;IACvD,IAAW,OAAO,IAAI,OAAO,CAE5B;IAED;;;;;OAKG;IACa,YAAY,IAAI,IAAI,CAiBnC;IAqDD;;;;;;;;OAQG;IACa,OAAO,IAAI,IAAI,CAkB9B;CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TileMapNode.d.ts","sourceRoot":"","sources":["../../src/TileMapNode.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,E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AQ,CAAC,WAAW,CAAU;IACtC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAA6C;IACzE,OAAO,CAAC,cAAc,CAAyC;IAE/D,YAAmB,GAAG,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,kBAAkB,EAW5D;IAED,yCAAyC;IACzC,IAAW,GAAG,IAAI,OAAO,CAExB;IAED;;;;;;;;;;;;;;;;OAgBG;IACH,IAAW,aAAa,IAAI,aAAa,CAExC;IAED,IAAW,aAAa,CAAC,IAAI,EAAE,aAAa,EAW3C;IAED;;;OAGG;IACH,IAAW,UAAU,IAAI,aAAa,CAAC,aAAa,GAAG,cAAc,CAAC,CAErE;IAED;;;OAGG;IACI,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,GAAG,cAAc,GAAG,SAAS,CAE5E;IAED;;;;OAIG;IACI,aAAa,IAAI,IAAI,CAa3B;IAED;;;;OAIG;IACa,cAAc,IAAI,iBAAiB,CAiBlD;IAEe,OAAO,IAAI,IAAI,CAU9B;IAED,OAAO,CAAC,gBAAgB;CAYzB"}
|
package/dist/esm/TileMapNode.js
CHANGED
|
@@ -106,7 +106,10 @@ var TileMapNode = class extends Container {
|
|
|
106
106
|
getLocalBounds() {
|
|
107
107
|
const bounds = this._localBounds;
|
|
108
108
|
const { pixelHeight, pixelWidth } = this._map;
|
|
109
|
-
if (
|
|
109
|
+
if (this._map.projection.orientation === "isometric") {
|
|
110
|
+
bounds.set(0, 0, 0, 0);
|
|
111
|
+
aggregateChildLocalBounds(this._layerNodes, bounds);
|
|
112
|
+
} else if (pixelWidth !== void 0 && pixelHeight !== void 0) bounds.set(this._map.projection.originX, this._map.projection.originY, pixelWidth, pixelHeight);
|
|
110
113
|
else if (this._layerNodes.length > 0) aggregateChildLocalBounds(this._layerNodes, bounds);
|
|
111
114
|
return bounds;
|
|
112
115
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TileMapNode.js","names":[],"sources":["../../src/TileMapNode.ts"],"sourcesContent":["import type { ReadonlyRectangle } from '@codexo/exojs';\nimport { Container } from '@codexo/exojs';\nimport { PixelSnapMode } from '@codexo/exojs/renderer-sdk';\n\nimport { ImageLayer } from './ImageLayer';\nimport { ImageLayerNode } from './ImageLayerNode';\nimport { aggregateChildLocalBounds } from './nodeBounds';\nimport { assertPixelSnapMode } from './pixelSnap';\nimport { TileLayerNode } from './TileLayerNode';\nimport type { TileMap } from './TileMap';\n\n/**\n * Options for a {@link TileMapNode}.\n * @advanced\n */\nexport interface TileMapNodeOptions {\n /**\n * Whether the map's chunk nodes participate in per-chunk view culling.\n * Forwarded to every {@link TileLayerNode}. Defaults to `true`.\n */\n readonly cullable?: boolean;\n}\n\n/**\n * A convenience scene node that renders a whole {@link TileMap} as a\n * {@link Container} of one node per renderable layer - a {@link TileLayerNode}\n * per tile layer and an {@link ImageLayerNode} per image layer, interleaved\n * back-to-front by the map's combined document order\n * ({@link import('./TileMap').TileMap.renderableLayers}).\n *\n * `TileMapNode` owns **only** its layer nodes - never application actors. Use\n * it for the simple, non-interleaved case (no actors between layers); for\n * actor interleaving, place individual `TileLayerNode`s / `ImageLayerNode`s\n * into your own scene graph instead (see `TileMapView`).\n *\n * The node references - but never owns - the {@link TileMap}: destroying the\n * node frees its layer/chunk nodes and their cached GPU geometry, while the\n * `TileMap` data and Loader-owned textures survive (free them via\n * `TileMap.destroy()` / `Loader.destroy()` respectively).\n *\n * Layers added to or removed from the map after construction are reflected only\n * after {@link TileMapNode.refreshLayers}.\n *\n * @advanced\n */\nexport class TileMapNode extends Container {\n private readonly _map: TileMap;\n private readonly _cullChunks: boolean;\n private readonly _layerNodes: Array<TileLayerNode | ImageLayerNode> = [];\n private _pixelSnapMode: PixelSnapMode = PixelSnapMode.Geometry;\n\n public constructor(map: TileMap, options?: TileMapNodeOptions) {\n super();\n\n this._map = map;\n this._cullChunks = options?.cullable ?? true;\n\n this._buildLayerNodes();\n\n if (!this._map.bounded) {\n this.cullable = false;\n }\n }\n\n /** The runtime map this node renders. */\n public get map(): TileMap {\n return this._map;\n }\n\n /**\n * Render-only pixel-snap mode applied to every layer (and forwarded to every\n * chunk node, current and rebuilt). Snaps tile chunk origins to the active\n * render target's device-pixel grid for crisp tiles; with integer tile pitch\n * the grid stays exact and adjacent chunks/layers cannot drift apart. Purely\n * visual - tile data, layer offsets, chunk revisions, and culling are\n * unchanged. Setting the current value is a no-op; an invalid value throws and\n * leaves the prior mode unchanged.\n *\n * Defaults to `Geometry` because a tile grid is made of quads that share\n * their edges: left unsnapped, a boundary landing between two device pixels\n * is sampled across both, so the seams blur and shimmer as the view moves.\n * Set `None` to opt out.\n *\n * @default PixelSnapMode.Geometry\n * @stable\n */\n public get pixelSnapMode(): PixelSnapMode {\n return this._pixelSnapMode;\n }\n\n public set pixelSnapMode(mode: PixelSnapMode) {\n if (mode === this._pixelSnapMode) {\n return;\n }\n\n assertPixelSnapMode(mode);\n this._pixelSnapMode = mode;\n\n for (const node of this._layerNodes) {\n node.pixelSnapMode = mode;\n }\n }\n\n /**\n * The layer render nodes - tile and image alike - in the map's combined\n * document order.\n */\n public get layerNodes(): ReadonlyArray<TileLayerNode | ImageLayerNode> {\n return this._layerNodes;\n }\n\n /**\n * Find the layer node rendering the named layer (tile or image; first match\n * in document order), or `undefined`.\n */\n public getLayerNode(name: string): TileLayerNode | ImageLayerNode | undefined {\n return this._layerNodes.find(node => node.layer.name === name);\n }\n\n /**\n * Rebuild the layer-node children from the map's current renderable layers.\n * Call after tile or image layers are structurally added to or removed from\n * the map.\n */\n public refreshLayers(): this {\n const previous = [...this._layerNodes];\n\n this.removeChildren();\n this._layerNodes.length = 0;\n\n for (const node of previous) {\n node.destroy();\n }\n\n this._buildLayerNodes();\n\n return this;\n }\n\n /**\n * Recomputed lazily on read, so it writes `_localBounds` directly rather than\n * going through `setLocalBounds`: an invalidating write inside a getter\n * would re-dirty the node on every read.\n */\n public override getLocalBounds(): ReadonlyRectangle {\n const bounds = this._localBounds;\n\n // Reading the pixel extents directly (rather than gating on `bounded`)\n // is what narrows them to numbers - `bounded` is a plain boolean getter.\n const { pixelHeight, pixelWidth } = this._map;\n\n if (pixelWidth !== undefined && pixelHeight !== undefined) {\n bounds.set(
|
|
1
|
+
{"version":3,"file":"TileMapNode.js","names":[],"sources":["../../src/TileMapNode.ts"],"sourcesContent":["import type { ReadonlyRectangle } from '@codexo/exojs';\nimport { Container } from '@codexo/exojs';\nimport { PixelSnapMode } from '@codexo/exojs/renderer-sdk';\n\nimport { ImageLayer } from './ImageLayer';\nimport { ImageLayerNode } from './ImageLayerNode';\nimport { aggregateChildLocalBounds } from './nodeBounds';\nimport { assertPixelSnapMode } from './pixelSnap';\nimport { TileLayerNode } from './TileLayerNode';\nimport type { TileMap } from './TileMap';\n\n/**\n * Options for a {@link TileMapNode}.\n * @advanced\n */\nexport interface TileMapNodeOptions {\n /**\n * Whether the map's chunk nodes participate in per-chunk view culling.\n * Forwarded to every {@link TileLayerNode}. Defaults to `true`.\n */\n readonly cullable?: boolean;\n}\n\n/**\n * A convenience scene node that renders a whole {@link TileMap} as a\n * {@link Container} of one node per renderable layer - a {@link TileLayerNode}\n * per tile layer and an {@link ImageLayerNode} per image layer, interleaved\n * back-to-front by the map's combined document order\n * ({@link import('./TileMap').TileMap.renderableLayers}).\n *\n * `TileMapNode` owns **only** its layer nodes - never application actors. Use\n * it for the simple, non-interleaved case (no actors between layers); for\n * actor interleaving, place individual `TileLayerNode`s / `ImageLayerNode`s\n * into your own scene graph instead (see `TileMapView`).\n *\n * The node references - but never owns - the {@link TileMap}: destroying the\n * node frees its layer/chunk nodes and their cached GPU geometry, while the\n * `TileMap` data and Loader-owned textures survive (free them via\n * `TileMap.destroy()` / `Loader.destroy()` respectively).\n *\n * Layers added to or removed from the map after construction are reflected only\n * after {@link TileMapNode.refreshLayers}.\n *\n * @advanced\n */\nexport class TileMapNode extends Container {\n private readonly _map: TileMap;\n private readonly _cullChunks: boolean;\n private readonly _layerNodes: Array<TileLayerNode | ImageLayerNode> = [];\n private _pixelSnapMode: PixelSnapMode = PixelSnapMode.Geometry;\n\n public constructor(map: TileMap, options?: TileMapNodeOptions) {\n super();\n\n this._map = map;\n this._cullChunks = options?.cullable ?? true;\n\n this._buildLayerNodes();\n\n if (!this._map.bounded) {\n this.cullable = false;\n }\n }\n\n /** The runtime map this node renders. */\n public get map(): TileMap {\n return this._map;\n }\n\n /**\n * Render-only pixel-snap mode applied to every layer (and forwarded to every\n * chunk node, current and rebuilt). Snaps tile chunk origins to the active\n * render target's device-pixel grid for crisp tiles; with integer tile pitch\n * the grid stays exact and adjacent chunks/layers cannot drift apart. Purely\n * visual - tile data, layer offsets, chunk revisions, and culling are\n * unchanged. Setting the current value is a no-op; an invalid value throws and\n * leaves the prior mode unchanged.\n *\n * Defaults to `Geometry` because a tile grid is made of quads that share\n * their edges: left unsnapped, a boundary landing between two device pixels\n * is sampled across both, so the seams blur and shimmer as the view moves.\n * Set `None` to opt out.\n *\n * @default PixelSnapMode.Geometry\n * @stable\n */\n public get pixelSnapMode(): PixelSnapMode {\n return this._pixelSnapMode;\n }\n\n public set pixelSnapMode(mode: PixelSnapMode) {\n if (mode === this._pixelSnapMode) {\n return;\n }\n\n assertPixelSnapMode(mode);\n this._pixelSnapMode = mode;\n\n for (const node of this._layerNodes) {\n node.pixelSnapMode = mode;\n }\n }\n\n /**\n * The layer render nodes - tile and image alike - in the map's combined\n * document order.\n */\n public get layerNodes(): ReadonlyArray<TileLayerNode | ImageLayerNode> {\n return this._layerNodes;\n }\n\n /**\n * Find the layer node rendering the named layer (tile or image; first match\n * in document order), or `undefined`.\n */\n public getLayerNode(name: string): TileLayerNode | ImageLayerNode | undefined {\n return this._layerNodes.find(node => node.layer.name === name);\n }\n\n /**\n * Rebuild the layer-node children from the map's current renderable layers.\n * Call after tile or image layers are structurally added to or removed from\n * the map.\n */\n public refreshLayers(): this {\n const previous = [...this._layerNodes];\n\n this.removeChildren();\n this._layerNodes.length = 0;\n\n for (const node of previous) {\n node.destroy();\n }\n\n this._buildLayerNodes();\n\n return this;\n }\n\n /**\n * Recomputed lazily on read, so it writes `_localBounds` directly rather than\n * going through `setLocalBounds`: an invalidating write inside a getter\n * would re-dirty the node on every read.\n */\n public override getLocalBounds(): ReadonlyRectangle {\n const bounds = this._localBounds;\n\n // Reading the pixel extents directly (rather than gating on `bounded`)\n // is what narrows them to numbers - `bounded` is a plain boolean getter.\n const { pixelHeight, pixelWidth } = this._map;\n\n if (this._map.projection.orientation === 'isometric') {\n bounds.set(0, 0, 0, 0);\n aggregateChildLocalBounds(this._layerNodes, bounds);\n } else if (pixelWidth !== undefined && pixelHeight !== undefined) {\n bounds.set(this._map.projection.originX, this._map.projection.originY, pixelWidth, pixelHeight);\n } else if (this._layerNodes.length > 0) {\n aggregateChildLocalBounds(this._layerNodes, bounds);\n }\n\n return bounds;\n }\n\n public override destroy(): void {\n const layerNodes = [...this._layerNodes];\n\n this._layerNodes.length = 0;\n\n super.destroy();\n\n for (const node of layerNodes) {\n node.destroy();\n }\n }\n\n private _buildLayerNodes(): void {\n for (const layer of this._map.renderableLayers) {\n const node = layer instanceof ImageLayer ? new ImageLayerNode(layer) : new TileLayerNode(layer, { cullable: this._cullChunks });\n\n // Unconditional: a node built after the map was set to `None` has to\n // inherit that too, not just a non-default mode.\n node.pixelSnapMode = this._pixelSnapMode;\n\n this._layerNodes.push(node);\n this.addChild(node);\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CA,IAAa,cAAb,cAAiC,UAAU;CACzC,AAAiB;CACjB,AAAiB;CACjB,AAAiB,cAAqD,CAAC;CACvE,AAAQ,iBAAgC,cAAc;CAEtD,AAAO,YAAY,KAAc,SAA8B;EAC7D,MAAM;EAEN,KAAK,OAAO;EACZ,KAAK,cAAc,SAAS,YAAY;EAExC,KAAK,iBAAiB;EAEtB,IAAI,CAAC,KAAK,KAAK,SACb,KAAK,WAAW;CAEpB;;CAGA,IAAW,MAAe;EACxB,OAAO,KAAK;CACd;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