@codexo/exojs-tilemap 0.15.3 → 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +33 -26
- package/dist/esm/ChunkSource.d.ts +33 -0
- package/dist/esm/ChunkSource.d.ts.map +1 -0
- package/dist/esm/ChunkStreamer.d.ts +98 -0
- package/dist/esm/ChunkStreamer.d.ts.map +1 -0
- package/dist/esm/ChunkStreamer.js +201 -0
- package/dist/esm/ChunkStreamer.js.map +1 -0
- package/dist/esm/ImageLayer.d.ts +11 -3
- package/dist/esm/ImageLayer.d.ts.map +1 -0
- package/dist/esm/ImageLayer.js +71 -64
- package/dist/esm/ImageLayer.js.map +1 -1
- package/dist/esm/ImageLayerNode.d.ts +89 -0
- package/dist/esm/ImageLayerNode.d.ts.map +1 -0
- package/dist/esm/ImageLayerNode.js +205 -0
- package/dist/esm/ImageLayerNode.js.map +1 -0
- package/dist/esm/MapObject.d.ts +70 -0
- package/dist/esm/MapObject.d.ts.map +1 -0
- package/dist/esm/MapObject.js +34 -0
- package/dist/esm/MapObject.js.map +1 -0
- package/dist/esm/MapObjectSpawner.d.ts +133 -0
- package/dist/esm/MapObjectSpawner.d.ts.map +1 -0
- package/dist/esm/MapObjectSpawner.js +147 -0
- package/dist/esm/MapObjectSpawner.js.map +1 -0
- package/dist/esm/MapSpawnSession.d.ts +53 -0
- package/dist/esm/MapSpawnSession.d.ts.map +1 -0
- package/dist/esm/MapSpawnSession.js +88 -0
- package/dist/esm/MapSpawnSession.js.map +1 -0
- package/dist/esm/MapWorld.d.ts +134 -0
- package/dist/esm/MapWorld.d.ts.map +1 -0
- package/dist/esm/MapWorld.js +150 -0
- package/dist/esm/MapWorld.js.map +1 -0
- package/dist/esm/MapWorldRuntime.d.ts +182 -0
- package/dist/esm/MapWorldRuntime.d.ts.map +1 -0
- package/dist/esm/MapWorldRuntime.js +261 -0
- package/dist/esm/MapWorldRuntime.js.map +1 -0
- package/dist/esm/ObjectLayer.d.ts +93 -7
- package/dist/esm/ObjectLayer.d.ts.map +1 -0
- package/dist/esm/ObjectLayer.js +184 -167
- package/dist/esm/ObjectLayer.js.map +1 -1
- package/dist/esm/SampledChunkSource.d.ts +43 -0
- package/dist/esm/SampledChunkSource.d.ts.map +1 -0
- package/dist/esm/SampledChunkSource.js +48 -0
- package/dist/esm/SampledChunkSource.js.map +1 -0
- package/dist/esm/TileAnimator.d.ts +12 -2
- package/dist/esm/TileAnimator.d.ts.map +1 -0
- package/dist/esm/TileAnimator.js +154 -165
- package/dist/esm/TileAnimator.js.map +1 -1
- package/dist/esm/TileChunk.d.ts +30 -5
- package/dist/esm/TileChunk.d.ts.map +1 -0
- package/dist/esm/TileChunk.js +190 -188
- package/dist/esm/TileChunk.js.map +1 -1
- package/dist/esm/TileChunkNode.d.ts +18 -3
- package/dist/esm/TileChunkNode.d.ts.map +1 -0
- package/dist/esm/TileChunkNode.js +104 -85
- package/dist/esm/TileChunkNode.js.map +1 -1
- package/dist/esm/TileLayer.d.ts +104 -24
- package/dist/esm/TileLayer.d.ts.map +1 -0
- package/dist/esm/TileLayer.js +511 -469
- package/dist/esm/TileLayer.js.map +1 -1
- package/dist/esm/TileLayerNode.d.ts +52 -11
- package/dist/esm/TileLayerNode.d.ts.map +1 -0
- package/dist/esm/TileLayerNode.js +224 -166
- package/dist/esm/TileLayerNode.js.map +1 -1
- package/dist/esm/TileMap.d.ts +96 -31
- package/dist/esm/TileMap.d.ts.map +1 -0
- package/dist/esm/TileMap.js +401 -357
- package/dist/esm/TileMap.js.map +1 -1
- package/dist/esm/TileMapBand.d.ts +42 -29
- package/dist/esm/TileMapBand.d.ts.map +1 -0
- package/dist/esm/TileMapBand.js +151 -158
- package/dist/esm/TileMapBand.js.map +1 -1
- package/dist/esm/TileMapNode.d.ts +34 -18
- package/dist/esm/TileMapNode.d.ts.map +1 -0
- package/dist/esm/TileMapNode.js +122 -109
- package/dist/esm/TileMapNode.js.map +1 -1
- package/dist/esm/TileMapView.d.ts +108 -47
- package/dist/esm/TileMapView.d.ts.map +1 -0
- package/dist/esm/TileMapView.js +385 -338
- package/dist/esm/TileMapView.js.map +1 -1
- package/dist/esm/TileSet.d.ts +15 -6
- package/dist/esm/TileSet.d.ts.map +1 -0
- package/dist/esm/TileSet.js +161 -181
- package/dist/esm/TileSet.js.map +1 -1
- package/dist/esm/WangSet.d.ts +5 -4
- package/dist/esm/WangSet.d.ts.map +1 -0
- package/dist/esm/WangSet.js +70 -78
- package/dist/esm/WangSet.js.map +1 -1
- package/dist/esm/WorkerSampledChunkSource.d.ts +95 -0
- package/dist/esm/WorkerSampledChunkSource.d.ts.map +1 -0
- package/dist/esm/WorkerSampledChunkSource.js +117 -0
- package/dist/esm/WorkerSampledChunkSource.js.map +1 -0
- package/dist/esm/autoTile.d.ts +10 -5
- package/dist/esm/autoTile.d.ts.map +1 -0
- package/dist/esm/autoTile.js +164 -205
- package/dist/esm/autoTile.js.map +1 -1
- package/dist/esm/chunkGeometry.d.ts +8 -7
- package/dist/esm/chunkGeometry.d.ts.map +1 -0
- package/dist/esm/chunkGeometry.js +83 -94
- package/dist/esm/chunkGeometry.js.map +1 -1
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +26 -15
- package/dist/esm/nodeBounds.d.ts +20 -0
- package/dist/esm/nodeBounds.d.ts.map +1 -0
- package/dist/esm/nodeBounds.js +40 -0
- package/dist/esm/nodeBounds.js.map +1 -0
- package/dist/esm/pixelSnap.d.ts +4 -3
- package/dist/esm/pixelSnap.d.ts.map +1 -0
- package/dist/esm/pixelSnap.js +18 -16
- package/dist/esm/pixelSnap.js.map +1 -1
- package/dist/esm/public.d.ts +23 -3
- package/dist/esm/public.d.ts.map +1 -0
- package/dist/esm/tileCollision.d.ts +190 -0
- package/dist/esm/tileCollision.d.ts.map +1 -0
- package/dist/esm/tileCollision.js +367 -0
- package/dist/esm/tileCollision.js.map +1 -0
- package/dist/esm/tileWord.d.ts +12 -0
- package/dist/esm/tileWord.d.ts.map +1 -0
- package/dist/esm/tileWord.js +16 -0
- package/dist/esm/tileWord.js.map +1 -0
- package/dist/esm/tilemapExtension.d.ts +4 -3
- package/dist/esm/tilemapExtension.d.ts.map +1 -0
- package/dist/esm/tilemapExtension.js +47 -47
- package/dist/esm/tilemapExtension.js.map +1 -1
- package/dist/esm/tilemapSerializers.d.ts +5 -4
- package/dist/esm/tilemapSerializers.d.ts.map +1 -0
- package/dist/esm/tilemapSerializers.js +48 -41
- package/dist/esm/tilemapSerializers.js.map +1 -1
- package/dist/esm/types.d.ts +34 -18
- package/dist/esm/types.d.ts.map +1 -0
- package/dist/esm/types.js +111 -120
- package/dist/esm/types.js.map +1 -1
- package/dist/esm/webgl2/WebGl2TileChunkRenderer.d.ts +50 -2
- package/dist/esm/webgl2/WebGl2TileChunkRenderer.d.ts.map +1 -0
- package/dist/esm/webgl2/WebGl2TileChunkRenderer.js +366 -332
- package/dist/esm/webgl2/WebGl2TileChunkRenderer.js.map +1 -1
- package/dist/esm/webgl2/shaders/tile-chunk.frag.js +6 -0
- package/dist/esm/webgl2/shaders/tile-chunk.frag.js.map +1 -0
- package/dist/esm/webgl2/shaders/tile-chunk.vert.js +6 -0
- package/dist/esm/webgl2/shaders/tile-chunk.vert.js.map +1 -0
- package/dist/esm/webgpu/WebGpuTileChunkRenderer.d.ts +70 -4
- package/dist/esm/webgpu/WebGpuTileChunkRenderer.d.ts.map +1 -0
- package/dist/esm/webgpu/WebGpuTileChunkRenderer.js +496 -383
- package/dist/esm/webgpu/WebGpuTileChunkRenderer.js.map +1 -1
- package/dist/esm/webgpu/shaders/tile-chunk.wgsl.js +6 -0
- package/dist/esm/webgpu/shaders/tile-chunk.wgsl.js.map +1 -0
- package/package.json +8 -15
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/register.d.ts +0 -1
- package/dist/esm/register.js +0 -25
- package/dist/esm/register.js.map +0 -1
|
@@ -35,6 +35,15 @@ export interface ObjectPoint {
|
|
|
35
35
|
interface TileMapObjectBase<P extends TileProperties = TileProperties> {
|
|
36
36
|
/** Source-unique object id. */
|
|
37
37
|
readonly id: number;
|
|
38
|
+
/**
|
|
39
|
+
* Stable string identity assigned by the authoring format, when it has one.
|
|
40
|
+
*
|
|
41
|
+
* LDtk sets it to the entity `iid`, which is globally unique and survives
|
|
42
|
+
* re-ordering, re-export and level moves - the identity to persist in a
|
|
43
|
+
* savegame. Tiled has no such field and leaves this unset; there, {@link id}
|
|
44
|
+
* is the identity and it is unique only within its map.
|
|
45
|
+
*/
|
|
46
|
+
readonly sourceId?: string;
|
|
38
47
|
/** Object name (may be empty; not unique). */
|
|
39
48
|
readonly name: string;
|
|
40
49
|
/** Object class/type string (Tiled `type`/`class`; may be empty). */
|
|
@@ -47,12 +56,25 @@ interface TileMapObjectBase<P extends TileProperties = TileProperties> {
|
|
|
47
56
|
readonly width: number;
|
|
48
57
|
/** Bounding height in px (0 for points). */
|
|
49
58
|
readonly height: number;
|
|
50
|
-
/**
|
|
59
|
+
/**
|
|
60
|
+
* Rotation in degrees, clockwise, about `(x, y)` - except on a
|
|
61
|
+
* {@link TileObject}, whose pivot stays at the source format's own anchor and
|
|
62
|
+
* is generally not `(x, y)`. See {@link TileObject} for why.
|
|
63
|
+
*/
|
|
51
64
|
readonly rotation: number;
|
|
52
65
|
/** Whether the object is marked visible. */
|
|
53
66
|
readonly visible: boolean;
|
|
54
67
|
/** Immutable custom properties. */
|
|
55
68
|
readonly properties: P;
|
|
69
|
+
/**
|
|
70
|
+
* The raw source-format record this object was parsed from, for the rare
|
|
71
|
+
* case that needs a field this model does not carry. Adapters that keep
|
|
72
|
+
* their parsed document alive set it (`LdtkEntityInstance` for LDtk,
|
|
73
|
+
* `TiledObject` for Tiled); a procedurally built object has none.
|
|
74
|
+
*
|
|
75
|
+
* Reading it ties the code to one source format - prefer the typed fields.
|
|
76
|
+
*/
|
|
77
|
+
readonly source?: unknown;
|
|
56
78
|
}
|
|
57
79
|
/** An axis-aligned rectangle object spanning `[x, y, width, height]`. */
|
|
58
80
|
export interface RectangleObject<P extends TileProperties = TileProperties> extends TileMapObjectBase<P> {
|
|
@@ -76,7 +98,23 @@ export interface PolylineObject<P extends TileProperties = TileProperties> exten
|
|
|
76
98
|
readonly kind: typeof ObjectKind.Polyline;
|
|
77
99
|
readonly points: readonly ObjectPoint[];
|
|
78
100
|
}
|
|
79
|
-
/**
|
|
101
|
+
/**
|
|
102
|
+
* A tile (GID) object carrying a resolved tile reference.
|
|
103
|
+
*
|
|
104
|
+
* `x`/`y` are the top-left corner of the bounding box, the same convention as
|
|
105
|
+
* every other object kind. Source formats that anchor a tile object elsewhere
|
|
106
|
+
* normalise to the corner on import: Tiled stores the position at the
|
|
107
|
+
* tileset's `objectalignment` point (bottom-left by default on an orthogonal
|
|
108
|
+
* map, bottom-centre on an isometric one) and rotates the tile image about
|
|
109
|
+
* that point, so a non-zero {@link TileMapObjectBase.rotation} on a tile
|
|
110
|
+
* object still pivots about the source anchor rather than about `(x, y)`.
|
|
111
|
+
*
|
|
112
|
+
* The owning tileset's drawing offset (Tiled `tileoffset`, reachable as
|
|
113
|
+
* `tile.tileset.offsetX`/`offsetY`) is likewise **not** folded into `x`/`y`.
|
|
114
|
+
* Object layers are data-only, so nothing in this package draws a tile object;
|
|
115
|
+
* code that does has to add that offset itself to match how a tile layer
|
|
116
|
+
* places the same tile.
|
|
117
|
+
*/
|
|
80
118
|
export interface TileObject<P extends TileProperties = TileProperties> extends TileMapObjectBase<P> {
|
|
81
119
|
readonly kind: typeof ObjectKind.Tile;
|
|
82
120
|
readonly tile: ResolvedTile;
|
|
@@ -131,7 +169,7 @@ export type TileMapObject<P extends TileProperties = TileProperties> = Rectangle
|
|
|
131
169
|
*
|
|
132
170
|
* @remarks
|
|
133
171
|
* A schema is a **developer promise, not a runtime guarantee.** Tiled data is
|
|
134
|
-
* untyped at runtime and ExoJS performs no validation against the schema
|
|
172
|
+
* untyped at runtime and ExoJS performs no validation against the schema -
|
|
135
173
|
* the property objects are returned exactly as parsed. The schema only refines
|
|
136
174
|
* the static type of `properties` for ergonomic, typo-safe field access. If the
|
|
137
175
|
* source data does not match the declared shape, reads still succeed but the
|
|
@@ -185,6 +223,23 @@ export interface ObjectLayerOptions {
|
|
|
185
223
|
readonly offsetX?: number;
|
|
186
224
|
/** Layer pixel offset Y. Default `0`. */
|
|
187
225
|
readonly offsetY?: number;
|
|
226
|
+
/**
|
|
227
|
+
* Parallax scroll factor on the X axis. `1` = full camera speed (normal),
|
|
228
|
+
* `0.5` = half speed (farther away), `0` = stationary. Default `1`.
|
|
229
|
+
*/
|
|
230
|
+
readonly parallaxX?: number;
|
|
231
|
+
/**
|
|
232
|
+
* Parallax scroll factor on the Y axis. `1` = full camera speed (normal),
|
|
233
|
+
* `0.5` = half speed (farther away), `0` = stationary. Default `1`.
|
|
234
|
+
*/
|
|
235
|
+
readonly parallaxY?: number;
|
|
236
|
+
/** Uniform parallax scale around the layer origin. Default `1`. */
|
|
237
|
+
readonly parallaxScale?: number;
|
|
238
|
+
/**
|
|
239
|
+
* Multiplicative layer tint as a `0xRRGGBB` integer, or `null` for no tint
|
|
240
|
+
* (Tiled `tintcolor`). Default `null`.
|
|
241
|
+
*/
|
|
242
|
+
readonly tintColor?: number | null;
|
|
188
243
|
/**
|
|
189
244
|
* Draw order for the objects (Tiled `draworder`): `'topdown'` (sorted by `y`)
|
|
190
245
|
* or `'index'` (source order). Informational; objects are stored as given.
|
|
@@ -197,20 +252,29 @@ export interface ObjectLayerOptions {
|
|
|
197
252
|
readonly properties?: TileProperties;
|
|
198
253
|
}
|
|
199
254
|
/**
|
|
200
|
-
* A data-only layer of {@link TileMapObject}s
|
|
255
|
+
* A data-only layer of {@link TileMapObject}s - spawn points, trigger zones,
|
|
201
256
|
* collision regions, markers. Object layers are not rendered by the tile
|
|
202
257
|
* renderer; they are parsed and exposed for gameplay use (e.g. building physics
|
|
203
258
|
* colliders, placing entities).
|
|
204
259
|
*
|
|
260
|
+
* The presentation fields the source format attaches to a layer -
|
|
261
|
+
* {@link visible}, {@link opacity}, {@link offsetX}/{@link offsetY},
|
|
262
|
+
* {@link parallaxX}/{@link parallaxY}, {@link parallaxScale}, and
|
|
263
|
+
* {@link tintColor} - are carried
|
|
264
|
+
* through in full, with any enclosing group layers' contribution already
|
|
265
|
+
* folded in, so an object layer describes the same placement and shading its
|
|
266
|
+
* neighbouring tile and image layers do. Nothing here acts on them: code that
|
|
267
|
+
* draws these objects itself is what applies them.
|
|
268
|
+
*
|
|
205
269
|
* Query with {@link query} (untyped, fully back-compatible) or, when an
|
|
206
270
|
* {@link ObjectSchema} type argument `S` is supplied, with the typed accessors
|
|
207
|
-
* {@link byType}, {@link byKind}, and {@link where}
|
|
271
|
+
* {@link byType}, {@link byKind}, and {@link where} - these narrow `properties`
|
|
208
272
|
* to the developer-declared shape. The schema is **opt-in**: the default type
|
|
209
273
|
* parameter reproduces the original untyped behaviour, so
|
|
210
274
|
* `new ObjectLayer(options)` and `map.getObjectLayer('x')` are unchanged.
|
|
211
275
|
*
|
|
212
276
|
* @remarks
|
|
213
|
-
* A schema is a developer promise, not a runtime guarantee
|
|
277
|
+
* A schema is a developer promise, not a runtime guarantee - Tiled data is
|
|
214
278
|
* untyped at runtime and ExoJS performs no validation. See {@link ObjectSchema}.
|
|
215
279
|
*
|
|
216
280
|
* @typeParam S - Optional {@link ObjectSchema} mapping object `type` strings to
|
|
@@ -236,6 +300,27 @@ export declare class ObjectLayer<S extends ObjectSchema = ObjectSchema> {
|
|
|
236
300
|
readonly offsetX: number;
|
|
237
301
|
/** Layer pixel offset Y. */
|
|
238
302
|
readonly offsetY: number;
|
|
303
|
+
/**
|
|
304
|
+
* Parallax scroll factor on the X axis - the same quantity
|
|
305
|
+
* {@link import('./TileLayer').TileLayer.parallaxX} carries, so an object
|
|
306
|
+
* layer authored beside a tile layer in the same parallax group reports the
|
|
307
|
+
* same factor. `1` = full camera speed, `0.5` = half speed, `0` =
|
|
308
|
+
* stationary. Nothing in this package applies it: object layers are
|
|
309
|
+
* data-only, so placing an object relative to the camera is the consumer's
|
|
310
|
+
* job (see {@link ObjectLayer}).
|
|
311
|
+
*/
|
|
312
|
+
readonly parallaxX: number;
|
|
313
|
+
/** Parallax scroll factor on the Y axis. See {@link ObjectLayer.parallaxX}. */
|
|
314
|
+
readonly parallaxY: number;
|
|
315
|
+
/** Uniform scale applied around the layer origin by consumers that render this data-only layer. */
|
|
316
|
+
readonly parallaxScale: number;
|
|
317
|
+
/**
|
|
318
|
+
* Multiplicative layer tint as `0xRRGGBB`, or `null` for no tint. Carried
|
|
319
|
+
* from the source map (including the accumulated tint of any enclosing group
|
|
320
|
+
* layers) for code that draws these objects itself; like
|
|
321
|
+
* {@link ObjectLayer.parallaxX}, nothing in this package applies it.
|
|
322
|
+
*/
|
|
323
|
+
readonly tintColor: number | null;
|
|
239
324
|
/** Draw order for the objects (Tiled `draworder`). Informational. */
|
|
240
325
|
readonly drawOrder: 'topdown' | 'index';
|
|
241
326
|
/** Immutable layer-level properties. */
|
|
@@ -249,7 +334,7 @@ export declare class ObjectLayer<S extends ObjectSchema = ObjectSchema> {
|
|
|
249
334
|
* Objects whose `type` equals `type`, with `properties` narrowed to the
|
|
250
335
|
* schema shape `S[T]`. Returns a fresh array (insertion order).
|
|
251
336
|
*
|
|
252
|
-
* The narrowing is a static convenience only
|
|
337
|
+
* The narrowing is a static convenience only - no runtime validation is
|
|
253
338
|
* performed (see {@link ObjectSchema}). On an unschematised layer this
|
|
254
339
|
* behaves like `query({ type })` with `TileProperties` properties.
|
|
255
340
|
*/
|
|
@@ -275,3 +360,4 @@ export declare class ObjectLayer<S extends ObjectSchema = ObjectSchema> {
|
|
|
275
360
|
getObjectByName(name: string): TileMapObject | undefined;
|
|
276
361
|
}
|
|
277
362
|
export {};
|
|
363
|
+
//# sourceMappingURL=ObjectLayer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ObjectLayer.d.ts","sourceR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{ TilePropertyKind } from "./types.js";
|
|
2
2
|
|
|
3
|
+
//#region src/ObjectLayer.ts
|
|
3
4
|
/**
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
5
|
+
* Geometry kinds for a {@link TileMapObject}, as an `as const` value object.
|
|
6
|
+
*
|
|
7
|
+
* Modelled as a frozen string map (not a TS `enum`) so the values stay
|
|
8
|
+
* wire-compatible with the Tiled string serialisation, survive
|
|
9
|
+
* `verbatimModuleSyntax` (no emitted runtime helper), and follow the package
|
|
10
|
+
* convention for enum-like constants. Use the members for ergonomic, typo-safe
|
|
11
|
+
* call sites: `layer.byKind(ObjectKind.Polygon)`.
|
|
12
|
+
* @stable
|
|
13
|
+
*/
|
|
13
14
|
const ObjectKind = {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
Rectangle: "rectangle",
|
|
16
|
+
Ellipse: "ellipse",
|
|
17
|
+
Polygon: "polygon",
|
|
18
|
+
Polyline: "polyline",
|
|
19
|
+
Point: "point",
|
|
20
|
+
Tile: "tile",
|
|
21
|
+
Text: "text"
|
|
21
22
|
};
|
|
22
23
|
/**
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
return (typeof value === 'object' &&
|
|
29
|
-
value !== null &&
|
|
30
|
-
!Array.isArray(value) &&
|
|
31
|
-
value.kind === TilePropertyKind.ObjectRef);
|
|
32
|
-
}
|
|
24
|
+
* Type guard for the {@link TilePropertyObjectRef} variant of
|
|
25
|
+
* {@link TilePropertyValue}.
|
|
26
|
+
* @internal
|
|
27
|
+
*/
|
|
28
|
+
const isTilePropertyObjectRef = (value) => typeof value === "object" && value !== null && !Array.isArray(value) && value.kind === TilePropertyKind.ObjectRef;
|
|
33
29
|
/**
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
return false;
|
|
51
|
-
}
|
|
30
|
+
* Equality used by {@link ObjectLayer.query}'s `value` filter.
|
|
31
|
+
*
|
|
32
|
+
* Scalars and `null` compare with `===`. `objectRef` values compare by `id`
|
|
33
|
+
* alone - the one genuinely common "find all objects referencing X" query
|
|
34
|
+
* need - regardless of differing LDtk navigation fields. Every other
|
|
35
|
+
* structured shape (`point`, `tileRef`, arrays, nested property bags) has no
|
|
36
|
+
* obvious value-equality semantics (exact float coordinates? array order?)
|
|
37
|
+
* and only matches when reference-identical; use `query({ property })`
|
|
38
|
+
* (presence-only) for those.
|
|
39
|
+
* @internal
|
|
40
|
+
*/
|
|
41
|
+
const tilePropertyValueEquals = (a, b) => {
|
|
42
|
+
if (a === b) return true;
|
|
43
|
+
if (isTilePropertyObjectRef(a) && isTilePropertyObjectRef(b)) return a.id === b.id;
|
|
44
|
+
return false;
|
|
45
|
+
};
|
|
52
46
|
/**
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
}
|
|
47
|
+
* A data-only layer of {@link TileMapObject}s - spawn points, trigger zones,
|
|
48
|
+
* collision regions, markers. Object layers are not rendered by the tile
|
|
49
|
+
* renderer; they are parsed and exposed for gameplay use (e.g. building physics
|
|
50
|
+
* colliders, placing entities).
|
|
51
|
+
*
|
|
52
|
+
* The presentation fields the source format attaches to a layer -
|
|
53
|
+
* {@link visible}, {@link opacity}, {@link offsetX}/{@link offsetY},
|
|
54
|
+
* {@link parallaxX}/{@link parallaxY}, {@link parallaxScale}, and
|
|
55
|
+
* {@link tintColor} - are carried
|
|
56
|
+
* through in full, with any enclosing group layers' contribution already
|
|
57
|
+
* folded in, so an object layer describes the same placement and shading its
|
|
58
|
+
* neighbouring tile and image layers do. Nothing here acts on them: code that
|
|
59
|
+
* draws these objects itself is what applies them.
|
|
60
|
+
*
|
|
61
|
+
* Query with {@link query} (untyped, fully back-compatible) or, when an
|
|
62
|
+
* {@link ObjectSchema} type argument `S` is supplied, with the typed accessors
|
|
63
|
+
* {@link byType}, {@link byKind}, and {@link where} - these narrow `properties`
|
|
64
|
+
* to the developer-declared shape. The schema is **opt-in**: the default type
|
|
65
|
+
* parameter reproduces the original untyped behaviour, so
|
|
66
|
+
* `new ObjectLayer(options)` and `map.getObjectLayer('x')` are unchanged.
|
|
67
|
+
*
|
|
68
|
+
* @remarks
|
|
69
|
+
* A schema is a developer promise, not a runtime guarantee - Tiled data is
|
|
70
|
+
* untyped at runtime and ExoJS performs no validation. See {@link ObjectSchema}.
|
|
71
|
+
*
|
|
72
|
+
* @typeParam S - Optional {@link ObjectSchema} mapping object `type` strings to
|
|
73
|
+
* their property shapes. Defaults to a generic schema (every type maps to the
|
|
74
|
+
* loose {@link TileProperties} bag).
|
|
75
|
+
*
|
|
76
|
+
* @advanced
|
|
77
|
+
*/
|
|
78
|
+
var ObjectLayer = class {
|
|
79
|
+
/** Layer-kind discriminant (distinguishes object layers from tile layers). */
|
|
80
|
+
kind = "object";
|
|
81
|
+
/** Layer id (unique within the map). */
|
|
82
|
+
id;
|
|
83
|
+
/** Layer name. */
|
|
84
|
+
name;
|
|
85
|
+
/** Layer class string. */
|
|
86
|
+
class;
|
|
87
|
+
/** Whether the layer is visible. */
|
|
88
|
+
visible;
|
|
89
|
+
/** Layer opacity in `[0, 1]`. */
|
|
90
|
+
opacity;
|
|
91
|
+
/** Layer pixel offset X. */
|
|
92
|
+
offsetX;
|
|
93
|
+
/** Layer pixel offset Y. */
|
|
94
|
+
offsetY;
|
|
95
|
+
/**
|
|
96
|
+
* Parallax scroll factor on the X axis - the same quantity
|
|
97
|
+
* {@link import('./TileLayer').TileLayer.parallaxX} carries, so an object
|
|
98
|
+
* layer authored beside a tile layer in the same parallax group reports the
|
|
99
|
+
* same factor. `1` = full camera speed, `0.5` = half speed, `0` =
|
|
100
|
+
* stationary. Nothing in this package applies it: object layers are
|
|
101
|
+
* data-only, so placing an object relative to the camera is the consumer's
|
|
102
|
+
* job (see {@link ObjectLayer}).
|
|
103
|
+
*/
|
|
104
|
+
parallaxX;
|
|
105
|
+
/** Parallax scroll factor on the Y axis. See {@link ObjectLayer.parallaxX}. */
|
|
106
|
+
parallaxY;
|
|
107
|
+
/** Uniform scale applied around the layer origin by consumers that render this data-only layer. */
|
|
108
|
+
parallaxScale;
|
|
109
|
+
/**
|
|
110
|
+
* Multiplicative layer tint as `0xRRGGBB`, or `null` for no tint. Carried
|
|
111
|
+
* from the source map (including the accumulated tint of any enclosing group
|
|
112
|
+
* layers) for code that draws these objects itself; like
|
|
113
|
+
* {@link ObjectLayer.parallaxX}, nothing in this package applies it.
|
|
114
|
+
*/
|
|
115
|
+
tintColor;
|
|
116
|
+
/** Draw order for the objects (Tiled `draworder`). Informational. */
|
|
117
|
+
drawOrder;
|
|
118
|
+
/** Immutable layer-level properties. */
|
|
119
|
+
properties;
|
|
120
|
+
/** The objects in this layer (insertion order). */
|
|
121
|
+
objects;
|
|
122
|
+
constructor(options) {
|
|
123
|
+
this.id = options.id;
|
|
124
|
+
this.name = options.name ?? "";
|
|
125
|
+
this.class = options.class ?? "";
|
|
126
|
+
this.visible = options.visible ?? true;
|
|
127
|
+
this.opacity = options.opacity ?? 1;
|
|
128
|
+
this.offsetX = options.offsetX ?? 0;
|
|
129
|
+
this.offsetY = options.offsetY ?? 0;
|
|
130
|
+
this.parallaxX = options.parallaxX ?? 1;
|
|
131
|
+
this.parallaxY = options.parallaxY ?? 1;
|
|
132
|
+
this.parallaxScale = options.parallaxScale ?? 1;
|
|
133
|
+
if (!Number.isFinite(this.parallaxScale) || this.parallaxScale <= 0) throw new Error("ObjectLayer parallaxScale must be a positive finite number.");
|
|
134
|
+
this.tintColor = options.tintColor ?? null;
|
|
135
|
+
this.drawOrder = options.drawOrder ?? "topdown";
|
|
136
|
+
this.properties = options.properties ? Object.freeze({ ...options.properties }) : Object.freeze({});
|
|
137
|
+
this.objects = options.objects ? Object.freeze([...options.objects]) : Object.freeze([]);
|
|
138
|
+
}
|
|
139
|
+
/** Objects matching every specified criterion of `filter`. Returns a fresh array. */
|
|
140
|
+
query(filter = {}) {
|
|
141
|
+
return this.objects.filter((object) => {
|
|
142
|
+
if (filter.name !== void 0 && object.name !== filter.name) return false;
|
|
143
|
+
if (filter.type !== void 0 && object.type !== filter.type) return false;
|
|
144
|
+
if (filter.kind !== void 0 && object.kind !== filter.kind) return false;
|
|
145
|
+
if (filter.property !== void 0) {
|
|
146
|
+
const value = object.properties[filter.property];
|
|
147
|
+
if (value === void 0) return false;
|
|
148
|
+
if (filter.value !== void 0 && !tilePropertyValueEquals(value, filter.value)) return false;
|
|
149
|
+
}
|
|
150
|
+
return true;
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Objects whose `type` equals `type`, with `properties` narrowed to the
|
|
155
|
+
* schema shape `S[T]`. Returns a fresh array (insertion order).
|
|
156
|
+
*
|
|
157
|
+
* The narrowing is a static convenience only - no runtime validation is
|
|
158
|
+
* performed (see {@link ObjectSchema}). On an unschematised layer this
|
|
159
|
+
* behaves like `query({ type })` with `TileProperties` properties.
|
|
160
|
+
*/
|
|
161
|
+
byType(type) {
|
|
162
|
+
return this.objects.filter((object) => object.type === type);
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Objects of the given geometry {@link ObjectKind}, narrowed to that
|
|
166
|
+
* geometry's member type (e.g. `byKind(ObjectKind.Polygon)` yields
|
|
167
|
+
* {@link PolygonObject}s with their `points`). Returns a fresh array.
|
|
168
|
+
*/
|
|
169
|
+
byKind(kind) {
|
|
170
|
+
return this.objects.filter((object) => object.kind === kind);
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Objects of `type` (typed as in {@link byType}) that also satisfy
|
|
174
|
+
* `predicate`. A convenience combination of {@link byType} and `Array.filter`
|
|
175
|
+
* that keeps the narrowed `properties` type inside the predicate. Returns a
|
|
176
|
+
* fresh array.
|
|
177
|
+
*/
|
|
178
|
+
where(type, predicate) {
|
|
179
|
+
return this.byType(type).filter((object) => predicate(object));
|
|
180
|
+
}
|
|
181
|
+
/** First object with the given id, or undefined. */
|
|
182
|
+
getObjectById(id) {
|
|
183
|
+
return this.objects.find((object) => object.id === id);
|
|
184
|
+
}
|
|
185
|
+
/** First object with the given name, or undefined. */
|
|
186
|
+
getObjectByName(name) {
|
|
187
|
+
return this.objects.find((object) => object.name === name);
|
|
188
|
+
}
|
|
189
|
+
};
|
|
174
190
|
|
|
191
|
+
//#endregion
|
|
175
192
|
export { ObjectKind, ObjectLayer };
|
|
176
|
-
//# sourceMappingURL=ObjectLayer.js.map
|
|
193
|
+
//# sourceMappingURL=ObjectLayer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ObjectLayer.js","sources":["../../../src/ObjectLayer.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAGA;;;;;;;;;AASG;AACI,MAAM,UAAU,GAAG;AACxB,IAAA,SAAS,EAAE,WAAW;AACtB,IAAA,OAAO,EAAE,SAAS;AAClB,IAAA,OAAO,EAAE,SAAS;AAClB,IAAA,QAAQ,EAAE,UAAU;AACpB,IAAA,KAAK,EAAE,OAAO;AACd,IAAA,IAAI,EAAE,MAAM;AACZ,IAAA,IAAI,EAAE,MAAM;;AAiLd;;;;AAIG;AACH,SAAS,uBAAuB,CAAC,KAAwB,EAAA;AACvD,IAAA,QACE,OAAO,KAAK,KAAK,QAAQ;AACzB,QAAA,KAAK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CAAC;IACJ;AAEA;;;;;;;AAOG;AACI,IAAA,MAAM,CAA6B,IAAO,EAAA;AAC/C,QAAA,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,IAAI,MAAM,CAAC,IAAI,KAAK,IAAI,CAAwC;IACnG;AAEA;;;;AAIG;AACI,IAAA,MAAM,CAAuB,IAAO,EAAA;AACzC,QAAA,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,IAAI,MAAM,CAAC,IAAI,KAAK,IAAI,CAA+C;IAC1G;AAEA;;;;;AAKG;IACI,KAAK,CACV,IAAO,EACP,SAAiD,EAAA;AAEjD,QAAA,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,MAAM,IAAI,SAAS,CAAC,MAAM,CAAC,CAAC;IAC9D;;AAGO,IAAA,aAAa,CAAC,EAAU,EAAA;AAC7B,QAAA,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,IAAI,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC;IACtD;;AAGO,IAAA,eAAe,CAAC,IAAY,EAAA;AACjC,QAAA,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,IAAI,MAAM,CAAC,IAAI,KAAK,IAAI,CAAC;IAC1D;AACD;;;;"}
|
|
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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