@codexo/exojs-tilemap 0.17.0 → 0.19.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.
- package/README.md +84 -109
- package/dist/esm/ChunkStreamer.d.ts.map +1 -1
- package/dist/esm/ChunkStreamer.js +28 -6
- package/dist/esm/ChunkStreamer.js.map +1 -1
- package/dist/esm/ImageLayer.d.ts +1 -1
- package/dist/esm/ImageLayer.d.ts.map +1 -1
- package/dist/esm/ImageLayerNode.d.ts +5 -1
- package/dist/esm/ImageLayerNode.d.ts.map +1 -1
- package/dist/esm/ImageLayerNode.js +7 -2
- package/dist/esm/ImageLayerNode.js.map +1 -1
- package/dist/esm/MapObject.d.ts +2 -2
- package/dist/esm/MapObject.d.ts.map +1 -1
- package/dist/esm/MapObject.js.map +1 -1
- package/dist/esm/MapObjectSpawner.d.ts.map +1 -1
- package/dist/esm/MapSpawnSession.d.ts.map +1 -1
- package/dist/esm/MapWorld.d.ts +8 -8
- package/dist/esm/MapWorld.d.ts.map +1 -1
- package/dist/esm/MapWorldRuntime.d.ts.map +1 -1
- package/dist/esm/ObjectLayer.d.ts +26 -10
- package/dist/esm/ObjectLayer.d.ts.map +1 -1
- package/dist/esm/ObjectLayer.js +28 -0
- package/dist/esm/ObjectLayer.js.map +1 -1
- package/dist/esm/SampledChunkSource.d.ts.map +1 -1
- package/dist/esm/TileAnimator.d.ts.map +1 -1
- package/dist/esm/TileChunk.d.ts.map +1 -1
- package/dist/esm/TileChunkNode.js +47 -10
- package/dist/esm/TileChunkNode.js.map +1 -1
- package/dist/esm/TileLayer.d.ts +11 -2
- package/dist/esm/TileLayer.d.ts.map +1 -1
- package/dist/esm/TileLayer.js +20 -10
- package/dist/esm/TileLayer.js.map +1 -1
- package/dist/esm/TileLayerNode.d.ts +12 -5
- package/dist/esm/TileLayerNode.d.ts.map +1 -1
- package/dist/esm/TileLayerNode.js +44 -24
- package/dist/esm/TileLayerNode.js.map +1 -1
- package/dist/esm/TileMap.d.ts +6 -2
- package/dist/esm/TileMap.d.ts.map +1 -1
- package/dist/esm/TileMap.js +13 -12
- package/dist/esm/TileMap.js.map +1 -1
- package/dist/esm/TileMapBand.d.ts.map +1 -1
- package/dist/esm/TileMapNode.d.ts +6 -1
- package/dist/esm/TileMapNode.d.ts.map +1 -1
- package/dist/esm/TileMapNode.js +12 -4
- package/dist/esm/TileMapNode.js.map +1 -1
- package/dist/esm/TileMapView.d.ts +6 -1
- package/dist/esm/TileMapView.d.ts.map +1 -1
- package/dist/esm/TileMapView.js +9 -4
- package/dist/esm/TileMapView.js.map +1 -1
- package/dist/esm/TileProjection.d.ts +59 -0
- package/dist/esm/TileProjection.d.ts.map +1 -0
- package/dist/esm/TileProjection.js +106 -0
- package/dist/esm/TileProjection.js.map +1 -0
- package/dist/esm/TileSet.d.ts.map +1 -1
- package/dist/esm/WangSet.d.ts.map +1 -1
- package/dist/esm/WorkerSampledChunkSource.d.ts +4 -7
- package/dist/esm/WorkerSampledChunkSource.d.ts.map +1 -1
- package/dist/esm/WorkerSampledChunkSource.js +12 -18
- package/dist/esm/WorkerSampledChunkSource.js.map +1 -1
- package/dist/esm/autoTile.d.ts.map +1 -1
- package/dist/esm/chunkGeometry.js +78 -50
- package/dist/esm/chunkGeometry.js.map +1 -1
- package/dist/esm/index.js +2 -1
- package/dist/esm/projectObject.d.ts +4 -0
- package/dist/esm/projectObject.d.ts.map +1 -0
- package/dist/esm/projectObject.js +87 -0
- package/dist/esm/projectObject.js.map +1 -0
- package/dist/esm/public.d.ts +1 -0
- package/dist/esm/public.d.ts.map +1 -1
- package/dist/esm/tileCollision.d.ts +2 -2
- package/dist/esm/tileCollision.d.ts.map +1 -1
- package/dist/esm/tileCollision.js +48 -16
- package/dist/esm/tileCollision.js.map +1 -1
- package/dist/esm/tilemapSerializers.js +1 -1
- package/dist/esm/tilemapSerializers.js.map +1 -1
- package/dist/esm/types.d.ts +3 -3
- package/dist/esm/types.d.ts.map +1 -1
- package/dist/esm/webgl2/WebGl2TileChunkRenderer.js +8 -7
- package/dist/esm/webgl2/WebGl2TileChunkRenderer.js.map +1 -1
- package/dist/esm/webgl2/shaders/tile-chunk.frag.js +1 -1
- package/dist/esm/webgl2/shaders/tile-chunk.frag.js.map +1 -1
- package/dist/esm/webgl2/shaders/tile-chunk.vert.js +1 -1
- package/dist/esm/webgl2/shaders/tile-chunk.vert.js.map +1 -1
- package/dist/esm/webgpu/WebGpuTileChunkRenderer.js +67 -31
- package/dist/esm/webgpu/WebGpuTileChunkRenderer.js.map +1 -1
- package/dist/esm/webgpu/shaders/tile-chunk.wgsl.js +1 -1
- package/dist/esm/webgpu/shaders/tile-chunk.wgsl.js.map +1 -1
- package/package.json +4 -4
package/dist/esm/TileLayer.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { packTile, tileToChunkCoord, tileToLocalInChunk, unpackTile, validateInteger, validateNonNegativeInteger, validatePairedDimensions, validatePositiveInteger } from "./types.js";
|
|
2
2
|
import { TileChunk } from "./TileChunk.js";
|
|
3
|
+
import { TileProjection } from "./TileProjection.js";
|
|
3
4
|
|
|
4
5
|
//#region src/TileLayer.ts
|
|
5
6
|
const DEFAULT_CHUNK_SIZE = 32;
|
|
@@ -62,6 +63,7 @@ const validateTileLayerOptions = (options) => {
|
|
|
62
63
|
* @advanced
|
|
63
64
|
*/
|
|
64
65
|
var TileLayer = class {
|
|
66
|
+
projection;
|
|
65
67
|
/** Stable unique ID within the map. */
|
|
66
68
|
id;
|
|
67
69
|
/** Display name (may not be unique). */
|
|
@@ -84,11 +86,11 @@ var TileLayer = class {
|
|
|
84
86
|
}
|
|
85
87
|
/** Pixel width, or `undefined` if unbounded. */
|
|
86
88
|
get pixelWidth() {
|
|
87
|
-
return this.width === void 0 ? void 0 : this.
|
|
89
|
+
return this.width === void 0 || this.height === void 0 ? void 0 : this.projection.getBounds(0, 0, this.width, this.height).width;
|
|
88
90
|
}
|
|
89
91
|
/** Pixel height, or `undefined` if unbounded. */
|
|
90
92
|
get pixelHeight() {
|
|
91
|
-
return this.height === void 0 ? void 0 : this.
|
|
93
|
+
return this.width === void 0 || this.height === void 0 ? void 0 : this.projection.getBounds(0, 0, this.width, this.height).height;
|
|
92
94
|
}
|
|
93
95
|
/** Visibility flag (mutable). */
|
|
94
96
|
visible;
|
|
@@ -143,6 +145,11 @@ var TileLayer = class {
|
|
|
143
145
|
this.chunkHeight = chunkHeight;
|
|
144
146
|
this.tileWidth = options.tileWidth;
|
|
145
147
|
this.tileHeight = options.tileHeight;
|
|
148
|
+
this.projection = options.projection ?? new TileProjection({
|
|
149
|
+
tileWidth: options.tileWidth,
|
|
150
|
+
tileHeight: options.tileHeight
|
|
151
|
+
});
|
|
152
|
+
if (this.projection.tileWidth !== this.tileWidth || this.projection.tileHeight !== this.tileHeight) throw new Error("Projection tile dimensions must match the layer or map.");
|
|
146
153
|
this.tilesets = options.tilesets;
|
|
147
154
|
this.visible = options.visible ?? true;
|
|
148
155
|
this.opacity = opacity;
|
|
@@ -450,15 +457,21 @@ var TileLayer = class {
|
|
|
450
457
|
}
|
|
451
458
|
}
|
|
452
459
|
}
|
|
460
|
+
/** Display layer translation expressed as a logical simulation-space vector. */
|
|
461
|
+
get logicalOffset() {
|
|
462
|
+
const p = this.projection;
|
|
463
|
+
return p.pixelToLogical(p.originX + this.offsetX, p.originY + this.offsetY);
|
|
464
|
+
}
|
|
453
465
|
/**
|
|
454
|
-
* Convert a
|
|
455
|
-
*
|
|
466
|
+
* Convert a grid vertex to display pixels (the top diamond vertex for isometric cells)
|
|
467
|
+
* including the layer's display offset.
|
|
456
468
|
* @advanced
|
|
457
469
|
*/
|
|
458
470
|
tileToPixel(tx, ty) {
|
|
471
|
+
const point = this.projection.tileToPixel(tx, ty);
|
|
459
472
|
return {
|
|
460
|
-
x:
|
|
461
|
-
y:
|
|
473
|
+
x: point.x + this.offsetX,
|
|
474
|
+
y: point.y + this.offsetY
|
|
462
475
|
};
|
|
463
476
|
}
|
|
464
477
|
/**
|
|
@@ -468,10 +481,7 @@ var TileLayer = class {
|
|
|
468
481
|
* @advanced
|
|
469
482
|
*/
|
|
470
483
|
pixelToTile(px, py) {
|
|
471
|
-
return
|
|
472
|
-
tx: Math.floor((px - this.offsetX) / this.tileWidth),
|
|
473
|
-
ty: Math.floor((py - this.offsetY) / this.tileHeight)
|
|
474
|
-
};
|
|
484
|
+
return this.projection.pixelToTile(px - this.offsetX, py - this.offsetY);
|
|
475
485
|
}
|
|
476
486
|
/**
|
|
477
487
|
* Monotonic layer revision counter.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TileLayer.js","names":[],"sources":["../../src/TileLayer.ts"],"sourcesContent":["import type { ChunkPayload } from './ChunkSource';\nimport type { ReadonlyTileChunk } from './TileChunk';\nimport { TileChunk } from './TileChunk';\nimport type { TileSet } from './TileSet';\nimport type { TileProperties } from './types';\nimport type { PackedTile, ResolvedTile } from './types';\nimport { packTile, unpackTile, validateInteger, validateNonNegativeInteger, validatePairedDimensions, validatePositiveInteger } from './types';\nimport { tileToChunkCoord, tileToLocalInChunk } from './types';\n\n/**\n * Options for constructing a {@link TileLayer}.\n * @advanced\n */\nexport interface TileLayerOptions {\n /** Stable layer ID (unique within the map). */\n readonly id: number;\n /** Display name (need not be unique). */\n readonly name: string;\n /**\n * Layer width in tiles. Omit together with {@link height} for an\n * unbounded layer - chunk storage then accepts any signed chunk\n * coordinate instead of being clamped to a fixed grid.\n */\n readonly width?: number;\n /** Layer height in tiles. Must be provided iff {@link width} is. */\n readonly height?: number;\n /** Chunk width in tiles (default 32). */\n readonly chunkWidth?: number;\n /** Chunk height in tiles (default 32). */\n readonly chunkHeight?: number;\n /** Tilesets available to this layer (shared with the map). */\n readonly tilesets: readonly TileSet[];\n /** Tile width in pixels (for coordinate conversion). */\n readonly tileWidth: number;\n /** Tile height in pixels (for coordinate conversion). */\n readonly tileHeight: number;\n /** Initial visibility. Default true. */\n readonly visible?: boolean;\n /** Opacity 0..1. Default 1. */\n readonly opacity?: number;\n /** Layer pixel offset X. Default 0. */\n readonly offsetX?: number;\n /** Layer pixel offset Y. Default 0. */\n readonly offsetY?: number;\n /**\n * Parallax scroll factor on the X axis. `1.0` = full camera speed (normal),\n * `0.5` = half speed (farther away), `0.0` = stationary. Default 1.\n */\n readonly parallaxX?: number;\n /**\n * Parallax scroll factor on the Y axis. `1.0` = full camera speed (normal),\n * `0.5` = half speed (farther away), `0.0` = stationary. Default 1.\n */\n readonly parallaxY?: number;\n /**\n * Uniform scale applied together with the camera-relative parallax shift.\n * `1` keeps the layer at its authored size. Default `1`.\n */\n readonly parallaxScale?: number;\n /** Layer class/type string (Tiled `class`). Defaults to `''`. */\n readonly class?: string;\n /**\n * Multiplicative layer tint as a `0xRRGGBB` integer, or `null` for none\n * (Tiled `tintcolor`). Applied to every chunk's render tint. Default `null`.\n */\n readonly tintColor?: number | null;\n /** Layer properties (copied and frozen). */\n readonly properties?: TileProperties;\n}\n\nconst DEFAULT_CHUNK_SIZE = 32;\n\n/**\n * The inclusive range of chunk coordinates that intersect a bounded\n * {@link TileLayer}. `null` for an unbounded layer (no range limit).\n * @advanced\n */\nexport interface ChunkRange {\n readonly minCx: number;\n readonly minCy: number;\n readonly maxCx: number;\n readonly maxCy: number;\n}\n\n/**\n * Fired via {@link TileLayer._addStructuralListener} whenever a chunk is\n * installed ({@link TileLayer._adoptChunk}) or evicted\n * ({@link TileLayer._evictChunk}) - structural changes only, not per-tile\n * edits (see {@link import('./TileChunk').TileChunk._addDirtyListener} for\n * those). `chunk` is `null` on eviction.\n * @internal\n */\nexport interface ChunkStructuralEvent {\n readonly cx: number;\n readonly cy: number;\n readonly chunk: ReadonlyTileChunk | null;\n}\n\n/**\n * Resolved, defaulted subset of {@link TileLayerOptions} produced by\n * {@link validateTileLayerOptions}.\n */\ninterface ResolvedTileLayerOptions {\n readonly chunkWidth: number;\n readonly chunkHeight: number;\n readonly opacity: number;\n readonly offsetX: number;\n readonly offsetY: number;\n readonly parallaxX: number;\n readonly parallaxY: number;\n readonly parallaxScale: number;\n}\n\n/** Resolve and validate the optional uniform parallax scale. */\nconst resolveParallaxScale = (value = 1): number => {\n if (!Number.isFinite(value) || value <= 0) {\n throw new Error('TileLayer parallaxScale must be a positive finite number.');\n }\n\n return value;\n};\n\n/**\n * Validate a {@link TileLayerOptions} bag and resolve its optional fields\n * (chunk size, opacity, offset, parallax) to concrete defaults.\n * @throws When dimensions, chunk size, or other options are invalid.\n */\nconst validateTileLayerOptions = (options: TileLayerOptions): ResolvedTileLayerOptions => {\n validateNonNegativeInteger(options.id, 'layer.id');\n if (!options.name || typeof options.name !== 'string') {\n throw new Error('TileLayer name must be a non-empty string.');\n }\n validatePairedDimensions(options.width, options.height, 'TileLayer', 'layer');\n validatePositiveInteger(options.tileWidth, 'layer.tileWidth');\n validatePositiveInteger(options.tileHeight, 'layer.tileHeight');\n\n const chunkWidth = options.chunkWidth ?? DEFAULT_CHUNK_SIZE;\n const chunkHeight = options.chunkHeight ?? DEFAULT_CHUNK_SIZE;\n validatePositiveInteger(chunkWidth, 'chunkWidth');\n validatePositiveInteger(chunkHeight, 'chunkHeight');\n\n if (!Array.isArray(options.tilesets)) {\n throw new Error('TileLayer tilesets must be an array.');\n }\n\n const opacity = options.opacity ?? 1;\n if (typeof opacity !== 'number' || opacity < 0 || opacity > 1) {\n throw new Error(`TileLayer opacity must be 0..1 (got ${opacity}).`);\n }\n\n const offsetX = options.offsetX ?? 0;\n const offsetY = options.offsetY ?? 0;\n if (!Number.isFinite(offsetX) || !Number.isFinite(offsetY)) {\n throw new Error('TileLayer offset must be finite numbers.');\n }\n\n const parallaxX = options.parallaxX ?? 1;\n const parallaxY = options.parallaxY ?? 1;\n if (!Number.isFinite(parallaxX) || !Number.isFinite(parallaxY)) {\n throw new Error('TileLayer parallax must be finite numbers.');\n }\n\n const parallaxScale = resolveParallaxScale(options.parallaxScale);\n\n return { chunkWidth, chunkHeight, opacity, offsetX, offsetY, parallaxX, parallaxY, parallaxScale };\n};\n\n/**\n * A generic, format-independent tile layer with chunk-first storage.\n *\n * Tile data is stored in fixed-size {@link TileChunk}s indexed by signed\n * chunk coordinates. For finite maps, only chunks that intersect the layer\n * bounds exist.\n *\n * **Mutation must go through the layer's public APIs only.**\n * `setTileAt` / `clearTileAt` validate coordinates, tileset references,\n * and increment revision counters only when the stored value actually\n * changes. Direct chunk mutation is not supported - the layer owns chunk\n * storage and exposes only a {@link ReadonlyTileChunk} view.\n *\n * The layer is NOT a SceneNode - that integration lives in\n * {@link import('./TileLayerNode').TileLayerNode}.\n *\n * @advanced\n */\nexport class TileLayer {\n /** Stable unique ID within the map. */\n public readonly id: number;\n /** Display name (may not be unique). */\n public readonly name: string;\n\n /** Width in tiles, or `undefined` if unbounded. */\n public readonly width: number | undefined;\n /** Height in tiles, or `undefined` if unbounded. */\n public readonly height: number | undefined;\n\n /** Chunk width (tiles). */\n public readonly chunkWidth: number;\n /** Chunk height (tiles). */\n public readonly chunkHeight: number;\n\n /** Tile width in pixels. */\n public readonly tileWidth: number;\n /** Tile height in pixels. */\n public readonly tileHeight: number;\n\n /** `true` if this layer has a fixed width/height; `false` if unbounded. */\n public get bounded(): boolean {\n return this.width !== undefined && this.height !== undefined;\n }\n\n /** Pixel width, or `undefined` if unbounded. */\n public get pixelWidth(): number | undefined {\n return this.width === undefined ? undefined : this.width * this.tileWidth;\n }\n /** Pixel height, or `undefined` if unbounded. */\n public get pixelHeight(): number | undefined {\n return this.height === undefined ? undefined : this.height * this.tileHeight;\n }\n\n /** Visibility flag (mutable). */\n public visible: boolean;\n /** Opacity 0..1 (mutable). */\n public opacity: number;\n /** Horizontal pixel offset (mutable). */\n public offsetX: number;\n /** Vertical pixel offset (mutable). */\n public offsetY: number;\n /**\n * Parallax scroll factor on the X axis.\n * `1.0` = full camera speed, `0.5` = half speed, `0.0` = stationary.\n */\n public readonly parallaxX: number;\n /**\n * Parallax scroll factor on the Y axis.\n * `1.0` = full camera speed, `0.5` = half speed, `0.0` = stationary.\n */\n public readonly parallaxY: number;\n /** Uniform scale applied around the layer origin during parallax rendering. */\n public readonly parallaxScale: number;\n\n /** Layer class/type string (Tiled `class`; may be empty). */\n public readonly class: string;\n /** Multiplicative layer tint as `0xRRGGBB`, or `null` for no tint. */\n public readonly tintColor: number | null;\n\n /** Immutable layer properties. */\n public readonly properties: TileProperties;\n\n /** The tilesets available to this layer (shared array reference). */\n public readonly tilesets: readonly TileSet[];\n\n /** Chunk storage: chunkKey → mutable TileChunk (internal). */\n private readonly _chunks = new Map<string, TileChunk>();\n\n /** Package-internal structural (adopt/evict) listeners. */\n private _structuralListeners: Set<(event: ChunkStructuralEvent) => void> | null = null;\n\n /**\n * Monotonic layer revision counter.\n * Increments on every cell mutation that actually changes a stored value.\n * Does NOT increment on no-op writes or failed mutations.\n */\n private _revision = 0;\n\n /** Whether the layer has been destroyed. */\n private _destroyed = false;\n\n /**\n * @throws When dimensions, chunk size, or other options are invalid.\n */\n public constructor(options: TileLayerOptions) {\n const { chunkWidth, chunkHeight, opacity, offsetX, offsetY, parallaxX, parallaxY, parallaxScale } = validateTileLayerOptions(options);\n\n this.id = options.id;\n this.name = options.name;\n this.width = options.width;\n this.height = options.height;\n this.chunkWidth = chunkWidth;\n this.chunkHeight = chunkHeight;\n this.tileWidth = options.tileWidth;\n this.tileHeight = options.tileHeight;\n this.tilesets = options.tilesets;\n this.visible = options.visible ?? true;\n this.opacity = opacity;\n this.offsetX = offsetX;\n this.offsetY = offsetY;\n this.parallaxX = parallaxX;\n this.parallaxY = parallaxY;\n this.parallaxScale = parallaxScale;\n this.class = options.class ?? '';\n this.tintColor = options.tintColor ?? null;\n this.properties = options.properties ? Object.freeze({ ...options.properties }) : Object.freeze({});\n }\n\n // ── Bounds helpers ────────────────────────────────────────────────────\n\n /**\n * Check whether a tile coordinate lies within the layer bounds.\n * Always `true` for an unbounded layer.\n * @advanced\n */\n public inBounds(tx: number, ty: number): boolean {\n if (this.width === undefined || this.height === undefined) return true;\n return tx >= 0 && tx < this.width && ty >= 0 && ty < this.height;\n }\n\n /**\n * Compute the range of chunk coordinates that intersect this layer, or\n * `null` if the layer is unbounded (any signed chunk coordinate is valid).\n */\n public chunkRange(): ChunkRange | null {\n if (this.width === undefined || this.height === undefined) return null;\n return {\n minCx: 0,\n minCy: 0,\n maxCx: Math.floor((this.width - 1) / this.chunkWidth),\n maxCy: Math.floor((this.height - 1) / this.chunkHeight),\n };\n }\n\n // ── Chunk keying ──────────────────────────────────────────────────────\n\n private _chunkKey(cx: number, cy: number): string {\n return `${cx},${cy}`;\n }\n\n /**\n * Get a readonly view of a chunk by signed chunk coordinates,\n * or undefined if it does not exist (never been touched).\n * @advanced\n */\n public getChunk(cx: number, cy: number): ReadonlyTileChunk | undefined {\n return this._chunks.get(this._chunkKey(cx, cy));\n }\n\n /**\n * Get or create a chunk at the given coordinates.\n * For a bounded layer, creation is only allowed within the valid chunk\n * range and edge chunks are clamped to the layer's remaining size. For an\n * unbounded layer, any signed chunk coordinate is accepted and every\n * chunk is full-size ({@link chunkWidth} × {@link chunkHeight}).\n *\n * @internal Package-private: used by {@link setTileAt}, {@link fillRect},\n * and future adapter ingest. External users should not allocate\n * chunks - use {@link setTileAt} to populate tiles.\n */\n public _ensureChunk(cx: number, cy: number): TileChunk {\n this._checkDestroyed();\n const key = this._chunkKey(cx, cy);\n let chunk = this._chunks.get(key);\n if (!chunk) {\n const range = this.chunkRange();\n let cw = this.chunkWidth;\n let ch = this.chunkHeight;\n if (range !== null && this.width !== undefined && this.height !== undefined) {\n if (cx < range.minCx || cx > range.maxCx || cy < range.minCy || cy > range.maxCy) {\n throw new Error(`Chunk (${cx}, ${cy}) outside layer chunk range ` + `[${range.minCx}..${range.maxCx}, ${range.minCy}..${range.maxCy}].`);\n }\n // Compute the actual tile dimensions for this chunk (edge chunks may be smaller).\n const startTx = cx * this.chunkWidth;\n const startTy = cy * this.chunkHeight;\n cw = Math.min(this.chunkWidth, this.width - startTx);\n ch = Math.min(this.chunkHeight, this.height - startTy);\n }\n chunk = new TileChunk(cx, cy, cw, ch);\n this._chunks.set(key, chunk);\n }\n return chunk;\n }\n\n /**\n * Install a chunk-provider-supplied payload directly, bypassing per-tile\n * `setTileAt` cost. Overwrites any existing chunk at `(cx, cy)`. Always\n * bumps the layer revision (installing a chunk is always a structural\n * change, even if the payload happens to be all-zero).\n *\n * Does not validate `(cx, cy)` against {@link chunkRange} - callers\n * (chunk-streaming controllers) are trusted to request coordinates within\n * whatever range they intend to manage.\n *\n * @internal Package-private: for future chunk-provider/streaming use.\n */\n public _adoptChunk(cx: number, cy: number, payload: ChunkPayload): void {\n this._checkDestroyed();\n const chunk = new TileChunk(cx, cy, payload.width, payload.height, payload.tiles);\n this._chunks.set(this._chunkKey(cx, cy), chunk);\n this._revision++;\n this._notifyStructural({ cx, cy, chunk });\n }\n\n /**\n * Evict a chunk from storage, freeing it for garbage collection. No-op if\n * no chunk is loaded at `(cx, cy)`.\n *\n * @returns `true` if a chunk was found and removed, `false` otherwise.\n * @internal Package-private: for future chunk-streaming eviction use.\n */\n public _evictChunk(cx: number, cy: number): boolean {\n this._checkDestroyed();\n const key = this._chunkKey(cx, cy);\n if (!this._chunks.delete(key)) return false;\n this._revision++;\n this._notifyStructural({ cx, cy, chunk: null });\n return true;\n }\n\n /**\n * Register a callback invoked synchronously whenever a chunk is installed\n * ({@link _adoptChunk}) or evicted ({@link _evictChunk}). Package-internal:\n * {@link import('./TileLayerNode').TileLayerNode} subscribes to keep its\n * chunk-node children in sync with chunk-provider-driven adopt/evict calls\n * (e.g. from {@link import('./ChunkStreamer').ChunkStreamer}) without\n * needing a full {@link import('./TileLayerNode').TileLayerNode.refresh}.\n * @internal\n */\n public _addStructuralListener(listener: (event: ChunkStructuralEvent) => void): void {\n (this._structuralListeners ??= new Set()).add(listener);\n }\n\n /**\n * Unregister a listener added via {@link _addStructuralListener} (node destroy).\n * @internal\n */\n public _removeStructuralListener(listener: (event: ChunkStructuralEvent) => void): void {\n this._structuralListeners?.delete(listener);\n }\n\n private _notifyStructural(event: ChunkStructuralEvent): void {\n if (this._structuralListeners === null) return;\n for (const listener of this._structuralListeners) {\n listener(event);\n }\n }\n\n /**\n * Iterate over all loaded chunks in deterministic (cy, cx) ascending order.\n * Returns readonly chunk views - callers cannot mutate storage.\n * @advanced\n */\n public loadedChunks(): IterableIterator<ReadonlyTileChunk> {\n const entries = [...this._chunks.values()];\n entries.sort((a, b) => a.cy - b.cy || a.cx - b.cx);\n return entries[Symbol.iterator]();\n }\n\n // ── Tile queries ──────────────────────────────────────────────────────\n\n /**\n * Get the raw packed tile word at (tx, ty). Returns 0 for empty or out-of-bounds.\n * @advanced\n */\n public getRawTileAt(tx: number, ty: number): PackedTile {\n validateInteger(tx, 'tx');\n validateInteger(ty, 'ty');\n if (!this.inBounds(tx, ty)) return 0;\n const { cx, cy } = tileToChunkCoord(tx, ty, this.chunkWidth, this.chunkHeight);\n const chunk = this._chunks.get(this._chunkKey(cx, cy));\n if (!chunk) return 0;\n const { lx, ly } = tileToLocalInChunk(tx, ty, this.chunkWidth, this.chunkHeight);\n return chunk.getRawAt(lx, ly);\n }\n\n /**\n * Query a resolved tile at (tx, ty). Returns null for empty or out-of-bounds.\n * @advanced\n */\n public getTileAt(tx: number, ty: number): ResolvedTile | null {\n const packed = this.getRawTileAt(tx, ty);\n if (packed === 0) return null;\n const decoded = unpackTile(packed);\n if (!decoded) return null;\n if (decoded.tilesetIndex >= this.tilesets.length) return null;\n const tileset = this.tilesets[decoded.tilesetIndex]!;\n if (decoded.localTileId >= tileset.tileCount) return null;\n return {\n tileset,\n localTileId: decoded.localTileId,\n transform: decoded.transform,\n };\n }\n\n // ── Mutation ──────────────────────────────────────────────────────────\n\n /**\n * Validate a tile reference against the layer's tilesets.\n * Returns the packed form or throws.\n */\n private _validateTileRef(tile: ResolvedTile): PackedTile {\n if (!tile?.tileset) {\n throw new Error('setTileAt requires a valid ResolvedTile.');\n }\n const tilesetIndex = this.tilesets.indexOf(tile.tileset);\n if (tilesetIndex === -1) {\n throw new Error(`Tileset \"${tile.tileset.name}\" is not available to layer \"${this.name}\".`);\n }\n if (tile.localTileId < 0 || tile.localTileId >= tile.tileset.tileCount) {\n throw new Error(`localTileId ${tile.localTileId} out of range for tileset \"${tile.tileset.name}\" ` + `(max ${tile.tileset.tileCount - 1}).`);\n }\n return packTile(tilesetIndex, tile.localTileId, tile.transform);\n }\n\n /**\n * Set a tile at the given tile coordinates.\n * No-op if the effective value is unchanged.\n * @throws If coordinates are out of bounds or the tile reference is invalid.\n * @advanced\n */\n public setTileAt(tx: number, ty: number, tile: ResolvedTile): void {\n this._checkDestroyed();\n validateInteger(tx, 'tx');\n validateInteger(ty, 'ty');\n if (!this.inBounds(tx, ty)) {\n const boundsMsg = this.width !== undefined && this.height !== undefined ? `[0..${this.width - 1}, 0..${this.height - 1}]` : '[unbounded]';\n throw new Error(`setTileAt (${tx}, ${ty}) out of bounds ${boundsMsg}.`);\n }\n const packed = this._validateTileRef(tile);\n const { cx, cy } = tileToChunkCoord(tx, ty, this.chunkWidth, this.chunkHeight);\n const chunk = this._ensureChunk(cx, cy);\n const { lx, ly } = tileToLocalInChunk(tx, ty, this.chunkWidth, this.chunkHeight);\n if (chunk._setRawAt(lx, ly, packed)) {\n this._revision++;\n }\n }\n\n /**\n * Clear (erase) the tile at the given coordinates.\n * No-op if the cell is already empty.\n * @throws If coordinates are out of bounds.\n * @advanced\n */\n public clearTileAt(tx: number, ty: number): void {\n this._checkDestroyed();\n validateInteger(tx, 'tx');\n validateInteger(ty, 'ty');\n if (!this.inBounds(tx, ty)) {\n const boundsMsg = this.width !== undefined && this.height !== undefined ? `[0..${this.width - 1}, 0..${this.height - 1}]` : '[unbounded]';\n throw new Error(`clearTileAt (${tx}, ${ty}) out of bounds ${boundsMsg}.`);\n }\n const { cx, cy } = tileToChunkCoord(tx, ty, this.chunkWidth, this.chunkHeight);\n const chunk = this._chunks.get(this._chunkKey(cx, cy));\n if (!chunk) return; // no chunk = already empty\n const { lx, ly } = tileToLocalInChunk(tx, ty, this.chunkWidth, this.chunkHeight);\n if (chunk._setRawAt(lx, ly, 0)) {\n this._revision++;\n }\n }\n\n // ── Bulk fill ─────────────────────────────────────────────────────────\n\n /**\n * Fill a rectangular region with a tile.\n * @advanced\n */\n public fillRect(x: number, y: number, w: number, h: number, tile: ResolvedTile): void {\n this._checkDestroyed();\n const packed = this._validateTileRef(tile);\n let changed = false;\n for (let ty = y; ty < y + h; ty++) {\n for (let tx = x; tx < x + w; tx++) {\n if (!this.inBounds(tx, ty)) continue;\n const { cx, cy } = tileToChunkCoord(tx, ty, this.chunkWidth, this.chunkHeight);\n const chunk = this._ensureChunk(cx, cy);\n const { lx, ly } = tileToLocalInChunk(tx, ty, this.chunkWidth, this.chunkHeight);\n if (chunk._setRawAt(lx, ly, packed)) {\n changed = true;\n }\n }\n }\n if (changed) this._revision++;\n }\n\n /**\n * Clear a rectangular region.\n * @advanced\n */\n public clearRect(x: number, y: number, w: number, h: number): void {\n this._checkDestroyed();\n let changed = false;\n for (let ty = y; ty < y + h; ty++) {\n for (let tx = x; tx < x + w; tx++) {\n if (!this.inBounds(tx, ty)) continue;\n const { cx, cy } = tileToChunkCoord(tx, ty, this.chunkWidth, this.chunkHeight);\n const chunk = this._chunks.get(this._chunkKey(cx, cy));\n if (!chunk) continue;\n const { lx, ly } = tileToLocalInChunk(tx, ty, this.chunkWidth, this.chunkHeight);\n if (chunk._setRawAt(lx, ly, 0)) {\n changed = true;\n }\n }\n }\n if (changed) this._revision++;\n }\n\n // ── Iteration ─────────────────────────────────────────────────────────\n\n /**\n * Iterate non-empty tiles within a rectangular region in row-major order.\n * Yields (tx, ty, resolvedTile) tuples. Skips empty cells.\n * @advanced\n */\n public *tilesInRect(x: number, y: number, w: number, h: number): Generator<{ tx: number; ty: number; tile: ResolvedTile }> {\n const startCx = Math.floor(x / this.chunkWidth);\n const endCx = Math.floor((x + w - 1) / this.chunkWidth);\n const startCy = Math.floor(y / this.chunkHeight);\n const endCy = Math.floor((y + h - 1) / this.chunkHeight);\n\n for (let cy = startCy; cy <= endCy; cy++) {\n for (let cx = startCx; cx <= endCx; cx++) {\n const chunk = this._chunks.get(this._chunkKey(cx, cy));\n if (!chunk || chunk.empty) continue;\n\n const chunkStartTx = cx * this.chunkWidth;\n const chunkStartTy = cy * this.chunkHeight;\n const minLx = Math.max(0, x - chunkStartTx);\n const maxLx = Math.min(chunk.width - 1, x + w - 1 - chunkStartTx);\n const minLy = Math.max(0, y - chunkStartTy);\n const maxLy = Math.min(chunk.height - 1, y + h - 1 - chunkStartTy);\n\n for (let ly = minLy; ly <= maxLy; ly++) {\n for (let lx = minLx; lx <= maxLx; lx++) {\n const packed = chunk.getRawAt(lx, ly);\n if (packed === 0) continue;\n const decoded = unpackTile(packed);\n if (!decoded) continue;\n if (decoded.tilesetIndex >= this.tilesets.length) continue;\n const tileset = this.tilesets[decoded.tilesetIndex]!;\n if (decoded.localTileId >= tileset.tileCount) continue;\n yield {\n tx: chunkStartTx + lx,\n ty: chunkStartTy + ly,\n tile: {\n tileset,\n localTileId: decoded.localTileId,\n transform: decoded.transform,\n },\n };\n }\n }\n }\n }\n }\n\n // ── Coordinate conversion ─────────────────────────────────────────────\n\n /**\n * Convert a tile coordinate to the pixel position of its top-left corner\n * in the layer's local space.\n * @advanced\n */\n public tileToPixel(tx: number, ty: number): { x: number; y: number } {\n return {\n x: tx * this.tileWidth + this.offsetX,\n y: ty * this.tileHeight + this.offsetY,\n };\n }\n\n /**\n * Convert a local pixel position to the tile coordinate that contains it.\n * Uses `floor`, so a point exactly on a tile boundary maps to the tile.\n * May return coordinates outside layer bounds.\n * @advanced\n */\n public pixelToTile(px: number, py: number): { tx: number; ty: number } {\n return {\n tx: Math.floor((px - this.offsetX) / this.tileWidth),\n ty: Math.floor((py - this.offsetY) / this.tileHeight),\n };\n }\n\n // ── Revision / lifecycle ──────────────────────────────────────────────\n\n /**\n * Monotonic layer revision counter.\n * Increments on every cell mutation that changes a stored value.\n * No-op writes and failed mutations do NOT increment.\n * @advanced\n */\n public get revision(): number {\n return this._revision;\n }\n\n /** Whether the layer has been destroyed. */\n public get destroyed(): boolean {\n return this._destroyed;\n }\n\n private _checkDestroyed(): void {\n if (this._destroyed) {\n throw new Error(`TileLayer \"${this.name}\" has been destroyed.`);\n }\n }\n\n /**\n * Destroy this layer: clear chunk storage and mark destroyed.\n * Does NOT destroy tileset textures or external resources.\n * Idempotent.\n */\n public destroy(): void {\n if (this._destroyed) return;\n this._destroyed = true;\n this._chunks.clear();\n }\n\n /**\n * Total number of non-empty tiles across all chunks.\n * Walk is cheap for dense layers; sparse layers benefit from empty-chunk fast path.\n * @advanced\n */\n public countNonEmptyTiles(): number {\n let count = 0;\n for (const chunk of this._chunks.values()) {\n for (let ly = 0; ly < chunk.height; ly++) {\n for (let lx = 0; lx < chunk.width; lx++) {\n if (chunk.getRawAt(lx, ly) !== 0) count++;\n }\n }\n }\n return count;\n }\n}\n"],"mappings":";;;;AAsEA,MAAM,qBAAqB;;AA4C3B,MAAM,wBAAwB,QAAQ,MAAc;CAClD,IAAI,CAAC,OAAO,SAAS,KAAK,KAAK,SAAS,GACtC,MAAM,IAAI,MAAM,2DAA2D;CAG7E,OAAO;AACT;;;;;;AAOA,MAAM,4BAA4B,YAAwD;CACxF,2BAA2B,QAAQ,IAAI,UAAU;CACjD,IAAI,CAAC,QAAQ,QAAQ,OAAO,QAAQ,SAAS,UAC3C,MAAM,IAAI,MAAM,4CAA4C;CAE9D,yBAAyB,QAAQ,OAAO,QAAQ,QAAQ,aAAa,OAAO;CAC5E,wBAAwB,QAAQ,WAAW,iBAAiB;CAC5D,wBAAwB,QAAQ,YAAY,kBAAkB;CAE9D,MAAM,aAAa,QAAQ,cAAc;CACzC,MAAM,cAAc,QAAQ,eAAe;CAC3C,wBAAwB,YAAY,YAAY;CAChD,wBAAwB,aAAa,aAAa;CAElD,IAAI,CAAC,MAAM,QAAQ,QAAQ,QAAQ,GACjC,MAAM,IAAI,MAAM,sCAAsC;CAGxD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B;EAClC,IAAI,QAAQ;EACZ,KAAK,MAAM,SAAS,KAAK,QAAQ,OAAO,GACtC,KAAK,IAAI,KAAK,GAAG,KAAK,MAAM,QAAQ,MAClC,KAAK,IAAI,KAAK,GAAG,KAAK,MAAM,OAAO,MACjC,IAAI,MAAM,SAAS,IAAI,EAAE,MAAM,GAAG;EAIxC,OAAO;CACT;AACF"}
|
|
1
|
+
{"version":3,"file":"TileLayer.js","names":[],"sources":["../../src/TileLayer.ts"],"sourcesContent":["import type { ChunkPayload } from './ChunkSource';\nimport type { ReadonlyTileChunk } from './TileChunk';\nimport { TileChunk } from './TileChunk';\nimport { TileProjection } from './TileProjection';\nimport type { TileSet } from './TileSet';\nimport type { TileProperties } from './types';\nimport type { PackedTile, ResolvedTile } from './types';\nimport { packTile, unpackTile, validateInteger, validateNonNegativeInteger, validatePairedDimensions, validatePositiveInteger } from './types';\nimport { tileToChunkCoord, tileToLocalInChunk } from './types';\n\n/**\n * Options for constructing a {@link TileLayer}.\n * @advanced\n */\nexport interface TileLayerOptions {\n /** Shared projection; defaults to an orthogonal grid of the supplied tile size. */\n readonly projection?: TileProjection;\n /** Stable layer ID (unique within the map). */\n readonly id: number;\n /** Display name (need not be unique). */\n readonly name: string;\n /**\n * Layer width in tiles. Omit together with {@link height} for an\n * unbounded layer - chunk storage then accepts any signed chunk\n * coordinate instead of being clamped to a fixed grid.\n */\n readonly width?: number;\n /** Layer height in tiles. Must be provided iff {@link width} is. */\n readonly height?: number;\n /** Chunk width in tiles (default 32). */\n readonly chunkWidth?: number;\n /** Chunk height in tiles (default 32). */\n readonly chunkHeight?: number;\n /** Tilesets available to this layer (shared with the map). */\n readonly tilesets: readonly TileSet[];\n /** Tile width in pixels (for coordinate conversion). */\n readonly tileWidth: number;\n /** Tile height in pixels (for coordinate conversion). */\n readonly tileHeight: number;\n /** Initial visibility. Default true. */\n readonly visible?: boolean;\n /** Opacity 0..1. Default 1. */\n readonly opacity?: number;\n /** Layer pixel offset X. Default 0. */\n readonly offsetX?: number;\n /** Layer pixel offset Y. Default 0. */\n readonly offsetY?: number;\n /**\n * Parallax scroll factor on the X axis. `1.0` = full camera speed (normal),\n * `0.5` = half speed (farther away), `0.0` = stationary. Default 1.\n */\n readonly parallaxX?: number;\n /**\n * Parallax scroll factor on the Y axis. `1.0` = full camera speed (normal),\n * `0.5` = half speed (farther away), `0.0` = stationary. Default 1.\n */\n readonly parallaxY?: number;\n /**\n * Uniform scale applied together with the camera-relative parallax shift.\n * `1` keeps the layer at its authored size. Default `1`.\n */\n readonly parallaxScale?: number;\n /** Layer class/type string (Tiled `class`). Defaults to `''`. */\n readonly class?: string;\n /**\n * Multiplicative layer tint as a `0xRRGGBB` integer, or `null` for none\n * (Tiled `tintcolor`). Applied to every chunk's render tint. Default `null`.\n */\n readonly tintColor?: number | null;\n /** Layer properties (copied and frozen). */\n readonly properties?: TileProperties;\n}\n\nconst DEFAULT_CHUNK_SIZE = 32;\n\n/**\n * The inclusive range of chunk coordinates that intersect a bounded\n * {@link TileLayer}. `null` for an unbounded layer (no range limit).\n * @advanced\n */\nexport interface ChunkRange {\n readonly minCx: number;\n readonly minCy: number;\n readonly maxCx: number;\n readonly maxCy: number;\n}\n\n/**\n * Fired via {@link TileLayer._addStructuralListener} whenever a chunk is\n * installed ({@link TileLayer._adoptChunk}) or evicted\n * ({@link TileLayer._evictChunk}) - structural changes only, not per-tile\n * edits (see {@link import('./TileChunk').TileChunk._addDirtyListener} for\n * those). `chunk` is `null` on eviction.\n * @internal\n */\nexport interface ChunkStructuralEvent {\n readonly cx: number;\n readonly cy: number;\n readonly chunk: ReadonlyTileChunk | null;\n}\n\n/**\n * Resolved, defaulted subset of {@link TileLayerOptions} produced by\n * {@link validateTileLayerOptions}.\n */\ninterface ResolvedTileLayerOptions {\n readonly chunkWidth: number;\n readonly chunkHeight: number;\n readonly opacity: number;\n readonly offsetX: number;\n readonly offsetY: number;\n readonly parallaxX: number;\n readonly parallaxY: number;\n readonly parallaxScale: number;\n}\n\n/** Resolve and validate the optional uniform parallax scale. */\nconst resolveParallaxScale = (value = 1): number => {\n if (!Number.isFinite(value) || value <= 0) {\n throw new Error('TileLayer parallaxScale must be a positive finite number.');\n }\n\n return value;\n};\n\n/**\n * Validate a {@link TileLayerOptions} bag and resolve its optional fields\n * (chunk size, opacity, offset, parallax) to concrete defaults.\n * @throws When dimensions, chunk size, or other options are invalid.\n */\nconst validateTileLayerOptions = (options: TileLayerOptions): ResolvedTileLayerOptions => {\n validateNonNegativeInteger(options.id, 'layer.id');\n if (!options.name || typeof options.name !== 'string') {\n throw new Error('TileLayer name must be a non-empty string.');\n }\n validatePairedDimensions(options.width, options.height, 'TileLayer', 'layer');\n validatePositiveInteger(options.tileWidth, 'layer.tileWidth');\n validatePositiveInteger(options.tileHeight, 'layer.tileHeight');\n\n const chunkWidth = options.chunkWidth ?? DEFAULT_CHUNK_SIZE;\n const chunkHeight = options.chunkHeight ?? DEFAULT_CHUNK_SIZE;\n validatePositiveInteger(chunkWidth, 'chunkWidth');\n validatePositiveInteger(chunkHeight, 'chunkHeight');\n\n if (!Array.isArray(options.tilesets)) {\n throw new Error('TileLayer tilesets must be an array.');\n }\n\n const opacity = options.opacity ?? 1;\n if (typeof opacity !== 'number' || opacity < 0 || opacity > 1) {\n throw new Error(`TileLayer opacity must be 0..1 (got ${opacity}).`);\n }\n\n const offsetX = options.offsetX ?? 0;\n const offsetY = options.offsetY ?? 0;\n if (!Number.isFinite(offsetX) || !Number.isFinite(offsetY)) {\n throw new Error('TileLayer offset must be finite numbers.');\n }\n\n const parallaxX = options.parallaxX ?? 1;\n const parallaxY = options.parallaxY ?? 1;\n if (!Number.isFinite(parallaxX) || !Number.isFinite(parallaxY)) {\n throw new Error('TileLayer parallax must be finite numbers.');\n }\n\n const parallaxScale = resolveParallaxScale(options.parallaxScale);\n\n return { chunkWidth, chunkHeight, opacity, offsetX, offsetY, parallaxX, parallaxY, parallaxScale };\n};\n\n/**\n * A generic, format-independent tile layer with chunk-first storage.\n *\n * Tile data is stored in fixed-size {@link TileChunk}s indexed by signed\n * chunk coordinates. For finite maps, only chunks that intersect the layer\n * bounds exist.\n *\n * **Mutation must go through the layer's public APIs only.**\n * `setTileAt` / `clearTileAt` validate coordinates, tileset references,\n * and increment revision counters only when the stored value actually\n * changes. Direct chunk mutation is not supported - the layer owns chunk\n * storage and exposes only a {@link ReadonlyTileChunk} view.\n *\n * The layer is NOT a SceneNode - that integration lives in\n * {@link import('./TileLayerNode').TileLayerNode}.\n *\n * @advanced\n */\nexport class TileLayer {\n public readonly projection: TileProjection;\n /** Stable unique ID within the map. */\n public readonly id: number;\n /** Display name (may not be unique). */\n public readonly name: string;\n\n /** Width in tiles, or `undefined` if unbounded. */\n public readonly width: number | undefined;\n /** Height in tiles, or `undefined` if unbounded. */\n public readonly height: number | undefined;\n\n /** Chunk width (tiles). */\n public readonly chunkWidth: number;\n /** Chunk height (tiles). */\n public readonly chunkHeight: number;\n\n /** Tile width in pixels. */\n public readonly tileWidth: number;\n /** Tile height in pixels. */\n public readonly tileHeight: number;\n\n /** `true` if this layer has a fixed width/height; `false` if unbounded. */\n public get bounded(): boolean {\n return this.width !== undefined && this.height !== undefined;\n }\n\n /** Pixel width, or `undefined` if unbounded. */\n public get pixelWidth(): number | undefined {\n return this.width === undefined || this.height === undefined ? undefined : this.projection.getBounds(0, 0, this.width, this.height).width;\n }\n /** Pixel height, or `undefined` if unbounded. */\n public get pixelHeight(): number | undefined {\n return this.width === undefined || this.height === undefined ? undefined : this.projection.getBounds(0, 0, this.width, this.height).height;\n }\n\n /** Visibility flag (mutable). */\n public visible: boolean;\n /** Opacity 0..1 (mutable). */\n public opacity: number;\n /** Horizontal pixel offset (mutable). */\n public offsetX: number;\n /** Vertical pixel offset (mutable). */\n public offsetY: number;\n /**\n * Parallax scroll factor on the X axis.\n * `1.0` = full camera speed, `0.5` = half speed, `0.0` = stationary.\n */\n public readonly parallaxX: number;\n /**\n * Parallax scroll factor on the Y axis.\n * `1.0` = full camera speed, `0.5` = half speed, `0.0` = stationary.\n */\n public readonly parallaxY: number;\n /** Uniform scale applied around the layer origin during parallax rendering. */\n public readonly parallaxScale: number;\n\n /** Layer class/type string (Tiled `class`; may be empty). */\n public readonly class: string;\n /** Multiplicative layer tint as `0xRRGGBB`, or `null` for no tint. */\n public readonly tintColor: number | null;\n\n /** Immutable layer properties. */\n public readonly properties: TileProperties;\n\n /** The tilesets available to this layer (shared array reference). */\n public readonly tilesets: readonly TileSet[];\n\n /** Chunk storage: chunkKey → mutable TileChunk (internal). */\n private readonly _chunks = new Map<string, TileChunk>();\n\n /** Package-internal structural (adopt/evict) listeners. */\n private _structuralListeners: Set<(event: ChunkStructuralEvent) => void> | null = null;\n\n /**\n * Monotonic layer revision counter.\n * Increments on every cell mutation that actually changes a stored value.\n * Does NOT increment on no-op writes or failed mutations.\n */\n private _revision = 0;\n\n /** Whether the layer has been destroyed. */\n private _destroyed = false;\n\n /**\n * @throws When dimensions, chunk size, or other options are invalid.\n */\n public constructor(options: TileLayerOptions) {\n const { chunkWidth, chunkHeight, opacity, offsetX, offsetY, parallaxX, parallaxY, parallaxScale } = validateTileLayerOptions(options);\n\n this.id = options.id;\n this.name = options.name;\n this.width = options.width;\n this.height = options.height;\n this.chunkWidth = chunkWidth;\n this.chunkHeight = chunkHeight;\n this.tileWidth = options.tileWidth;\n this.tileHeight = options.tileHeight;\n this.projection = options.projection ?? new TileProjection({ tileWidth: options.tileWidth, tileHeight: options.tileHeight });\n if (this.projection.tileWidth !== this.tileWidth || this.projection.tileHeight !== this.tileHeight) {\n throw new Error('Projection tile dimensions must match the layer or map.');\n }\n this.tilesets = options.tilesets;\n this.visible = options.visible ?? true;\n this.opacity = opacity;\n this.offsetX = offsetX;\n this.offsetY = offsetY;\n this.parallaxX = parallaxX;\n this.parallaxY = parallaxY;\n this.parallaxScale = parallaxScale;\n this.class = options.class ?? '';\n this.tintColor = options.tintColor ?? null;\n this.properties = options.properties ? Object.freeze({ ...options.properties }) : Object.freeze({});\n }\n\n // ── Bounds helpers ────────────────────────────────────────────────────\n\n /**\n * Check whether a tile coordinate lies within the layer bounds.\n * Always `true` for an unbounded layer.\n * @advanced\n */\n public inBounds(tx: number, ty: number): boolean {\n if (this.width === undefined || this.height === undefined) return true;\n return tx >= 0 && tx < this.width && ty >= 0 && ty < this.height;\n }\n\n /**\n * Compute the range of chunk coordinates that intersect this layer, or\n * `null` if the layer is unbounded (any signed chunk coordinate is valid).\n */\n public chunkRange(): ChunkRange | null {\n if (this.width === undefined || this.height === undefined) return null;\n return {\n minCx: 0,\n minCy: 0,\n maxCx: Math.floor((this.width - 1) / this.chunkWidth),\n maxCy: Math.floor((this.height - 1) / this.chunkHeight),\n };\n }\n\n // ── Chunk keying ──────────────────────────────────────────────────────\n\n private _chunkKey(cx: number, cy: number): string {\n return `${cx},${cy}`;\n }\n\n /**\n * Get a readonly view of a chunk by signed chunk coordinates,\n * or undefined if it does not exist (never been touched).\n * @advanced\n */\n public getChunk(cx: number, cy: number): ReadonlyTileChunk | undefined {\n return this._chunks.get(this._chunkKey(cx, cy));\n }\n\n /**\n * Get or create a chunk at the given coordinates.\n * For a bounded layer, creation is only allowed within the valid chunk\n * range and edge chunks are clamped to the layer's remaining size. For an\n * unbounded layer, any signed chunk coordinate is accepted and every\n * chunk is full-size ({@link chunkWidth} × {@link chunkHeight}).\n *\n * @internal Package-private: used by {@link setTileAt}, {@link fillRect},\n * and future adapter ingest. External users should not allocate\n * chunks - use {@link setTileAt} to populate tiles.\n */\n public _ensureChunk(cx: number, cy: number): TileChunk {\n this._checkDestroyed();\n const key = this._chunkKey(cx, cy);\n let chunk = this._chunks.get(key);\n if (!chunk) {\n const range = this.chunkRange();\n let cw = this.chunkWidth;\n let ch = this.chunkHeight;\n if (range !== null && this.width !== undefined && this.height !== undefined) {\n if (cx < range.minCx || cx > range.maxCx || cy < range.minCy || cy > range.maxCy) {\n throw new Error(`Chunk (${cx}, ${cy}) outside layer chunk range ` + `[${range.minCx}..${range.maxCx}, ${range.minCy}..${range.maxCy}].`);\n }\n // Compute the actual tile dimensions for this chunk (edge chunks may be smaller).\n const startTx = cx * this.chunkWidth;\n const startTy = cy * this.chunkHeight;\n cw = Math.min(this.chunkWidth, this.width - startTx);\n ch = Math.min(this.chunkHeight, this.height - startTy);\n }\n chunk = new TileChunk(cx, cy, cw, ch);\n this._chunks.set(key, chunk);\n }\n return chunk;\n }\n\n /**\n * Install a chunk-provider-supplied payload directly, bypassing per-tile\n * `setTileAt` cost. Overwrites any existing chunk at `(cx, cy)`. Always\n * bumps the layer revision (installing a chunk is always a structural\n * change, even if the payload happens to be all-zero).\n *\n * Does not validate `(cx, cy)` against {@link chunkRange} - callers\n * (chunk-streaming controllers) are trusted to request coordinates within\n * whatever range they intend to manage.\n *\n * @internal Package-private: for future chunk-provider/streaming use.\n */\n public _adoptChunk(cx: number, cy: number, payload: ChunkPayload): void {\n this._checkDestroyed();\n const chunk = new TileChunk(cx, cy, payload.width, payload.height, payload.tiles);\n this._chunks.set(this._chunkKey(cx, cy), chunk);\n this._revision++;\n this._notifyStructural({ cx, cy, chunk });\n }\n\n /**\n * Evict a chunk from storage, freeing it for garbage collection. No-op if\n * no chunk is loaded at `(cx, cy)`.\n *\n * @returns `true` if a chunk was found and removed, `false` otherwise.\n * @internal Package-private: for future chunk-streaming eviction use.\n */\n public _evictChunk(cx: number, cy: number): boolean {\n this._checkDestroyed();\n const key = this._chunkKey(cx, cy);\n if (!this._chunks.delete(key)) return false;\n this._revision++;\n this._notifyStructural({ cx, cy, chunk: null });\n return true;\n }\n\n /**\n * Register a callback invoked synchronously whenever a chunk is installed\n * ({@link _adoptChunk}) or evicted ({@link _evictChunk}). Package-internal:\n * {@link import('./TileLayerNode').TileLayerNode} subscribes to keep its\n * chunk-node children in sync with chunk-provider-driven adopt/evict calls\n * (e.g. from {@link import('./ChunkStreamer').ChunkStreamer}) without\n * needing a full {@link import('./TileLayerNode').TileLayerNode.refresh}.\n * @internal\n */\n public _addStructuralListener(listener: (event: ChunkStructuralEvent) => void): void {\n (this._structuralListeners ??= new Set()).add(listener);\n }\n\n /**\n * Unregister a listener added via {@link _addStructuralListener} (node destroy).\n * @internal\n */\n public _removeStructuralListener(listener: (event: ChunkStructuralEvent) => void): void {\n this._structuralListeners?.delete(listener);\n }\n\n private _notifyStructural(event: ChunkStructuralEvent): void {\n if (this._structuralListeners === null) return;\n for (const listener of this._structuralListeners) {\n listener(event);\n }\n }\n\n /**\n * Iterate over all loaded chunks in deterministic (cy, cx) ascending order.\n * Returns readonly chunk views - callers cannot mutate storage.\n * @advanced\n */\n public loadedChunks(): IterableIterator<ReadonlyTileChunk> {\n const entries = [...this._chunks.values()];\n entries.sort((a, b) => a.cy - b.cy || a.cx - b.cx);\n return entries[Symbol.iterator]();\n }\n\n // ── Tile queries ──────────────────────────────────────────────────────\n\n /**\n * Get the raw packed tile word at (tx, ty). Returns 0 for empty or out-of-bounds.\n * @advanced\n */\n public getRawTileAt(tx: number, ty: number): PackedTile {\n validateInteger(tx, 'tx');\n validateInteger(ty, 'ty');\n if (!this.inBounds(tx, ty)) return 0;\n const { cx, cy } = tileToChunkCoord(tx, ty, this.chunkWidth, this.chunkHeight);\n const chunk = this._chunks.get(this._chunkKey(cx, cy));\n if (!chunk) return 0;\n const { lx, ly } = tileToLocalInChunk(tx, ty, this.chunkWidth, this.chunkHeight);\n return chunk.getRawAt(lx, ly);\n }\n\n /**\n * Query a resolved tile at (tx, ty). Returns null for empty or out-of-bounds.\n * @advanced\n */\n public getTileAt(tx: number, ty: number): ResolvedTile | null {\n const packed = this.getRawTileAt(tx, ty);\n if (packed === 0) return null;\n const decoded = unpackTile(packed);\n if (!decoded) return null;\n if (decoded.tilesetIndex >= this.tilesets.length) return null;\n const tileset = this.tilesets[decoded.tilesetIndex]!;\n if (decoded.localTileId >= tileset.tileCount) return null;\n return {\n tileset,\n localTileId: decoded.localTileId,\n transform: decoded.transform,\n };\n }\n\n // ── Mutation ──────────────────────────────────────────────────────────\n\n /**\n * Validate a tile reference against the layer's tilesets.\n * Returns the packed form or throws.\n */\n private _validateTileRef(tile: ResolvedTile): PackedTile {\n if (!tile?.tileset) {\n throw new Error('setTileAt requires a valid ResolvedTile.');\n }\n const tilesetIndex = this.tilesets.indexOf(tile.tileset);\n if (tilesetIndex === -1) {\n throw new Error(`Tileset \"${tile.tileset.name}\" is not available to layer \"${this.name}\".`);\n }\n if (tile.localTileId < 0 || tile.localTileId >= tile.tileset.tileCount) {\n throw new Error(`localTileId ${tile.localTileId} out of range for tileset \"${tile.tileset.name}\" ` + `(max ${tile.tileset.tileCount - 1}).`);\n }\n return packTile(tilesetIndex, tile.localTileId, tile.transform);\n }\n\n /**\n * Set a tile at the given tile coordinates.\n * No-op if the effective value is unchanged.\n * @throws If coordinates are out of bounds or the tile reference is invalid.\n * @advanced\n */\n public setTileAt(tx: number, ty: number, tile: ResolvedTile): void {\n this._checkDestroyed();\n validateInteger(tx, 'tx');\n validateInteger(ty, 'ty');\n if (!this.inBounds(tx, ty)) {\n const boundsMsg = this.width !== undefined && this.height !== undefined ? `[0..${this.width - 1}, 0..${this.height - 1}]` : '[unbounded]';\n throw new Error(`setTileAt (${tx}, ${ty}) out of bounds ${boundsMsg}.`);\n }\n const packed = this._validateTileRef(tile);\n const { cx, cy } = tileToChunkCoord(tx, ty, this.chunkWidth, this.chunkHeight);\n const chunk = this._ensureChunk(cx, cy);\n const { lx, ly } = tileToLocalInChunk(tx, ty, this.chunkWidth, this.chunkHeight);\n if (chunk._setRawAt(lx, ly, packed)) {\n this._revision++;\n }\n }\n\n /**\n * Clear (erase) the tile at the given coordinates.\n * No-op if the cell is already empty.\n * @throws If coordinates are out of bounds.\n * @advanced\n */\n public clearTileAt(tx: number, ty: number): void {\n this._checkDestroyed();\n validateInteger(tx, 'tx');\n validateInteger(ty, 'ty');\n if (!this.inBounds(tx, ty)) {\n const boundsMsg = this.width !== undefined && this.height !== undefined ? `[0..${this.width - 1}, 0..${this.height - 1}]` : '[unbounded]';\n throw new Error(`clearTileAt (${tx}, ${ty}) out of bounds ${boundsMsg}.`);\n }\n const { cx, cy } = tileToChunkCoord(tx, ty, this.chunkWidth, this.chunkHeight);\n const chunk = this._chunks.get(this._chunkKey(cx, cy));\n if (!chunk) return; // no chunk = already empty\n const { lx, ly } = tileToLocalInChunk(tx, ty, this.chunkWidth, this.chunkHeight);\n if (chunk._setRawAt(lx, ly, 0)) {\n this._revision++;\n }\n }\n\n // ── Bulk fill ─────────────────────────────────────────────────────────\n\n /**\n * Fill a rectangular region with a tile.\n * @advanced\n */\n public fillRect(x: number, y: number, w: number, h: number, tile: ResolvedTile): void {\n this._checkDestroyed();\n const packed = this._validateTileRef(tile);\n let changed = false;\n for (let ty = y; ty < y + h; ty++) {\n for (let tx = x; tx < x + w; tx++) {\n if (!this.inBounds(tx, ty)) continue;\n const { cx, cy } = tileToChunkCoord(tx, ty, this.chunkWidth, this.chunkHeight);\n const chunk = this._ensureChunk(cx, cy);\n const { lx, ly } = tileToLocalInChunk(tx, ty, this.chunkWidth, this.chunkHeight);\n if (chunk._setRawAt(lx, ly, packed)) {\n changed = true;\n }\n }\n }\n if (changed) this._revision++;\n }\n\n /**\n * Clear a rectangular region.\n * @advanced\n */\n public clearRect(x: number, y: number, w: number, h: number): void {\n this._checkDestroyed();\n let changed = false;\n for (let ty = y; ty < y + h; ty++) {\n for (let tx = x; tx < x + w; tx++) {\n if (!this.inBounds(tx, ty)) continue;\n const { cx, cy } = tileToChunkCoord(tx, ty, this.chunkWidth, this.chunkHeight);\n const chunk = this._chunks.get(this._chunkKey(cx, cy));\n if (!chunk) continue;\n const { lx, ly } = tileToLocalInChunk(tx, ty, this.chunkWidth, this.chunkHeight);\n if (chunk._setRawAt(lx, ly, 0)) {\n changed = true;\n }\n }\n }\n if (changed) this._revision++;\n }\n\n // ── Iteration ─────────────────────────────────────────────────────────\n\n /**\n * Iterate non-empty tiles within a rectangular region in row-major order.\n * Yields (tx, ty, resolvedTile) tuples. Skips empty cells.\n * @advanced\n */\n public *tilesInRect(x: number, y: number, w: number, h: number): Generator<{ tx: number; ty: number; tile: ResolvedTile }> {\n const startCx = Math.floor(x / this.chunkWidth);\n const endCx = Math.floor((x + w - 1) / this.chunkWidth);\n const startCy = Math.floor(y / this.chunkHeight);\n const endCy = Math.floor((y + h - 1) / this.chunkHeight);\n\n for (let cy = startCy; cy <= endCy; cy++) {\n for (let cx = startCx; cx <= endCx; cx++) {\n const chunk = this._chunks.get(this._chunkKey(cx, cy));\n if (!chunk || chunk.empty) continue;\n\n const chunkStartTx = cx * this.chunkWidth;\n const chunkStartTy = cy * this.chunkHeight;\n const minLx = Math.max(0, x - chunkStartTx);\n const maxLx = Math.min(chunk.width - 1, x + w - 1 - chunkStartTx);\n const minLy = Math.max(0, y - chunkStartTy);\n const maxLy = Math.min(chunk.height - 1, y + h - 1 - chunkStartTy);\n\n for (let ly = minLy; ly <= maxLy; ly++) {\n for (let lx = minLx; lx <= maxLx; lx++) {\n const packed = chunk.getRawAt(lx, ly);\n if (packed === 0) continue;\n const decoded = unpackTile(packed);\n if (!decoded) continue;\n if (decoded.tilesetIndex >= this.tilesets.length) continue;\n const tileset = this.tilesets[decoded.tilesetIndex]!;\n if (decoded.localTileId >= tileset.tileCount) continue;\n yield {\n tx: chunkStartTx + lx,\n ty: chunkStartTy + ly,\n tile: {\n tileset,\n localTileId: decoded.localTileId,\n transform: decoded.transform,\n },\n };\n }\n }\n }\n }\n }\n\n /** Display layer translation expressed as a logical simulation-space vector. */\n public get logicalOffset(): { x: number; y: number } {\n const p = this.projection;\n return p.pixelToLogical(p.originX + this.offsetX, p.originY + this.offsetY);\n }\n\n // ── Coordinate conversion ─────────────────────────────────────────────\n\n /**\n * Convert a grid vertex to display pixels (the top diamond vertex for isometric cells)\n * including the layer's display offset.\n * @advanced\n */\n public tileToPixel(tx: number, ty: number): { x: number; y: number } {\n const point = this.projection.tileToPixel(tx, ty);\n return { x: point.x + this.offsetX, y: point.y + this.offsetY };\n }\n\n /**\n * Convert a local pixel position to the tile coordinate that contains it.\n * Uses `floor`, so a point exactly on a tile boundary maps to the tile.\n * May return coordinates outside layer bounds.\n * @advanced\n */\n public pixelToTile(px: number, py: number): { tx: number; ty: number } {\n return this.projection.pixelToTile(px - this.offsetX, py - this.offsetY);\n }\n\n // ── Revision / lifecycle ──────────────────────────────────────────────\n\n /**\n * Monotonic layer revision counter.\n * Increments on every cell mutation that changes a stored value.\n * No-op writes and failed mutations do NOT increment.\n * @advanced\n */\n public get revision(): number {\n return this._revision;\n }\n\n /** Whether the layer has been destroyed. */\n public get destroyed(): boolean {\n return this._destroyed;\n }\n\n private _checkDestroyed(): void {\n if (this._destroyed) {\n throw new Error(`TileLayer \"${this.name}\" has been destroyed.`);\n }\n }\n\n /**\n * Destroy this layer: clear chunk storage and mark destroyed.\n * Does NOT destroy tileset textures or external resources.\n * Idempotent.\n */\n public destroy(): void {\n if (this._destroyed) return;\n this._destroyed = true;\n this._chunks.clear();\n }\n\n /**\n * Total number of non-empty tiles across all chunks.\n * Walk is cheap for dense layers; sparse layers benefit from empty-chunk fast path.\n * @advanced\n */\n public countNonEmptyTiles(): number {\n let count = 0;\n for (const chunk of this._chunks.values()) {\n for (let ly = 0; ly < chunk.height; ly++) {\n for (let lx = 0; lx < chunk.width; lx++) {\n if (chunk.getRawAt(lx, ly) !== 0) count++;\n }\n }\n }\n return count;\n }\n}\n"],"mappings":";;;;;AAyEA,MAAM,qBAAqB;;AA4C3B,MAAM,wBAAwB,QAAQ,MAAc;CAClD,IAAI,CAAC,OAAO,SAAS,KAAK,KAAK,SAAS,GACtC,MAAM,IAAI,MAAM,2DAA2D;CAG7E,OAAO;AACT;;;;;;AAOA,MAAM,4BAA4B,YAAwD;CACxF,2BAA2B,QAAQ,IAAI,UAAU;CACjD,IAAI,CAAC,QAAQ,QAAQ,OAAO,QAAQ,SAAS,UAC3C,MAAM,IAAI,MAAM,4CAA4C;CAE9D,yBAAyB,QAAQ,OAAO,QAAQ,QAAQ,aAAa,OAAO;CAC5E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AGA,IAAW,gBAA0C;EACnD,MAAM,IAAI,KAAK;EACf,OAAO,EAAE,eAAe,EAAE,UAAU,KAAK,SAAS,EAAE,UAAU,KAAK,OAAO;CAC5E;;;;;;CASA,AAAO,YAAY,IAAY,IAAsC;EACnE,MAAM,QAAQ,KAAK,WAAW,YAAY,IAAI,EAAE;EAChD,OAAO;GAAE,GAAG,MAAM,IAAI,KAAK;GAAS,GAAG,MAAM,IAAI,KAAK;EAAQ;CAChE;;;;;;;CAQA,AAAO,YAAY,IAAY,IAAwC;EACrE,OAAO,KAAK,WAAW,YAAY,KAAK,KAAK,SAAS,KAAK,KAAK,OAAO;CACzE;;;;;;;CAUA,IAAW,WAAmB;EAC5B,OAAO,KAAK;CACd;;CAGA,IAAW,YAAqB;EAC9B,OAAO,KAAK;CACd;CAEA,AAAQ,kBAAwB;EAC9B,IAAI,KAAK,YACP,MAAM,IAAI,MAAM,cAAc,KAAK,KAAK,sBAAsB;CAElE;;;;;;CAOA,AAAO,UAAgB;EACrB,IAAI,KAAK,YAAY;EACrB,KAAK,aAAa;EAClB,KAAK,QAAQ,MAAM;CACrB;;;;;;CAOA,AAAO,qBAA6B;EAClC,IAAI,QAAQ;EACZ,KAAK,MAAM,SAAS,KAAK,QAAQ,OAAO,GACtC,KAAK,IAAI,KAAK,GAAG,KAAK,MAAM,QAAQ,MAClC,KAAK,IAAI,KAAK,GAAG,KAAK,MAAM,OAAO,MACjC,IAAI,MAAM,SAAS,IAAI,EAAE,MAAM,GAAG;EAIxC,OAAO;CACT;AACF"}
|
|
@@ -19,9 +19,9 @@ export interface TileLayerNodeOptions {
|
|
|
19
19
|
* A scene node that renders one generic {@link TileLayer} as a
|
|
20
20
|
* {@link Container} of per-chunk {@link TileChunkNode} drawables.
|
|
21
21
|
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
22
|
+
* Orthogonal chunks become one child each. Isometric chunks become diagonal
|
|
23
|
+
* slices ordered across storage boundaries, preserving painter order and
|
|
24
|
+
* texture runs. Each drawable has its own culling bounds. The layer's pixel
|
|
25
25
|
* `offset`, `visible` and `opacity` are all read live from the runtime layer on
|
|
26
26
|
* every frame (no rebuild required).
|
|
27
27
|
*
|
|
@@ -77,7 +77,12 @@ export declare class TileLayerNode extends Container {
|
|
|
77
77
|
* integer pixel grid by construction). Setting the current value is a no-op;
|
|
78
78
|
* an invalid value throws and leaves the prior mode unchanged.
|
|
79
79
|
*
|
|
80
|
-
*
|
|
80
|
+
* Defaults to `Geometry` because a tile grid is made of quads that share
|
|
81
|
+
* their edges: left unsnapped, a boundary landing between two device pixels
|
|
82
|
+
* is sampled across both, so the seams blur and shimmer as the view moves.
|
|
83
|
+
* Set `None` to opt out.
|
|
84
|
+
*
|
|
85
|
+
* @default PixelSnapMode.Geometry
|
|
81
86
|
* @stable
|
|
82
87
|
*/
|
|
83
88
|
get pixelSnapMode(): PixelSnapMode;
|
|
@@ -97,11 +102,13 @@ export declare class TileLayerNode extends Container {
|
|
|
97
102
|
destroy(): void;
|
|
98
103
|
private _buildChunkNodes;
|
|
99
104
|
/**
|
|
100
|
-
* Construct
|
|
105
|
+
* Construct the configured draw nodes for `chunk` - shared by
|
|
101
106
|
* the initial bulk build ({@link _buildChunkNodes}) and the incremental
|
|
102
107
|
* structural-listener handler, so a future constructor argument or
|
|
103
108
|
* per-node setting only needs to be added in one place.
|
|
104
109
|
*/
|
|
110
|
+
private _addChunkNodes;
|
|
111
|
+
private _sortChunks;
|
|
105
112
|
private _createChunkNode;
|
|
106
113
|
/**
|
|
107
114
|
* Compute and apply this layer's live tint (opacity as alpha, `tintColor`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TileLayerNode.d.ts","sourceRoot":"","sources":["../../src/TileLayerNode.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAE,aAA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;;;OAMG;IACH,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAWlC;IAEF,YAAmB,KAAK,EAAE,SAAS,EAAE,OAAO,CAAC,EAAE,oBAAoB,EAclE;IAED,2CAA2C;IAC3C,IAAW,KAAK,IAAI,SAAS,CAE5B;IAED;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,IAAW,aAAa,IAAI,aAAa,CAExC;IAED,IAAW,aAAa,CAAC,IAAI,EAAE,aAAa,EAW3C;IAED;;;;OAIG;IACI,OAAO,IAAI,IAAI,CAerB;IAOD;;;;OAIG;IACa,cAAc,IAAI,iBAAiB,CAiBlD;IAoDe,OAAO,IAAI,IAAI,CAY9B;IAED,OAAO,CAAC,gBAAgB;IAexB;;;;;OAKG;IACH,OAAO,CAAC,cAAc;IAWtB,OAAO,CAAC,WAAW;IAMnB,OAAO,CAAC,gBAAgB;IAYxB;;;;;;;OAOG;IACH,OAAO,CAAC,UAAU;IAQlB;;;;OAIG;IACH,OAAO,CAAC,SAAS;CAelB"}
|
|
@@ -9,9 +9,9 @@ import { Container } from "@codexo/exojs";
|
|
|
9
9
|
* A scene node that renders one generic {@link TileLayer} as a
|
|
10
10
|
* {@link Container} of per-chunk {@link TileChunkNode} drawables.
|
|
11
11
|
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
12
|
+
* Orthogonal chunks become one child each. Isometric chunks become diagonal
|
|
13
|
+
* slices ordered across storage boundaries, preserving painter order and
|
|
14
|
+
* texture runs. Each drawable has its own culling bounds. The layer's pixel
|
|
15
15
|
* `offset`, `visible` and `opacity` are all read live from the runtime layer on
|
|
16
16
|
* every frame (no rebuild required).
|
|
17
17
|
*
|
|
@@ -42,7 +42,7 @@ var TileLayerNode = class extends Container {
|
|
|
42
42
|
_chunkNodes = [];
|
|
43
43
|
_syncedOpacity = -1;
|
|
44
44
|
_syncedTint = void 0;
|
|
45
|
-
_pixelSnapMode = PixelSnapMode.
|
|
45
|
+
_pixelSnapMode = PixelSnapMode.Geometry;
|
|
46
46
|
/**
|
|
47
47
|
* Bound once so `TileLayer._addStructuralListener`/`_removeStructuralListener`
|
|
48
48
|
* add and remove the SAME function reference. Incrementally adds/removes
|
|
@@ -51,18 +51,16 @@ var TileLayerNode = class extends Container {
|
|
|
51
51
|
* revision-cached geometry survives untouched.
|
|
52
52
|
*/
|
|
53
53
|
_onStructuralChange = (event) => {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
this.
|
|
59
|
-
|
|
54
|
+
for (let i = this._chunkNodes.length - 1; i >= 0; i--) {
|
|
55
|
+
const node = this._chunkNodes[i];
|
|
56
|
+
if (!node) continue;
|
|
57
|
+
if (node.chunkX !== event.cx || node.chunkY !== event.cy) continue;
|
|
58
|
+
this._chunkNodes.splice(i, 1);
|
|
59
|
+
this.removeChild(node);
|
|
60
|
+
node.destroy();
|
|
60
61
|
}
|
|
61
|
-
if (event.chunk
|
|
62
|
-
|
|
63
|
-
this._chunkNodes.push(node);
|
|
64
|
-
this.addChild(node);
|
|
65
|
-
this._applyTint(node);
|
|
62
|
+
if (event.chunk !== null && !event.chunk.empty) this._addChunkNodes(event.chunk);
|
|
63
|
+
this._sortChunks();
|
|
66
64
|
};
|
|
67
65
|
constructor(layer, options) {
|
|
68
66
|
super();
|
|
@@ -90,7 +88,12 @@ var TileLayerNode = class extends Container {
|
|
|
90
88
|
* integer pixel grid by construction). Setting the current value is a no-op;
|
|
91
89
|
* an invalid value throws and leaves the prior mode unchanged.
|
|
92
90
|
*
|
|
93
|
-
*
|
|
91
|
+
* Defaults to `Geometry` because a tile grid is made of quads that share
|
|
92
|
+
* their edges: left unsnapped, a boundary landing between two device pixels
|
|
93
|
+
* is sampled across both, so the seams blur and shimmer as the view moves.
|
|
94
|
+
* Set `None` to opt out.
|
|
95
|
+
*
|
|
96
|
+
* @default PixelSnapMode.Geometry
|
|
94
97
|
* @stable
|
|
95
98
|
*/
|
|
96
99
|
get pixelSnapMode() {
|
|
@@ -129,7 +132,10 @@ var TileLayerNode = class extends Container {
|
|
|
129
132
|
getLocalBounds() {
|
|
130
133
|
const bounds = this._localBounds;
|
|
131
134
|
const { pixelHeight, pixelWidth } = this._layer;
|
|
132
|
-
if (
|
|
135
|
+
if (this._layer.projection.orientation === "isometric") {
|
|
136
|
+
bounds.set(0, 0, 0, 0);
|
|
137
|
+
aggregateChildLocalBounds(this._chunkNodes, bounds);
|
|
138
|
+
} else if (pixelWidth !== void 0 && pixelHeight !== void 0) bounds.set(this._layer.projection.originX, this._layer.projection.originY, pixelWidth, pixelHeight);
|
|
133
139
|
else if (this._chunkNodes.length > 0) aggregateChildLocalBounds(this._chunkNodes, bounds);
|
|
134
140
|
return bounds;
|
|
135
141
|
}
|
|
@@ -171,23 +177,37 @@ var TileLayerNode = class extends Container {
|
|
|
171
177
|
const layer = this._layer;
|
|
172
178
|
for (const chunk of layer.loadedChunks()) {
|
|
173
179
|
if (chunk.empty) continue;
|
|
174
|
-
|
|
175
|
-
this._chunkNodes.push(node);
|
|
176
|
-
this.addChild(node);
|
|
180
|
+
this._addChunkNodes(chunk);
|
|
177
181
|
}
|
|
182
|
+
this._sortChunks();
|
|
178
183
|
this._syncTint();
|
|
179
184
|
}
|
|
180
185
|
/**
|
|
181
|
-
* Construct
|
|
186
|
+
* Construct the configured draw nodes for `chunk` - shared by
|
|
182
187
|
* the initial bulk build ({@link _buildChunkNodes}) and the incremental
|
|
183
188
|
* structural-listener handler, so a future constructor argument or
|
|
184
189
|
* per-node setting only needs to be added in one place.
|
|
185
190
|
*/
|
|
186
|
-
|
|
191
|
+
_addChunkNodes(chunk) {
|
|
192
|
+
const iso = this._layer.projection.orientation === "isometric";
|
|
193
|
+
const count = iso ? chunk.width + chunk.height - 1 : 1;
|
|
194
|
+
for (let i = 0; i < count; i++) {
|
|
195
|
+
const node = this._createChunkNode(chunk, iso ? i : void 0);
|
|
196
|
+
this._chunkNodes.push(node);
|
|
197
|
+
this.addChild(node);
|
|
198
|
+
this._applyTint(node);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
_sortChunks() {
|
|
202
|
+
if (this._layer.projection.orientation !== "isometric") return;
|
|
203
|
+
this._chunkNodes.sort((a, b) => a.depth - b.depth || a.firstColumn - b.firstColumn);
|
|
204
|
+
for (const [index, node] of this._chunkNodes.entries()) this.setChildIndex(node, index);
|
|
205
|
+
}
|
|
206
|
+
_createChunkNode(chunk, diagonal) {
|
|
187
207
|
const layer = this._layer;
|
|
188
|
-
const node = new TileChunkNode(chunk, layer.tilesets, layer.tileWidth, layer.tileHeight, layer.chunkWidth, layer.chunkHeight);
|
|
208
|
+
const node = new TileChunkNode(chunk, layer.tilesets, layer.tileWidth, layer.tileHeight, layer.chunkWidth, layer.chunkHeight, layer.projection, diagonal);
|
|
189
209
|
node.cullable = this._cullChunks;
|
|
190
|
-
|
|
210
|
+
node.pixelSnapMode = this._pixelSnapMode;
|
|
191
211
|
return node;
|
|
192
212
|
}
|
|
193
213
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TileLayerNode.js","names":[],"sources":["../../src/TileLayerNode.ts"],"sourcesContent":["import type { ReadonlyRectangle } from '@codexo/exojs';\nimport { Container } from '@codexo/exojs';\nimport { PixelSnapMode, type RenderPlanBuilder } from '@codexo/exojs/renderer-sdk';\n\nimport { aggregateChildLocalBounds } from './nodeBounds';\nimport { assertPixelSnapMode } from './pixelSnap';\nimport type { ReadonlyTileChunk } from './TileChunk';\nimport { TileChunkNode } from './TileChunkNode';\nimport type { ChunkStructuralEvent, TileLayer } from './TileLayer';\n\n/**\n * Options for a {@link TileLayerNode}. All optional; reserved for forward\n * compatibility.\n * @advanced\n */\nexport interface TileLayerNodeOptions {\n /**\n * Whether the layer's chunk nodes participate in per-chunk view culling.\n * Defaults to `true`. Disable only for tiny, always-on-screen layers where\n * the per-chunk bounds test is pure overhead.\n */\n readonly cullable?: boolean;\n}\n\n/**\n * A scene node that renders one generic {@link TileLayer} as a\n * {@link Container} of per-chunk {@link TileChunkNode} drawables.\n *\n * Each non-empty loaded chunk becomes one child positioned at its pixel\n * origin, so the engine's existing per-node culling drops individual chunks and\n * the render-plan optimiser batches them by tileset texture. The layer's pixel\n * `offset`, `visible` and `opacity` are all read live from the runtime layer on\n * every frame (no rebuild required).\n *\n * A `parallax` factor other than `1` makes this node's rendered position\n * camera-dependent, resolved per frame in {@link _collectContent} by patching\n * the node position against the camera centre, then restoring it - the cull\n * test runs before that patch, so a bounded layer with parallax would be\n * culled at its static base-offset bounds while actually rendering elsewhere.\n * Such a layer therefore opts out of view culling (`cullable = false`), same\n * as an unbounded layer (exactly like {@link import('./ImageLayerNode').ImageLayerNode}).\n *\n * The node references - but never owns - the {@link TileLayer}: destroying it\n * frees its chunk nodes and their cached geometry but leaves the layer, map,\n * and Loader-owned textures intact.\n *\n * Structural changes made via `_adoptChunk`/`_evictChunk` (chunk streaming)\n * are picked up incrementally as they happen, without a full rebuild.\n * {@link TileLayerNode.refresh} remains available for callers that mutate\n * chunk structure by other means (e.g. a bulk edit that bypasses\n * `_adoptChunk`/`_evictChunk`) and need a full resync. In-place tile edits to\n * existing chunks are picked up automatically via chunk revisions.\n *\n * @advanced\n */\nexport class TileLayerNode extends Container {\n private readonly _layer: TileLayer;\n private readonly _cullChunks: boolean;\n private readonly _chunkNodes: TileChunkNode[] = [];\n private _syncedOpacity = -1;\n private _syncedTint: number | null | undefined = undefined;\n private _pixelSnapMode: PixelSnapMode = PixelSnapMode.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,KAAK,mBAAmB;CAC7D;;CAGA,IAAW,QAAmB;E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M,YAAY;EACjD,KAAK,KAAK,IAAI,GAAG,GAAG,GAAG,KAAK,OAAO,OAAO;CAC5C;;;;;;CAOA,AAAQ,YAAkB;EACxB,MAAM,UAAU,KAAK,OAAO;EAC5B,MAAM,YAAY,KAAK,OAAO;EAE9B,IAAI,YAAY,KAAK,kBAAkB,cAAc,KAAK,aACxD;EAGF,KAAK,MAAM,SAAS,KAAK,aACvB,KAAK,WAAW,KAAK;EAGvB,KAAK,iBAAiB;EACtB,KAAK,cAAc;CACrB;AACF"}
|
|
1
|
+
{"version":3,"file":"TileLayerNode.js","names":[],"sources":["../../src/TileLayerNode.ts"],"sourcesContent":["import type { ReadonlyRectangle } from '@codexo/exojs';\nimport { Container } from '@codexo/exojs';\nimport { PixelSnapMode, type RenderPlanBuilder } from '@codexo/exojs/renderer-sdk';\n\nimport { aggregateChildLocalBounds } from './nodeBounds';\nimport { assertPixelSnapMode } from './pixelSnap';\nimport type { ReadonlyTileChunk } from './TileChunk';\nimport { TileChunkNode } from './TileChunkNode';\nimport type { ChunkStructuralEvent, TileLayer } from './TileLayer';\n\n/**\n * Options for a {@link TileLayerNode}. All optional; reserved for forward\n * compatibility.\n * @advanced\n */\nexport interface TileLayerNodeOptions {\n /**\n * Whether the layer's chunk nodes participate in per-chunk view culling.\n * Defaults to `true`. Disable only for tiny, always-on-screen layers where\n * the per-chunk bounds test is pure overhead.\n */\n readonly cullable?: boolean;\n}\n\n/**\n * A scene node that renders one generic {@link TileLayer} as a\n * {@link Container} of per-chunk {@link TileChunkNode} drawables.\n *\n * Orthogonal chunks become one child each. Isometric chunks become diagonal\n * slices ordered across storage boundaries, preserving painter order and\n * texture runs. Each drawable has its own culling bounds. The layer's pixel\n * `offset`, `visible` and `opacity` are all read live from the runtime layer on\n * every frame (no rebuild required).\n *\n * A `parallax` factor other than `1` makes this node's rendered position\n * camera-dependent, resolved per frame in {@link _collectContent} by patching\n * the node position against the camera centre, then restoring it - the cull\n * test runs before that patch, so a bounded layer with parallax would be\n * culled at its static base-offset bounds while actually rendering elsewhere.\n * Such a layer therefore opts out of view culling (`cullable = false`), same\n * as an unbounded layer (exactly like {@link import('./ImageLayerNode').ImageLayerNode}).\n *\n * The node references - but never owns - the {@link TileLayer}: destroying it\n * frees its chunk nodes and their cached geometry but leaves the layer, map,\n * and Loader-owned textures intact.\n *\n * Structural changes made via `_adoptChunk`/`_evictChunk` (chunk streaming)\n * are picked up incrementally as they happen, without a full rebuild.\n * {@link TileLayerNode.refresh} remains available for callers that mutate\n * chunk structure by other means (e.g. a bulk edit that bypasses\n * `_adoptChunk`/`_evictChunk`) and need a full resync. In-place tile edits to\n * existing chunks are picked up automatically via chunk revisions.\n *\n * @advanced\n */\nexport class TileLayerNode extends Container {\n private readonly _layer: TileLayer;\n private readonly _cullChunks: boolean;\n private readonly _chunkNodes: TileChunkNode[] = [];\n private _syncedOpacity = -1;\n private _syncedTint: number | null | undefined = undefined;\n private _pixelSnapMode: PixelSnapMode = PixelSnapMode.Geometry;\n\n /**\n * Bound once so `TileLayer._addStructuralListener`/`_removeStructuralListener`\n * add and remove the SAME function reference. Incrementally adds/removes\n * the `TileChunkNode` child for exactly the chunk that changed - never\n * triggers a full {@link refresh}, so every other chunk node's\n * revision-cached geometry survives untouched.\n */\n private readonly _onStructuralChange = (event: ChunkStructuralEvent): void => {\n for (let i = this._chunkNodes.length - 1; i >= 0; i--) {\n const node = this._chunkNodes[i];\n if (!node) continue;\n if (node.chunkX !== event.cx || node.chunkY !== event.cy) continue;\n this._chunkNodes.splice(i, 1);\n this.removeChild(node);\n node.destroy();\n }\n if (event.chunk !== null && !event.chunk.empty) this._addChunkNodes(event.chunk);\n this._sortChunks();\n };\n\n public constructor(layer: TileLayer, options?: TileLayerNodeOptions) {\n super();\n\n this._layer = layer;\n this._cullChunks = options?.cullable ?? true;\n\n this.setPosition(layer.offsetX, layer.offsetY);\n this._buildChunkNodes();\n\n if (!this._layer.bounded || layer.parallaxX !== 1 || layer.parallaxY !== 1 || layer.parallaxScale !== 1) {\n this.cullable = false;\n }\n\n this._layer._addStructuralListener(this._onStructuralChange);\n }\n\n /** The runtime layer this node renders. */\n public get layer(): TileLayer {\n return this._layer;\n }\n\n /**\n * Render-only pixel-snap mode applied to every chunk node in this layer (and\n * to chunks rebuilt later by {@link refresh}). Each chunk's rendered origin is\n * snapped to the active render target's device-pixel grid; because chunk\n * origins are integer multiples of the integer tile pitch from the same layer\n * origin, the whole grid stays exact and adjacent chunks cannot drift apart.\n *\n * Purely visual: tile data, the layer offset, chunk content revisions, and\n * culling bounds are never changed. `PixelSnapMode.Geometry` and `PixelSnapMode.Position` both resolve\n * to coherent origin snapping for tile chunks (chunk quads are already on the\n * integer pixel grid by construction). Setting the current value is a no-op;\n * an invalid value throws and leaves the prior mode unchanged.\n *\n * Defaults to `Geometry` because a tile grid is made of quads that share\n * their edges: left unsnapped, a boundary landing between two device pixels\n * is sampled across both, so the seams blur and shimmer as the view moves.\n * Set `None` to opt out.\n *\n * @default PixelSnapMode.Geometry\n * @stable\n */\n public get pixelSnapMode(): PixelSnapMode {\n return this._pixelSnapMode;\n }\n\n public set pixelSnapMode(mode: PixelSnapMode) {\n if (mode === this._pixelSnapMode) {\n return;\n }\n\n assertPixelSnapMode(mode);\n this._pixelSnapMode = mode;\n\n for (const chunk of this._chunkNodes) {\n chunk.pixelSnapMode = mode;\n }\n }\n\n /**\n * Rebuild the chunk-node children from the layer's current loaded chunks.\n * Call after structural mutation that creates or empties chunks. In-place\n * tile edits to existing chunks do not need a refresh.\n */\n public refresh(): this {\n const previous = [...this._chunkNodes];\n\n this.removeChildren();\n this._chunkNodes.length = 0;\n\n for (const child of previous) {\n child.destroy();\n }\n\n this._syncedOpacity = -1;\n this._syncedTint = undefined;\n this._buildChunkNodes();\n\n return this;\n }\n\n /** The chunk render nodes owned by this layer node, in build order. @internal */\n public get chunkNodes(): readonly TileChunkNode[] {\n return this._chunkNodes;\n }\n\n /**\n * Recomputed lazily on read, so it writes `_localBounds` directly rather than\n * going through `setLocalBounds`: an invalidating write inside a getter\n * would re-dirty the node on every read.\n */\n public override getLocalBounds(): ReadonlyRectangle {\n const bounds = this._localBounds;\n\n // Reading the pixel extents directly (rather than gating on `bounded`)\n // is what narrows them to numbers - `bounded` is a plain boolean getter.\n const { pixelHeight, pixelWidth } = this._layer;\n\n if (this._layer.projection.orientation === 'isometric') {\n bounds.set(0, 0, 0, 0);\n aggregateChildLocalBounds(this._chunkNodes, bounds);\n } else if (pixelWidth !== undefined && pixelHeight !== undefined) {\n bounds.set(this._layer.projection.originX, this._layer.projection.originY, pixelWidth, pixelHeight);\n } else if (this._chunkNodes.length > 0) {\n aggregateChildLocalBounds(this._chunkNodes, bounds);\n }\n\n return bounds;\n }\n\n /** @internal */\n protected override _collectContent(builder: RenderPlanBuilder): void {\n if (!this._layer.visible) {\n return;\n }\n\n this._syncTint();\n\n const layer = this._layer;\n\n const patchesPosition = layer.parallaxX !== 1 || layer.parallaxY !== 1;\n const patchesScale = layer.parallaxScale !== 1;\n\n // `offsetX`/`offsetY` are live, mutable fields (`TileColliderStreamer` and\n // `pixelToTile` already read them per call) - re-read here every frame so a\n // runtime-moved layer's rendering follows its collision rather than freezing\n // at the position it had when this node was constructed.\n if (patchesPosition || patchesScale) {\n const camCenter = builder.view.center;\n const prevScaleX = this.scale.x;\n const prevScaleY = this.scale.y;\n\n if (patchesPosition) {\n this.x = layer.offsetX + camCenter.x * (1 - layer.parallaxX);\n this.y = layer.offsetY + camCenter.y * (1 - layer.parallaxY);\n } else {\n this.setPosition(layer.offsetX, layer.offsetY);\n }\n\n if (patchesScale) {\n this.setScale(prevScaleX * layer.parallaxScale, prevScaleY * layer.parallaxScale);\n }\n\n try {\n super._collectContent(builder);\n } finally {\n if (patchesPosition) {\n this.setPosition(layer.offsetX, layer.offsetY);\n }\n\n if (patchesScale) {\n this.setScale(prevScaleX, prevScaleY);\n }\n }\n } else {\n this.setPosition(layer.offsetX, layer.offsetY);\n super._collectContent(builder);\n }\n }\n\n public override destroy(): void {\n this._layer._removeStructuralListener(this._onStructuralChange);\n\n const children = [...this._chunkNodes];\n\n this._chunkNodes.length = 0;\n\n super.destroy();\n\n for (const child of children) {\n child.destroy();\n }\n }\n\n private _buildChunkNodes(): void {\n const layer = this._layer;\n\n for (const chunk of layer.loadedChunks()) {\n if (chunk.empty) {\n continue;\n }\n\n this._addChunkNodes(chunk);\n }\n\n this._sortChunks();\n this._syncTint();\n }\n\n /**\n * Construct the configured draw nodes for `chunk` - shared by\n * the initial bulk build ({@link _buildChunkNodes}) and the incremental\n * structural-listener handler, so a future constructor argument or\n * per-node setting only needs to be added in one place.\n */\n private _addChunkNodes(chunk: ReadonlyTileChunk): void {\n const iso = this._layer.projection.orientation === 'isometric';\n const count = iso ? chunk.width + chunk.height - 1 : 1;\n for (let i = 0; i < count; i++) {\n const node = this._createChunkNode(chunk, iso ? i : undefined);\n this._chunkNodes.push(node);\n this.addChild(node);\n this._applyTint(node);\n }\n }\n\n private _sortChunks(): void {\n if (this._layer.projection.orientation !== 'isometric') return;\n this._chunkNodes.sort((a, b) => a.depth - b.depth || a.firstColumn - b.firstColumn);\n for (const [index, node] of this._chunkNodes.entries()) this.setChildIndex(node, index);\n }\n\n private _createChunkNode(chunk: ReadonlyTileChunk, diagonal?: number): TileChunkNode {\n const layer = this._layer;\n const node = new TileChunkNode(chunk, layer.tilesets, layer.tileWidth, layer.tileHeight, layer.chunkWidth, layer.chunkHeight, layer.projection, diagonal);\n\n node.cullable = this._cullChunks;\n // Unconditional: a chunk built after the layer was set to `None` has to\n // inherit that too, not just a non-default mode.\n node.pixelSnapMode = this._pixelSnapMode;\n\n return node;\n }\n\n /**\n * Compute and apply this layer's live tint (opacity as alpha, `tintColor`\n * as RGB multiply) to a single chunk node. Used both by {@link _syncTint}'s\n * bulk pass and by the structural-listener handler for a freshly-added\n * node - a node added between two \"nothing changed\" full syncs must still\n * receive the current tint, which a change-detection-guarded bulk pass\n * alone would skip.\n */\n private _applyTint(node: TileChunkNode): void {\n const tintColor = this._layer.tintColor;\n const r = tintColor === null ? 255 : (tintColor >> 16) & 0xff;\n const g = tintColor === null ? 255 : (tintColor >> 8) & 0xff;\n const b = tintColor === null ? 255 : tintColor & 0xff;\n node.tint.set(r, g, b, this._layer.opacity);\n }\n\n /**\n * Propagate the layer's live opacity and tint colour onto every chunk\n * render tint if either changed since the last call. Opacity drives the\n * tint alpha; `tintColor` (`0xRRGGBB`) multiplies the RGB (white = no tint).\n */\n private _syncTint(): void {\n const opacity = this._layer.opacity;\n const tintColor = this._layer.tintColor;\n\n if (opacity === this._syncedOpacity && tintColor === this._syncedTint) {\n return;\n }\n\n for (const child of this._chunkNodes) {\n this._applyTint(child);\n }\n\n this._syncedOpacity = opacity;\n this._syncedTint = tintColor;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuDA,IAAa,gBAAb,cAAmC,UAAU;CAC3C,AAAiB;CACjB,AAAiB;CACjB,AAAiB,cAA+B,CAAC;CACjD,AAAQ,iBAAiB;CACzB,AAAQ,cAAyC;CACjD,AAAQ,iBAAgC,cAAc;;;;;;;;CAStD,AAAiB,uBAAuB,UAAsC;EAC5E,KAAK,IAAI,IAAI,KAAK,YAAY,SAAS,GAAG,KAAK,GAAG,KAAK;GACrD,MAAM,OAAO,KAAK,YAAY;GAC9B,IAAI,CAAC,MAAM;GACX,IAAI,KAAK,WAAW,MAAM,MAAM,KAAK,WAAW,MAAM,IAAI;GAC1D,KAAK,YAAY,OAAO,GAAG,CAAC;GAC5B,KAAK,YAAY,IAAI;GACrB,KAAK,QAAQ;EACf;EACA,IAAI,MAAM,UAAU,QAAQ,CAAC,MAAM,MAAM,OAAO,KAAK,eAAe,MAAM,KAAK;EAC/E,KAAK,YAAY;CACnB;CAEA,AAAO,YAAY,OAAkB,SAAgC;EACnE,MAAM;EAEN,KAAK,SAAS;EACd,KAAK,cAAc,SAAS,YAAY;EAExC,KAAK,YAAY,MAAM,SAAS,MAAM,OAAO;EAC7C,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3,6 +3,7 @@ import type { ObjectLayer, ObjectSchema } from './ObjectLayer';
|
|
|
3
3
|
import { type TileLayer } from './TileLayer';
|
|
4
4
|
import type { TileMapViewOptions } from './TileMapView';
|
|
5
5
|
import { TileMapView } from './TileMapView';
|
|
6
|
+
import { TileProjection } from './TileProjection';
|
|
6
7
|
import { type TileSet } from './TileSet';
|
|
7
8
|
import type { ResolvedTile, TileProperties } from './types';
|
|
8
9
|
/**
|
|
@@ -10,6 +11,8 @@ import type { ResolvedTile, TileProperties } from './types';
|
|
|
10
11
|
* @advanced
|
|
11
12
|
*/
|
|
12
13
|
export interface TileMapOptions {
|
|
14
|
+
/** Shared projection; defaults to an orthogonal grid of the supplied tile size. */
|
|
15
|
+
readonly projection?: TileProjection;
|
|
13
16
|
/** Map name (for debugging). */
|
|
14
17
|
readonly name?: string;
|
|
15
18
|
/**
|
|
@@ -92,6 +95,7 @@ export interface TileMapOptions {
|
|
|
92
95
|
* @advanced
|
|
93
96
|
*/
|
|
94
97
|
export declare class TileMap {
|
|
98
|
+
readonly projection: TileProjection;
|
|
95
99
|
/** Map name (debug). */
|
|
96
100
|
readonly name: string;
|
|
97
101
|
/** Map width in tiles, or `undefined` if unbounded. */
|
|
@@ -277,7 +281,7 @@ export declare class TileMap {
|
|
|
277
281
|
*/
|
|
278
282
|
clearTileAt(layerId: number, tx: number, ty: number): void;
|
|
279
283
|
/**
|
|
280
|
-
* Convert a
|
|
284
|
+
* Convert a grid vertex to display pixels (the top diamond vertex for isometric cells)
|
|
281
285
|
* in map-local space (ignoring layer offsets).
|
|
282
286
|
*/
|
|
283
287
|
tileToPixel(tx: number, ty: number): {
|
|
@@ -285,7 +289,7 @@ export declare class TileMap {
|
|
|
285
289
|
y: number;
|
|
286
290
|
};
|
|
287
291
|
/**
|
|
288
|
-
* Convert a
|
|
292
|
+
* Convert a display position in map-local space to the tile coordinate
|
|
289
293
|
* that contains it. Uses `floor`. May return coordinates outside map bounds.
|
|
290
294
|
*/
|
|
291
295
|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