@codexo/exojs-tilemap 0.19.0 → 0.20.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 (157) hide show
  1. package/README.md +7 -163
  2. package/index.d.ts +1 -0
  3. package/index.js +1 -0
  4. package/package.json +12 -20
  5. package/dist/esm/ChunkSource.d.ts +0 -33
  6. package/dist/esm/ChunkSource.d.ts.map +0 -1
  7. package/dist/esm/ChunkStreamer.d.ts +0 -104
  8. package/dist/esm/ChunkStreamer.d.ts.map +0 -1
  9. package/dist/esm/ChunkStreamer.js +0 -229
  10. package/dist/esm/ChunkStreamer.js.map +0 -1
  11. package/dist/esm/ImageLayer.d.ts +0 -89
  12. package/dist/esm/ImageLayer.d.ts.map +0 -1
  13. package/dist/esm/ImageLayer.js +0 -74
  14. package/dist/esm/ImageLayer.js.map +0 -1
  15. package/dist/esm/ImageLayerNode.d.ts +0 -91
  16. package/dist/esm/ImageLayerNode.d.ts.map +0 -1
  17. package/dist/esm/ImageLayerNode.js +0 -210
  18. package/dist/esm/ImageLayerNode.js.map +0 -1
  19. package/dist/esm/MapObject.d.ts +0 -70
  20. package/dist/esm/MapObject.d.ts.map +0 -1
  21. package/dist/esm/MapObject.js +0 -34
  22. package/dist/esm/MapObject.js.map +0 -1
  23. package/dist/esm/MapObjectSpawner.d.ts +0 -133
  24. package/dist/esm/MapObjectSpawner.d.ts.map +0 -1
  25. package/dist/esm/MapObjectSpawner.js +0 -147
  26. package/dist/esm/MapObjectSpawner.js.map +0 -1
  27. package/dist/esm/MapSpawnSession.d.ts +0 -46
  28. package/dist/esm/MapSpawnSession.d.ts.map +0 -1
  29. package/dist/esm/MapSpawnSession.js +0 -88
  30. package/dist/esm/MapSpawnSession.js.map +0 -1
  31. package/dist/esm/MapWorld.d.ts +0 -134
  32. package/dist/esm/MapWorld.d.ts.map +0 -1
  33. package/dist/esm/MapWorld.js +0 -150
  34. package/dist/esm/MapWorld.js.map +0 -1
  35. package/dist/esm/MapWorldRuntime.d.ts +0 -180
  36. package/dist/esm/MapWorldRuntime.d.ts.map +0 -1
  37. package/dist/esm/MapWorldRuntime.js +0 -261
  38. package/dist/esm/MapWorldRuntime.js.map +0 -1
  39. package/dist/esm/ObjectLayer.d.ts +0 -379
  40. package/dist/esm/ObjectLayer.d.ts.map +0 -1
  41. package/dist/esm/ObjectLayer.js +0 -221
  42. package/dist/esm/ObjectLayer.js.map +0 -1
  43. package/dist/esm/SampledChunkSource.d.ts +0 -43
  44. package/dist/esm/SampledChunkSource.d.ts.map +0 -1
  45. package/dist/esm/SampledChunkSource.js +0 -48
  46. package/dist/esm/SampledChunkSource.js.map +0 -1
  47. package/dist/esm/TileAnimator.d.ts +0 -72
  48. package/dist/esm/TileAnimator.d.ts.map +0 -1
  49. package/dist/esm/TileAnimator.js +0 -158
  50. package/dist/esm/TileAnimator.js.map +0 -1
  51. package/dist/esm/TileChunk.d.ts +0 -103
  52. package/dist/esm/TileChunk.d.ts.map +0 -1
  53. package/dist/esm/TileChunk.js +0 -194
  54. package/dist/esm/TileChunk.js.map +0 -1
  55. package/dist/esm/TileChunkNode.d.ts +0 -2
  56. package/dist/esm/TileChunkNode.d.ts.map +0 -1
  57. package/dist/esm/TileChunkNode.js +0 -145
  58. package/dist/esm/TileChunkNode.js.map +0 -1
  59. package/dist/esm/TileLayer.d.ts +0 -286
  60. package/dist/esm/TileLayer.d.ts.map +0 -1
  61. package/dist/esm/TileLayer.js +0 -526
  62. package/dist/esm/TileLayer.js.map +0 -1
  63. package/dist/esm/TileLayerNode.d.ts +0 -129
  64. package/dist/esm/TileLayerNode.d.ts.map +0 -1
  65. package/dist/esm/TileLayerNode.js +0 -245
  66. package/dist/esm/TileLayerNode.js.map +0 -1
  67. package/dist/esm/TileMap.d.ts +0 -317
  68. package/dist/esm/TileMap.d.ts.map +0 -1
  69. package/dist/esm/TileMap.js +0 -406
  70. package/dist/esm/TileMap.js.map +0 -1
  71. package/dist/esm/TileMapBand.d.ts +0 -80
  72. package/dist/esm/TileMapBand.d.ts.map +0 -1
  73. package/dist/esm/TileMapBand.js +0 -155
  74. package/dist/esm/TileMapBand.js.map +0 -1
  75. package/dist/esm/TileMapNode.d.ts +0 -92
  76. package/dist/esm/TileMapNode.d.ts.map +0 -1
  77. package/dist/esm/TileMapNode.js +0 -134
  78. package/dist/esm/TileMapNode.js.map +0 -1
  79. package/dist/esm/TileMapView.d.ts +0 -248
  80. package/dist/esm/TileMapView.d.ts.map +0 -1
  81. package/dist/esm/TileMapView.js +0 -394
  82. package/dist/esm/TileMapView.js.map +0 -1
  83. package/dist/esm/TileProjection.d.ts +0 -59
  84. package/dist/esm/TileProjection.d.ts.map +0 -1
  85. package/dist/esm/TileProjection.js +0 -106
  86. package/dist/esm/TileProjection.js.map +0 -1
  87. package/dist/esm/TileSet.d.ts +0 -116
  88. package/dist/esm/TileSet.d.ts.map +0 -1
  89. package/dist/esm/TileSet.js +0 -168
  90. package/dist/esm/TileSet.js.map +0 -1
  91. package/dist/esm/WangSet.d.ts +0 -80
  92. package/dist/esm/WangSet.d.ts.map +0 -1
  93. package/dist/esm/WangSet.js +0 -73
  94. package/dist/esm/WangSet.js.map +0 -1
  95. package/dist/esm/WorkerSampledChunkSource.d.ts +0 -94
  96. package/dist/esm/WorkerSampledChunkSource.d.ts.map +0 -1
  97. package/dist/esm/WorkerSampledChunkSource.js +0 -113
  98. package/dist/esm/WorkerSampledChunkSource.js.map +0 -1
  99. package/dist/esm/autoTile.d.ts +0 -88
  100. package/dist/esm/autoTile.d.ts.map +0 -1
  101. package/dist/esm/autoTile.js +0 -173
  102. package/dist/esm/autoTile.js.map +0 -1
  103. package/dist/esm/chunkGeometry.d.ts +0 -2
  104. package/dist/esm/chunkGeometry.d.ts.map +0 -1
  105. package/dist/esm/chunkGeometry.js +0 -116
  106. package/dist/esm/chunkGeometry.js.map +0 -1
  107. package/dist/esm/index.d.ts +0 -2
  108. package/dist/esm/index.d.ts.map +0 -1
  109. package/dist/esm/index.js +0 -27
  110. package/dist/esm/nodeBounds.d.ts +0 -2
  111. package/dist/esm/nodeBounds.d.ts.map +0 -1
  112. package/dist/esm/nodeBounds.js +0 -40
  113. package/dist/esm/nodeBounds.js.map +0 -1
  114. package/dist/esm/pixelSnap.d.ts +0 -2
  115. package/dist/esm/pixelSnap.d.ts.map +0 -1
  116. package/dist/esm/pixelSnap.js +0 -21
  117. package/dist/esm/pixelSnap.js.map +0 -1
  118. package/dist/esm/projectObject.d.ts +0 -4
  119. package/dist/esm/projectObject.d.ts.map +0 -1
  120. package/dist/esm/projectObject.js +0 -87
  121. package/dist/esm/projectObject.js.map +0 -1
  122. package/dist/esm/public.d.ts +0 -48
  123. package/dist/esm/public.d.ts.map +0 -1
  124. package/dist/esm/tileCollision.d.ts +0 -190
  125. package/dist/esm/tileCollision.d.ts.map +0 -1
  126. package/dist/esm/tileCollision.js +0 -399
  127. package/dist/esm/tileCollision.js.map +0 -1
  128. package/dist/esm/tileWord.d.ts +0 -2
  129. package/dist/esm/tileWord.d.ts.map +0 -1
  130. package/dist/esm/tileWord.js +0 -16
  131. package/dist/esm/tileWord.js.map +0 -1
  132. package/dist/esm/tilemapExtension.d.ts +0 -20
  133. package/dist/esm/tilemapExtension.d.ts.map +0 -1
  134. package/dist/esm/tilemapExtension.js +0 -53
  135. package/dist/esm/tilemapExtension.js.map +0 -1
  136. package/dist/esm/tilemapSerializers.d.ts +0 -2
  137. package/dist/esm/tilemapSerializers.d.ts.map +0 -1
  138. package/dist/esm/tilemapSerializers.js +0 -54
  139. package/dist/esm/tilemapSerializers.js.map +0 -1
  140. package/dist/esm/types.d.ts +0 -231
  141. package/dist/esm/types.d.ts.map +0 -1
  142. package/dist/esm/types.js +0 -129
  143. package/dist/esm/types.js.map +0 -1
  144. package/dist/esm/webgl2/WebGl2TileChunkRenderer.d.ts +0 -2
  145. package/dist/esm/webgl2/WebGl2TileChunkRenderer.d.ts.map +0 -1
  146. package/dist/esm/webgl2/WebGl2TileChunkRenderer.js +0 -376
  147. package/dist/esm/webgl2/WebGl2TileChunkRenderer.js.map +0 -1
  148. package/dist/esm/webgl2/shaders/tile-chunk.frag.js +0 -6
  149. package/dist/esm/webgl2/shaders/tile-chunk.frag.js.map +0 -1
  150. package/dist/esm/webgl2/shaders/tile-chunk.vert.js +0 -6
  151. package/dist/esm/webgl2/shaders/tile-chunk.vert.js.map +0 -1
  152. package/dist/esm/webgpu/WebGpuTileChunkRenderer.d.ts +0 -2
  153. package/dist/esm/webgpu/WebGpuTileChunkRenderer.d.ts.map +0 -1
  154. package/dist/esm/webgpu/WebGpuTileChunkRenderer.js +0 -539
  155. package/dist/esm/webgpu/WebGpuTileChunkRenderer.js.map +0 -1
  156. package/dist/esm/webgpu/shaders/tile-chunk.wgsl.js +0 -6
  157. package/dist/esm/webgpu/shaders/tile-chunk.wgsl.js.map +0 -1
