@codexo/exojs-tilemap 0.18.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.
Files changed (75) hide show
  1. package/README.md +56 -34
  2. package/dist/esm/ChunkStreamer.d.ts.map +1 -1
  3. package/dist/esm/ChunkStreamer.js +28 -6
  4. package/dist/esm/ChunkStreamer.js.map +1 -1
  5. package/dist/esm/ImageLayer.d.ts +1 -1
  6. package/dist/esm/ImageLayer.d.ts.map +1 -1
  7. package/dist/esm/ImageLayerNode.d.ts.map +1 -1
  8. package/dist/esm/MapObject.d.ts +2 -2
  9. package/dist/esm/MapObject.d.ts.map +1 -1
  10. package/dist/esm/MapObject.js.map +1 -1
  11. package/dist/esm/MapObjectSpawner.d.ts.map +1 -1
  12. package/dist/esm/MapSpawnSession.d.ts.map +1 -1
  13. package/dist/esm/MapWorld.d.ts +8 -8
  14. package/dist/esm/MapWorld.d.ts.map +1 -1
  15. package/dist/esm/MapWorldRuntime.d.ts.map +1 -1
  16. package/dist/esm/ObjectLayer.d.ts +26 -10
  17. package/dist/esm/ObjectLayer.d.ts.map +1 -1
  18. package/dist/esm/ObjectLayer.js +28 -0
  19. package/dist/esm/ObjectLayer.js.map +1 -1
  20. package/dist/esm/SampledChunkSource.d.ts.map +1 -1
  21. package/dist/esm/TileAnimator.d.ts.map +1 -1
  22. package/dist/esm/TileChunk.d.ts.map +1 -1
  23. package/dist/esm/TileChunkNode.js +47 -10
  24. package/dist/esm/TileChunkNode.js.map +1 -1
  25. package/dist/esm/TileLayer.d.ts +11 -2
  26. package/dist/esm/TileLayer.d.ts.map +1 -1
  27. package/dist/esm/TileLayer.js +20 -10
  28. package/dist/esm/TileLayer.js.map +1 -1
  29. package/dist/esm/TileLayerNode.d.ts +6 -4
  30. package/dist/esm/TileLayerNode.d.ts.map +1 -1
  31. package/dist/esm/TileLayerNode.js +36 -21
  32. package/dist/esm/TileLayerNode.js.map +1 -1
  33. package/dist/esm/TileMap.d.ts +6 -2
  34. package/dist/esm/TileMap.d.ts.map +1 -1
  35. package/dist/esm/TileMap.js +13 -12
  36. package/dist/esm/TileMap.js.map +1 -1
  37. package/dist/esm/TileMapBand.d.ts.map +1 -1
  38. package/dist/esm/TileMapNode.d.ts.map +1 -1
  39. package/dist/esm/TileMapNode.js +4 -1
  40. package/dist/esm/TileMapNode.js.map +1 -1
  41. package/dist/esm/TileMapView.d.ts.map +1 -1
  42. package/dist/esm/TileProjection.d.ts +59 -0
  43. package/dist/esm/TileProjection.d.ts.map +1 -0
  44. package/dist/esm/TileProjection.js +106 -0
  45. package/dist/esm/TileProjection.js.map +1 -0
  46. package/dist/esm/TileSet.d.ts.map +1 -1
  47. package/dist/esm/WangSet.d.ts.map +1 -1
  48. package/dist/esm/WorkerSampledChunkSource.d.ts.map +1 -1
  49. package/dist/esm/autoTile.d.ts.map +1 -1
  50. package/dist/esm/chunkGeometry.js +78 -50
  51. package/dist/esm/chunkGeometry.js.map +1 -1
  52. package/dist/esm/index.js +2 -1
  53. package/dist/esm/projectObject.d.ts +4 -0
  54. package/dist/esm/projectObject.d.ts.map +1 -0
  55. package/dist/esm/projectObject.js +87 -0
  56. package/dist/esm/projectObject.js.map +1 -0
  57. package/dist/esm/public.d.ts +1 -0
  58. package/dist/esm/public.d.ts.map +1 -1
  59. package/dist/esm/tileCollision.d.ts +2 -2
  60. package/dist/esm/tileCollision.d.ts.map +1 -1
  61. package/dist/esm/tileCollision.js +48 -16
  62. package/dist/esm/tileCollision.js.map +1 -1
  63. package/dist/esm/tilemapSerializers.js +1 -1
  64. package/dist/esm/tilemapSerializers.js.map +1 -1
  65. package/dist/esm/types.d.ts +3 -3
  66. package/dist/esm/types.d.ts.map +1 -1
  67. package/dist/esm/webgl2/WebGl2TileChunkRenderer.js +5 -4
  68. package/dist/esm/webgl2/WebGl2TileChunkRenderer.js.map +1 -1
  69. package/dist/esm/webgl2/shaders/tile-chunk.vert.js +1 -1
  70. package/dist/esm/webgl2/shaders/tile-chunk.vert.js.map +1 -1
  71. package/dist/esm/webgpu/WebGpuTileChunkRenderer.js +63 -27
  72. package/dist/esm/webgpu/WebGpuTileChunkRenderer.js.map +1 -1
  73. package/dist/esm/webgpu/shaders/tile-chunk.wgsl.js +1 -1
  74. package/dist/esm/webgpu/shaders/tile-chunk.wgsl.js.map +1 -1
  75. package/package.json +4 -4
