@codexo/exojs-tilemap 0.16.1 → 0.17.0

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.
Files changed (59) hide show
  1. package/dist/esm/ChunkStreamer.d.ts +6 -0
  2. package/dist/esm/ChunkStreamer.d.ts.map +1 -1
  3. package/dist/esm/ChunkStreamer.js +6 -0
  4. package/dist/esm/ChunkStreamer.js.map +1 -1
  5. package/dist/esm/ImageLayerNode.d.ts +1 -3
  6. package/dist/esm/ImageLayerNode.d.ts.map +1 -1
  7. package/dist/esm/MapSpawnSession.d.ts +0 -7
  8. package/dist/esm/MapSpawnSession.d.ts.map +1 -1
  9. package/dist/esm/MapWorldRuntime.d.ts +0 -2
  10. package/dist/esm/MapWorldRuntime.d.ts.map +1 -1
  11. package/dist/esm/TileChunk.d.ts +0 -58
  12. package/dist/esm/TileChunk.d.ts.map +1 -1
  13. package/dist/esm/TileChunkNode.d.ts +1 -73
  14. package/dist/esm/TileChunkNode.d.ts.map +1 -1
  15. package/dist/esm/TileChunkNode.js +1 -1
  16. package/dist/esm/TileChunkNode.js.map +1 -1
  17. package/dist/esm/TileLayer.d.ts +0 -63
  18. package/dist/esm/TileLayer.d.ts.map +1 -1
  19. package/dist/esm/TileLayerNode.d.ts +4 -11
  20. package/dist/esm/TileLayerNode.d.ts.map +1 -1
  21. package/dist/esm/TileLayerNode.js +11 -14
  22. package/dist/esm/TileLayerNode.js.map +1 -1
  23. package/dist/esm/TileMapBand.d.ts +0 -33
  24. package/dist/esm/TileMapBand.d.ts.map +1 -1
  25. package/dist/esm/TileMapNode.d.ts +1 -1
  26. package/dist/esm/TileMapNode.js +1 -1
  27. package/dist/esm/TileMapNode.js.map +1 -1
  28. package/dist/esm/TileSet.d.ts +6 -10
  29. package/dist/esm/TileSet.d.ts.map +1 -1
  30. package/dist/esm/TileSet.js +6 -4
  31. package/dist/esm/TileSet.js.map +1 -1
  32. package/dist/esm/WorkerSampledChunkSource.d.ts +6 -4
  33. package/dist/esm/WorkerSampledChunkSource.d.ts.map +1 -1
  34. package/dist/esm/WorkerSampledChunkSource.js +6 -4
  35. package/dist/esm/WorkerSampledChunkSource.js.map +1 -1
  36. package/dist/esm/chunkGeometry.d.ts +1 -71
  37. package/dist/esm/chunkGeometry.d.ts.map +1 -1
  38. package/dist/esm/nodeBounds.d.ts +1 -19
  39. package/dist/esm/nodeBounds.d.ts.map +1 -1
  40. package/dist/esm/pixelSnap.d.ts +1 -12
  41. package/dist/esm/pixelSnap.d.ts.map +1 -1
  42. package/dist/esm/tileWord.d.ts +1 -11
  43. package/dist/esm/tileWord.d.ts.map +1 -1
  44. package/dist/esm/tilemapExtension.d.ts.map +1 -1
  45. package/dist/esm/tilemapExtension.js +5 -8
  46. package/dist/esm/tilemapExtension.js.map +1 -1
  47. package/dist/esm/tilemapSerializers.d.ts +1 -19
  48. package/dist/esm/tilemapSerializers.d.ts.map +1 -1
  49. package/dist/esm/types.d.ts +0 -6
  50. package/dist/esm/types.d.ts.map +1 -1
  51. package/dist/esm/webgl2/WebGl2TileChunkRenderer.d.ts +1 -86
  52. package/dist/esm/webgl2/WebGl2TileChunkRenderer.d.ts.map +1 -1
  53. package/dist/esm/webgl2/WebGl2TileChunkRenderer.js +30 -28
  54. package/dist/esm/webgl2/WebGl2TileChunkRenderer.js.map +1 -1
  55. package/dist/esm/webgpu/WebGpuTileChunkRenderer.d.ts +1 -107
  56. package/dist/esm/webgpu/WebGpuTileChunkRenderer.d.ts.map +1 -1
  57. package/dist/esm/webgpu/WebGpuTileChunkRenderer.js +9 -9
  58. package/dist/esm/webgpu/WebGpuTileChunkRenderer.js.map +1 -1
  59. package/package.json +3 -3