@@ -1,379 +0,0 @@
1
- import type { TileProjection } from './TileProjection';
2
- import type { ResolvedTile, TileProperties, TilePropertyValue } from './types';
3
- /**
4
- * Geometry kinds for a {@link TileMapObject}, as an `as const` value object.
5
- *
6
- * Modelled as a frozen string map (not a TS `enum`) so the values stay
7
- * wire-compatible with the Tiled string serialisation, survive
8
- * `verbatimModuleSyntax` (no emitted runtime helper), and follow the package
9
- * convention for enum-like constants. Use the members for ergonomic, typo-safe
10
- * call sites: `layer.byKind(ObjectKind.Polygon)`.
11
- * @stable
12
- */
13
- export declare const ObjectKind: {
14
- readonly Rectangle: 'rectangle';
15
- readonly Ellipse: 'ellipse';
16
- readonly Polygon: 'polygon';
17
- readonly Polyline: 'polyline';
18
- readonly Point: 'point';
19
- readonly Tile: 'tile';
20
- readonly Text: 'text';
21
- };
22
- /** Geometry discriminant for a {@link TileMapObject}. */
23
- export type ObjectKind = (typeof ObjectKind)[keyof typeof ObjectKind];
24
- /**
25
- * Geometry discriminant for a {@link TileMapObject}.
26
- * Structural alias of {@link ObjectKind}; retained so existing code keeps
27
- * compiling. New code may prefer {@link ObjectKind}.
28
- */
29
- export type TileMapObjectKind = ObjectKind;
30
- /** A point in object-layer space (pixels, relative to the object). */
31
- export interface ObjectPoint {
32
- readonly x: number;
33
- readonly y: number;
34
- }
35
- /** Fields shared by every {@link TileMapObject} kind. */
36
- interface TileMapObjectBase<P extends TileProperties = TileProperties> {
37
- /** Source-unique object id. */
38
- readonly id: number;
39
- /**
40
- * Stable string identity assigned by the authoring format, when it has one.
41
- *
42
- * LDtk sets it to the entity `iid`, which is globally unique and survives
43
- * re-ordering, re-export and level moves - the identity to persist in a
44
- * savegame. Tiled has no such field and leaves this unset; there, {@link id}
45
- * is the identity and it is unique only within its map.
46
- */
47
- readonly sourceId?: string;
48
- /** Object name (may be empty; not unique). */
49
- readonly name: string;
50
- /** Object class/type string (Tiled `type`/`class`; may be empty). */
51
- readonly type: string;
52
- /** X of the object origin in layer coordinates; logical pixels when the layer has a projection. */
53
- readonly x: number;
54
- /** Y of the object origin in layer coordinates; logical pixels when the layer has a projection. */
55
- readonly y: number;
56
- /** Bounding width in px (0 for points). */
57
- readonly width: number;
58
- /** Bounding height in px (0 for points). */
59
- readonly height: number;
60
- /**
61
- * Rotation in degrees, clockwise, about `(x, y)` - except on a
62
- * {@link TileObject}, whose pivot stays at the source format's own anchor and
63
- * is generally not `(x, y)`. See {@link TileObject} for why.
64
- */
65
- readonly rotation: number;
66
- /** Whether the object is marked visible. */
67
- readonly visible: boolean;
68
- /** Immutable custom properties. */
69
- readonly properties: P;
70
- /**
71
- * The raw source-format record this object was parsed from, for the rare
72
- * case that needs a field this model does not carry. Adapters that keep
73
- * their parsed document alive set it (`LdtkEntityInstance` for LDtk,
74
- * `TiledObject` for Tiled); a procedurally built object has none.
75
- *
76
- * Reading it ties the code to one source format - prefer the typed fields.
77
- */
78
- readonly source?: unknown;
79
- }
80
- /** An axis-aligned rectangle object spanning `[x, y, width, height]`. */
81
- export interface RectangleObject<P extends TileProperties = TileProperties> extends TileMapObjectBase<P> {
82
- readonly kind: typeof ObjectKind.Rectangle;
83
- }
84
- /** An ellipse inscribed in `[x, y, width, height]`. */
85
- export interface EllipseObject<P extends TileProperties = TileProperties> extends TileMapObjectBase<P> {
86
- readonly kind: typeof ObjectKind.Ellipse;
87
- }
88
- /** A single point at `(x, y)`. */
89
- export interface PointObject<P extends TileProperties = TileProperties> extends TileMapObjectBase<P> {
90
- readonly kind: typeof ObjectKind.Point;
91
- }
92
- /** A closed polygon; `points` are relative to the object origin. */
93
- export interface PolygonObject<P extends TileProperties = TileProperties> extends TileMapObjectBase<P> {
94
- readonly kind: typeof ObjectKind.Polygon;
95
- readonly points: readonly ObjectPoint[];
96
- }
97
- /** An open polyline; `points` are relative to the object origin. */
98
- export interface PolylineObject<P extends TileProperties = TileProperties> extends TileMapObjectBase<P> {
99
- readonly kind: typeof ObjectKind.Polyline;
100
- readonly points: readonly ObjectPoint[];
101
- }
102
- /**
103
- * A tile (GID) object carrying a resolved tile reference.
104
- *
105
- * `x`/`y` are the top-left corner of the bounding box, the same convention as
106
- * every other object kind. Source formats that anchor a tile object elsewhere
107
- * normalise to the corner on import: Tiled stores the position at the
108
- * tileset's `objectalignment` point (bottom-left by default on an orthogonal
109
- * map, bottom-centre on an isometric one) and rotates the tile image about
110
- * that point, so a non-zero {@link TileMapObjectBase.rotation} on a tile
111
- * object still pivots about the source anchor rather than about `(x, y)`.
112
- * Isometric Tiled objects expose this anchor as `rotationOrigin`;
113
- * `getDisplayObject` projects both the unrotated corner and this pivot.
114
- *
115
- * The owning tileset's drawing offset (Tiled `tileoffset`, reachable as
116
- * `tile.tileset.offsetX`/`offsetY`) is likewise **not** folded into `x`/`y`.
117
- * Object layers are data-only, so nothing in this package draws a tile object;
118
- * code that does has to add that offset itself to match how a tile layer
119
- * places the same tile.
120
- */
121
- export interface TileObject<P extends TileProperties = TileProperties> extends TileMapObjectBase<P> {
122
- readonly kind: typeof ObjectKind.Tile;
123
- readonly tile: ResolvedTile;
124
- /** Image rotation pivot in layer coordinates, logical when projected. Adapters may omit it when unavailable. */
125
- readonly rotationOrigin?: ObjectPoint;
126
- }
127
- /** Text styling options carried by a {@link TextObject}. */
128
- export interface TextStyle {
129
- /** The text content. */
130
- readonly text: string;
131
- /** Text colour as 0xRRGGBB, or `null` if default. */
132
- readonly color?: number | null;
133
- /** Font family name. */
134
- readonly fontFamily?: string;
135
- /** Font size in pixels. */
136
- readonly pixelSize?: number;
137
- /** Bold text. */
138
- readonly bold?: boolean;
139
- /** Italic text. */
140
- readonly italic?: boolean;
141
- /** Underline text. */
142
- readonly underline?: boolean;
143
- /** Strikeout text. */
144
- readonly strikeout?: boolean;
145
- /** Wrap text within the object bounds. */
146
- readonly wrap?: boolean;
147
- /** Horizontal alignment. */
148
- readonly halign?: 'left' | 'center' | 'right' | 'justify';
149
- /** Vertical alignment. */
150
- readonly valign?: 'top' | 'center' | 'bottom';
151
- }
152
- /** A text object carrying styled text content within `[x, y, width, height]`. */
153
- export interface TextObject<P extends TileProperties = TileProperties> extends TileMapObjectBase<P> {
154
- readonly kind: typeof ObjectKind.Text;
155
- readonly text: TextStyle;
156
- }
157
- /**
158
- * A format-independent map object. The geometry kind is the discriminant;
159
- * narrow on `kind` to read shape-specific fields. Template objects are not
160
- * yet represented.
161
- *
162
- * The optional property-shape parameter `P` lets typed accessors
163
- * (see {@link ObjectLayer.byType}) narrow `properties` to a developer-declared
164
- * schema. It defaults to the generic {@link TileProperties} bag, so the plain
165
- * `TileMapObject` form is unchanged.
166
- * @advanced
167
- */
168
- export type TileMapObject<P extends TileProperties = TileProperties> = RectangleObject<P> | EllipseObject<P> | PointObject<P> | PolygonObject<P> | PolylineObject<P> | TileObject<P> | TextObject<P>;
169
- /**
170
- * A developer-declared mapping from object `type`/class strings to the property
171
- * shape an object of that type is expected to carry. Supplied as the type
172
- * parameter to {@link ObjectLayer} to unlock the typed accessors
173
- * ({@link ObjectLayer.byType}, {@link ObjectLayer.where}).
174
- *
175
- * @remarks
176
- * A schema is a **developer promise, not a runtime guarantee.** Tiled data is
177
- * untyped at runtime and ExoJS performs no validation against the schema -
178
- * the property objects are returned exactly as parsed. The schema only refines
179
- * the static type of `properties` for ergonomic, typo-safe field access. If the
180
- * source data does not match the declared shape, reads still succeed but the
181
- * static type is a fiction. Validate at the boundary if you need certainty.
182
- *
183
- * @example
184
- * ```ts
185
- * const EntityType = { Spawn: 'spawn', Pickup: 'pickup' } as const;
186
- * interface LevelObjects {
187
- * [EntityType.Spawn]: { team: 'red' | 'blue' };
188
- * [EntityType.Pickup]: { item: 'coin' | 'gem'; amount: number };
189
- * }
190
- * const entities = map.getObjectLayer<LevelObjects>('Entities');
191
- * entities.byType(EntityType.Spawn)[0].properties.team; // 'red' | 'blue'
192
- * ```
193
- * @stable
194
- */
195
- export type ObjectSchema = Record<string, TileProperties>;
196
- /**
197
- * A {@link TileMapObject} whose `properties` are narrowed to the schema shape
198
- * declared for the object `type` `T` in schema `S`.
199
- * @advanced
200
- */
201
- export type TypedObject<S extends ObjectSchema, T extends keyof S & string> = TileMapObject<S[T]>;
202
- /** Filter for {@link ObjectLayer.query}. Unspecified fields match everything. */
203
- export interface ObjectQuery {
204
- /** Match objects whose `name` equals this. */
205
- readonly name?: string;
206
- /** Match objects whose `type`/class equals this. */
207
- readonly type?: string;
208
- /** Match objects of this geometry kind. */
209
- readonly kind?: TileMapObjectKind;
210
- /** Match objects that carry this property key. */
211
- readonly property?: string;
212
- /** When combined with `property`, also require the property value to equal this. */
213
- readonly value?: TilePropertyValue;
214
- }
215
- /** Construction options for an {@link ObjectLayer}. */
216
- export interface ObjectLayerOptions {
217
- /** Object geometry uses logical pixels when supplied; display placement is available through getDisplayObject. */
218
- readonly projection?: TileProjection;
219
- /** Layer id (unique within the map). */
220
- readonly id: number;
221
- /** Layer name. */
222
- readonly name?: string;
223
- /** Layer class string. */
224
- readonly class?: string;
225
- /** Whether the layer is visible. Default `true`. */
226
- readonly visible?: boolean;
227
- /** Layer opacity in `[0, 1]`. Default `1`. */
228
- readonly opacity?: number;
229
- /** Layer pixel offset X. Default `0`. */
230
- readonly offsetX?: number;
231
- /** Layer pixel offset Y. Default `0`. */
232
- readonly offsetY?: number;
233
- /**
234
- * Parallax scroll factor on the X axis. `1` = full camera speed (normal),
235
- * `0.5` = half speed (farther away), `0` = stationary. Default `1`.
236
- */
237
- readonly parallaxX?: number;
238
- /**
239
- * Parallax scroll factor on the Y axis. `1` = full camera speed (normal),
240
- * `0.5` = half speed (farther away), `0` = stationary. Default `1`.
241
- */
242
- readonly parallaxY?: number;
243
- /** Uniform parallax scale around the layer origin. Default `1`. */
244
- readonly parallaxScale?: number;
245
- /**
246
- * Multiplicative layer tint as a `0xRRGGBB` integer, or `null` for no tint
247
- * (Tiled `tintcolor`). Default `null`.
248
- */
249
- readonly tintColor?: number | null;
250
- /**
251
- * Draw order for the objects (Tiled `draworder`): `'topdown'` (sorted by `y`)
252
- * or `'index'` (source order). Informational; objects are stored as given.
253
- * Default `'topdown'`.
254
- */
255
- readonly drawOrder?: 'topdown' | 'index';
256
- /** The objects in this layer. */
257
- readonly objects?: readonly TileMapObject[];
258
- /** Layer-level properties (copied and frozen). */
259
- readonly properties?: TileProperties;
260
- }
261
- /**
262
- * A data-only layer of {@link TileMapObject}s - spawn points, trigger zones,
263
- * collision regions, markers. Object layers are not rendered by the tile
264
- * renderer; they are parsed and exposed for gameplay use (e.g. building physics
265
- * colliders, placing entities).
266
- *
267
- * The presentation fields the source format attaches to a layer -
268
- * {@link visible}, {@link opacity}, {@link offsetX}/{@link offsetY},
269
- * {@link parallaxX}/{@link parallaxY}, {@link parallaxScale}, and
270
- * {@link tintColor} - are carried
271
- * through in full, with any enclosing group layers' contribution already
272
- * folded in, so an object layer describes the same placement and shading its
273
- * neighbouring tile and image layers do. Nothing here acts on them: code that
274
- * draws these objects itself is what applies them.
275
- *
276
- * Query with {@link query} (untyped, fully back-compatible) or, when an
277
- * {@link ObjectSchema} type argument `S` is supplied, with the typed accessors
278
- * {@link byType}, {@link byKind}, and {@link where} - these narrow `properties`
279
- * to the developer-declared shape. The schema is **opt-in**: the default type
280
- * parameter reproduces the original untyped behaviour, so
281
- * `new ObjectLayer(options)` and `map.getObjectLayer('x')` are unchanged.
282
- *
283
- * @remarks
284
- * A schema is a developer promise, not a runtime guarantee - Tiled data is
285
- * untyped at runtime and ExoJS performs no validation. See {@link ObjectSchema}.
286
- *
287
- * @typeParam S - Optional {@link ObjectSchema} mapping object `type` strings to
288
- * their property shapes. Defaults to a generic schema (every type maps to the
289
- * loose {@link TileProperties} bag).
290
- *
291
- * @advanced
292
- */
293
- export declare class ObjectLayer<S extends ObjectSchema = ObjectSchema> {
294
- /** Projection of the logical object geometry, or undefined for ordinary display-space objects. */
295
- readonly projection: TileProjection | undefined;
296
- /** Layer-kind discriminant (distinguishes object layers from tile layers). */
297
- readonly kind: 'object';
298
- /** Layer id (unique within the map). */
299
- readonly id: number;
300
- /** Layer name. */
301
- readonly name: string;
302
- /** Layer class string. */
303
- readonly class: string;
304
- /** Whether the layer is visible. */
305
- readonly visible: boolean;
306
- /** Layer opacity in `[0, 1]`. */
307
- readonly opacity: number;
308
- /** Layer pixel offset X. */
309
- readonly offsetX: number;
310
- /** Layer pixel offset Y. */
311
- readonly offsetY: number;
312
- /**
313
- * Parallax scroll factor on the X axis - the same quantity
314
- * {@link import('./TileLayer').TileLayer.parallaxX} carries, so an object
315
- * layer authored beside a tile layer in the same parallax group reports the
316
- * same factor. `1` = full camera speed, `0.5` = half speed, `0` =
317
- * stationary. Nothing in this package applies it: object layers are
318
- * data-only, so placing an object relative to the camera is the consumer's
319
- * job (see {@link ObjectLayer}).
320
- */
321
- readonly parallaxX: number;
322
- /** Parallax scroll factor on the Y axis. See {@link ObjectLayer.parallaxX}. */
323
- readonly parallaxY: number;
324
- /** Uniform scale applied around the layer origin by consumers that render this data-only layer. */
325
- readonly parallaxScale: number;
326
- /**
327
- * Multiplicative layer tint as `0xRRGGBB`, or `null` for no tint. Carried
328
- * from the source map (including the accumulated tint of any enclosing group
329
- * layers) for code that draws these objects itself; like
330
- * {@link ObjectLayer.parallaxX}, nothing in this package applies it.
331
- */
332
- readonly tintColor: number | null;
333
- /** Draw order for the objects (Tiled `draworder`). Informational. */
334
- readonly drawOrder: 'topdown' | 'index';
335
- /** Immutable layer-level properties. */
336
- readonly properties: TileProperties;
337
- /** The objects in this layer (insertion order). */
338
- readonly objects: readonly TileMapObject[];
339
- constructor(options: ObjectLayerOptions);
340
- /**
341
- * Returns display-space geometry including the layer offset. Isometric
342
- * rectangles become polygons; ellipses retain their exact affine shape.
343
- * Tile/text dimensions remain display pixels. Parallax and scene transforms
344
- * are applied by the consumer, after this conversion.
345
- */
346
- getDisplayObject(object: TileMapObject): TileMapObject;
347
- /** Objects matching every specified criterion of `filter`. Returns a fresh array. */
348
- query(filter?: ObjectQuery): TileMapObject[];
349
- /**
350
- * Objects whose `type` equals `type`, with `properties` narrowed to the
351
- * schema shape `S[T]`. Returns a fresh array (insertion order).
352
- *
353
- * The narrowing is a static convenience only - no runtime validation is
354
- * performed (see {@link ObjectSchema}). On an unschematised layer this
355
- * behaves like `query({ type })` with `TileProperties` properties.
356
- */
357
- byType<T extends keyof S & string>(type: T): Array<TypedObject<S, T>>;
358
- /**
359
- * Objects of the given geometry {@link ObjectKind}, narrowed to that
360
- * geometry's member type (e.g. `byKind(ObjectKind.Polygon)` yields
361
- * {@link PolygonObject}s with their `points`). Returns a fresh array.
362
- */
363
- byKind<K extends ObjectKind>(kind: K): Array<Extract<TileMapObject, {
364
- kind: K;
365
- }>>;
366
- /**
367
- * Objects of `type` (typed as in {@link byType}) that also satisfy
368
- * `predicate`. A convenience combination of {@link byType} and `Array.filter`
369
- * that keeps the narrowed `properties` type inside the predicate. Returns a
370
- * fresh array.
371
- */
372
- where<T extends keyof S & string>(type: T, predicate: (object: TypedObject<S, T>) => boolean): Array<TypedObject<S, T>>;
373
- /** First object with the given id, or undefined. */
374
- getObjectById(id: number): TileMapObject | undefined;
375
- /** First object with the given name, or undefined. */
376
- getObjectByName(name: string): TileMapObject | undefined;
377
- }
378
- export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,GAAG,KAAK,CAAC,OAAO,CAAC,aAAa,EAAE;QAAE,IAAI,EAAE,CAAC,CAAA;KAAE,CAAC,CAAC,CAEvF;IAED;;;;;OAKG;IACI,KAAK,CAAC,CAAC,SAAS,MAAM,CAAC,GAAG,MAAM,EAAE,IAAI,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,OAAO,GAAG,KAAK,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAE7H;IAED,oDAAoD;IAC7C,aAAa,CAAC,EAAE,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS,CAE1D;IAED,sDAAsD;IAC/C,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS,CAE9D;CACF"}
@@ -1,221 +0,0 @@
1
- import { TilePropertyKind } from "./types.js";
2
-
3
- //#region src/ObjectLayer.ts
4
- /**
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
- */
14
- const ObjectKind = {
15
- Rectangle: "rectangle",
16
- Ellipse: "ellipse",
17
- Polygon: "polygon",
18
- Polyline: "polyline",
19
- Point: "point",
20
- Tile: "tile",
21
- Text: "text"
22
- };
23
- /**
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;
29
- /**
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
- };
46
- /**
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
- /** Projection of the logical object geometry, or undefined for ordinary display-space objects. */
80
- projection;
81
- /** Layer-kind discriminant (distinguishes object layers from tile layers). */
82
- kind = "object";
83
- /** Layer id (unique within the map). */
84
- id;
85
- /** Layer name. */
86
- name;
87
- /** Layer class string. */
88
- class;
89
- /** Whether the layer is visible. */
90
- visible;
91
- /** Layer opacity in `[0, 1]`. */
92
- opacity;
93
- /** Layer pixel offset X. */
94
- offsetX;
95
- /** Layer pixel offset Y. */
96
- offsetY;
97
- /**
98
- * Parallax scroll factor on the X axis - the same quantity
99
- * {@link import('./TileLayer').TileLayer.parallaxX} carries, so an object
100
- * layer authored beside a tile layer in the same parallax group reports the
101
- * same factor. `1` = full camera speed, `0.5` = half speed, `0` =
102
- * stationary. Nothing in this package applies it: object layers are
103
- * data-only, so placing an object relative to the camera is the consumer's
104
- * job (see {@link ObjectLayer}).
105
- */
106
- parallaxX;
107
- /** Parallax scroll factor on the Y axis. See {@link ObjectLayer.parallaxX}. */
108
- parallaxY;
109
- /** Uniform scale applied around the layer origin by consumers that render this data-only layer. */
110
- parallaxScale;
111
- /**
112
- * Multiplicative layer tint as `0xRRGGBB`, or `null` for no tint. Carried
113
- * from the source map (including the accumulated tint of any enclosing group
114
- * layers) for code that draws these objects itself; like
115
- * {@link ObjectLayer.parallaxX}, nothing in this package applies it.
116
- */
117
- tintColor;
118
- /** Draw order for the objects (Tiled `draworder`). Informational. */
119
- drawOrder;
120
- /** Immutable layer-level properties. */
121
- properties;
122
- /** The objects in this layer (insertion order). */
123
- objects;
124
- constructor(options) {
125
- this.id = options.id;
126
- this.projection = options.projection;
127
- this.name = options.name ?? "";
128
- this.class = options.class ?? "";
129
- this.visible = options.visible ?? true;
130
- this.opacity = options.opacity ?? 1;
131
- this.offsetX = options.offsetX ?? 0;
132
- this.offsetY = options.offsetY ?? 0;
133
- this.parallaxX = options.parallaxX ?? 1;
134
- this.parallaxY = options.parallaxY ?? 1;
135
- this.parallaxScale = options.parallaxScale ?? 1;
136
- if (!Number.isFinite(this.parallaxScale) || this.parallaxScale <= 0) throw new Error("ObjectLayer parallaxScale must be a positive finite number.");
137
- this.tintColor = options.tintColor ?? null;
138
- this.drawOrder = options.drawOrder ?? "topdown";
139
- this.properties = options.properties ? Object.freeze({ ...options.properties }) : Object.freeze({});
140
- this.objects = options.objects ? Object.freeze([...options.objects]) : Object.freeze([]);
141
- }
142
- /**
143
- * Returns display-space geometry including the layer offset. Isometric
144
- * rectangles become polygons; ellipses retain their exact affine shape.
145
- * Tile/text dimensions remain display pixels. Parallax and scene transforms
146
- * are applied by the consumer, after this conversion.
147
- */
148
- getDisplayObject(object) {
149
- const projected = this.projection?.projectObject(object) ?? object;
150
- const position = {
151
- x: projected.x + this.offsetX,
152
- y: projected.y + this.offsetY
153
- };
154
- if (projected.kind === "tile" && projected.rotationOrigin) return {
155
- ...projected,
156
- ...position,
157
- rotationOrigin: {
158
- x: projected.rotationOrigin.x + this.offsetX,
159
- y: projected.rotationOrigin.y + this.offsetY
160
- }
161
- };
162
- return {
163
- ...projected,
164
- ...position
165
- };
166
- }
167
- /** Objects matching every specified criterion of `filter`. Returns a fresh array. */
168
- query(filter = {}) {
169
- return this.objects.filter((object) => {
170
- if (filter.name !== void 0 && object.name !== filter.name) return false;
171
- if (filter.type !== void 0 && object.type !== filter.type) return false;
172
- if (filter.kind !== void 0 && object.kind !== filter.kind) return false;
173
- if (filter.property !== void 0) {
174
- const value = object.properties[filter.property];
175
- if (value === void 0) return false;
176
- if (filter.value !== void 0 && !tilePropertyValueEquals(value, filter.value)) return false;
177
- }
178
- return true;
179
- });
180
- }
181
- /**
182
- * Objects whose `type` equals `type`, with `properties` narrowed to the
183
- * schema shape `S[T]`. Returns a fresh array (insertion order).
184
- *
185
- * The narrowing is a static convenience only - no runtime validation is
186
- * performed (see {@link ObjectSchema}). On an unschematised layer this
187
- * behaves like `query({ type })` with `TileProperties` properties.
188
- */
189
- byType(type) {
190
- return this.objects.filter((object) => object.type === type);
191
- }
192
- /**
193
- * Objects of the given geometry {@link ObjectKind}, narrowed to that
194
- * geometry's member type (e.g. `byKind(ObjectKind.Polygon)` yields
195
- * {@link PolygonObject}s with their `points`). Returns a fresh array.
196
- */
197
- byKind(kind) {
198
- return this.objects.filter((object) => object.kind === kind);
199
- }
200
- /**
201
- * Objects of `type` (typed as in {@link byType}) that also satisfy
202
- * `predicate`. A convenience combination of {@link byType} and `Array.filter`
203
- * that keeps the narrowed `properties` type inside the predicate. Returns a
204
- * fresh array.
205
- */
206
- where(type, predicate) {
207
- return this.byType(type).filter((object) => predicate(object));
208
- }
209
- /** First object with the given id, or undefined. */
210
- getObjectById(id) {
211
- return this.objects.find((object) => object.id === id);
212
- }
213
- /** First object with the given name, or undefined. */
214
- getObjectByName(name) {
215
- return this.objects.find((object) => object.name === name);
216
- }
217
- };
218
-
219
- //#endregion
220
- export { ObjectKind, ObjectLayer };
221
- //# sourceMappingURL=ObjectLayer.js.map