@@ -1 +1 @@
1
- {"version":3,"file":"ObjectLayer.js","names":[],"sources":["../../src/ObjectLayer.ts"],"sourcesContent":["import type { ResolvedTile, TileProperties, TilePropertyObjectRef, TilePropertyValue } from './types';\nimport { TilePropertyKind } from './types';\n\n/**\n * Geometry kinds for a {@link TileMapObject}, as an `as const` value object.\n *\n * Modelled as a frozen string map (not a TS `enum`) so the values stay\n * wire-compatible with the Tiled string serialisation, survive\n * `verbatimModuleSyntax` (no emitted runtime helper), and follow the package\n * convention for enum-like constants. Use the members for ergonomic, typo-safe\n * call sites: `layer.byKind(ObjectKind.Polygon)`.\n * @stable\n */\nexport const ObjectKind = {\n Rectangle: 'rectangle',\n Ellipse: 'ellipse',\n Polygon: 'polygon',\n Polyline: 'polyline',\n Point: 'point',\n Tile: 'tile',\n Text: 'text',\n} as const;\n\n/** Geometry discriminant for a {@link TileMapObject}. */\nexport type ObjectKind = (typeof ObjectKind)[keyof typeof ObjectKind];\n\n/**\n * Geometry discriminant for a {@link TileMapObject}.\n * Structural alias of {@link ObjectKind}; retained so existing code keeps\n * compiling. New code may prefer {@link ObjectKind}.\n */\nexport type TileMapObjectKind = ObjectKind;\n\n/** A point in object-layer space (pixels, relative to the object). */\nexport interface ObjectPoint {\n readonly x: number;\n readonly y: number;\n}\n\n/** Fields shared by every {@link TileMapObject} kind. */\ninterface TileMapObjectBase<P extends TileProperties = TileProperties> {\n /** Source-unique object id. */\n readonly id: number;\n /**\n * Stable string identity assigned by the authoring format, when it has one.\n *\n * LDtk sets it to the entity `iid`, which is globally unique and survives\n * re-ordering, re-export and level moves - the identity to persist in a\n * savegame. Tiled has no such field and leaves this unset; there, {@link id}\n * is the identity and it is unique only within its map.\n */\n readonly sourceId?: string;\n /** Object name (may be empty; not unique). */\n readonly name: string;\n /** Object class/type string (Tiled `type`/`class`; may be empty). */\n readonly type: string;\n /** X of the object origin in object-layer pixel space. */\n readonly x: number;\n /** Y of the object origin in object-layer pixel space. */\n readonly y: number;\n /** Bounding width in px (0 for points). */\n readonly width: number;\n /** Bounding height in px (0 for points). */\n readonly height: number;\n /**\n * Rotation in degrees, clockwise, about `(x, y)` - except on a\n * {@link TileObject}, whose pivot stays at the source format's own anchor and\n * is generally not `(x, y)`. See {@link TileObject} for why.\n */\n readonly rotation: number;\n /** Whether the object is marked visible. */\n readonly visible: boolean;\n /** Immutable custom properties. */\n readonly properties: P;\n /**\n * The raw source-format record this object was parsed from, for the rare\n * case that needs a field this model does not carry. Adapters that keep\n * their parsed document alive set it (`LdtkEntityInstance` for LDtk,\n * `TiledObject` for Tiled); a procedurally built object has none.\n *\n * Reading it ties the code to one source format - prefer the typed fields.\n */\n readonly source?: unknown;\n}\n\n/** An axis-aligned rectangle object spanning `[x, y, width, height]`. */\nexport interface RectangleObject<P extends TileProperties = TileProperties> extends TileMapObjectBase<P> {\n readonly kind: typeof ObjectKind.Rectangle;\n}\n\n/** An ellipse inscribed in `[x, y, width, height]`. */\nexport interface EllipseObject<P extends TileProperties = TileProperties> extends TileMapObjectBase<P> {\n readonly kind: typeof ObjectKind.Ellipse;\n}\n\n/** A single point at `(x, y)`. */\nexport interface PointObject<P extends TileProperties = TileProperties> extends TileMapObjectBase<P> {\n readonly kind: typeof ObjectKind.Point;\n}\n\n/** A closed polygon; `points` are relative to the object origin. */\nexport interface PolygonObject<P extends TileProperties = TileProperties> extends TileMapObjectBase<P> {\n readonly kind: typeof ObjectKind.Polygon;\n readonly points: readonly ObjectPoint[];\n}\n\n/** An open polyline; `points` are relative to the object origin. */\nexport interface PolylineObject<P extends TileProperties = TileProperties> extends TileMapObjectBase<P> {\n readonly kind: typeof ObjectKind.Polyline;\n readonly points: readonly ObjectPoint[];\n}\n\n/**\n * A tile (GID) object carrying a resolved tile reference.\n *\n * `x`/`y` are the top-left corner of the bounding box, the same convention as\n * every other object kind. Source formats that anchor a tile object elsewhere\n * normalise to the corner on import: Tiled stores the position at the\n * tileset's `objectalignment` point (bottom-left by default on an orthogonal\n * map, bottom-centre on an isometric one) and rotates the tile image about\n * that point, so a non-zero {@link TileMapObjectBase.rotation} on a tile\n * object still pivots about the source anchor rather than about `(x, y)`.\n *\n * The owning tileset's drawing offset (Tiled `tileoffset`, reachable as\n * `tile.tileset.offsetX`/`offsetY`) is likewise **not** folded into `x`/`y`.\n * Object layers are data-only, so nothing in this package draws a tile object;\n * code that does has to add that offset itself to match how a tile layer\n * places the same tile.\n */\nexport interface TileObject<P extends TileProperties = TileProperties> extends TileMapObjectBase<P> {\n readonly kind: typeof ObjectKind.Tile;\n readonly tile: ResolvedTile;\n}\n\n/** Text styling options carried by a {@link TextObject}. */\nexport interface TextStyle {\n /** The text content. */\n readonly text: string;\n /** Text colour as 0xRRGGBB, or `null` if default. */\n readonly color?: number | null;\n /** Font family name. */\n readonly fontFamily?: string;\n /** Font size in pixels. */\n readonly pixelSize?: number;\n /** Bold text. */\n readonly bold?: boolean;\n /** Italic text. */\n readonly italic?: boolean;\n /** Underline text. */\n readonly underline?: boolean;\n /** Strikeout text. */\n readonly strikeout?: boolean;\n /** Wrap text within the object bounds. */\n readonly wrap?: boolean;\n /** Horizontal alignment. */\n readonly halign?: 'left' | 'center' | 'right' | 'justify';\n /** Vertical alignment. */\n readonly valign?: 'top' | 'center' | 'bottom';\n}\n\n/** A text object carrying styled text content within `[x, y, width, height]`. */\nexport interface TextObject<P extends TileProperties = TileProperties> extends TileMapObjectBase<P> {\n readonly kind: typeof ObjectKind.Text;\n readonly text: TextStyle;\n}\n\n/**\n * A format-independent map object. The geometry kind is the discriminant;\n * narrow on `kind` to read shape-specific fields. Template objects are not\n * yet represented.\n *\n * The optional property-shape parameter `P` lets typed accessors\n * (see {@link ObjectLayer.byType}) narrow `properties` to a developer-declared\n * schema. It defaults to the generic {@link TileProperties} bag, so the plain\n * `TileMapObject` form is unchanged.\n * @advanced\n */\nexport type TileMapObject<P extends TileProperties = TileProperties> =\n RectangleObject<P> | EllipseObject<P> | PointObject<P> | PolygonObject<P> | PolylineObject<P> | TileObject<P> | TextObject<P>;\n\n/**\n * A developer-declared mapping from object `type`/class strings to the property\n * shape an object of that type is expected to carry. Supplied as the type\n * parameter to {@link ObjectLayer} to unlock the typed accessors\n * ({@link ObjectLayer.byType}, {@link ObjectLayer.where}).\n *\n * @remarks\n * A schema is a **developer promise, not a runtime guarantee.** Tiled data is\n * untyped at runtime and ExoJS performs no validation against the schema -\n * the property objects are returned exactly as parsed. The schema only refines\n * the static type of `properties` for ergonomic, typo-safe field access. If the\n * source data does not match the declared shape, reads still succeed but the\n * static type is a fiction. Validate at the boundary if you need certainty.\n *\n * @example\n * ```ts\n * const EntityType = { Spawn: 'spawn', Pickup: 'pickup' } as const;\n * interface LevelObjects {\n * [EntityType.Spawn]: { team: 'red' | 'blue' };\n * [EntityType.Pickup]: { item: 'coin' | 'gem'; amount: number };\n * }\n * const entities = map.getObjectLayer<LevelObjects>('Entities');\n * entities.byType(EntityType.Spawn)[0].properties.team; // 'red' | 'blue'\n * ```\n * @stable\n */\nexport type ObjectSchema = Record<string, TileProperties>;\n\n/**\n * A {@link TileMapObject} whose `properties` are narrowed to the schema shape\n * declared for the object `type` `T` in schema `S`.\n * @advanced\n */\nexport type TypedObject<S extends ObjectSchema, T extends keyof S & string> = TileMapObject<S[T]>;\n\n/** Filter for {@link ObjectLayer.query}. Unspecified fields match everything. */\nexport interface ObjectQuery {\n /** Match objects whose `name` equals this. */\n readonly name?: string;\n /** Match objects whose `type`/class equals this. */\n readonly type?: string;\n /** Match objects of this geometry kind. */\n readonly kind?: TileMapObjectKind;\n /** Match objects that carry this property key. */\n readonly property?: string;\n /** When combined with `property`, also require the property value to equal this. */\n readonly value?: TilePropertyValue;\n}\n\n/**\n * Type guard for the {@link TilePropertyObjectRef} variant of\n * {@link TilePropertyValue}.\n * @internal\n */\nconst isTilePropertyObjectRef = (value: TilePropertyValue): value is TilePropertyObjectRef =>\n typeof value === 'object' && value !== null && !Array.isArray(value) && (value as { kind?: unknown }).kind === TilePropertyKind.ObjectRef;\n\n/**\n * Equality used by {@link ObjectLayer.query}'s `value` filter.\n *\n * Scalars and `null` compare with `===`. `objectRef` values compare by `id`\n * alone - the one genuinely common \"find all objects referencing X\" query\n * need - regardless of differing LDtk navigation fields. Every other\n * structured shape (`point`, `tileRef`, arrays, nested property bags) has no\n * obvious value-equality semantics (exact float coordinates? array order?)\n * and only matches when reference-identical; use `query({ property })`\n * (presence-only) for those.\n * @internal\n */\nconst tilePropertyValueEquals = (a: TilePropertyValue, b: TilePropertyValue): boolean => {\n if (a === b) return true;\n if (isTilePropertyObjectRef(a) && isTilePropertyObjectRef(b)) return a.id === b.id;\n return false;\n};\n\n/** Construction options for an {@link ObjectLayer}. */\nexport interface ObjectLayerOptions {\n /** Layer id (unique within the map). */\n readonly id: number;\n /** Layer name. */\n readonly name?: string;\n /** Layer class string. */\n readonly class?: string;\n /** Whether the layer is visible. Default `true`. */\n readonly visible?: boolean;\n /** Layer opacity in `[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` = full camera speed (normal),\n * `0.5` = half speed (farther away), `0` = stationary. Default `1`.\n */\n readonly parallaxX?: number;\n /**\n * Parallax scroll factor on the Y axis. `1` = full camera speed (normal),\n * `0.5` = half speed (farther away), `0` = stationary. Default `1`.\n */\n readonly parallaxY?: number;\n /** Uniform parallax scale around the layer origin. Default `1`. */\n readonly parallaxScale?: number;\n /**\n * Multiplicative layer tint as a `0xRRGGBB` integer, or `null` for no tint\n * (Tiled `tintcolor`). Default `null`.\n */\n readonly tintColor?: number | null;\n /**\n * Draw order for the objects (Tiled `draworder`): `'topdown'` (sorted by `y`)\n * or `'index'` (source order). Informational; objects are stored as given.\n * Default `'topdown'`.\n */\n readonly drawOrder?: 'topdown' | 'index';\n /** The objects in this layer. */\n readonly objects?: readonly TileMapObject[];\n /** Layer-level properties (copied and frozen). */\n readonly properties?: TileProperties;\n}\n\n/**\n * A data-only layer of {@link TileMapObject}s - spawn points, trigger zones,\n * collision regions, markers. Object layers are not rendered by the tile\n * renderer; they are parsed and exposed for gameplay use (e.g. building physics\n * colliders, placing entities).\n *\n * The presentation fields the source format attaches to a layer -\n * {@link visible}, {@link opacity}, {@link offsetX}/{@link offsetY},\n * {@link parallaxX}/{@link parallaxY}, {@link parallaxScale}, and\n * {@link tintColor} - are carried\n * through in full, with any enclosing group layers' contribution already\n * folded in, so an object layer describes the same placement and shading its\n * neighbouring tile and image layers do. Nothing here acts on them: code that\n * draws these objects itself is what applies them.\n *\n * Query with {@link query} (untyped, fully back-compatible) or, when an\n * {@link ObjectSchema} type argument `S` is supplied, with the typed accessors\n * {@link byType}, {@link byKind}, and {@link where} - these narrow `properties`\n * to the developer-declared shape. The schema is **opt-in**: the default type\n * parameter reproduces the original untyped behaviour, so\n * `new ObjectLayer(options)` and `map.getObjectLayer('x')` are unchanged.\n *\n * @remarks\n * A schema is a developer promise, not a runtime guarantee - Tiled data is\n * untyped at runtime and ExoJS performs no validation. See {@link ObjectSchema}.\n *\n * @typeParam S - Optional {@link ObjectSchema} mapping object `type` strings to\n * their property shapes. Defaults to a generic schema (every type maps to the\n * loose {@link TileProperties} bag).\n *\n * @advanced\n */\nexport class ObjectLayer<S extends ObjectSchema = ObjectSchema> {\n /** Layer-kind discriminant (distinguishes object layers from tile layers). */\n public readonly kind = 'object' as const;\n\n /** Layer id (unique within the map). */\n public readonly id: number;\n /** Layer name. */\n public readonly name: string;\n /** Layer class string. */\n public readonly class: string;\n /** Whether the layer is visible. */\n public readonly visible: boolean;\n /** Layer opacity in `[0, 1]`. */\n public readonly opacity: number;\n /** Layer pixel offset X. */\n public readonly offsetX: number;\n /** Layer pixel offset Y. */\n public readonly offsetY: number;\n /**\n * Parallax scroll factor on the X axis - the same quantity\n * {@link import('./TileLayer').TileLayer.parallaxX} carries, so an object\n * layer authored beside a tile layer in the same parallax group reports the\n * same factor. `1` = full camera speed, `0.5` = half speed, `0` =\n * stationary. Nothing in this package applies it: object layers are\n * data-only, so placing an object relative to the camera is the consumer's\n * job (see {@link ObjectLayer}).\n */\n public readonly parallaxX: number;\n /** Parallax scroll factor on the Y axis. See {@link ObjectLayer.parallaxX}. */\n public readonly parallaxY: number;\n /** Uniform scale applied around the layer origin by consumers that render this data-only layer. */\n public readonly parallaxScale: number;\n /**\n * Multiplicative layer tint as `0xRRGGBB`, or `null` for no tint. Carried\n * from the source map (including the accumulated tint of any enclosing group\n * layers) for code that draws these objects itself; like\n * {@link ObjectLayer.parallaxX}, nothing in this package applies it.\n */\n public readonly tintColor: number | null;\n /** Draw order for the objects (Tiled `draworder`). Informational. */\n public readonly drawOrder: 'topdown' | 'index';\n /** Immutable layer-level properties. */\n public readonly properties: TileProperties;\n /** The objects in this layer (insertion order). */\n public readonly objects: readonly TileMapObject[];\n\n public constructor(options: ObjectLayerOptions) {\n this.id = options.id;\n this.name = options.name ?? '';\n this.class = options.class ?? '';\n this.visible = options.visible ?? true;\n this.opacity = options.opacity ?? 1;\n this.offsetX = options.offsetX ?? 0;\n this.offsetY = options.offsetY ?? 0;\n this.parallaxX = options.parallaxX ?? 1;\n this.parallaxY = options.parallaxY ?? 1;\n this.parallaxScale = options.parallaxScale ?? 1;\n if (!Number.isFinite(this.parallaxScale) || this.parallaxScale <= 0) {\n throw new Error('ObjectLayer parallaxScale must be a positive finite number.');\n }\n this.tintColor = options.tintColor ?? null;\n this.drawOrder = options.drawOrder ?? 'topdown';\n this.properties = options.properties ? Object.freeze({ ...options.properties }) : Object.freeze({});\n this.objects = options.objects ? Object.freeze([...options.objects]) : Object.freeze([]);\n }\n\n /** Objects matching every specified criterion of `filter`. Returns a fresh array. */\n public query(filter: ObjectQuery = {}): TileMapObject[] {\n return this.objects.filter(object => {\n if (filter.name !== undefined && object.name !== filter.name) {\n return false;\n }\n\n if (filter.type !== undefined && object.type !== filter.type) {\n return false;\n }\n\n if (filter.kind !== undefined && object.kind !== filter.kind) {\n return false;\n }\n\n if (filter.property !== undefined) {\n // TilePropertyValue never includes `undefined`, so an `undefined`\n // read is a reliable \"key absent\" signal (equivalent to, but avoids\n // re-indexing after, an `in` check).\n const value = object.properties[filter.property];\n if (value === undefined) {\n return false;\n }\n\n if (filter.value !== undefined && !tilePropertyValueEquals(value, filter.value)) {\n return false;\n }\n }\n\n return true;\n });\n }\n\n /**\n * Objects whose `type` equals `type`, with `properties` narrowed to the\n * schema shape `S[T]`. Returns a fresh array (insertion order).\n *\n * The narrowing is a static convenience only - no runtime validation is\n * performed (see {@link ObjectSchema}). On an unschematised layer this\n * behaves like `query({ type })` with `TileProperties` properties.\n */\n public byType<T extends keyof S & string>(type: T): Array<TypedObject<S, T>> {\n return this.objects.filter(object => object.type === type) as unknown as Array<TypedObject<S, T>>;\n }\n\n /**\n * Objects of the given geometry {@link ObjectKind}, narrowed to that\n * geometry's member type (e.g. `byKind(ObjectKind.Polygon)` yields\n * {@link PolygonObject}s with their `points`). Returns a fresh array.\n */\n public byKind<K extends ObjectKind>(kind: K): Array<Extract<TileMapObject, { kind: K }>> {\n return this.objects.filter(object => object.kind === kind) as Array<Extract<TileMapObject, { kind: K }>>;\n }\n\n /**\n * Objects of `type` (typed as in {@link byType}) that also satisfy\n * `predicate`. A convenience combination of {@link byType} and `Array.filter`\n * that keeps the narrowed `properties` type inside the predicate. Returns a\n * fresh array.\n */\n public where<T extends keyof S & string>(type: T, predicate: (object: TypedObject<S, T>) => boolean): Array<TypedObject<S, T>> {\n return this.byType(type).filter(object => predicate(object));\n }\n\n /** First object with the given id, or undefined. */\n public getObjectById(id: number): TileMapObject | undefined {\n return this.objects.find(object => object.id === id);\n }\n\n /** First object with the given name, or undefined. */\n public getObjectByName(name: string): TileMapObject | undefined {\n return this.objects.find(object => object.name === name);\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAaA,MAAa,aAAa;CACxB,WAAW;CACX,SAAS;CACT,SAAS;CACT,UAAU;CACV,OAAO;CACP,MAAM;CACN,MAAM;AACR;;;;;;AAqNA,MAAM,2BAA2B,UAC/B,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK,KAAM,MAA6B,SAAS,iBAAiB;;;;;;;;;;;;;AAclI,MAAM,2BAA2B,GAAsB,MAAkC;CACvF,IAAI,MAAM,GAAG,OAAO;CACpB,IAAI,wBAAwB,CAAC,KAAK,wBAAwB,CAAC,GAAG,OAAO,EAAE,OAAO,EAAE;CAChF,OAAO;AACT;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+EA,IAAa,cAAb,MAAgE;;CAE9D,AAAgB,OAAO;;CAGvB,AAAgB;;CAEhB,AAAgB;;CAEhB,AAAgB;;CAEhB,AAAgB;;CAEhB,AAAgB;;CAEhB,AAAgB;;CAEhB,AAAgB;;;;;;;;;;CAUhB,AAAgB;;CAEhB,AAAgB;;CAEhB,AAAgB;;;;;;;CAOhB,AAAgB;;CAEhB,AAAgB;;CAEhB,AAAgB;;CAEhB,AAAgB;CAEhB,AAAO,YAAY,SAA6B;EAC9C,KAAK,KAAK,QAAQ;EAClB,KAAK,OAAO,QAAQ,QAAQ;EAC5B,KAAK,QAAQ,QAAQ,SAAS;EAC9B,KAAK,UAAU,QAAQ,WAAW;EAClC,KAAK,UAAU,QAAQ,WAAW;EAClC,KAAK,UAAU,QAAQ,WAAW;EAClC,KAAK,UAAU,QAAQ,WAAW;EAClC,KAAK,YAAY,QAAQ,aAAa;EACtC,KAAK,YAAY,QAAQ,aAAa;EACtC,KAAK,gBAAgB,QAAQ,iBAAiB;EAC9C,IAAI,CAAC,OAAO,SAAS,KAAK,a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yC;EAC9D,OAAO,KAAK,QAAQ,MAAK,WAAU,OAAO,SAAS,IAAI;CACzD;AACF"}
1
+ {"version":3,"file":"ObjectLayer.js","names":[],"sources":["../../src/ObjectLayer.ts"],"sourcesContent":["import type { TileProjection } from './TileProjection';\nimport type { ResolvedTile, TileProperties, TilePropertyObjectRef, TilePropertyValue } from './types';\nimport { TilePropertyKind } from './types';\n\n/**\n * Geometry kinds for a {@link TileMapObject}, as an `as const` value object.\n *\n * Modelled as a frozen string map (not a TS `enum`) so the values stay\n * wire-compatible with the Tiled string serialisation, survive\n * `verbatimModuleSyntax` (no emitted runtime helper), and follow the package\n * convention for enum-like constants. Use the members for ergonomic, typo-safe\n * call sites: `layer.byKind(ObjectKind.Polygon)`.\n * @stable\n */\nexport const ObjectKind = {\n Rectangle: 'rectangle',\n Ellipse: 'ellipse',\n Polygon: 'polygon',\n Polyline: 'polyline',\n Point: 'point',\n Tile: 'tile',\n Text: 'text',\n} as const;\n\n/** Geometry discriminant for a {@link TileMapObject}. */\nexport type ObjectKind = (typeof ObjectKind)[keyof typeof ObjectKind];\n\n/**\n * Geometry discriminant for a {@link TileMapObject}.\n * Structural alias of {@link ObjectKind}; retained so existing code keeps\n * compiling. New code may prefer {@link ObjectKind}.\n */\nexport type TileMapObjectKind = ObjectKind;\n\n/** A point in object-layer space (pixels, relative to the object). */\nexport interface ObjectPoint {\n readonly x: number;\n readonly y: number;\n}\n\n/** Fields shared by every {@link TileMapObject} kind. */\ninterface TileMapObjectBase<P extends TileProperties = TileProperties> {\n /** Source-unique object id. */\n readonly id: number;\n /**\n * Stable string identity assigned by the authoring format, when it has one.\n *\n * LDtk sets it to the entity `iid`, which is globally unique and survives\n * re-ordering, re-export and level moves - the identity to persist in a\n * savegame. Tiled has no such field and leaves this unset; there, {@link id}\n * is the identity and it is unique only within its map.\n */\n readonly sourceId?: string;\n /** Object name (may be empty; not unique). */\n readonly name: string;\n /** Object class/type string (Tiled `type`/`class`; may be empty). */\n readonly type: string;\n /** X of the object origin in layer coordinates; logical pixels when the layer has a projection. */\n readonly x: number;\n /** Y of the object origin in layer coordinates; logical pixels when the layer has a projection. */\n readonly y: number;\n /** Bounding width in px (0 for points). */\n readonly width: number;\n /** Bounding height in px (0 for points). */\n readonly height: number;\n /**\n * Rotation in degrees, clockwise, about `(x, y)` - except on a\n * {@link TileObject}, whose pivot stays at the source format's own anchor and\n * is generally not `(x, y)`. See {@link TileObject} for why.\n */\n readonly rotation: number;\n /** Whether the object is marked visible. */\n readonly visible: boolean;\n /** Immutable custom properties. */\n readonly properties: P;\n /**\n * The raw source-format record this object was parsed from, for the rare\n * case that needs a field this model does not carry. Adapters that keep\n * their parsed document alive set it (`LdtkEntityInstance` for LDtk,\n * `TiledObject` for Tiled); a procedurally built object has none.\n *\n * Reading it ties the code to one source format - prefer the typed fields.\n */\n readonly source?: unknown;\n}\n\n/** An axis-aligned rectangle object spanning `[x, y, width, height]`. */\nexport interface RectangleObject<P extends TileProperties = TileProperties> extends TileMapObjectBase<P> {\n readonly kind: typeof ObjectKind.Rectangle;\n}\n\n/** An ellipse inscribed in `[x, y, width, height]`. */\nexport interface EllipseObject<P extends TileProperties = TileProperties> extends TileMapObjectBase<P> {\n readonly kind: typeof ObjectKind.Ellipse;\n}\n\n/** A single point at `(x, y)`. */\nexport interface PointObject<P extends TileProperties = TileProperties> extends TileMapObjectBase<P> {\n readonly kind: typeof ObjectKind.Point;\n}\n\n/** A closed polygon; `points` are relative to the object origin. */\nexport interface PolygonObject<P extends TileProperties = TileProperties> extends TileMapObjectBase<P> {\n readonly kind: typeof ObjectKind.Polygon;\n readonly points: readonly ObjectPoint[];\n}\n\n/** An open polyline; `points` are relative to the object origin. */\nexport interface PolylineObject<P extends TileProperties = TileProperties> extends TileMapObjectBase<P> {\n readonly kind: typeof ObjectKind.Polyline;\n readonly points: readonly ObjectPoint[];\n}\n\n/**\n * A tile (GID) object carrying a resolved tile reference.\n *\n * `x`/`y` are the top-left corner of the bounding box, the same convention as\n * every other object kind. Source formats that anchor a tile object elsewhere\n * normalise to the corner on import: Tiled stores the position at the\n * tileset's `objectalignment` point (bottom-left by default on an orthogonal\n * map, bottom-centre on an isometric one) and rotates the tile image about\n * that point, so a non-zero {@link TileMapObjectBase.rotation} on a tile\n * object still pivots about the source anchor rather than about `(x, y)`.\n * Isometric Tiled objects expose this anchor as `rotationOrigin`;\n * `getDisplayObject` projects both the unrotated corner and this pivot.\n *\n * The owning tileset's drawing offset (Tiled `tileoffset`, reachable as\n * `tile.tileset.offsetX`/`offsetY`) is likewise **not** folded into `x`/`y`.\n * Object layers are data-only, so nothing in this package draws a tile object;\n * code that does has to add that offset itself to match how a tile layer\n * places the same tile.\n */\nexport interface TileObject<P extends TileProperties = TileProperties> extends TileMapObjectBase<P> {\n readonly kind: typeof ObjectKind.Tile;\n readonly tile: ResolvedTile;\n /** Image rotation pivot in layer coordinates, logical when projected. Adapters may omit it when unavailable. */\n readonly rotationOrigin?: ObjectPoint;\n}\n\n/** Text styling options carried by a {@link TextObject}. */\nexport interface TextStyle {\n /** The text content. */\n readonly text: string;\n /** Text colour as 0xRRGGBB, or `null` if default. */\n readonly color?: number | null;\n /** Font family name. */\n readonly fontFamily?: string;\n /** Font size in pixels. */\n readonly pixelSize?: number;\n /** Bold text. */\n readonly bold?: boolean;\n /** Italic text. */\n readonly italic?: boolean;\n /** Underline text. */\n readonly underline?: boolean;\n /** Strikeout text. */\n readonly strikeout?: boolean;\n /** Wrap text within the object bounds. */\n readonly wrap?: boolean;\n /** Horizontal alignment. */\n readonly halign?: 'left' | 'center' | 'right' | 'justify';\n /** Vertical alignment. */\n readonly valign?: 'top' | 'center' | 'bottom';\n}\n\n/** A text object carrying styled text content within `[x, y, width, height]`. */\nexport interface TextObject<P extends TileProperties = TileProperties> extends TileMapObjectBase<P> {\n readonly kind: typeof ObjectKind.Text;\n readonly text: TextStyle;\n}\n\n/**\n * A format-independent map object. The geometry kind is the discriminant;\n * narrow on `kind` to read shape-specific fields. Template objects are not\n * yet represented.\n *\n * The optional property-shape parameter `P` lets typed accessors\n * (see {@link ObjectLayer.byType}) narrow `properties` to a developer-declared\n * schema. It defaults to the generic {@link TileProperties} bag, so the plain\n * `TileMapObject` form is unchanged.\n * @advanced\n */\nexport type TileMapObject<P extends TileProperties = TileProperties> =\n RectangleObject<P> | EllipseObject<P> | PointObject<P> | PolygonObject<P> | PolylineObject<P> | TileObject<P> | TextObject<P>;\n\n/**\n * A developer-declared mapping from object `type`/class strings to the property\n * shape an object of that type is expected to carry. Supplied as the type\n * parameter to {@link ObjectLayer} to unlock the typed accessors\n * ({@link ObjectLayer.byType}, {@link ObjectLayer.where}).\n *\n * @remarks\n * A schema is a **developer promise, not a runtime guarantee.** Tiled data is\n * untyped at runtime and ExoJS performs no validation against the schema -\n * the property objects are returned exactly as parsed. The schema only refines\n * the static type of `properties` for ergonomic, typo-safe field access. If the\n * source data does not match the declared shape, reads still succeed but the\n * static type is a fiction. Validate at the boundary if you need certainty.\n *\n * @example\n * ```ts\n * const EntityType = { Spawn: 'spawn', Pickup: 'pickup' } as const;\n * interface LevelObjects {\n * [EntityType.Spawn]: { team: 'red' | 'blue' };\n * [EntityType.Pickup]: { item: 'coin' | 'gem'; amount: number };\n * }\n * const entities = map.getObjectLayer<LevelObjects>('Entities');\n * entities.byType(EntityType.Spawn)[0].properties.team; // 'red' | 'blue'\n * ```\n * @stable\n */\nexport type ObjectSchema = Record<string, TileProperties>;\n\n/**\n * A {@link TileMapObject} whose `properties` are narrowed to the schema shape\n * declared for the object `type` `T` in schema `S`.\n * @advanced\n */\nexport type TypedObject<S extends ObjectSchema, T extends keyof S & string> = TileMapObject<S[T]>;\n\n/** Filter for {@link ObjectLayer.query}. Unspecified fields match everything. */\nexport interface ObjectQuery {\n /** Match objects whose `name` equals this. */\n readonly name?: string;\n /** Match objects whose `type`/class equals this. */\n readonly type?: string;\n /** Match objects of this geometry kind. */\n readonly kind?: TileMapObjectKind;\n /** Match objects that carry this property key. */\n readonly property?: string;\n /** When combined with `property`, also require the property value to equal this. */\n readonly value?: TilePropertyValue;\n}\n\n/**\n * Type guard for the {@link TilePropertyObjectRef} variant of\n * {@link TilePropertyValue}.\n * @internal\n */\nconst isTilePropertyObjectRef = (value: TilePropertyValue): value is TilePropertyObjectRef =>\n typeof value === 'object' && value !== null && !Array.isArray(value) && (value as { kind?: unknown }).kind === TilePropertyKind.ObjectRef;\n\n/**\n * Equality used by {@link ObjectLayer.query}'s `value` filter.\n *\n * Scalars and `null` compare with `===`. `objectRef` values compare by `id`\n * alone - the one genuinely common \"find all objects referencing X\" query\n * need - regardless of differing LDtk navigation fields. Every other\n * structured shape (`point`, `tileRef`, arrays, nested property bags) has no\n * obvious value-equality semantics (exact float coordinates? array order?)\n * and only matches when reference-identical; use `query({ property })`\n * (presence-only) for those.\n * @internal\n */\nconst tilePropertyValueEquals = (a: TilePropertyValue, b: TilePropertyValue): boolean => {\n if (a === b) return true;\n if (isTilePropertyObjectRef(a) && isTilePropertyObjectRef(b)) return a.id === b.id;\n return false;\n};\n\n/** Construction options for an {@link ObjectLayer}. */\nexport interface ObjectLayerOptions {\n /** Object geometry uses logical pixels when supplied; display placement is available through getDisplayObject. */\n readonly projection?: TileProjection;\n /** Layer id (unique within the map). */\n readonly id: number;\n /** Layer name. */\n readonly name?: string;\n /** Layer class string. */\n readonly class?: string;\n /** Whether the layer is visible. Default `true`. */\n readonly visible?: boolean;\n /** Layer opacity in `[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` = full camera speed (normal),\n * `0.5` = half speed (farther away), `0` = stationary. Default `1`.\n */\n readonly parallaxX?: number;\n /**\n * Parallax scroll factor on the Y axis. `1` = full camera speed (normal),\n * `0.5` = half speed (farther away), `0` = stationary. Default `1`.\n */\n readonly parallaxY?: number;\n /** Uniform parallax scale around the layer origin. Default `1`. */\n readonly parallaxScale?: number;\n /**\n * Multiplicative layer tint as a `0xRRGGBB` integer, or `null` for no tint\n * (Tiled `tintcolor`). Default `null`.\n */\n readonly tintColor?: number | null;\n /**\n * Draw order for the objects (Tiled `draworder`): `'topdown'` (sorted by `y`)\n * or `'index'` (source order). Informational; objects are stored as given.\n * Default `'topdown'`.\n */\n readonly drawOrder?: 'topdown' | 'index';\n /** The objects in this layer. */\n readonly objects?: readonly TileMapObject[];\n /** Layer-level properties (copied and frozen). */\n readonly properties?: TileProperties;\n}\n\n/**\n * A data-only layer of {@link TileMapObject}s - spawn points, trigger zones,\n * collision regions, markers. Object layers are not rendered by the tile\n * renderer; they are parsed and exposed for gameplay use (e.g. building physics\n * colliders, placing entities).\n *\n * The presentation fields the source format attaches to a layer -\n * {@link visible}, {@link opacity}, {@link offsetX}/{@link offsetY},\n * {@link parallaxX}/{@link parallaxY}, {@link parallaxScale}, and\n * {@link tintColor} - are carried\n * through in full, with any enclosing group layers' contribution already\n * folded in, so an object layer describes the same placement and shading its\n * neighbouring tile and image layers do. Nothing here acts on them: code that\n * draws these objects itself is what applies them.\n *\n * Query with {@link query} (untyped, fully back-compatible) or, when an\n * {@link ObjectSchema} type argument `S` is supplied, with the typed accessors\n * {@link byType}, {@link byKind}, and {@link where} - these narrow `properties`\n * to the developer-declared shape. The schema is **opt-in**: the default type\n * parameter reproduces the original untyped behaviour, so\n * `new ObjectLayer(options)` and `map.getObjectLayer('x')` are unchanged.\n *\n * @remarks\n * A schema is a developer promise, not a runtime guarantee - Tiled data is\n * untyped at runtime and ExoJS performs no validation. See {@link ObjectSchema}.\n *\n * @typeParam S - Optional {@link ObjectSchema} mapping object `type` strings to\n * their property shapes. Defaults to a generic schema (every type maps to the\n * loose {@link TileProperties} bag).\n *\n * @advanced\n */\nexport class ObjectLayer<S extends ObjectSchema = ObjectSchema> {\n /** Projection of the logical object geometry, or undefined for ordinary display-space objects. */\n public readonly projection: TileProjection | undefined;\n /** Layer-kind discriminant (distinguishes object layers from tile layers). */\n public readonly kind = 'object' as const;\n\n /** Layer id (unique within the map). */\n public readonly id: number;\n /** Layer name. */\n public readonly name: string;\n /** Layer class string. */\n public readonly class: string;\n /** Whether the layer is visible. */\n public readonly visible: boolean;\n /** Layer opacity in `[0, 1]`. */\n public readonly opacity: number;\n /** Layer pixel offset X. */\n public readonly offsetX: number;\n /** Layer pixel offset Y. */\n public readonly offsetY: number;\n /**\n * Parallax scroll factor on the X axis - the same quantity\n * {@link import('./TileLayer').TileLayer.parallaxX} carries, so an object\n * layer authored beside a tile layer in the same parallax group reports the\n * same factor. `1` = full camera speed, `0.5` = half speed, `0` =\n * stationary. Nothing in this package applies it: object layers are\n * data-only, so placing an object relative to the camera is the consumer's\n * job (see {@link ObjectLayer}).\n */\n public readonly parallaxX: number;\n /** Parallax scroll factor on the Y axis. See {@link ObjectLayer.parallaxX}. */\n public readonly parallaxY: number;\n /** Uniform scale applied around the layer origin by consumers that render this data-only layer. */\n public readonly parallaxScale: number;\n /**\n * Multiplicative layer tint as `0xRRGGBB`, or `null` for no tint. Carried\n * from the source map (including the accumulated tint of any enclosing group\n * layers) for code that draws these objects itself; like\n * {@link ObjectLayer.parallaxX}, nothing in this package applies it.\n */\n public readonly tintColor: number | null;\n /** Draw order for the objects (Tiled `draworder`). Informational. */\n public readonly drawOrder: 'topdown' | 'index';\n /** Immutable layer-level properties. */\n public readonly properties: TileProperties;\n /** The objects in this layer (insertion order). */\n public readonly objects: readonly TileMapObject[];\n\n public constructor(options: ObjectLayerOptions) {\n this.id = options.id;\n this.projection = options.projection;\n this.name = options.name ?? '';\n this.class = options.class ?? '';\n this.visible = options.visible ?? true;\n this.opacity = options.opacity ?? 1;\n this.offsetX = options.offsetX ?? 0;\n this.offsetY = options.offsetY ?? 0;\n this.parallaxX = options.parallaxX ?? 1;\n this.parallaxY = options.parallaxY ?? 1;\n this.parallaxScale = options.parallaxScale ?? 1;\n if (!Number.isFinite(this.parallaxScale) || this.parallaxScale <= 0) {\n throw new Error('ObjectLayer parallaxScale must be a positive finite number.');\n }\n this.tintColor = options.tintColor ?? null;\n this.drawOrder = options.drawOrder ?? 'topdown';\n this.properties = options.properties ? Object.freeze({ ...options.properties }) : Object.freeze({});\n this.objects = options.objects ? Object.freeze([...options.objects]) : Object.freeze([]);\n }\n\n /**\n * Returns display-space geometry including the layer offset. Isometric\n * rectangles become polygons; ellipses retain their exact affine shape.\n * Tile/text dimensions remain display pixels. Parallax and scene transforms\n * are applied by the consumer, after this conversion.\n */\n public getDisplayObject(object: TileMapObject): TileMapObject {\n const projected = this.projection?.projectObject(object) ?? object;\n const position = { x: projected.x + this.offsetX, y: projected.y + this.offsetY };\n if (projected.kind === 'tile' && projected.rotationOrigin) {\n return { ...projected, ...position, rotationOrigin: { x: projected.rotationOrigin.x + this.offsetX, y: projected.rotationOrigin.y + this.offsetY } };\n }\n return { ...projected, ...position };\n }\n\n /** Objects matching every specified criterion of `filter`. Returns a fresh array. */\n public query(filter: ObjectQuery = {}): TileMapObject[] {\n return this.objects.filter(object => {\n if (filter.name !== undefined && object.name !== filter.name) {\n return false;\n }\n\n if (filter.type !== undefined && object.type !== filter.type) {\n return false;\n }\n\n if (filter.kind !== undefined && object.kind !== filter.kind) {\n return false;\n }\n\n if (filter.property !== undefined) {\n // TilePropertyValue never includes `undefined`, so an `undefined`\n // read is a reliable \"key absent\" signal (equivalent to, but avoids\n // re-indexing after, an `in` check).\n const value = object.properties[filter.property];\n if (value === undefined) {\n return false;\n }\n\n if (filter.value !== undefined && !tilePropertyValueEquals(value, filter.value)) {\n return false;\n }\n }\n\n return true;\n });\n }\n\n /**\n * Objects whose `type` equals `type`, with `properties` narrowed to the\n * schema shape `S[T]`. Returns a fresh array (insertion order).\n *\n * The narrowing is a static convenience only - no runtime validation is\n * performed (see {@link ObjectSchema}). On an unschematised layer this\n * behaves like `query({ type })` with `TileProperties` properties.\n */\n public byType<T extends keyof S & string>(type: T): Array<TypedObject<S, T>> {\n return this.objects.filter(object => object.type === type) as unknown as Array<TypedObject<S, T>>;\n }\n\n /**\n * Objects of the given geometry {@link ObjectKind}, narrowed to that\n * geometry's member type (e.g. `byKind(ObjectKind.Polygon)` yields\n * {@link PolygonObject}s with their `points`). Returns a fresh array.\n */\n public byKind<K extends ObjectKind>(kind: K): Array<Extract<TileMapObject, { kind: K }>> {\n return this.objects.filter(object => object.kind === kind) as Array<Extract<TileMapObject, { kind: K }>>;\n }\n\n /**\n * Objects of `type` (typed as in {@link byType}) that also satisfy\n * `predicate`. A convenience combination of {@link byType} and `Array.filter`\n * that keeps the narrowed `properties` type inside the predicate. Returns a\n * fresh array.\n */\n public where<T extends keyof S & string>(type: T, predicate: (object: TypedObject<S, T>) => boolean): Array<TypedObject<S, T>> {\n return this.byType(type).filter(object => predicate(object));\n }\n\n /** First object with the given id, or undefined. */\n public getObjectById(id: number): TileMapObject | undefined {\n return this.objects.find(object => object.id === id);\n }\n\n /** First object with the given name, or undefined. */\n public getObjectByName(name: string): TileMapObject | undefined {\n return this.objects.find(object => object.name === name);\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAcA,MAAa,aAAa;CACxB,WAAW;CACX,SAAS;CACT,SAAS;CACT,UAAU;CACV,OAAO;CACP,MAAM;CACN,MAAM;AACR;;;;;;AAyNA,MAAM,2BAA2B,UAC/B,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK,KAAM,MAA6B,SAAS,iBAAiB;;;;;;;;;;;;;AAclI,MAAM,2BAA2B,GAAsB,MAAkC;CACvF,IAAI,MAAM,GAAG,OAAO;CACpB,IAAI,wBAAwB,CAAC,KAAK,wBAAwB,CAAC,GAAG,OAAO,EAAE,OAAO,EAAE;CAChF,OAAO;AACT;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiFA,IAAa,cAAb,MAAgE;;CAE9D,AAAgB;;CAEhB,AAAgB,OAAO;;CAGvB,AAAgB;;CAEhB,AAAgB;;CAEhB,AAAgB;;CAEhB,AAAgB;;CAEhB,A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,aAAa,CAAC;AAC7C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAG5C;;;GAGG;AACH,MAAM,WAAW,yBAAyB;IACxC;;;;;;;OAOG;IACH,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC;IACvC;;;;;OAKG;IACH,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,YAAY,GAAG,IAAI,CAAC;CAC5E;AAED;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,wBAAwB,GAAI,OAAO,SAAS,EAAE,SAAS,yBAAyB,KAAG,WAiC/F,CAAC"}
1
+ {"version":3,"file":"SampledChunkSource.d.ts","sourceRoot":"","sources":["../../src/SampledChunkSource.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAgB,WAAW,EAAE,MAAM,eAAe,CAAC;AAC/D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAG5C;;;GAGG;AACH,MAAM,WAAW,yBAAyB;IACxC;;;;;;;OAOG;IACH,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC;IACvC;;;;;OAKG;IACH,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,YAAY,GAAG,IAAI,CAAC;CAC5E;AAED;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,wBAAwB,UAAW,SAAS,WAAW,yBAAyB,KAAG,WAiC/F,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"TileAnimator.d.ts","sourceRoot":"","sources":["../../src/TileAnimator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAm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BAAiB;IACjD,iCAAiC;IACjC,SAAgB,EAAE,EAAE,MAAM,CAAC;IAC3B,iCAAiC;IACjC,SAAgB,EAAE,EAAE,MAAM,CAAC;IAE3B,oCAAoC;IACpC,SAAgB,KAAK,EAAE,MAAM,CAAC;IAC9B,qCAAqC;IACrC,SAAgB,MAAM,EAAE,MAAM,CAAC;IAE/B,yEAAyE;IACzE,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAc;IAErC,oEAAoE;IACpE,OAAO,CAAC,MAAM,CAAwB;IAEtC,kEAAkE;IAClE,OAAO,CAAC,SAAS,CAAK;IAEtB;;;;;;;OAOG;IACH,OAAO,CAAC,eAAe,CAAgC;IAEvD;;;;;;OAMG;IACH,YAAmB,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,EAwC7F;IAED,2DAA2D;IAC3D,OAAO,CAAC,MAAM;IAId;;;OAGG;IACH,OAAO,CAAC,mBAAmB;IAa3B,kBAAkB;IACX,QAAQ,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,UAAU,CAGlD;IAED,kBAAkB;IAClB,IAAW,KAAK,IAAI,OAAO,CAK1B;IAED,kBAAkB;IAClB,IAAW,QAAQ,IAAI,MAAM,CAE5B;IAED,kBAAkB;IACX,UAAU,IAAI,WAAW,CAE/B;IAqGD,OAAO,CAAC,YAAY;CAMrB"}
@@ -1,13 +1,15 @@
1
1
  import { buildChunkPages } from "./chunkGeometry.js";
2
2
  import { TileChunk } from "./TileChunk.js";
3
+ import { TileProjection } from "./TileProjection.js";
3
4
  import { Drawable } from "@codexo/exojs/renderer-sdk";
4
5
 
5
6
  //#region src/TileChunkNode.ts
6
7
  /**
7
8
  * A single renderable tile chunk. One `TileChunkNode` is a {@link Drawable}
8
9
  * that owns the batched quad geometry for exactly one {@link ReadonlyTileChunk}
9
- * of one {@link import('./TileLayer').TileLayer}, positioned at the chunk's
10
- * pixel origin within the owning {@link TileLayerNode}.
10
+ * of one {@link import('./TileLayer').TileLayer}. Orthogonal nodes use the
11
+ * chunk's pixel origin; isometric nodes draw one diagonal slice and share
12
+ * the projection origin to keep pixel snapping independent of chunk layout.
11
13
  *
12
14
  * Geometry is built lazily and cached against the source chunk's `revision`:
13
15
  * the renderer reads {@link TileChunkNode.pages} on each visible frame, but a
@@ -27,8 +29,12 @@ var TileChunkNode = class extends Drawable {
27
29
  _tilesets;
28
30
  _tileWidth;
29
31
  _tileHeight;
30
- _pixelWidth;
31
- _pixelHeight;
32
+ _projection;
33
+ _geometryX;
34
+ _geometryY;
35
+ diagonal;
36
+ depth;
37
+ firstColumn;
32
38
  _pages = [];
33
39
  _builtRevision = -1;
34
40
  /**
@@ -53,15 +59,26 @@ var TileChunkNode = class extends Drawable {
53
59
  * `cx * chunkWidthTiles`.
54
60
  * @param chunkHeightTiles The layer's (unclamped) chunk height in tiles.
55
61
  */
56
- constructor(chunk, tilesets, tileWidth, tileHeight, chunkWidthTiles, chunkHeightTiles) {
62
+ constructor(chunk, tilesets, tileWidth, tileHeight, chunkWidthTiles, chunkHeightTiles, projection = new TileProjection({
63
+ tileWidth,
64
+ tileHeight
65
+ }), diagonal) {
57
66
  super();
58
67
  this._chunk = chunk;
59
68
  this._tilesets = tilesets;
60
69
  this._tileWidth = tileWidth;
61
70
  this._tileHeight = tileHeight;
62
- this._pixelWidth = chunk.width * tileWidth;
63
- this._pixelHeight = chunk.height * tileHeight;
64
- this.setPosition(chunk.cx * chunkWidthTiles * tileWidth, chunk.cy * chunkHeightTiles * tileHeight);
71
+ this._projection = projection;
72
+ this.diagonal = diagonal;
73
+ const tx = chunk.cx * chunkWidthTiles;
74
+ const ty = chunk.cy * chunkHeightTiles;
75
+ this.depth = tx + ty + (diagonal ?? 0);
76
+ this.firstColumn = tx + Math.max(0, (diagonal ?? 0) - chunk.height + 1);
77
+ const position = projection.tileToPixel(tx, ty);
78
+ const iso = projection.orientation === "isometric";
79
+ this._geometryX = iso ? position.x - projection.originX : 0;
80
+ this._geometryY = iso ? position.y - projection.originY : 0;
81
+ this.setPosition(iso ? projection.originX : position.x, iso ? projection.originY : position.y);
65
82
  if (chunk instanceof TileChunk) chunk._addDirtyListener(this._onChunkDirty);
66
83
  }
67
84
  /** The signed chunk coordinates this node renders. */
@@ -78,7 +95,7 @@ var TileChunkNode = class extends Drawable {
78
95
  */
79
96
  get pages() {
80
97
  if (this._builtRevision !== this._chunk.revision) {
81
- this._pages = buildChunkPages(this._chunk, this._tilesets, this._tileWidth, this._tileHeight);
98
+ this._pages = buildChunkPages(this._chunk, this._tilesets, this._tileWidth, this._tileHeight, this._projection, this.diagonal, this._geometryX, this._geometryY);
82
99
  this._builtRevision = this._chunk.revision;
83
100
  }
84
101
  return this._pages;
@@ -93,7 +110,27 @@ var TileChunkNode = class extends Drawable {
93
110
  * would re-dirty the node on every read.
94
111
  */
95
112
  getLocalBounds() {
96
- return this._localBounds.set(0, 0, this._pixelWidth, this._pixelHeight);
113
+ if (!(this._projection.orientation === "isometric")) return this._localBounds.set(0, 0, this._chunk.width * this._tileWidth, this._chunk.height * this._tileHeight);
114
+ const d = this.diagonal;
115
+ const minX = d === void 0 ? 0 : Math.max(0, d - this._chunk.height + 1);
116
+ const maxX = d === void 0 ? this._chunk.width - 1 : Math.min(this._chunk.width - 1, d);
117
+ const minY = d === void 0 ? 0 : d - maxX;
118
+ const maxY = d === void 0 ? this._chunk.height - 1 : d - minX;
119
+ let left = (minX - maxY - 1) * this._tileWidth / 2;
120
+ let top = (minX + maxY) * this._tileHeight / 2;
121
+ let right = (maxX - minY + 1) * this._tileWidth / 2;
122
+ let bottom = (maxX + minY) * this._tileHeight / 2 + this._tileHeight;
123
+ const baseLeft = left;
124
+ const baseTop = top;
125
+ const baseRight = right;
126
+ const baseBottom = bottom;
127
+ for (const tileset of this._tilesets) {
128
+ left = Math.min(left, baseLeft + tileset.offsetX);
129
+ top = Math.min(top, baseTop + this._tileHeight - tileset.tileHeight + tileset.offsetY);
130
+ right = Math.max(right, baseRight + tileset.tileWidth - this._tileWidth + tileset.offsetX);
131
+ bottom = Math.max(bottom, baseBottom + tileset.offsetY);
132
+ }
133
+ return this._localBounds.set(left + this._geometryX, top + this._geometryY, right - left, bottom - top);
97
134
  }
98
135
  destroy() {
99
136
  if (this._chunk instanceof TileChunk) this._chunk._removeDirtyListener(this._onChunkDirty);
@@ -1 +1 @@
1
- {"version":3,"file":"TileChunkNode.js","names":[],"sources":["../../src/TileChunkNode.ts"],"sourcesContent":["import type { ReadonlyRectangle } from '@codexo/exojs';\nimport { Drawable } from '@codexo/exojs/renderer-sdk';\n\nimport type { ChunkPage } from './chunkGeometry';\nimport { buildChunkPages } from './chunkGeometry';\nimport type { ReadonlyTileChunk } from './TileChunk';\nimport { TileChunk } from './TileChunk';\nimport type { TileSet } from './TileSet';\n\n/**\n * A single renderable tile chunk. One `TileChunkNode` is a {@link Drawable}\n * that owns the batched quad geometry for exactly one {@link ReadonlyTileChunk}\n * of one {@link import('./TileLayer').TileLayer}, positioned at the chunk's\n * pixel origin within the owning {@link TileLayerNode}.\n *\n * Geometry is built lazily and cached against the source chunk's `revision`:\n * the renderer reads {@link TileChunkNode.pages} on each visible frame, but a\n * rebuild only happens when the underlying chunk actually changed. Off-screen\n * chunks are culled by their accurate {@link getLocalBounds} before `render`\n * is ever called, so a camera pan rebuilds nothing.\n *\n * The node references - but never owns - the runtime chunk, tilesets, and\n * tileset textures. Destroying it releases only its cached CPU geometry; the\n * `TileMap`/`TileLayer` data and Loader-owned textures are untouched.\n *\n * @internal Package-internal render node; the renderer is registered for this\n * class. Applications use {@link TileMapNode} / {@link TileLayerNode}.\n */\nexport class TileChunkNode extends Drawable {\n private readonly _chunk: ReadonlyTileChunk;\n private readonly _tilesets: readonly TileSet[];\n private readonly _tileWidth: number;\n private readonly _tileHeight: number;\n private readonly _pixelWidth: number;\n private readonly _pixelHeight: number;\n\n private _pages: ChunkPage[] = [];\n private _builtRevision = -1;\n\n /**\n * Bound once so `TileChunk._addDirtyListener`/`_removeDirtyListener` add and\n * remove the SAME function reference. Pushes the chunk's revision bump onto\n * this node's own content revision (see `TileChunk._dirtyListeners`) so a\n * `RetainedContainer` ancestor - which skips walking a content-clean\n * subtree entirely - observes the mutation and re-collects instead of\n * replaying stale cached geometry.\n */\n private readonly _onChunkDirty = (): void => {\n this.invalidateContent();\n };\n\n /**\n * @param chunk The readonly chunk this node renders.\n * @param tilesets The owning layer's tileset array.\n * @param tileWidth Map/layer tile cell width in pixels.\n * @param tileHeight Map/layer tile cell height in pixels.\n * @param chunkWidthTiles The layer's (unclamped) chunk width in tiles, used\n * to compute the chunk's pixel origin. Edge chunks\n * report a smaller `chunk.width`, but always start at\n * `cx * chunkWidthTiles`.\n * @param chunkHeightTiles The layer's (unclamped) chunk height in tiles.\n */\n public constructor(\n chunk: ReadonlyTileChunk,\n tilesets: readonly TileSet[],\n tileWidth: number,\n tileHeight: number,\n chunkWidthTiles: number,\n chunkHeightTiles: number,\n ) {\n super();\n\n this._chunk = chunk;\n this._tilesets = tilesets;\n this._tileWidth = tileWidth;\n this._tileHeight = tileHeight;\n this._pixelWidth = chunk.width * tileWidth;\n this._pixelHeight = chunk.height * tileHeight;\n\n this.setPosition(chunk.cx * chunkWidthTiles * tileWidth, chunk.cy * chunkHeightTiles * tileHeight);\n\n // `loadedChunks()` always yields the concrete `TileChunk` behind the\n // readonly view (see TileLayer); the guard is defensive only.\n if (chunk instanceof TileChunk) {\n chunk._addDirtyListener(this._onChunkDirty);\n }\n }\n\n /** The signed chunk coordinates this node renders. */\n public get chunkX(): number {\n return this._chunk.cx;\n }\n\n public get chunkY(): number {\n return this._chunk.cy;\n }\n\n /**\n * The revision-cached per-tileset page geometry. Rebuilt only when the source\n * chunk's `revision` advances; otherwise the same arrays are returned.\n * @internal Read by the per-backend tile chunk renderer.\n */\n public get pages(): readonly ChunkPage[] {\n if (this._builtRevision !== this._chunk.revision) {\n this._pages = buildChunkPages(this._chunk, this._tilesets, this._tileWidth, this._tileHeight);\n this._builtRevision = this._chunk.revision;\n }\n\n return this._pages;\n }\n\n /** `true` when the chunk has no drawable tiles (no geometry, no draw calls). */\n public get isEmpty(): boolean {\n return this.pages.length === 0;\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 return this._localBounds.set(0, 0, this._pixelWidth, this._pixelHeight);\n }\n\n public override destroy(): void {\n if (this._chunk instanceof TileChunk) {\n this._chunk._removeDirtyListener(this._onChunkDirty);\n }\n\n this._pages = [];\n this._builtRevision = -1;\n\n super.destroy();\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA4BA,IAAa,gBAAb,cAAmC,SAAS;CAC1C,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CAEjB,AAAQ,SAAsB,CAAC;CAC/B,AAAQ,iBAAiB;;;;;;;;;CAUzB,AAAiB,sBAA4B;EAC3C,KAAK,kBAAkB;CACzB;;;;;;;;;;;;CAaA,AAAO,YACL,OACA,UACA,WACA,YACA,iBACA,kBACA;EACA,MAAM;EAEN,KAAK,SAAS;EACd,KAAK,YAAY;EACjB,KAAK,aAAa;EAClB,KAAK,cAAc;EACnB,KAAK,cAAc,MAAM,QAAQ;EACjC,KAAK,eAAe,MAAM,SAAS;EAEnC,KAAK,YAAY,MAAM,KAAK,kBAAkB,WAAW,MAAM,KAAK,mBAAmB,UAAU;EAIjG,IAAI,iBAAiB,WACnB,MAAM,kBAAkB,KAAK,aAAa;CAE9C;;CAGA,IAAW,SAAiB;EAC1B,OAAO,KAAK,OAAO;CACrB;CAEA,IAAW,SAAiB;EAC1B,OAAO,KAAK,OAAO;CACrB;;;;;;CAOA,IAAW,QAA8B;EACvC,IAAI,KAAK,mBAAmB,KAAK,OAAO,UAAU;GAChD,KAAK,SAAS,gBAAgB,KAAK,QAAQ,KAAK,WAAW,KAAK,YAAY,KAAK,WAAW;GAC5F,KAAK,iBAAiB,KAAK,OAAO;EACpC;EAEA,OAAO,KAAK;CACd;;CAGA,IAAW,UAAmB;EAC5B,OAAO,KAAK,MAAM,WAAW;CAC/B;;;;;;CAOA,AAAgB,iBAAoC;EAClD,OAAO,KAAK,aAAa,IAAI,GAAG,GAAG,KAAK,aAAa,KAAK,YAAY;CACxE;CAEA,AAAgB,UAAgB;EAC9B,IAAI,KAAK,kBAAkB,WACzB,KAAK,OAAO,qBAAqB,KAAK,aAAa;EAGrD,KAAK,SAAS,CAAC;EACf,KAAK,iBAAiB;EAEtB,MAAM,QAAQ;CAChB;AACF"}
1
+ {"version":3,"file":"TileChunkNode.js","names":[],"sources":["../../src/TileChunkNode.ts"],"sourcesContent":["import type { ReadonlyRectangle } from '@codexo/exojs';\nimport { Drawable } from '@codexo/exojs/renderer-sdk';\n\nimport type { ChunkPage } from './chunkGeometry';\nimport { buildChunkPages } from './chunkGeometry';\nimport type { ReadonlyTileChunk } from './TileChunk';\nimport { TileChunk } from './TileChunk';\nimport { TileProjection } from './TileProjection';\nimport type { TileSet } from './TileSet';\n\n/**\n * A single renderable tile chunk. One `TileChunkNode` is a {@link Drawable}\n * that owns the batched quad geometry for exactly one {@link ReadonlyTileChunk}\n * of one {@link import('./TileLayer').TileLayer}. Orthogonal nodes use the\n * chunk's pixel origin; isometric nodes draw one diagonal slice and share\n * the projection origin to keep pixel snapping independent of chunk layout.\n *\n * Geometry is built lazily and cached against the source chunk's `revision`:\n * the renderer reads {@link TileChunkNode.pages} on each visible frame, but a\n * rebuild only happens when the underlying chunk actually changed. Off-screen\n * chunks are culled by their accurate {@link getLocalBounds} before `render`\n * is ever called, so a camera pan rebuilds nothing.\n *\n * The node references - but never owns - the runtime chunk, tilesets, and\n * tileset textures. Destroying it releases only its cached CPU geometry; the\n * `TileMap`/`TileLayer` data and Loader-owned textures are untouched.\n *\n * @internal Package-internal render node; the renderer is registered for this\n * class. Applications use {@link TileMapNode} / {@link TileLayerNode}.\n */\nexport class TileChunkNode extends Drawable {\n private readonly _chunk: ReadonlyTileChunk;\n private readonly _tilesets: readonly TileSet[];\n private readonly _tileWidth: number;\n private readonly _tileHeight: number;\n private readonly _projection: TileProjection;\n private readonly _geometryX: number;\n private readonly _geometryY: number;\n public readonly diagonal: number | undefined;\n public readonly depth: number;\n public readonly firstColumn: number;\n\n private _pages: ChunkPage[] = [];\n private _builtRevision = -1;\n\n /**\n * Bound once so `TileChunk._addDirtyListener`/`_removeDirtyListener` add and\n * remove the SAME function reference. Pushes the chunk's revision bump onto\n * this node's own content revision (see `TileChunk._dirtyListeners`) so a\n * `RetainedContainer` ancestor - which skips walking a content-clean\n * subtree entirely - observes the mutation and re-collects instead of\n * replaying stale cached geometry.\n */\n private readonly _onChunkDirty = (): void => {\n this.invalidateContent();\n };\n\n /**\n * @param chunk The readonly chunk this node renders.\n * @param tilesets The owning layer's tileset array.\n * @param tileWidth Map/layer tile cell width in pixels.\n * @param tileHeight Map/layer tile cell height in pixels.\n * @param chunkWidthTiles The layer's (unclamped) chunk width in tiles, used\n * to compute the chunk's pixel origin. Edge chunks\n * report a smaller `chunk.width`, but always start at\n * `cx * chunkWidthTiles`.\n * @param chunkHeightTiles The layer's (unclamped) chunk height in tiles.\n */\n public constructor(\n chunk: ReadonlyTileChunk,\n tilesets: readonly TileSet[],\n tileWidth: number,\n tileHeight: number,\n chunkWidthTiles: number,\n chunkHeightTiles: number,\n projection = new TileProjection({ tileWidth, tileHeight }),\n diagonal?: number,\n ) {\n super();\n\n this._chunk = chunk;\n this._tilesets = tilesets;\n this._tileWidth = tileWidth;\n this._tileHeight = tileHeight;\n this._projection = projection;\n this.diagonal = diagonal;\n const tx = chunk.cx * chunkWidthTiles;\n const ty = chunk.cy * chunkHeightTiles;\n this.depth = tx + ty + (diagonal ?? 0);\n this.firstColumn = tx + Math.max(0, (diagonal ?? 0) - chunk.height + 1);\n const position = projection.tileToPixel(tx, ty);\n const iso = projection.orientation === 'isometric';\n this._geometryX = iso ? position.x - projection.originX : 0;\n this._geometryY = iso ? position.y - projection.originY : 0;\n // Shared origin keeps pixel snapping coherent when projected pitches are fractional.\n this.setPosition(iso ? projection.originX : position.x, iso ? projection.originY : position.y);\n\n // `loadedChunks()` always yields the concrete `TileChunk` behind the\n // readonly view (see TileLayer); the guard is defensive only.\n if (chunk instanceof TileChunk) {\n chunk._addDirtyListener(this._onChunkDirty);\n }\n }\n\n /** The signed chunk coordinates this node renders. */\n public get chunkX(): number {\n return this._chunk.cx;\n }\n\n public get chunkY(): number {\n return this._chunk.cy;\n }\n\n /**\n * The revision-cached per-tileset page geometry. Rebuilt only when the source\n * chunk's `revision` advances; otherwise the same arrays are returned.\n * @internal Read by the per-backend tile chunk renderer.\n */\n public get pages(): readonly ChunkPage[] {\n if (this._builtRevision !== this._chunk.revision) {\n this._pages = buildChunkPages(\n this._chunk,\n this._tilesets,\n this._tileWidth,\n this._tileHeight,\n this._projection,\n this.diagonal,\n this._geometryX,\n this._geometryY,\n );\n this._builtRevision = this._chunk.revision;\n }\n\n return this._pages;\n }\n\n /** `true` when the chunk has no drawable tiles (no geometry, no draw calls). */\n public get isEmpty(): boolean {\n return this.pages.length === 0;\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 iso = this._projection.orientation === 'isometric';\n if (!iso) return this._localBounds.set(0, 0, this._chunk.width * this._tileWidth, this._chunk.height * this._tileHeight);\n const d = this.diagonal;\n const minX = d === undefined ? 0 : Math.max(0, d - this._chunk.height + 1);\n const maxX = d === undefined ? this._chunk.width - 1 : Math.min(this._chunk.width - 1, d);\n const minY = d === undefined ? 0 : d - maxX;\n const maxY = d === undefined ? this._chunk.height - 1 : d - minX;\n let left = ((minX - maxY - 1) * this._tileWidth) / 2;\n let top = ((minX + maxY) * this._tileHeight) / 2;\n let right = ((maxX - minY + 1) * this._tileWidth) / 2;\n let bottom = ((maxX + minY) * this._tileHeight) / 2 + this._tileHeight;\n const baseLeft = left;\n const baseTop = top;\n const baseRight = right;\n const baseBottom = bottom;\n for (const tileset of this._tilesets) {\n left = Math.min(left, baseLeft + tileset.offsetX);\n top = Math.min(top, baseTop + this._tileHeight - tileset.tileHeight + tileset.offsetY);\n right = Math.max(right, baseRight + tileset.tileWidth - this._tileWidth + tileset.offsetX);\n bottom = Math.max(bottom, baseBottom + tileset.offsetY);\n }\n return this._localBounds.set(left + this._geometryX, top + this._geometryY, right - left, bottom - top);\n }\n\n public override destroy(): void {\n if (this._chunk instanceof TileChunk) {\n this._chunk._removeDirtyListener(this._onChunkDirty);\n }\n\n this._pages = [];\n this._builtRevision = -1;\n\n super.destroy();\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AA8BA,IAAa,gBAAb,cAAmC,SAAS;CAC1C,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CACjB,AAAgB;CAChB,AAAgB;CAChB,AAAgB;CAEhB,AAAQ,SAAsB,CAAC;CAC/B,AAAQ,iBAAiB;;;;;;;;;CAUzB,AAAiB,sBAA4B;EAC3C,KAAK,kBAAkB;CACzB;;;;;;;;;;;;CAaA,AAAO,YACL,OACA,UACA,WACA,YACA,iBACA,kBACA,aAAa,IAAI,eAAe;EAAE;EAAW;CAAW,CAAC,GACzD,UACA;EACA,MAAM;EAEN,KAAK,SAAS;EACd,KAAK,YAAY;EACjB,KAAK,aAAa;EAClB,KAAK,cAAc;EACnB,KAAK,cAAc;EACnB,KAAK,WAAW;EAChB,MAAM,KAAK,MAAM,KAAK;EACtB,MAAM,KAAK,MAAM,KAAK;EACtB,KAAK,QAAQ,KAAK,MAAM,YAAY;EACpC,KAAK,cAAc,KAAK,KAAK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IAAI;EAC5D,IAAI,QAAS,OAAO,OAAO,KAAK,KAAK,aAAc;EACnD,IAAI,OAAQ,OAAO,QAAQ,KAAK,cAAe;EAC/C,IAAI,SAAU,OAAO,OAAO,KAAK,KAAK,aAAc;EACpD,IAAI,UAAW,OAAO,QAAQ,KAAK,cAAe,IAAI,KAAK;EAC3D,MAAM,WAAW;EACjB,MAAM,UAAU;EAChB,MAAM,YAAY;EAClB,MAAM,aAAa;EACnB,KAAK,MAAM,WAAW,KAAK,WAAW;GACpC,OAAO,KAAK,IAAI,MAAM,WAAW,QAAQ,OAAO;GAChD,MAAM,KAAK,IAAI,KAAK,UAAU,KAAK,cAAc,QAAQ,aAAa,QAAQ,OAAO;GACrF,QAAQ,KAAK,IAAI,OAAO,YAAY,QAAQ,YAAY,KAAK,aAAa,QAAQ,OAAO;GACzF,SAAS,KAAK,IAAI,QAAQ,aAAa,QAAQ,OAAO;EACxD;EACA,OAAO,KAAK,aAAa,IAAI,OAAO,KAAK,YAAY,MAAM,KAAK,YAAY,QAAQ,MAAM,SAAS,GAAG;CACxG;CAEA,AAAgB,UAAgB;EAC9B,IAAI,KAAK,kBAAkB,WACzB,KAAK,OAAO,qBAAqB,KAAK,aAAa;EAGrD,KAAK,SAAS,CAAC;EACf,KAAK,iBAAiB;EAEtB,MAAM,QAAQ;CAChB;AACF"}
@@ -1,4 +1,5 @@
1
1
  import type { ReadonlyTileChunk } from './TileChunk';
2
+ import { TileProjection } from './TileProjection';
2
3
  import type { TileSet } from './TileSet';
3
4
  import type { TileProperties } from './types';
4
5
  import type { PackedTile, ResolvedTile } from './types';
@@ -7,6 +8,8 @@ import type { PackedTile, ResolvedTile } from './types';
7
8
  * @advanced
8
9
  */
9
10
  export interface TileLayerOptions {
11
+ /** Shared projection; defaults to an orthogonal grid of the supplied tile size. */
12
+ readonly projection?: TileProjection;
10
13
  /** Stable layer ID (unique within the map). */
11
14
  readonly id: number;
12
15
  /** Display name (need not be unique). */
@@ -92,6 +95,7 @@ export interface ChunkRange {
92
95
  * @advanced
93
96
  */
94
97
  export declare class TileLayer {
98
+ readonly projection: TileProjection;
95
99
  /** Stable unique ID within the map. */
96
100
  readonly id: number;
97
101
  /** Display name (may not be unique). */
@@ -232,9 +236,14 @@ export declare class TileLayer {
232
236
  ty: number;
233
237
  tile: ResolvedTile;
234
238
  }>;
239
+ /** Display layer translation expressed as a logical simulation-space vector. */
240
+ get logicalOffset(): {
241
+ x: number;
242
+ y: number;
243
+ };
235
244
  /**
236
- * Convert a tile coordinate to the pixel position of its top-left corner
237
- * in the layer's local space.
245
+ * Convert a grid vertex to display pixels (the top diamond vertex for isometric cells)
246
+ * including the layer's display offset.
238
247
  * @advanced
239
248
  */
240
249
  tileToPixel(tx: number, ty: number): {
@@ -1 +1 @@
1
- {"version":3,"file":"TileLayer.d.ts","sourceRoot":"","sources":["../../src/TileLayer.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAErD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAC9C,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAIxD;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B,+CAA+C;IAC/C,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,yCAAyC;IACzC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB;;;;OAIG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,oEAAoE;IACpE,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,yCAAyC;IACzC,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,0CAA0C;IAC1C,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,8DAA8D;IAC9D,QAAQ,C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C;CACF"}
@@ -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.width * this.tileWidth;
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.height * this.tileHeight;
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 tile coordinate to the pixel position of its top-left corner
455
- * in the layer's local space.
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: tx * this.tileWidth + this.offsetX,
461
- y: ty * this.tileHeight + this.offsetY
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,yBAA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;CACF;;;;;;;CAUA,IAAW,WAAmB;EAC5B,OAAO,KAAK;CACd;;CAGA,IAAW,YAAqB;EAC9B,OAAO,KAAK;CACd;CAEA,AAAQ,kBAAwB;EAC9B,IAAI,KAAK,YACP,MAAM,IAAI,MAAM,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"}
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;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