@@ -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` is applied to this node's transform; `visible` and `opacity` are\n * read live from the runtime layer on 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.None;\n private readonly _baseOffsetX: number;\n private readonly _baseOffsetY: number;\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 this._baseOffsetX = layer.offsetX;\n this._baseOffsetY = layer.offsetY;\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 * @default PixelSnapMode.None\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 if (patchesPosition || patchesScale) {\n const camCenter = builder.view.center;\n const prevX = this.x;\n const prevY = this.y;\n const prevScaleX = this.scale.x;\n const prevScaleY = this.scale.y;\n\n if (patchesPosition) {\n this.x = this._baseOffsetX + camCenter.x * (1 - layer.parallaxX);\n this.y = this._baseOffsetY + camCenter.y * (1 - layer.parallaxY);\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(prevX, prevY);\n }\n\n if (patchesScale) {\n this.setScale(prevScaleX, prevScaleY);\n }\n }\n } else {\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\n if (this._pixelSnapMode !== PixelSnapMode.None) {\n node.pixelSnapMode = this._pixelSnapMode;\n }\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;CACtD,AAAiB;CACjB,AAAiB;;;;;;;;CASjB,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,QAAQ;GACzB,SAAS,QAAQ;EACnB;EAEA,IAAI,MAAM,UAAU,QAAQ,MAAM,MAAM,OACtC;EAGF,MAAM,OAAO,KAAK,iBAAiB,MAAM,KAAK;EAE9C,KAAK,YAAY,KAAK,IAAI;EAC1B,KAAK,SAAS,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MAAM,UAAU,MAAM,WAAW,MAAM,YAAY,MAAM,YAAY,MAAM,WAAW;EAE5H,KAAK,WAAW,KAAK;EAErB,IAAI,KAAK,mBAAmB,cAAc,MACxC,KAAK,gBAAgB,KAAK;EAG5B,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 * 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.None;\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 * @default PixelSnapMode.None\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\n if (this._pixelSnapMode !== PixelSnapMode.None) {\n node.pixelSnapMode = this._pixelSnapMode;\n }\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,QAAQ;GACzB,SAAS,QAAQ;EACnB;EAEA,IAAI,MAAM,UAAU,QAAQ,MAAM,MAAM,OACtC;EAGF,MAAM,OAAO,KAAK,iBAAiB,MAAM,KAAK;EAE9C,KAAK,YAAY,KAAK,IAAI;EAC1B,KAAK,SAAS,IAAI;EAClB,KAAK,WAAW,IAAI;CACtB;CAEA,AAAO,YAAY,OAAkB,SAAgC;EACnE,MAAM;EAEN,KAAK,SAAS;EACd,KAAK,cAAc,SAAS,YAAY;EAExC,KAAK,YAAY,MAAM,SAAS,MAAM,OAAO;EAC7C,KAAK,iBAAiB;EAEtB,IAAI,CAAC,KAAK,OAAO,WAAW,MAAM,cAAc,KAAK,MAAM,cAAc,KAAK,MAAM,kBAAkB,GACpG,KAAK,WAAW;EAGlB,KAAK,OAAO,uBAAuB,KA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,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,7 +1,5 @@
1
1
  import { Container } from '@codexo/exojs';
2
- import type { ImageLayer } from './ImageLayer';
3
2
  import type { ImageLayerNode } from './ImageLayerNode';
4
- import type { TileLayer } from './TileLayer';
5
3
  import type { TileLayerNode } from './TileLayerNode';
6
4
  /**
7
5
  * A named, ordered group of layer nodes ({@link TileLayerNode}s and
@@ -47,13 +45,6 @@ export declare class TileMapBand extends Container {
47
45
  name: string;
48
46
  private readonly _layerNodes;
49
47
  private _destroyed;
50
- /**
51
- * @param name The band name (unique within its owning view).
52
- * @param layerNodes The layer nodes composing this band, already ordered by
53
- * map document order. Adopted as children.
54
- * @internal Constructed by {@link TileMapView}.
55
- */
56
- constructor(name: string, layerNodes: ReadonlyArray<TileLayerNode | ImageLayerNode>);
57
48
  /**
58
49
  * The layer nodes that compose this band, in map document order - tile and
59
50
  * image members interleaved. This is the band's **membership** list (the
@@ -75,30 +66,6 @@ export declare class TileMapBand extends Container {
75
66
  * would report).
76
67
  */
77
68
  updateBounds(): this;
78
- /**
79
- * Adopt a freshly created layer node into this band (used by
80
- * {@link TileMapView.refreshLayers} when a newly added map layer joins this
81
- * band). Appended; call {@link TileMapBand._reorder} afterwards to restore
82
- * map document order.
83
- * @internal
84
- */
85
- _adopt(node: TileLayerNode | ImageLayerNode): void;
86
- /**
87
- * Drop a layer node from this band's membership without destroying it (used
88
- * when its map layer was removed; the view destroys the node separately).
89
- * @internal
90
- */
91
- _release(node: TileLayerNode | ImageLayerNode): void;
92
- /**
93
- * Reorder this band's membership and its still-parented children to map
94
- * document order. `documentIndex` maps a layer **instance** to its index in
95
- * the map's combined document order - keyed by instance rather than id
96
- * because a tile layer and an image layer may share an id in fallback-ordered
97
- * maps. Layer nodes the caller has reparented away from this band keep their
98
- * membership (for ownership) but are not re-adopted.
99
- * @internal
100
- */
101
- _reorder(documentIndex: ReadonlyMap<TileLayer | ImageLayer, number>): void;
102
69
  /**
103
70
  * Destroy the band: detach it from its application parent, then destroy the
104
71
  * layer nodes it owns (freeing their chunk geometry / image sprites).
@@ -1 +1 @@
1
- {"version":3,"file":"TileMapBand.d.ts","sourceRoot":"","sources":["../../src/TileMapBand.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE1C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC7C,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;IAE3B;;;;;OAKG;gBACgB,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,aAAa,CAAC,aAAa,GAAG,cAAc,CAAC;IAW1F;;;;;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;IAI/E,uDAAuD;IACvD,IAAW,OAAO,IAAI,OAAO,CAE5B;IAED;;;;;OAKG;IACa,YAAY,IAAI,IAAI;IAmBpC;;;;;;OAMG;IACI,MAAM,CAAC,IAAI,EAAE,aAAa,GAAG,cAAc,GAAG,IAAI;IAQzD;;;;OAIG;IACI,QAAQ,CAAC,IAAI,EAAE,aAAa,GAAG,cAAc,GAAG,IAAI;IAY3D;;;;;;;;OAQG;IACI,QAAQ,CAAC,aAAa,EAAE,WAAW,CAAC,SAAS,GAAG,UAAU,EAAE,MAAM,CAAC,GAAG,IAAI;IAUjF;;;;;;;;OAQG;IACa,OAAO,IAAI,IAAI;CAmBhC"}
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;IAI/E,uDAAuD;IACvD,IAAW,OAAO,IAAI,OAAO,CAE5B;IAED;;;;;OAKG;IACa,YAAY,IAAI,IAAI;IAsEpC;;;;;;;;OAQG;IACa,OAAO,IAAI,IAAI;CAmBhC"}
@@ -77,7 +77,7 @@ export declare class TileMapNode extends Container {
77
77
  refreshLayers(): this;
78
78
  /**
79
79
  * Recomputed lazily on read, so it writes `_localBounds` directly rather than
80
- * going through `_setLocalBounds`: an invalidating write inside a getter
80
+ * going through `setLocalBounds`: an invalidating write inside a getter
81
81
  * would re-dirty the node on every read.
82
82
  */
83
83
  getLocalBounds(): ReadonlyRectangle;
@@ -95,7 +95,7 @@ var TileMapNode = class extends Container {
95
95
  }
96
96
  /**
97
97
  * Recomputed lazily on read, so it writes `_localBounds` directly rather than
98
- * going through `_setLocalBounds`: an invalidating write inside a getter
98
+ * going through `setLocalBounds`: an invalidating write inside a getter
99
99
  * would re-dirty the node on every read.
100
100
  */
101
101
  getLocalBounds() {
@@ -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.None;\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 * @default PixelSnapMode.None\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(0, 0, 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 if (this._pixelSnapMode !== PixelSnapMode.None) {\n node.pixelSnapMode = this._pixelSnapMode;\n }\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,O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AY,KAAK,IAAI;GAC1B,KAAK,SAAS,IAAI;EACpB;CACF;AACF"}
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.None;\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 * @default PixelSnapMode.None\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(0, 0, 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 if (this._pixelSnapMode !== PixelSnapMode.None) {\n node.pixelSnapMode = this._pixelSnapMode;\n }\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;;;;;;;;;;;;;CAcA,IAAW,gBAA+B;EACxC,OAAO,KAAK;CACd;CAEA,IAAW,cAAc,MAAqB;EAC5C,IAAI,SAAS,KAAK,gBAChB;EAGF,oBAAoB,IAAI;EACxB,KAAK,iBAAiB;EAEtB,KAAK,MAAM,QAAQ,KAAK,aACtB,KAAK,gBAAgB;CAEzB;;;;;CAMA,IAAW,aAA4D;EACrE,OAAO,KAAK;CACd;;;;;CAMA,AAAO,aAAa,MAA0D;EAC5E,OAAO,KAAK,YAAY,MAAK,SAAQ,KAAK,MAAM,SAAS,IAAI;CAC/D;;;;;;CAOA,AAAO,gBAAsB;EAC3B,MAAM,WAAW,CAAC,GAAG,KAAK,WAAW;EAErC,KAAK,eAAe;EACpB,KAAK,YAAY,SAAS;EAE1B,KAAK,MAAM,QAAQ,UACjB,KAAK,QAAQ;EAGf,KAAK,iBAAiB;EAEtB,OAAO;CACT;;;;;;CAOA,AAAgB,iBAAoC;EAClD,MAAM,SAAS,KAAK;EAIpB,MAAM,EAAE,aAAa,eAAe,KAAK;EAEzC,IAAI,eAAe,UAAa,gBAAgB,QAC9C,OAAO,IAAI,GAAG,GAAG,YAAY,WAAW;OACnC,IAAI,KAAK,YAAY,SAAS,GACnC,0BAA0B,KAAK,aAAa,MAAM;EAGpD,OAAO;CACT;CAEA,AAAgB,UAAgB;EAC9B,MAAM,aAAa,CAAC,GAAG,KAAK,WAAW;EAEvC,KAAK,YAAY,SAAS;EAE1B,MAAM,QAAQ;EAEd,KAAK,MAAM,QAAQ,YACjB,KAAK,QAAQ;CAEjB;CAEA,AAAQ,mBAAyB;EAC/B,KAAK,MAAM,SAAS,KAAK,KAAK,kBAAkB;GAC9C,MAAM,OAAO,iBAAiB,aAAa,IAAI,eAAe,KAAK,IAAI,IAAI,cAAc,OAAO,EAAE,UAAU,KAAK,YAAY,CAAC;GAE9H,IAAI,KAAK,mBAAmB,cAAc,MACxC,KAAK,gBAAgB,KAAK;GAG5B,KAAK,YAAY,KAAK,IAAI;GAC1B,KAAK,SAAS,IAAI;EACpB;CACF;AACF"}
@@ -78,17 +78,13 @@ export declare class TileSet {
78
78
  */
79
79
  constructor(options: TileSetOptions);
80
80
  /**
81
- * Set per-tile metadata for a local tile ID.
82
- * Copies input to prevent caller-owned mutation leaking into the tileset.
83
- * @internal
84
- */
85
- _setDefinition(localTileId: number, definition: Partial<TileDefinition>): void;
86
- /**
87
- * Build definitions from an array, replacing the internal definitions map.
88
- * Each entry's properties are copied and frozen.
89
- * @internal
81
+ * Replace all tile definitions with the given array. Each entry's
82
+ * properties are copied and frozen.
83
+ *
84
+ * Part of the tilemap SDK contract for extension packages that build
85
+ * tilesets programmatically.
90
86
  */
91
- _setDefinitions(definitions: readonly TileDefinition[]): void;
87
+ setDefinitions(definitions: readonly TileDefinition[]): void;
92
88
  /**
93
89
  * Retrieve per-tile metadata, or undefined if none defined.
94
90
  * @advanced
@@ -1 +1 @@
1
- {"version":3,"file":"TileSet.d.ts","sourceRoot":"","sources":["../../src/TileSet.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAEnD,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAG9D;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B,6DAA6D;IAC7D,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,iEAAiE;IACjE,QAAQ,CAAC,OAAO,EAAE,aAAa,CAAC;IAChC,oCAAoC;IACpC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,qCAAqC;IACrC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,6CAA6C;IAC7C,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,oGAAoG;IACpG,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,+DAA+D;IAC/D,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,oDAAoD;IACpD,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,mEAAmE;IACnE,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,8GAA8G;IAC9G,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,8GAA8G;IAC9G,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED;;;;;;;;;;GAUG;AACH,qBAAa,OAAO;IAClB,2BAA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C;IAClC,6BAA6B;IAC7B,SAAgB,UAAU,EAAE,MAAM,CAAC;IAEnC,4CAA4C;IAC5C,SAAgB,SAAS,EAAE,MAAM,CAAC;IAElC,2CAA2C;IAC3C,SAAgB,OAAO,EAAE,MAAM,CAAC;IAChC,uDAAuD;IACvD,SAAgB,IAAI,EAAE,MAAM,CAAC;IAE7B,gDAAgD;IAChD,SAAgB,OAAO,EAAE,MAAM,CAAC;IAChC,qCAAqC;IACrC,SAAgB,MAAM,EAAE,MAAM,CAAC;IAE/B,+DAA+D;IAC/D,SAAgB,KAAK,EAAE,MAAM,CAAC;IAC9B;;;;;;;;OAQG;IACH,SAAgB,OAAO,EAAE,MAAM,CAAC;IAChC,yGAAyG;IACzG,SAAgB,OAAO,EAAE,MAAM,CAAC;IAEhC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAsC;IAEnE;;OAEG;gBACgB,OAAO,EAAE,cAAc;IAwF1C;;;;;;OAMG;IACI,cAAc,CAAC,WAAW,EAAE,SAAS,cAAc,EAAE,GAAG,IAAI;IAgBnE;;;OAGG;IACI,iBAAiB,CAAC,WAAW,EAAE,MAAM,GAAG,cAAc,GAAG,SAAS;IAIzE;;;;OAIG;IACI,WAAW,CAAC,WAAW,EAAE,MAAM,GAAG;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE;IAchG;;;OAGG;IACI,YAAY,IAAI,gBAAgB,CAAC,cAAc,CAAC;IAIvD;;;;OAIG;IACH,IAAW,cAAc,IAAI,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,cAAc,GAAG,SAAS,CAAC,CAAC,CAMhF;CACF"}
@@ -100,11 +100,13 @@ var TileSet = class {
100
100
  });
101
101
  }
102
102
  /**
103
- * Build definitions from an array, replacing the internal definitions map.
104
- * Each entry's properties are copied and frozen.
105
- * @internal
103
+ * Replace all tile definitions with the given array. Each entry's
104
+ * properties are copied and frozen.
105
+ *
106
+ * Part of the tilemap SDK contract for extension packages that build
107
+ * tilesets programmatically.
106
108
  */
107
- _setDefinitions(definitions) {
109
+ setDefinitions(definitions) {
108
110
  const map = this._definitions;
109
111
  map.clear();
110
112
  for (const def of definitions) {
@@ -1 +1 @@
1
- {"version":3,"file":"TileSet.js","names":[],"sources":["../../src/TileSet.ts"],"sourcesContent":["import type { TextureRegion } from '@codexo/exojs';\n\nimport type { TileDefinition, TileProperties } from './types';\nimport { validateNonNegativeInteger, validatePositiveInteger } from './types';\n\n/**\n * Options for constructing a {@link TileSet}.\n * @advanced\n */\nexport interface TileSetOptions {\n /** Stable runtime name (unique within a {@link TileMap}). */\n readonly name: string;\n /** Texture atlas for this tileset. Textures are Loader-owned. */\n readonly texture: TextureRegion;\n /** Width of each tile in pixels. */\n readonly tileWidth: number;\n /** Height of each tile in pixels. */\n readonly tileHeight: number;\n /** Total number of tiles in this tileset. */\n readonly tileCount: number;\n /** Number of tile columns in the atlas grid. Computed from texture width / tileWidth if omitted. */\n readonly columns?: number;\n /** Pixel spacing between tiles in the atlas. Defaults to 0. */\n readonly spacing?: number;\n /** Pixel margin around the atlas. Defaults to 0. */\n readonly margin?: number;\n /** Tileset class/type string (Tiled `class`). Defaults to `''`. */\n readonly class?: string;\n /** Visual drawing offset in pixels applied to every tile of this set drawn by a tile layer. Defaults to 0. */\n readonly offsetX?: number;\n /** Visual drawing offset in pixels applied to every tile of this set drawn by a tile layer. Defaults to 0. */\n readonly offsetY?: number;\n}\n\n/**\n * A resolved tileset: a uniform grid of tiles within a texture atlas.\n *\n * Does **not** own its texture - the Loader or application code retains\n * texture ownership. Tileset dimensions are validated at construction and\n * frozen thereafter.\n *\n * Multiple tilesets are supported per {@link TileMap}; each carries its own\n * tile dimensions, spacing, and optional per-tile metadata.\n * @advanced\n */\nexport class TileSet {\n /** Stable runtime name. */\n public readonly name: string;\n\n /** Atlas texture region - Loader-owned, never destroyed by the tileset. */\n public readonly texture: TextureRegion;\n\n /** Tile width in pixels. */\n public readonly tileWidth: number;\n /** Tile height in pixels. */\n public readonly tileHeight: number;\n\n /** Total number of tiles in the tileset. */\n public readonly tileCount: number;\n\n /** Number of columns in the atlas grid. */\n public readonly columns: number;\n /** Number of rows implied by tileCount and columns. */\n public readonly rows: number;\n\n /** Pixel spacing between tiles in the atlas. */\n public readonly spacing: number;\n /** Pixel margin around the atlas. */\n public readonly margin: number;\n\n /** Tileset class/type string (Tiled `class`; may be empty). */\n public readonly class: string;\n /**\n * Visual drawing offset X in pixels (Tiled `tileoffset`).\n *\n * Applied by the tile-layer geometry builder and by the tile-collision\n * helpers - i.e. wherever this package places a tile on a grid. It is **not**\n * folded into a {@link TileObject}'s `x`/`y`: object layers are data-only, so\n * code that draws a tile object itself has to add this offset the way a tile\n * layer would.\n */\n public readonly offsetX: number;\n /** Visual drawing offset Y in pixels (Tiled `tileoffset`) - see {@link offsetX} for where it applies. */\n public readonly offsetY: number;\n\n private readonly _definitions: ReadonlyMap<number, TileDefinition>;\n\n /**\n * @throws When dimensions, counts, or spacing values are invalid.\n */\n public constructor(options: TileSetOptions) {\n if (!options.name || typeof options.name !== 'string') {\n throw new Error('TileSet name must be a non-empty string.');\n }\n\n if (!options.texture) {\n throw new Error('TileSet requires a valid TextureRegion.');\n }\n\n validatePositiveInteger(options.tileWidth, 'tileWidth');\n validatePositiveInteger(options.tileHeight, 'tileHeight');\n validatePositiveInteger(options.tileCount, 'tileCount');\n\n const spacing = options.spacing ?? 0;\n const margin = options.margin ?? 0;\n validateNonNegativeInteger(spacing, 'spacing');\n validateNonNegativeInteger(margin, 'margin');\n\n // A tile grid is derived from the atlas dimensions and then fixed, so it\n // cannot be built against a texture that has not loaded yet - and the\n // dimension checks below would otherwise report the resulting zeros as a\n // bad tile size rather than as the real cause.\n if (options.texture.width <= 0 || options.texture.height <= 0) {\n throw new Error(\n `TileSet needs a loaded texture to derive its grid, but \"${options.name}\" was given one measuring ` +\n `${options.texture.width}x${options.texture.height}. Await it (loader.load(...) or texture.loaded) before constructing the tile set.`,\n );\n }\n\n const atlasWidth = options.texture.width - margin * 2;\n const atlasHeight = options.texture.height - margin * 2;\n\n const columns = options.columns ?? Math.floor(atlasWidth / options.tileWidth);\n\n validatePositiveInteger(columns, 'columns');\n if (columns <= 0) {\n throw new Error(`TileSet columns must be positive (got ${columns}).`);\n }\n\n if (options.tileWidth * columns + spacing * (columns - 1) > atlasWidth) {\n throw new Error(`TileSet grid width exceeds atlas: ${options.tileWidth}*${columns}` + ` + ${spacing}*${columns - 1} > ${atlasWidth}.`);\n }\n\n const rows = Math.ceil(options.tileCount / columns);\n if (rows > 0 && options.tileHeight * rows + spacing * (rows - 1) > atlasHeight) {\n throw new Error(`TileSet grid height exceeds atlas: ${options.tileHeight}*${rows}` + ` + ${spacing}*${rows - 1} > ${atlasHeight}.`);\n }\n\n this.name = options.name;\n this.texture = options.texture;\n this.tileWidth = options.tileWidth;\n this.tileHeight = options.tileHeight;\n this.tileCount = options.tileCount;\n this.columns = columns;\n this.rows = rows;\n this.spacing = spacing;\n this.margin = margin;\n this.class = options.class ?? '';\n this.offsetX = options.offsetX ?? 0;\n this.offsetY = options.offsetY ?? 0;\n\n this._definitions = new Map();\n\n if (__DEV__) {\n Object.freeze(this);\n }\n }\n\n /**\n * Set per-tile metadata for a local tile ID.\n * Copies input to prevent caller-owned mutation leaking into the tileset.\n * @internal\n */\n public _setDefinition(localTileId: number, definition: Partial<TileDefinition>): void {\n if (localTileId < 0 || localTileId >= this.tileCount) {\n throw new Error(`Tile definition localTileId ${localTileId} out of range [0, ${this.tileCount - 1}].`);\n }\n const props = definition.properties ? Object.freeze({ ...definition.properties }) : undefined;\n const animation = definition.animation ? Object.freeze(definition.animation.map(frame => Object.freeze({ ...frame }))) : undefined;\n const collision = definition.collision ? Object.freeze([...definition.collision]) : undefined;\n (this._definitions as Map<number, TileDefinition>).set(localTileId, {\n localTileId,\n ...(props !== undefined && { properties: props }),\n ...(animation !== undefined && { animation }),\n ...(collision !== undefined && { collision }),\n });\n }\n\n /**\n * Build definitions from an array, replacing the internal definitions map.\n * Each entry's properties are copied and frozen.\n * @internal\n */\n public _setDefinitions(definitions: readonly TileDefinition[]): void {\n const map = this._definitions as Map<number, TileDefinition>;\n map.clear();\n for (const def of definitions) {\n const props = def.properties ? Object.freeze({ ...def.properties }) : undefined;\n const animation = def.animation ? Object.freeze(def.animation.map(frame => Object.freeze({ ...frame }))) : undefined;\n const collision = def.collision ? Object.freeze([...def.collision]) : undefined;\n map.set(def.localTileId, {\n localTileId: def.localTileId,\n ...(props !== undefined && { properties: props }),\n ...(animation !== undefined && { animation }),\n ...(collision !== undefined && { collision }),\n });\n }\n }\n\n /**\n * Retrieve per-tile metadata, or undefined if none defined.\n * @advanced\n */\n public getTileDefinition(localTileId: number): TileDefinition | undefined {\n return this._definitions.get(localTileId);\n }\n\n /**\n * Compute the pixel-space source rectangle for a local tile ID\n * within the atlas, accounting for columns, spacing, and margin.\n * @advanced\n */\n public getTileRect(localTileId: number): { x: number; y: number; width: number; height: number } {\n if (localTileId < 0 || localTileId >= this.tileCount) {\n throw new Error(`getTileRect: localTileId ${localTileId} out of range [0, ${this.tileCount - 1}].`);\n }\n const col = localTileId % this.columns;\n const row = Math.floor(localTileId / this.columns);\n return {\n x: this.margin + col * (this.tileWidth + this.spacing),\n y: this.margin + row * (this.tileHeight + this.spacing),\n width: this.tileWidth,\n height: this.tileHeight,\n };\n }\n\n /**\n * Iterate over all defined tiles (sparse).\n * @advanced\n */\n public definedTiles(): IterableIterator<TileDefinition> {\n return this._definitions.values();\n }\n\n /**\n * Read-only snapshot of all per-tile definitions.\n * The returned record is a caller-owned copy.\n * @advanced\n */\n public get allDefinitions(): Readonly<Record<number, TileProperties | undefined>> {\n const result: Record<number, TileProperties | undefined> = {};\n for (const [id, def] of this._definitions) {\n result[id] = def.properties;\n }\n return Object.freeze(result);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AA6CA,IAAa,UAAb,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a,OAAO,OAAO,EAAE,GAAG,IAAI,WAAW,CAAC,IAAI;GACtE,MAAM,YAAY,IAAI,YAAY,OAAO,OAAO,IAAI,UAAU,KAAI,UAAS,OAAO,OAAO,EAAE,GAAG,MAAM,CAAC,CAAC,CAAC,IAAI;GAC3G,MAAM,YAAY,IAAI,YAAY,OAAO,OAAO,CAAC,GAAG,IAAI,SAAS,CAAC,IAAI;GACtE,IAAI,IAAI,IAAI,aAAa;IACvB,aAAa,IAAI;IACjB,GAAI,UAAU,UAAa,EAAE,YAAY,MAAM;IAC/C,GAAI,cAAc,UAAa,EAAE,UAAU;IAC3C,GAAI,cAAc,UAAa,EAAE,UAAU;GAC7C,CAAC;EACH;CACF;;;;;CAMA,AAAO,kBAAkB,aAAiD;EACxE,OAAO,KAAK,aAAa,IAAI,WAAW;CAC1C;;;;;;CAOA,AAAO,YAAY,aAA8E;EAC/F,IAAI,cAAc,KAAK,eAAe,KAAK,WACzC,MAAM,IAAI,MAAM,4BAA4B,YAAY,oBAAoB,KAAK,YAAY,EAAE,GAAG;EAEpG,MAAM,MAAM,cAAc,KAAK;EAC/B,MAAM,MAAM,KAAK,MAAM,cAAc,KAAK,OAAO;EACjD,OAAO;GACL,GAAG,KAAK,SAAS,OAAO,KAAK,YAAY,KAAK;GAC9C,GAAG,KAAK,SAAS,OAAO,KAAK,aAAa,KAAK;GAC/C,OAAO,KAAK;GACZ,QAAQ,KAAK;EACf;CACF;;;;;CAMA,AAAO,eAAiD;EACtD,OAAO,KAAK,aAAa,OAAO;CAClC;;;;;;CAOA,IAAW,iBAAuE;EAChF,MAAM,SAAqD,CAAC;EAC5D,KAAK,MAAM,CAAC,IAAI,QAAQ,KAAK,cAC3B,OAAO,MAAM,IAAI;EAEnB,OAAO,OAAO,OAAO,MAAM;CAC7B;AACF"}
1
+ {"version":3,"file":"TileSet.js","names":[],"sources":["../../src/TileSet.ts"],"sourcesContent":["import type { TextureRegion } from '@codexo/exojs';\n\nimport type { TileDefinition, TileProperties } from './types';\nimport { validateNonNegativeInteger, validatePositiveInteger } from './types';\n\n/**\n * Options for constructing a {@link TileSet}.\n * @advanced\n */\nexport interface TileSetOptions {\n /** Stable runtime name (unique within a {@link TileMap}). */\n readonly name: string;\n /** Texture atlas for this tileset. Textures are Loader-owned. */\n readonly texture: TextureRegion;\n /** Width of each tile in pixels. */\n readonly tileWidth: number;\n /** Height of each tile in pixels. */\n readonly tileHeight: number;\n /** Total number of tiles in this tileset. */\n readonly tileCount: number;\n /** Number of tile columns in the atlas grid. Computed from texture width / tileWidth if omitted. */\n readonly columns?: number;\n /** Pixel spacing between tiles in the atlas. Defaults to 0. */\n readonly spacing?: number;\n /** Pixel margin around the atlas. Defaults to 0. */\n readonly margin?: number;\n /** Tileset class/type string (Tiled `class`). Defaults to `''`. */\n readonly class?: string;\n /** Visual drawing offset in pixels applied to every tile of this set drawn by a tile layer. Defaults to 0. */\n readonly offsetX?: number;\n /** Visual drawing offset in pixels applied to every tile of this set drawn by a tile layer. Defaults to 0. */\n readonly offsetY?: number;\n}\n\n/**\n * A resolved tileset: a uniform grid of tiles within a texture atlas.\n *\n * Does **not** own its texture - the Loader or application code retains\n * texture ownership. Tileset dimensions are validated at construction and\n * frozen thereafter.\n *\n * Multiple tilesets are supported per {@link TileMap}; each carries its own\n * tile dimensions, spacing, and optional per-tile metadata.\n * @advanced\n */\nexport class TileSet {\n /** Stable runtime name. */\n public readonly name: string;\n\n /** Atlas texture region - Loader-owned, never destroyed by the tileset. */\n public readonly texture: TextureRegion;\n\n /** Tile width in pixels. */\n public readonly tileWidth: number;\n /** Tile height in pixels. */\n public readonly tileHeight: number;\n\n /** Total number of tiles in the tileset. */\n public readonly tileCount: number;\n\n /** Number of columns in the atlas grid. */\n public readonly columns: number;\n /** Number of rows implied by tileCount and columns. */\n public readonly rows: number;\n\n /** Pixel spacing between tiles in the atlas. */\n public readonly spacing: number;\n /** Pixel margin around the atlas. */\n public readonly margin: number;\n\n /** Tileset class/type string (Tiled `class`; may be empty). */\n public readonly class: string;\n /**\n * Visual drawing offset X in pixels (Tiled `tileoffset`).\n *\n * Applied by the tile-layer geometry builder and by the tile-collision\n * helpers - i.e. wherever this package places a tile on a grid. It is **not**\n * folded into a {@link TileObject}'s `x`/`y`: object layers are data-only, so\n * code that draws a tile object itself has to add this offset the way a tile\n * layer would.\n */\n public readonly offsetX: number;\n /** Visual drawing offset Y in pixels (Tiled `tileoffset`) - see {@link offsetX} for where it applies. */\n public readonly offsetY: number;\n\n private readonly _definitions: ReadonlyMap<number, TileDefinition>;\n\n /**\n * @throws When dimensions, counts, or spacing values are invalid.\n */\n public constructor(options: TileSetOptions) {\n if (!options.name || typeof options.name !== 'string') {\n throw new Error('TileSet name must be a non-empty string.');\n }\n\n if (!options.texture) {\n throw new Error('TileSet requires a valid TextureRegion.');\n }\n\n validatePositiveInteger(options.tileWidth, 'tileWidth');\n validatePositiveInteger(options.tileHeight, 'tileHeight');\n validatePositiveInteger(options.tileCount, 'tileCount');\n\n const spacing = options.spacing ?? 0;\n const margin = options.margin ?? 0;\n validateNonNegativeInteger(spacing, 'spacing');\n validateNonNegativeInteger(margin, 'margin');\n\n // A tile grid is derived from the atlas dimensions and then fixed, so it\n // cannot be built against a texture that has not loaded yet - and the\n // dimension checks below would otherwise report the resulting zeros as a\n // bad tile size rather than as the real cause.\n if (options.texture.width <= 0 || options.texture.height <= 0) {\n throw new Error(\n `TileSet needs a loaded texture to derive its grid, but \"${options.name}\" was given one measuring ` +\n `${options.texture.width}x${options.texture.height}. Await it (loader.load(...) or texture.loaded) before constructing the tile set.`,\n );\n }\n\n const atlasWidth = options.texture.width - margin * 2;\n const atlasHeight = options.texture.height - margin * 2;\n\n const columns = options.columns ?? Math.floor(atlasWidth / options.tileWidth);\n\n validatePositiveInteger(columns, 'columns');\n if (columns <= 0) {\n throw new Error(`TileSet columns must be positive (got ${columns}).`);\n }\n\n if (options.tileWidth * columns + spacing * (columns - 1) > atlasWidth) {\n throw new Error(`TileSet grid width exceeds atlas: ${options.tileWidth}*${columns}` + ` + ${spacing}*${columns - 1} > ${atlasWidth}.`);\n }\n\n const rows = Math.ceil(options.tileCount / columns);\n if (rows > 0 && options.tileHeight * rows + spacing * (rows - 1) > atlasHeight) {\n throw new Error(`TileSet grid height exceeds atlas: ${options.tileHeight}*${rows}` + ` + ${spacing}*${rows - 1} > ${atlasHeight}.`);\n }\n\n this.name = options.name;\n this.texture = options.texture;\n this.tileWidth = options.tileWidth;\n this.tileHeight = options.tileHeight;\n this.tileCount = options.tileCount;\n this.columns = columns;\n this.rows = rows;\n this.spacing = spacing;\n this.margin = margin;\n this.class = options.class ?? '';\n this.offsetX = options.offsetX ?? 0;\n this.offsetY = options.offsetY ?? 0;\n\n this._definitions = new Map();\n\n if (__DEV__) {\n Object.freeze(this);\n }\n }\n\n /**\n * Set per-tile metadata for a local tile ID.\n * Copies input to prevent caller-owned mutation leaking into the tileset.\n * @internal\n */\n public _setDefinition(localTileId: number, definition: Partial<TileDefinition>): void {\n if (localTileId < 0 || localTileId >= this.tileCount) {\n throw new Error(`Tile definition localTileId ${localTileId} out of range [0, ${this.tileCount - 1}].`);\n }\n const props = definition.properties ? Object.freeze({ ...definition.properties }) : undefined;\n const animation = definition.animation ? Object.freeze(definition.animation.map(frame => Object.freeze({ ...frame }))) : undefined;\n const collision = definition.collision ? Object.freeze([...definition.collision]) : undefined;\n (this._definitions as Map<number, TileDefinition>).set(localTileId, {\n localTileId,\n ...(props !== undefined && { properties: props }),\n ...(animation !== undefined && { animation }),\n ...(collision !== undefined && { collision }),\n });\n }\n\n /**\n * Replace all tile definitions with the given array. Each entry's\n * properties are copied and frozen.\n *\n * Part of the tilemap SDK contract for extension packages that build\n * tilesets programmatically.\n */\n public setDefinitions(definitions: readonly TileDefinition[]): void {\n const map = this._definitions as Map<number, TileDefinition>;\n map.clear();\n for (const def of definitions) {\n const props = def.properties ? Object.freeze({ ...def.properties }) : undefined;\n const animation = def.animation ? Object.freeze(def.animation.map(frame => Object.freeze({ ...frame }))) : undefined;\n const collision = def.collision ? Object.freeze([...def.collision]) : undefined;\n map.set(def.localTileId, {\n localTileId: def.localTileId,\n ...(props !== undefined && { properties: props }),\n ...(animation !== undefined && { animation }),\n ...(collision !== undefined && { collision }),\n });\n }\n }\n\n /**\n * Retrieve per-tile metadata, or undefined if none defined.\n * @advanced\n */\n public getTileDefinition(localTileId: number): TileDefinition | undefined {\n return this._definitions.get(localTileId);\n }\n\n /**\n * Compute the pixel-space source rectangle for a local tile ID\n * within the atlas, accounting for columns, spacing, and margin.\n * @advanced\n */\n public getTileRect(localTileId: number): { x: number; y: number; width: number; height: number } {\n if (localTileId < 0 || localTileId >= this.tileCount) {\n throw new Error(`getTileRect: localTileId ${localTileId} out of range [0, ${this.tileCount - 1}].`);\n }\n const col = localTileId % this.columns;\n const row = Math.floor(localTileId / this.columns);\n return {\n x: this.margin + col * (this.tileWidth + this.spacing),\n y: this.margin + row * (this.tileHeight + this.spacing),\n width: this.tileWidth,\n height: this.tileHeight,\n };\n }\n\n /**\n * Iterate over all defined tiles (sparse).\n * @advanced\n */\n public definedTiles(): IterableIterator<TileDefinition> {\n return this._definitions.values();\n }\n\n /**\n * Read-only snapshot of all per-tile definitions.\n * The returned record is a caller-owned copy.\n * @advanced\n */\n public get allDefinitions(): Readonly<Record<number, TileProperties | undefined>> {\n const result: Record<number, TileProperties | undefined> = {};\n for (const [id, def] of this._definitions) {\n result[id] = def.properties;\n }\n return Object.freeze(result);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AA6CA,IAAa,UAAb,MAAqB;;CAEnB,AAAgB;;CAGhB,AAAgB;;CAGhB,AAAgB;;CAEhB,AAAgB;;CAGhB,AAAgB;;CAGhB,AAAgB;;CAEhB,AAAgB;;CAGhB,AAAgB;;CAEhB,AAAgB;;CAGhB,AAAgB;;;;;;;;;;CAUhB,AAAgB;;CAEhB,AAAgB;CAEhB,AAAiB;;;;CAKjB,AAAO,YAAY,SAAyB;EAC1C,IAAI,CAAC,QAAQ,QAAQ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ACvB,aAAa,IAAI;IACjB,GAAI,UAAU,UAAa,EAAE,YAAY,MAAM;IAC/C,GAAI,cAAc,UAAa,EAAE,UAAU;IAC3C,GAAI,cAAc,UAAa,EAAE,UAAU;GAC7C,CAAC;EACH;CACF;;;;;CAMA,AAAO,kBAAkB,aAAiD;EACxE,OAAO,KAAK,aAAa,IAAI,WAAW;CAC1C;;;;;;CAOA,AAAO,YAAY,aAA8E;EAC/F,IAAI,cAAc,KAAK,eAAe,KAAK,WACzC,MAAM,IAAI,MAAM,4BAA4B,YAAY,oBAAoB,KAAK,YAAY,EAAE,GAAG;EAEpG,MAAM,MAAM,cAAc,KAAK;EAC/B,MAAM,MAAM,KAAK,MAAM,cAAc,KAAK,OAAO;EACjD,OAAO;GACL,GAAG,KAAK,SAAS,OAAO,KAAK,YAAY,KAAK;GAC9C,GAAG,KAAK,SAAS,OAAO,KAAK,aAAa,KAAK;GAC/C,OAAO,KAAK;GACZ,QAAQ,KAAK;EACf;CACF;;;;;CAMA,AAAO,eAAiD;EACtD,OAAO,KAAK,aAAa,OAAO;CAClC;;;;;;CAOA,IAAW,iBAAuE;EAChF,MAAM,SAAqD,CAAC;EAC5D,KAAK,MAAM,CAAC,IAAI,QAAQ,KAAK,cAC3B,OAAO,MAAM,IAAI;EAEnB,OAAO,OAAO,OAAO,MAAM;CAC7B;AACF"}
@@ -75,10 +75,12 @@ export interface WorkerSampledChunkSourceOptions {
75
75
  * {@link WorkerSampledChunkSourceOptions.workerSource} is a self-contained
76
76
  * worker script string; see its documentation for the protocol.
77
77
  *
78
- * The returned value's `destroy()` MUST be called when done with it (e.g.
79
- * alongside your `ChunkStreamer.destroy()` call) - the underlying `Worker`
80
- * is a real resource that leaks otherwise. `ChunkSource` itself has no
81
- * lifecycle hook, so this is not automatic.
78
+ * The returned value's `destroy()` MUST be called when done with it - the
79
+ * underlying `Worker` is a real resource that leaks otherwise.
80
+ * {@link import('./ChunkStreamer').ChunkStreamer} does not own the source it
81
+ * is given and never calls this for you: `ChunkSource` itself has no
82
+ * lifecycle hook, so nothing ties the two together automatically. Call it
83
+ * yourself alongside your own `ChunkStreamer.destroy()` call.
82
84
  *
83
85
  * Implementation note: `workerSource` is Blob-URL'd into a real `Worker`
84
86
  * (`new Blob([workerSource])` → `URL.createObjectURL` → `new Worker(url)`) -
@@ -1 +1 @@
1
- {"version":3,"file":"WorkerSampledChunkSource.d.ts","sourceRoot":"","sources":["../../src/WorkerSampledChunkSource.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAgB,WAAW,EAAE,MAAM,eAAe,CAAC;AAC/D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAG5C;;;GAGG;AACH,MAAM,WAAW,+BAA+B;IAC9C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA+BG;IACH,YAAY,EAAE,MAAM,CAAC;IACrB;;;;;;;;;;;;OAYG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB;;;;;;;OAOG;IACH,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,YAAY,GAAG,IAAI,CAAC;CAC5E;AAiCD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,8BAA8B,GAAI,OAAO,SAAS,EAAE,SAAS,+BAA+B,KAAG,WAAW,GAAG;IAAE,OAAO,IAAI,IAAI,CAAA;CA8F1I,CAAC"}
1
+ {"version":3,"file":"WorkerSampledChunkSource.d.ts","sourceRoot":"","sources":["../../src/WorkerSampledChunkSource.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAgB,WAAW,EAAE,MAAM,eAAe,CAAC;AAC/D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAG5C;;;GAGG;AACH,MAAM,WAAW,+BAA+B;IAC9C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA+BG;IACH,YAAY,EAAE,MAAM,CAAC;IACrB;;;;;;;;;;;;OAYG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB;;;;;;;OAOG;IACH,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,YAAY,GAAG,IAAI,CAAC;CAC5E;AAiCD;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,eAAO,MAAM,8BAA8B,GAAI,OAAO,SAAS,EAAE,SAAS,+BAA+B,KAAG,WAAW,GAAG;IAAE,OAAO,IAAI,IAAI,CAAA;CA8F1I,CAAC"}
@@ -14,10 +14,12 @@ const isWorkerErrorMessage = (message) => "error" in message;
14
14
  * {@link WorkerSampledChunkSourceOptions.workerSource} is a self-contained
15
15
  * worker script string; see its documentation for the protocol.
16
16
  *
17
- * The returned value's `destroy()` MUST be called when done with it (e.g.
18
- * alongside your `ChunkStreamer.destroy()` call) - the underlying `Worker`
19
- * is a real resource that leaks otherwise. `ChunkSource` itself has no
20
- * lifecycle hook, so this is not automatic.
17
+ * The returned value's `destroy()` MUST be called when done with it - the
18
+ * underlying `Worker` is a real resource that leaks otherwise.
19
+ * {@link import('./ChunkStreamer').ChunkStreamer} does not own the source it
20
+ * is given and never calls this for you: `ChunkSource` itself has no
21
+ * lifecycle hook, so nothing ties the two together automatically. Call it
22
+ * yourself alongside your own `ChunkStreamer.destroy()` call.
21
23
  *
22
24
  * Implementation note: `workerSource` is Blob-URL'd into a real `Worker`
23
25
  * (`new Blob([workerSource])` → `URL.createObjectURL` → `new Worker(url)`) -
@@ -1 +1 @@
1
- {"version":3,"file":"WorkerSampledChunkSource.js","names":[],"sources":["../../src/WorkerSampledChunkSource.ts"],"sourcesContent":["import type { ChunkPayload, ChunkSource } from './ChunkSource';\nimport type { TileLayer } from './TileLayer';\nimport type { ResolvedTile } from './types';\nimport { packTile } from './types';\n\n/**\n * Options for {@link createWorkerSampledChunkSource}.\n * @advanced\n */\nexport interface WorkerSampledChunkSourceOptions {\n /**\n * Complete worker script source as a single self-contained string, Blob-URL'd\n * into a real `Worker` at construction time - the same technique\n * {@link import('@codexo/exojs').WorkletEffect} uses for AudioWorklet\n * processors. No separate worker asset is fetched and no bundler-specific\n * worker-import syntax is involved.\n *\n * Producing that string by hand-writing JavaScript into a template literal\n * works but gives up type checking, linting and shared code. Prefer a build\n * step that bundles a real module into a string: this repository's own\n * examples are authored as `*.worker.ts` and imported through a `?worker`\n * query, which is why they can `import` the sampling functions the main\n * thread uses instead of restating them.\n *\n * Must implement this request/response protocol:\n * - Request (received via `self.onmessage`):\n * `{ requestId: number; cx: number; cy: number; chunkWidth: number; chunkHeight: number }`.\n * - Response, success (send via `self.postMessage`, transferring the\n * buffer for a zero-copy handoff - `postMessage(response, [response.values.buffer])`):\n * `{ requestId: number; values: Float64Array }`, `values.length ===\n * chunkWidth * chunkHeight`, row-major (`localTy * chunkWidth + localTx`),\n * one sampled value per tile in the requested chunk. Compute each tile's\n * absolute coordinate as `cx * chunkWidth + localTx` /\n * `cy * chunkHeight + localTy`.\n * - Response, error (one request failed without crashing the worker):\n * `{ requestId: number; error: string }`.\n *\n * Your worker must reply to every request with exactly one success or\n * error message bearing the same `requestId`. A request left unanswered\n * leaves that chunk permanently unfetched - there is no timeout - since\n * `ChunkStreamer` tracks it as still in flight and never retries it.\n */\n workerSource: string;\n /**\n * Posted to the worker once, before any chunk request, when present.\n *\n * The transport for whatever the sampler needs to know that is not per-chunk\n * - a seed, a feature size, a cost knob. Without it those values would have\n * to be interpolated into {@link WorkerSampledChunkSourceOptions.workerSource}\n * as literals, which turns every parameter change into a source rebuild and a\n * new `Worker`.\n *\n * `postMessage` delivery is ordered, so the worker is guaranteed to see this\n * before the first request. Distinguish it from a chunk request by its own\n * shape; requests carry a `requestId`.\n */\n initMessage?: unknown;\n /**\n * Convert a sampled value (and its absolute tile coordinate) into a\n * resolved tile, or `null` for an empty cell. Always runs on the main\n * thread - a `ResolvedTile` references a `TileSet`/`Texture`, neither of\n * which can cross a `postMessage` boundary. Must be pure and\n * deterministic, same requirement as\n * {@link import('./SampledChunkSource').SampledChunkSourceOptions.mapValueToTile}.\n */\n mapValueToTile(value: number, tx: number, ty: number): ResolvedTile | null;\n}\n\ninterface WorkerRequestMessage {\n readonly requestId: number;\n readonly cx: number;\n readonly cy: number;\n readonly chunkWidth: number;\n readonly chunkHeight: number;\n}\n\ninterface WorkerSuccessMessage {\n readonly requestId: number;\n readonly values: Float64Array;\n}\n\ninterface WorkerErrorMessage {\n readonly requestId: number;\n readonly error: string;\n}\n\ntype WorkerResponseMessage = WorkerSuccessMessage | WorkerErrorMessage;\n\nconst isWorkerErrorMessage = (message: WorkerResponseMessage): message is WorkerErrorMessage => 'error' in message;\n\ninterface PendingRequest {\n readonly resolve: (payload: ChunkPayload | null) => void;\n readonly reject: (error: Error) => void;\n readonly cx: number;\n readonly cy: number;\n readonly chunkWidth: number;\n readonly chunkHeight: number;\n}\n\n/**\n * Build a {@link import('./ChunkStreamer').ChunkStreamer}-ready\n * {@link ChunkSource} that samples off the main thread via a Web Worker -\n * the async counterpart to\n * {@link import('./SampledChunkSource').createSampledChunkSource}, for\n * sampling functions expensive enough to want off-thread execution.\n *\n * Unlike the synchronous provider, sampling logic cannot be passed as a\n * live function - functions cannot cross a `postMessage` boundary. Instead\n * {@link WorkerSampledChunkSourceOptions.workerSource} is a self-contained\n * worker script string; see its documentation for the protocol.\n *\n * The returned value's `destroy()` MUST be called when done with it (e.g.\n * alongside your `ChunkStreamer.destroy()` call) - the underlying `Worker`\n * is a real resource that leaks otherwise. `ChunkSource` itself has no\n * lifecycle hook, so this is not automatic.\n *\n * Implementation note: `workerSource` is Blob-URL'd into a real `Worker`\n * (`new Blob([workerSource])` → `URL.createObjectURL` → `new Worker(url)`) -\n * the same technique {@link import('@codexo/exojs').WorkletEffect} already\n * uses for AudioWorklet processors. This is bundler-agnostic (no special\n * config needed in Vite/webpack/etc.) but requires a Content-Security-Policy\n * that permits `blob:` in `worker-src` (or `script-src` as a fallback) if\n * your deployment sets one.\n * @advanced\n */\nexport const createWorkerSampledChunkSource = (layer: TileLayer, options: WorkerSampledChunkSourceOptions): ChunkSource & { destroy(): void } => {\n const mapValueToTile = options.mapValueToTile.bind(options);\n\n const blob = new Blob([options.workerSource], { type: 'application/javascript' });\n const url = URL.createObjectURL(blob);\n const worker = new Worker(url);\n URL.revokeObjectURL(url);\n\n if (options.initMessage !== undefined) {\n worker.postMessage(options.initMessage);\n }\n\n let requestCounter = 0;\n const pending = new Map<number, PendingRequest>();\n let destroyed = false;\n\n const composePayload = (values: Float64Array, request: PendingRequest): ChunkPayload | null => {\n const { cx, cy, chunkWidth, chunkHeight } = request;\n const startTx = cx * chunkWidth;\n const startTy = cy * chunkHeight;\n\n let out: Uint32Array | null = null;\n for (let ty = startTy; ty < startTy + chunkHeight; ty++) {\n for (let tx = startTx; tx < startTx + chunkWidth; tx++) {\n // Bounded-layer edge chunks may be smaller than a full chunk - same\n // clamp createSampledChunkSource applies, computed here (not asked\n // of the worker) since only this side knows the layer's bounds.\n if (layer.width !== undefined && layer.height !== undefined && (tx >= layer.width || ty >= layer.height)) continue;\n\n const localIndex = (ty - startTy) * chunkWidth + (tx - startTx);\n const value = values[localIndex];\n if (value === undefined) continue; // defensive: malformed/short values array\n const resolved = mapValueToTile(value, tx, ty);\n if (!resolved) continue;\n\n out ??= new Uint32Array(chunkWidth * chunkHeight);\n const tilesetIndex = layer.tilesets.indexOf(resolved.tileset);\n out[localIndex] = packTile(tilesetIndex, resolved.localTileId, resolved.transform);\n }\n }\n\n return out === null ? null : { width: chunkWidth, height: chunkHeight, tiles: out };\n };\n\n worker.onmessage = (event: MessageEvent<WorkerResponseMessage>): void => {\n const message = event.data;\n const entry = pending.get(message.requestId);\n if (!entry) return; // stale/unknown requestId (e.g. arrived after destroy())\n pending.delete(message.requestId);\n\n if (isWorkerErrorMessage(message)) {\n entry.reject(new Error(message.error));\n return;\n }\n\n entry.resolve(composePayload(message.values, entry));\n };\n\n worker.onerror = (event: ErrorEvent): void => {\n const error = new Error(`WorkerSampledChunkSource worker error: ${event.message}`);\n for (const entry of pending.values()) {\n entry.reject(error);\n }\n pending.clear();\n };\n\n return {\n getChunk(cx: number, cy: number): Promise<ChunkPayload | null> {\n if (destroyed) {\n return Promise.reject(new Error('WorkerSampledChunkSource: getChunk() called after destroy().'));\n }\n\n const chunkWidth = layer.chunkWidth;\n const chunkHeight = layer.chunkHeight;\n const requestId = ++requestCounter;\n\n return new Promise<ChunkPayload | null>((resolve, reject) => {\n pending.set(requestId, { resolve, reject, cx, cy, chunkWidth, chunkHeight });\n const request: WorkerRequestMessage = { requestId, cx, cy, chunkWidth, chunkHeight };\n worker.postMessage(request);\n });\n },\n\n destroy(): void {\n if (destroyed) return;\n destroyed = true;\n const error = new Error('WorkerSampledChunkSource destroyed.');\n for (const entry of pending.values()) {\n entry.reject(error);\n }\n pending.clear();\n worker.terminate();\n },\n };\n};\n"],"mappings":";;;AAwFA,MAAM,wBAAwB,YAAkE,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqC3G,MAAa,kCAAkC,OAAkB,YAAgF;CAC/I,MAAM,iBAAiB,QAAQ,eAAe,KAAK,OAAO;CAE1D,MAAM,OAAO,IAAI,KAAK,CAAC,QAAQ,YAAY,GAAG,EAAE,MAAM,yBAAyB,CAAC;CAChF,MAAM,MAAM,IAAI,gBAAgB,IAAI;CACpC,MAAM,SAAS,IAAI,OAAO,GAAG;CAC7B,IAAI,gBAAgB,GAAG;CAEvB,IAAI,QAAQ,gBAAgB,QAC1B,OAAO,YAAY,QAAQ,WAAW;CAGxC,IAAI,iBAAiB;CACrB,MAAM,0BAAU,IAAI,IAA4B;CAChD,IAAI,YAAY;CAEhB,MAAM,kBAAkB,QAAsB,YAAiD;EAC7F,MAAM,EAAE,IAAI,IAAI,Y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AGjG,MAAM,aAAa,MAAM;GACzB,MAAM,cAAc,MAAM;GAC1B,MAAM,YAAY,EAAE;GAEpB,OAAO,IAAI,SAA8B,SAAS,WAAW;IAC3D,QAAQ,IAAI,WAAW;KAAE;KAAS;KAAQ;KAAI;KAAI;KAAY;IAAY,CAAC;IAC3E,MAAM,UAAgC;KAAE;KAAW;KAAI;KAAI;KAAY;IAAY;IACnF,OAAO,YAAY,OAAO;GAC5B,CAAC;EACH;EAEA,UAAgB;GACd,IAAI,WAAW;GACf,YAAY;GACZ,MAAM,wBAAQ,IAAI,MAAM,qCAAqC;GAC7D,KAAK,MAAM,SAAS,QAAQ,OAAO,GACjC,MAAM,OAAO,KAAK;GAEpB,QAAQ,MAAM;GACd,OAAO,UAAU;EACnB;CACF;AACF"}
1
+ {"version":3,"file":"WorkerSampledChunkSource.js","names":[],"sources":["../../src/WorkerSampledChunkSource.ts"],"sourcesContent":["import type { ChunkPayload, ChunkSource } from './ChunkSource';\nimport type { TileLayer } from './TileLayer';\nimport type { ResolvedTile } from './types';\nimport { packTile } from './types';\n\n/**\n * Options for {@link createWorkerSampledChunkSource}.\n * @advanced\n */\nexport interface WorkerSampledChunkSourceOptions {\n /**\n * Complete worker script source as a single self-contained string, Blob-URL'd\n * into a real `Worker` at construction time - the same technique\n * {@link import('@codexo/exojs').WorkletEffect} uses for AudioWorklet\n * processors. No separate worker asset is fetched and no bundler-specific\n * worker-import syntax is involved.\n *\n * Producing that string by hand-writing JavaScript into a template literal\n * works but gives up type checking, linting and shared code. Prefer a build\n * step that bundles a real module into a string: this repository's own\n * examples are authored as `*.worker.ts` and imported through a `?worker`\n * query, which is why they can `import` the sampling functions the main\n * thread uses instead of restating them.\n *\n * Must implement this request/response protocol:\n * - Request (received via `self.onmessage`):\n * `{ requestId: number; cx: number; cy: number; chunkWidth: number; chunkHeight: number }`.\n * - Response, success (send via `self.postMessage`, transferring the\n * buffer for a zero-copy handoff - `postMessage(response, [response.values.buffer])`):\n * `{ requestId: number; values: Float64Array }`, `values.length ===\n * chunkWidth * chunkHeight`, row-major (`localTy * chunkWidth + localTx`),\n * one sampled value per tile in the requested chunk. Compute each tile's\n * absolute coordinate as `cx * chunkWidth + localTx` /\n * `cy * chunkHeight + localTy`.\n * - Response, error (one request failed without crashing the worker):\n * `{ requestId: number; error: string }`.\n *\n * Your worker must reply to every request with exactly one success or\n * error message bearing the same `requestId`. A request left unanswered\n * leaves that chunk permanently unfetched - there is no timeout - since\n * `ChunkStreamer` tracks it as still in flight and never retries it.\n */\n workerSource: string;\n /**\n * Posted to the worker once, before any chunk request, when present.\n *\n * The transport for whatever the sampler needs to know that is not per-chunk\n * - a seed, a feature size, a cost knob. Without it those values would have\n * to be interpolated into {@link WorkerSampledChunkSourceOptions.workerSource}\n * as literals, which turns every parameter change into a source rebuild and a\n * new `Worker`.\n *\n * `postMessage` delivery is ordered, so the worker is guaranteed to see this\n * before the first request. Distinguish it from a chunk request by its own\n * shape; requests carry a `requestId`.\n */\n initMessage?: unknown;\n /**\n * Convert a sampled value (and its absolute tile coordinate) into a\n * resolved tile, or `null` for an empty cell. Always runs on the main\n * thread - a `ResolvedTile` references a `TileSet`/`Texture`, neither of\n * which can cross a `postMessage` boundary. Must be pure and\n * deterministic, same requirement as\n * {@link import('./SampledChunkSource').SampledChunkSourceOptions.mapValueToTile}.\n */\n mapValueToTile(value: number, tx: number, ty: number): ResolvedTile | null;\n}\n\ninterface WorkerRequestMessage {\n readonly requestId: number;\n readonly cx: number;\n readonly cy: number;\n readonly chunkWidth: number;\n readonly chunkHeight: number;\n}\n\ninterface WorkerSuccessMessage {\n readonly requestId: number;\n readonly values: Float64Array;\n}\n\ninterface WorkerErrorMessage {\n readonly requestId: number;\n readonly error: string;\n}\n\ntype WorkerResponseMessage = WorkerSuccessMessage | WorkerErrorMessage;\n\nconst isWorkerErrorMessage = (message: WorkerResponseMessage): message is WorkerErrorMessage => 'error' in message;\n\ninterface PendingRequest {\n readonly resolve: (payload: ChunkPayload | null) => void;\n readonly reject: (error: Error) => void;\n readonly cx: number;\n readonly cy: number;\n readonly chunkWidth: number;\n readonly chunkHeight: number;\n}\n\n/**\n * Build a {@link import('./ChunkStreamer').ChunkStreamer}-ready\n * {@link ChunkSource} that samples off the main thread via a Web Worker -\n * the async counterpart to\n * {@link import('./SampledChunkSource').createSampledChunkSource}, for\n * sampling functions expensive enough to want off-thread execution.\n *\n * Unlike the synchronous provider, sampling logic cannot be passed as a\n * live function - functions cannot cross a `postMessage` boundary. Instead\n * {@link WorkerSampledChunkSourceOptions.workerSource} is a self-contained\n * worker script string; see its documentation for the protocol.\n *\n * The returned value's `destroy()` MUST be called when done with it - the\n * underlying `Worker` is a real resource that leaks otherwise.\n * {@link import('./ChunkStreamer').ChunkStreamer} does not own the source it\n * is given and never calls this for you: `ChunkSource` itself has no\n * lifecycle hook, so nothing ties the two together automatically. Call it\n * yourself alongside your own `ChunkStreamer.destroy()` call.\n *\n * Implementation note: `workerSource` is Blob-URL'd into a real `Worker`\n * (`new Blob([workerSource])` → `URL.createObjectURL` → `new Worker(url)`) -\n * the same technique {@link import('@codexo/exojs').WorkletEffect} already\n * uses for AudioWorklet processors. This is bundler-agnostic (no special\n * config needed in Vite/webpack/etc.) but requires a Content-Security-Policy\n * that permits `blob:` in `worker-src` (or `script-src` as a fallback) if\n * your deployment sets one.\n * @advanced\n */\nexport const createWorkerSampledChunkSource = (layer: TileLayer, options: WorkerSampledChunkSourceOptions): ChunkSource & { destroy(): void } => {\n const mapValueToTile = options.mapValueToTile.bind(options);\n\n const blob = new Blob([options.workerSource], { type: 'application/javascript' });\n const url = URL.createObjectURL(blob);\n const worker = new Worker(url);\n URL.revokeObjectURL(url);\n\n if (options.initMessage !== undefined) {\n worker.postMessage(options.initMessage);\n }\n\n let requestCounter = 0;\n const pending = new Map<number, PendingRequest>();\n let destroyed = false;\n\n const composePayload = (values: Float64Array, request: PendingRequest): ChunkPayload | null => {\n const { cx, cy, chunkWidth, chunkHeight } = request;\n const startTx = cx * chunkWidth;\n const startTy = cy * chunkHeight;\n\n let out: Uint32Array | null = null;\n for (let ty = startTy; ty < startTy + chunkHeight; ty++) {\n for (let tx = startTx; tx < startTx + chunkWidth; tx++) {\n // Bounded-layer edge chunks may be smaller than a full chunk - same\n // clamp createSampledChunkSource applies, computed here (not asked\n // of the worker) since only this side knows the layer's bounds.\n if (layer.width !== undefined && layer.height !== undefined && (tx >= layer.width || ty >= layer.height)) continue;\n\n const localIndex = (ty - startTy) * chunkWidth + (tx - startTx);\n const value = values[localIndex];\n if (value === undefined) continue; // defensive: malformed/short values array\n const resolved = mapValueToTile(value, tx, ty);\n if (!resolved) continue;\n\n out ??= new Uint32Array(chunkWidth * chunkHeight);\n const tilesetIndex = layer.tilesets.indexOf(resolved.tileset);\n out[localIndex] = packTile(tilesetIndex, resolved.localTileId, resolved.transform);\n }\n }\n\n return out === null ? null : { width: chunkWidth, height: chunkHeight, tiles: out };\n };\n\n worker.onmessage = (event: MessageEvent<WorkerResponseMessage>): void => {\n const message = event.data;\n const entry = pending.get(message.requestId);\n if (!entry) return; // stale/unknown requestId (e.g. arrived after destroy())\n pending.delete(message.requestId);\n\n if (isWorkerErrorMessage(message)) {\n entry.reject(new Error(message.error));\n return;\n }\n\n entry.resolve(composePayload(message.values, entry));\n };\n\n worker.onerror = (event: ErrorEvent): void => {\n const error = new Error(`WorkerSampledChunkSource worker error: ${event.message}`);\n for (const entry of pending.values()) {\n entry.reject(error);\n }\n pending.clear();\n };\n\n return {\n getChunk(cx: number, cy: number): Promise<ChunkPayload | null> {\n if (destroyed) {\n return Promise.reject(new Error('WorkerSampledChunkSource: getChunk() called after destroy().'));\n }\n\n const chunkWidth = layer.chunkWidth;\n const chunkHeight = layer.chunkHeight;\n const requestId = ++requestCounter;\n\n return new Promise<ChunkPayload | null>((resolve, reject) => {\n pending.set(requestId, { resolve, reject, cx, cy, chunkWidth, chunkHeight });\n const request: WorkerRequestMessage = { requestId, cx, cy, chunkWidth, chunkHeight };\n worker.postMessage(request);\n });\n },\n\n destroy(): void {\n if (destroyed) return;\n destroyed = true;\n const error = new Error('WorkerSampledChunkSource destroyed.');\n for (const entry of pending.values()) {\n entry.reject(error);\n }\n pending.clear();\n worker.terminate();\n },\n };\n};\n"],"mappings":";;;AAwFA,MAAM,wBAAwB,YAAkE,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuC3G,MAAa,kCAAkC,OAAkB,YAAgF;CAC/I,MAAM,iBAAiB,QAAQ,eAAe,KAAK,OAAO;CAE1D,MAAM,OAAO,IAAI,KAAK,CAAC,QAAQ,YAAY,GAAG,EAAE,MAAM,yBAAyB,CAAC;CAChF,MAAM,MAAM,IAAI,gBAAgB,IAAI;CACpC,MAAM,SAAS,IAAI,OAAO,GAAG;CAC7B,IAAI,gBAAgB,GAAG;CAEvB,IAAI,QAAQ,gBAAgB,QAC1B,OAAO,YAAY,QAAQ,WAAW;CAGxC,IAAI,iBAAiB;CACrB,MAAM,0BAAU,IAAI,IAA4B;CAChD,IAAI,YAAY;CAEhB,MAAM,kBAAkB,QAAsB,YAAiD;EAC7F,MAAM,EAAE,IAAI,IAAI,YAAY,gBAAgB;EAC5C,MAAM,UAAU,KAAK;EACrB,MAAM,UAAU,KAAK;EAErB,IAAI,MAA0B;EAC9B,KAAK,IAAI,KAAK,SAAS,KAAK,UAAU,aAAa,MACjD,KAAK,IAAI,KAAK,SAAS,KAAK,UAAU,YAAY,MAAM;GAItD,IAAI,MAAM,UAAU,UAAa,MAAM,WAAW,WAAc,MAAM,MAAM,SAAS,MAAM,MAAM,SAAS;GAE1G,MAAM,cAAc,KAAK,WAAW,cAAc,KAAK;GACvD,MAAM,QAAQ,OAAO;GACrB,IAAI,UAAU,QAAW;GACzB,MAAM,WAAW,eAAe,OAAO,IAAI,EAAE;GAC7C,IAAI,CAAC,UAAU;GAEf,QAAQ,IAAI,YAAY,aAAa,WAAW;GAChD,MAAM,eAAe,MAAM,SAAS,QAAQ,SAAS,OAAO;GAC5D,IAAI,cAAc,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import type { ReadonlyTileChunk } from './TileChunk';
3
- import type { TileSet } from './TileSet';
4
- import type { TileTransform } from './types';
5
- /**
6
- * One textured tile quad in chunk-local pixel space.
7
- *
8
- * `u0/v0/u1/v1` are the raw (min/max) source UV bounds of the tile within its
9
- * tileset texture - flip/orientation is **not** baked here; it travels in
10
- * {@link TileQuad.orient} and is applied by the per-backend renderer (flipX/Y
11
- * via UV-corner swap, diagonal via an axis swap in the shader). Keeping the
12
- * geometry orientation-neutral lets both backends share one CPU builder.
13
- * @internal
14
- */
15
- export interface TileQuad {
16
- /** Local destination rect, left/top (chunk-local pixels). */
17
- readonly x0: number;
18
- readonly y0: number;
19
- /** Local destination rect, right/bottom (chunk-local pixels). */
20
- readonly x1: number;
21
- readonly y1: number;
22
- /** Normalised source UV bounds (always min ≤ max). */
23
- readonly u0: number;
24
- readonly v0: number;
25
- readonly u1: number;
26
- readonly v1: number;
27
- /** Orientation code: bit0 = flipX, bit1 = flipY, bit2 = diagonal. */
28
- readonly orient: number;
29
- }
30
- /**
31
- * Geometry for one tileset "page" within a chunk: every tile in the chunk that
32
- * draws from a single tileset texture, grouped so the renderer can batch by
33
- * `(shader, texture)`.
34
- * @internal
35
- */
36
- export interface ChunkPage {
37
- /** The tileset all quads in this page draw from. */
38
- readonly tileset: TileSet;
39
- /** The underlying GPU texture (the tileset's atlas), bound once per page. */
40
- readonly texture: Texture;
41
- /** The tile quads for this page, in deterministic row-major order. */
42
- readonly quads: readonly TileQuad[];
43
- }
44
- /** Pack a {@link TileTransform} into a 3-bit orientation code. @internal */
45
- export declare const orientCode: (transform: TileTransform) => number;
46
- /** Read the cumulative chunk-geometry rebuild count. @internal */
47
- export declare const getTileGeometryRebuildCount: () => number;
48
- /** Reset the chunk-geometry rebuild counter (call before a measured frame). @internal */
49
- export declare const resetTileGeometryRebuildCount: () => void;
50
- /**
51
- * Build per-tileset page geometry for a single chunk.
52
- *
53
- * Iterates the chunk's packed cells in deterministic row-major order, skipping
54
- * empties, out-of-range tilesets, and out-of-range local tile ids (all treated
55
- * as empty - this is the renderer's half of the G-GID contract). Each surviving
56
- * cell is resolved to its source UV rect (from `tileset.getTileRect` + the
57
- * tileset `TextureRegion`) and a chunk-local destination rect (bottom-left
58
- * aligned per Tiled orthogonal semantics, so tilesets whose tiles are taller
59
- * than the map grid extend upward).
60
- *
61
- * Allocation happens here only - the result is cached on the owning
62
- * {@link import('./TileChunkNode').TileChunkNode} keyed by `chunk.revision`, so
63
- * unchanged chunks never rebuild and the per-frame path stays allocation-free.
64
- *
65
- * @param chunk The readonly chunk view to build from.
66
- * @param tilesets The layer's tileset array (packed `tilesetIndex` selects one).
67
- * @param tileWidth Map/layer tile cell width in pixels.
68
- * @param tileHeight Map/layer tile cell height in pixels.
69
- * @internal
70
- */
71
- export declare const buildChunkPages: (chunk: ReadonlyTileChunk, tilesets: readonly TileSet[], tileWidth: number, tileHeight: number) => ChunkPage[];
1
+ export {};
72
2
  //# sourceMappingURL=chunkGeometry.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"chunkGeometry.d.ts","sourceRoot":"","sources":["../../src/chunkGeometry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAE7C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAG7C;;;;;;;;;GASG;AACH,MAAM,WAAW,QAAQ;IACvB,6DAA6D;IAC7D,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,iEAAiE;IACjE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,sDAAsD;IACtD,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,qEAAqE;IACrE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED;;;;;GAKG;AACH,MAAM,WAAW,SAAS;IACxB,oDAAoD;IACpD,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,6EAA6E;IAC7E,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,sEAAsE;IACtE,QAAQ,CAAC,KAAK,EAAE,SAAS,QAAQ,EAAE,CAAC;CACrC;AAED,4EAA4E;AAC5E,eAAO,MAAM,UAAU,GAAI,WAAW,aAAa,KAAG,MAA8F,CAAC;AASrJ,kEAAkE;AAClE,eAAO,MAAM,2BAA2B,QAAO,MAAkC,CAAC;AAElF,yFAAyF;AACzF,eAAO,MAAM,6BAA6B,QAAO,IAEhD,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,eAAe,GAAI,OAAO,iBAAiB,EAAE,UAAU,SAAS,OAAO,EAAE,EAAE,WAAW,MAAM,EAAE,YAAY,MAAM,KAAG,SAAS,EAyFxI,CAAC"}
1
+ {"version":3,"file":"chunkGeometry.d.ts","sourceRoot":"","sources":["../../src/chunkGeometry.ts"],"names":[],"mappings":""}
@@ -1,20 +1,2 @@
1
- import type { SceneNode } from '@codexo/exojs';
2
- import { Rectangle } from '@codexo/exojs';
3
- /**
4
- * Grow `out` to the union of `children`'s local bounds, each transformed by
5
- * the child's own (translation-only, in practice) local transform - i.e. the
6
- * children's combined extent expressed in the *parent's* local coordinate
7
- * space, not the parent's own position/scale/rotation.
8
- *
9
- * Used as the unbounded-layer/-map fallback for `getLocalBounds()`: `Container`
10
- * does not aggregate children into its own local bounds automatically (only
11
- * `getBounds()` - global - does that), so nodes that want a children-derived
12
- * local rect must compute it explicitly. Mirrors `Container.updateBounds()`'s
13
- * own aggregation semantics, including skipping invisible children. Callers
14
- * are expected to only invoke this when `children.length > 0`; `out` is left
15
- * untouched otherwise (also guarded internally in case a future call site
16
- * forgets to check).
17
- * @internal
18
- */
19
- export declare const aggregateChildLocalBounds: (children: readonly SceneNode[], out: Rectangle) => void;
1
+ export {};
20
2
  //# sourceMappingURL=nodeBounds.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"nodeBounds.d.ts","sourceRoot":"","sources":["../../src/nodeBounds.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE1C;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,yBAAyB,GAAI,UAAU,SAAS,SAAS,EAAE,EAAE,KAAK,SAAS,KAAG,IA6B1F,CAAC"}
1
+ {"version":3,"file":"nodeBounds.d.ts","sourceRoot":"","sources":["../../src/nodeBounds.ts"],"names":[],"mappings":""}
@@ -1,13 +1,2 @@
1
- import { PixelSnapMode } from '@codexo/exojs/renderer-sdk';
2
- /**
3
- * Throw a deterministic error when `mode` is not a valid {@link PixelSnapMode}.
4
- *
5
- * Mirrors the core `Drawable` setter's guard so the tilemap node passthroughs
6
- * (`TileMapView` / `TileMapNode` / `TileLayerNode`) reject JavaScript-invalid
7
- * values atomically - even for an empty layer that has no chunk drawable to
8
- * delegate the validation to. Kept local because the core guard is not part of
9
- * the public API surface.
10
- * @internal
11
- */
12
- export declare const assertPixelSnapMode: (mode: PixelSnapMode) => void;
1
+ export {};
13
2
  //# sourceMappingURL=pixelSnap.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"pixelSnap.d.ts","sourceRoot":"","sources":["../../src/pixelSnap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAE3D;;;;;;;;;GASG;AACH,eAAO,MAAM,mBAAmB,GAAI,MAAM,aAAa,KAAG,IASzD,CAAC"}
1
+ {"version":3,"file":"pixelSnap.d.ts","sourceRoot":"","sources":["../../src/pixelSnap.ts"],"names":[],"mappings":""}
@@ -1,12 +1,2 @@
1
- /**
2
- * Tile word packing, shared by both backends and by the shader sources they
3
- * fill: transform-buffer row in the low 29 bits, diagonal flip in bit 29.
4
- * flipX/flipY are baked into the UV bounds at write time, so the shader only
5
- * needs the diagonal axis swap.
6
- *
7
- * @internal
8
- */
9
- export declare const TILE_ROW_MASK = 536870911;
10
- /** @internal */
11
- export declare const TILE_DIAGONAL_BIT = 536870912;
1
+ export {};
12
2
  //# sourceMappingURL=tileWord.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"tileWord.d.ts","sourceRoot":"","sources":["../../src/tileWord.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,eAAO,MAAM,aAAa,YAAa,CAAC;AAExC,gBAAgB;AAChB,eAAO,MAAM,iBAAiB,YAAa,CAAC"}
1
+ {"version":3,"file":"tileWord.d.ts","sourceRoot":"","sources":["../../src/tileWord.ts"],"names":[],"mappings":""}
@@ -1 +1 @@
1
- {"version":3,"file":"tilemapExtension.d.ts","sourceRoot":"","sources":["../../src/tilemapExtension.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAmB,MAAM,0BAA0B,CAAC;AAoC3E;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,gBAAgB,EAAE,SAI7B,CAAC"}
1
+ {"version":3,"file":"tilemapExtension.d.ts","sourceRoot":"","sources":["../../src/tilemapExtension.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAmB,MAAM,0BAA0B,CAAC;AAiC3E;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,gBAAgB,EAAE,SAI7B,CAAC"}
@@ -3,7 +3,7 @@ import { TileMapNode } from "./TileMapNode.js";
3
3
  import { tileMapNodeSerializer } from "./tilemapSerializers.js";
4
4
  import { WebGl2TileChunkRenderer } from "./webgl2/WebGl2TileChunkRenderer.js";
5
5
  import { WebGpuTileChunkRenderer } from "./webgpu/WebGpuTileChunkRenderer.js";
6
- import { RenderBackendType } from "@codexo/exojs/renderer-sdk";
6
+ import { RenderBackendType, defineRendererBinding } from "@codexo/exojs/renderer-sdk";
7
7
 
8
8
  //#region src/tilemapExtension.ts
9
9
  /** Per-tile instance batch size for the WebGL2 tile chunk renderer. */
@@ -16,13 +16,10 @@ const tileRendererBatchSize = 4096;
16
16
  * {@link import('./TileLayerNode').TileLayerNode}, whose chunk children resolve
17
17
  * to this renderer through the registry prototype walk.
18
18
  */
19
- const buildTileChunkRendererBinding = (batchSize) => ({
20
- targets: [TileChunkNode],
21
- create(backend) {
22
- if (backend.backendType === RenderBackendType.WebGl2) return new WebGl2TileChunkRenderer(batchSize);
23
- if (backend.backendType === RenderBackendType.WebGpu) return new WebGpuTileChunkRenderer();
24
- throw new Error(`Unsupported render backend: ${String(backend.backendType)}`);
25
- }
19
+ const buildTileChunkRendererBinding = (batchSize) => defineRendererBinding([TileChunkNode], (backend) => {
20
+ if (backend.backendType === RenderBackendType.WebGl2) return new WebGl2TileChunkRenderer(batchSize);
21
+ if (backend.backendType === RenderBackendType.WebGpu) return new WebGpuTileChunkRenderer();
22
+ throw new Error(`Unsupported render backend: ${String(backend.backendType)}`);
26
23
  });
27
24
  /**
28
25
  * Default immutable tilemap extension descriptor.