@codexo/exojs-ldtk 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 +38 -20
- package/dist/esm/LdtkData.d.ts +59 -14
- package/dist/esm/LdtkData.d.ts.map +1 -0
- package/dist/esm/LdtkData.js +8 -16
- package/dist/esm/LdtkData.js.map +1 -1
- package/dist/esm/LdtkMap.d.ts +25 -6
- package/dist/esm/LdtkMap.d.ts.map +1 -0
- package/dist/esm/LdtkMap.js +88 -63
- package/dist/esm/LdtkMap.js.map +1 -1
- package/dist/esm/LdtkProject.d.ts +107 -0
- package/dist/esm/LdtkProject.d.ts.map +1 -0
- package/dist/esm/LdtkProject.js +136 -0
- package/dist/esm/LdtkProject.js.map +1 -0
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +11 -7
- package/dist/esm/ldtkExtension.d.ts +9 -5
- package/dist/esm/ldtkExtension.d.ts.map +1 -0
- package/dist/esm/ldtkExtension.js +25 -22
- package/dist/esm/ldtkExtension.js.map +1 -1
- package/dist/esm/ldtkLevelEntries.d.ts +4 -3
- package/dist/esm/ldtkLevelEntries.d.ts.map +1 -0
- package/dist/esm/ldtkLevelEntries.js +30 -26
- package/dist/esm/ldtkLevelEntries.js.map +1 -1
- package/dist/esm/ldtkParallax.d.ts +22 -0
- package/dist/esm/ldtkParallax.d.ts.map +1 -0
- package/dist/esm/ldtkParallax.js +22 -0
- package/dist/esm/ldtkParallax.js.map +1 -0
- package/dist/esm/ldtkToMapWorld.d.ts +20 -0
- package/dist/esm/ldtkToMapWorld.d.ts.map +1 -0
- package/dist/esm/ldtkToMapWorld.js +76 -0
- package/dist/esm/ldtkToMapWorld.js.map +1 -0
- package/dist/esm/ldtkToTileMap.d.ts +48 -10
- package/dist/esm/ldtkToTileMap.d.ts.map +1 -0
- package/dist/esm/ldtkToTileMap.js +410 -387
- package/dist/esm/ldtkToTileMap.js.map +1 -1
- package/dist/esm/ldtkTypes.d.ts +47 -0
- package/dist/esm/ldtkTypes.d.ts.map +1 -0
- package/dist/esm/ldtkTypes.js +57 -0
- package/dist/esm/ldtkTypes.js.map +1 -0
- package/dist/esm/loadLdtkMap.d.ts +30 -5
- package/dist/esm/loadLdtkMap.d.ts.map +1 -0
- package/dist/esm/loadLdtkMap.js +139 -133
- package/dist/esm/loadLdtkMap.js.map +1 -1
- package/dist/esm/loadLdtkProject.d.ts +17 -0
- package/dist/esm/loadLdtkProject.d.ts.map +1 -0
- package/dist/esm/loadLdtkProject.js +31 -0
- package/dist/esm/loadLdtkProject.js.map +1 -0
- package/dist/esm/public.d.ts +24 -9
- package/dist/esm/public.d.ts.map +1 -0
- package/dist/esm/public.js +11 -0
- package/dist/esm/url.d.ts +16 -0
- package/dist/esm/url.d.ts.map +1 -0
- package/dist/esm/url.js +31 -0
- package/dist/esm/url.js.map +1 -0
- package/dist/esm/validate.d.ts +27 -0
- package/dist/esm/validate.d.ts.map +1 -0
- package/dist/esm/validate.js +327 -0
- package/dist/esm/validate.js.map +1 -0
- package/package.json +10 -18
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/ldtkBinding.d.ts +0 -22
- package/dist/esm/ldtkBinding.js +0 -31
- package/dist/esm/ldtkBinding.js.map +0 -1
- package/dist/esm/register.d.ts +0 -1
- package/dist/esm/register.js +0 -17
- package/dist/esm/register.js.map +0 -1
package/README.md
CHANGED
|
@@ -6,23 +6,34 @@ Official ExoJS extension for loading [LDtk](https://ldtk.io) level files (`.ldtk
|
|
|
6
6
|
## Installation
|
|
7
7
|
|
|
8
8
|
```sh
|
|
9
|
-
npm install @codexo/exojs @codexo/exojs-ldtk
|
|
9
|
+
npm install @codexo/exojs @codexo/exojs-tilemap @codexo/exojs-ldtk
|
|
10
10
|
```
|
|
11
11
|
|
|
12
|
-
`@codexo/exojs`
|
|
13
|
-
|
|
12
|
+
Both `@codexo/exojs` and `@codexo/exojs-tilemap` are **peer** dependencies, so install them
|
|
13
|
+
explicitly alongside the adapter. Nothing is pulled in transitively: strict package managers
|
|
14
|
+
(pnpm, Yarn PnP) will not resolve an unlisted peer, and npm's auto-install of peers still leaves
|
|
15
|
+
the versions outside your control. Keep the engine and every adapter on the same version.
|
|
14
16
|
|
|
15
17
|
## What this package provides
|
|
16
18
|
|
|
17
|
-
- `LdtkMap` — parsed LDtk world; the result of `loader.load(
|
|
19
|
+
- `LdtkMap` — parsed LDtk world; the result of `loader.load('world.ldtk')`. Exposes the raw `data`,
|
|
18
20
|
the converted runtime `levels` (`readonly TileMap[]`, in document order), and
|
|
19
21
|
`getLevelByName(identifier)`
|
|
22
|
+
- `LdtkProject` — the streaming counterpart of `LdtkMap`: the result of
|
|
23
|
+
`loader.load(Asset.type('ldtkProject', 'world.ldtk'))`. Loads the document and every tileset
|
|
24
|
+
atlas, and **no** level payload. Exposes the world layout (`worlds` / `world`, one `MapWorld`
|
|
25
|
+
per LDtk world) and `createRuntime({ scope })` for loading levels one at a time
|
|
26
|
+
- `ldtkToMapWorld` — build the format-neutral world model (level ids, bounds, neighbours) from a
|
|
27
|
+
raw document, without reading any layer payload
|
|
20
28
|
- `ldtkToTileMap` — convert a single LDtk level to a `TileMap` (used internally; available for
|
|
21
29
|
custom pipelines), plus its `LdtkToTileMapOptions`
|
|
30
|
+
- `getLdtkIntGridValueAt` — the named/coloured IntGrid value at a tile coordinate
|
|
31
|
+
- `createLdtkIntGridCellSource` — the layer's IntGrid as a `TileCellSource`, ready to hand to
|
|
32
|
+
`buildTileCollisionGeometry` or `TileColliderStreamer` for collision authored per cell
|
|
22
33
|
- `ldtkExtension` — extension descriptor; depends on `tilemapExtension` automatically
|
|
23
|
-
- `ldtkMapBinding` — the underlying `AssetBinding` (advanced/custom wiring)
|
|
34
|
+
- `ldtkMapBinding` / `ldtkProjectBinding` — the underlying `AssetBinding`s (advanced/custom wiring)
|
|
24
35
|
- The raw LDtk JSON types (`LdtkData`, `LdtkLevel`, `LdtkLayerInstance`, `LdtkEntityInstance`, …)
|
|
25
|
-
and the flip-bit constants (`
|
|
36
|
+
and the flip-bit constants (`LDTK_FLIP_X`, `LDTK_FLIP_Y`, `LDTK_FLIP_XY`, `LDTK_FLIP_NONE`)
|
|
26
37
|
- `TileMap`, `TileMapNode`, `TileMapView`, `TileLayer`, `TileSet`, `ObjectLayer`, … re-exported
|
|
27
38
|
from `@codexo/exojs-tilemap` (same class identity — `instanceof TileMap` holds across both import
|
|
28
39
|
paths)
|
|
@@ -39,33 +50,40 @@ import { LdtkMap, TileMapNode, ldtkExtension } from '@codexo/exojs-ldtk';
|
|
|
39
50
|
|
|
40
51
|
const app = new Application({ extensions: [ldtkExtension] });
|
|
41
52
|
|
|
42
|
-
const world = await app.loader.load(
|
|
53
|
+
const world = await app.loader.load('levels/world.ldtk');
|
|
43
54
|
|
|
44
55
|
// Render the first level (each LDtk level is its own TileMap):
|
|
45
56
|
const level = world.getLevelByName('Level_0') ?? world.levels[0];
|
|
46
|
-
app.
|
|
57
|
+
app.scenes.root.addChild(new TileMapNode(level));
|
|
47
58
|
```
|
|
48
59
|
|
|
49
60
|
`TileMapNode` is the same class exported by `@codexo/exojs-tilemap` (see its
|
|
50
61
|
[README](https://www.npmjs.com/package/@codexo/exojs-tilemap) for the rendering/culling model and
|
|
51
62
|
actor interleaving).
|
|
52
63
|
|
|
53
|
-
|
|
64
|
+
### Streaming levels
|
|
54
65
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
66
|
+
`ldtkMap` converts every level up front. For a project too large for that, load it as an
|
|
67
|
+
`ldtkProject` and load levels individually — each gets its own `LoaderScope`, and external
|
|
68
|
+
`.ldtkl` payloads are fetched only when their level is:
|
|
58
69
|
|
|
59
70
|
```ts
|
|
60
|
-
|
|
61
|
-
import '@codexo/exojs-ldtk
|
|
71
|
+
import { Application, Asset } from '@codexo/exojs';
|
|
72
|
+
import { ldtkExtension } from '@codexo/exojs-ldtk';
|
|
62
73
|
|
|
63
|
-
|
|
64
|
-
|
|
74
|
+
const app = new Application({ extensions: [ldtkExtension] });
|
|
75
|
+
|
|
76
|
+
const project = await app.loader.load(Asset.type('ldtkProject', 'levels/world.ldtk'));
|
|
77
|
+
const runtime = project.createRuntime({ scope: app.loader });
|
|
78
|
+
|
|
79
|
+
const forest = await runtime.loadLevel(project.world.getLevelByName('Forest')!.id);
|
|
80
|
+
|
|
81
|
+
// ... later
|
|
82
|
+
forest.destroy(); // map, spawned objects and the level's asset claims, in that order
|
|
65
83
|
```
|
|
66
84
|
|
|
67
|
-
|
|
68
|
-
|
|
85
|
+
Which levels to load, and when, stays game policy — `project.world` carries the bounds and
|
|
86
|
+
neighbour graph to decide with.
|
|
69
87
|
|
|
70
88
|
## Texture ownership
|
|
71
89
|
|
|
@@ -76,8 +94,8 @@ scene nodes — the application owns those.
|
|
|
76
94
|
## Core compatibility
|
|
77
95
|
|
|
78
96
|
| `@codexo/exojs-ldtk` | `@codexo/exojs` |
|
|
79
|
-
|
|
80
|
-
| 0.14.x
|
|
97
|
+
| -------------------- | --------------- |
|
|
98
|
+
| 0.14.x | 0.14.x |
|
|
81
99
|
|
|
82
100
|
## Links
|
|
83
101
|
|
package/dist/esm/LdtkData.d.ts
CHANGED
|
@@ -9,10 +9,10 @@
|
|
|
9
9
|
*/
|
|
10
10
|
import type { TilePropertyPoint, TilePropertyTileRef } from '@codexo/exojs-tilemap';
|
|
11
11
|
/** Flip-bit constants for {@link LdtkTileData.f}. */
|
|
12
|
-
export declare const
|
|
13
|
-
export declare const
|
|
14
|
-
export declare const
|
|
15
|
-
export declare const
|
|
12
|
+
export declare const LDTK_FLIP_NONE = 0;
|
|
13
|
+
export declare const LDTK_FLIP_X = 1;
|
|
14
|
+
export declare const LDTK_FLIP_Y = 2;
|
|
15
|
+
export declare const LDTK_FLIP_XY = 3;
|
|
16
16
|
/** A single tile placed in a Tiles or AutoLayer layer instance. */
|
|
17
17
|
export interface LdtkTileData {
|
|
18
18
|
/** Pixel position `[x, y]` of this tile within the layer. */
|
|
@@ -43,7 +43,7 @@ export type LdtkFieldPointValue = Omit<TilePropertyPoint, 'kind'>;
|
|
|
43
43
|
/**
|
|
44
44
|
* Raw `__value` shape for an `EntityRef`-typed field: the referenced
|
|
45
45
|
* entity's own iid plus LDtk's navigation context (owning layer/level/world).
|
|
46
|
-
* Maps to {@link import('@codexo/exojs-tilemap').TilePropertyObjectRef}
|
|
46
|
+
* Maps to {@link import('@codexo/exojs-tilemap').TilePropertyObjectRef} -
|
|
47
47
|
* `entityIid` becomes `id`.
|
|
48
48
|
*/
|
|
49
49
|
export interface LdtkFieldEntityRefValue {
|
|
@@ -94,7 +94,7 @@ export interface LdtkEntityInstance {
|
|
|
94
94
|
/** Alias of `__identifier`, mirrors the entity definition type. */
|
|
95
95
|
readonly __type: string;
|
|
96
96
|
/**
|
|
97
|
-
* Pixel position `[x, y]` of the entity's pivot-adjusted anchor
|
|
97
|
+
* Pixel position `[x, y]` of the entity's pivot-adjusted anchor - NOT the
|
|
98
98
|
* top-left corner. Combine with {@link __pivot} to recover the bounding
|
|
99
99
|
* box's top-left corner: `topLeftX = px[0] - width * __pivot[0]`.
|
|
100
100
|
*/
|
|
@@ -135,10 +135,10 @@ export interface LdtkLayerInstance {
|
|
|
135
135
|
/** Globally unique instance id (UUID string). */
|
|
136
136
|
readonly iid: string;
|
|
137
137
|
/**
|
|
138
|
-
* UID of the tileset used by this layer
|
|
139
|
-
*
|
|
138
|
+
* UID of the tileset used by this layer, or `null` on a layer that draws no
|
|
139
|
+
* tiles - LDtk writes the key either way.
|
|
140
140
|
*/
|
|
141
|
-
readonly __tilesetDefUid?: number;
|
|
141
|
+
readonly __tilesetDefUid?: number | null;
|
|
142
142
|
/** Placed tiles for `Tiles` layer type. */
|
|
143
143
|
readonly gridTiles?: readonly LdtkTileData[];
|
|
144
144
|
/** Auto-computed tiles for `AutoLayer` (and `IntGrid` + auto-rules) layer types. */
|
|
@@ -157,6 +157,22 @@ export interface LdtkLayerInstance {
|
|
|
157
157
|
/** Layer opacity in `[0, 1]`. */
|
|
158
158
|
readonly opacity?: number;
|
|
159
159
|
}
|
|
160
|
+
/**
|
|
161
|
+
* One entry of a level's `__neighbours` array: an adjacency to another level,
|
|
162
|
+
* plus the direction code LDtk assigned it.
|
|
163
|
+
*/
|
|
164
|
+
export interface LdtkLevelNeighbour {
|
|
165
|
+
/** `iid` of the neighbouring level. */
|
|
166
|
+
readonly levelIid: string;
|
|
167
|
+
/**
|
|
168
|
+
* Direction code: `"n"`, `"s"`, `"e"`, `"w"` for the cardinal sides, and
|
|
169
|
+
* `"<"`, `">"`, `"o"` for the depth relations LDtk 1.x adds (lower depth,
|
|
170
|
+
* greater depth, overlapping at the same depth). Mapped onto
|
|
171
|
+
* {@link import('@codexo/exojs-tilemap').MapLevelSide} by
|
|
172
|
+
* {@link import('./ldtkToMapWorld').ldtkToMapWorld}.
|
|
173
|
+
*/
|
|
174
|
+
readonly dir: string;
|
|
175
|
+
}
|
|
160
176
|
/** A level in the LDtk world. */
|
|
161
177
|
export interface LdtkLevel {
|
|
162
178
|
/** Human-readable level identifier (unique within the world). */
|
|
@@ -180,8 +196,16 @@ export interface LdtkLevel {
|
|
|
180
196
|
*/
|
|
181
197
|
readonly layerInstances: readonly LdtkLayerInstance[] | null;
|
|
182
198
|
readonly fieldInstances?: readonly LdtkFieldInstance[];
|
|
183
|
-
/**
|
|
184
|
-
|
|
199
|
+
/**
|
|
200
|
+
* Relative path to this level's external `.ldtkl` file, or `null` when the
|
|
201
|
+
* project does not save levels separately - LDtk writes the key either way.
|
|
202
|
+
*/
|
|
203
|
+
readonly externalRelPath?: string | null;
|
|
204
|
+
/**
|
|
205
|
+
* Levels LDtk computed as adjacent to this one. Absent in documents written
|
|
206
|
+
* before LDtk emitted the field, and empty for an isolated level.
|
|
207
|
+
*/
|
|
208
|
+
readonly __neighbours?: readonly LdtkLevelNeighbour[] | null;
|
|
185
209
|
}
|
|
186
210
|
/**
|
|
187
211
|
* How a {@link LdtkWorldData}'s levels are spatially organised. `null` is a
|
|
@@ -194,7 +218,7 @@ export type LdtkWorldLayout = 'Free' | 'GridVania' | 'LinearHorizontal' | 'Linea
|
|
|
194
218
|
* when the project has "Multi-Worlds" enabled in its advanced settings).
|
|
195
219
|
* Each world owns its own {@link levels}; `defs` (tilesets/layers/entity
|
|
196
220
|
* definitions) is declared once at the document root and shared by every
|
|
197
|
-
* world rather than duplicated per-world
|
|
221
|
+
* world rather than duplicated per-world - see {@link LdtkData.defs}.
|
|
198
222
|
*/
|
|
199
223
|
export interface LdtkWorldData {
|
|
200
224
|
/** Human-readable world identifier (unique within the project). */
|
|
@@ -246,6 +270,26 @@ export interface LdtkLayerDef {
|
|
|
246
270
|
readonly tilesetDefUid?: number | null;
|
|
247
271
|
readonly gridSize: number;
|
|
248
272
|
readonly intGridValues?: readonly LdtkIntGridValueDef[];
|
|
273
|
+
/** Definition-level horizontal pixel offset, added to each layer instance offset. */
|
|
274
|
+
readonly pxOffsetX?: number;
|
|
275
|
+
/** Definition-level vertical pixel offset, added to each layer instance offset. */
|
|
276
|
+
readonly pxOffsetY?: number;
|
|
277
|
+
/**
|
|
278
|
+
* Parallax horizontal factor, in `[-1, 1]`. `0` (the default) means "no
|
|
279
|
+
* parallax" - the layer scrolls at normal camera speed, same as every
|
|
280
|
+
* other layer. See {@link import('./ldtkToTileMap').ldtkToTileMap} for how
|
|
281
|
+
* this is carried onto the runtime layer's `parallaxX`.
|
|
282
|
+
*/
|
|
283
|
+
readonly parallaxFactorX?: number;
|
|
284
|
+
/** Parallax vertical factor, in `[-1, 1]`. `0` (the default) means "no parallax". */
|
|
285
|
+
readonly parallaxFactorY?: number;
|
|
286
|
+
/**
|
|
287
|
+
* Whether a non-zero parallax factor also scales this layer up/down to
|
|
288
|
+
* simulate depth. Defaults to `true` (LDtk's own default) when absent.
|
|
289
|
+
*
|
|
290
|
+
* Converted to the runtime layer's uniform `parallaxScale` multiplier.
|
|
291
|
+
*/
|
|
292
|
+
readonly parallaxScaling?: boolean;
|
|
249
293
|
}
|
|
250
294
|
/** Top-level definitions block (`defs`). */
|
|
251
295
|
export interface LdtkDefs {
|
|
@@ -264,7 +308,7 @@ export interface LdtkData {
|
|
|
264
308
|
/**
|
|
265
309
|
* Levels not organised into worlds. Always populated for pre-multi-world
|
|
266
310
|
* documents; kept EMPTY (per the LDtk spec's backward-compatibility rule)
|
|
267
|
-
* when {@link worlds} is used instead
|
|
311
|
+
* when {@link worlds} is used instead - read levels via `worlds[].levels`
|
|
268
312
|
* in that case, or use {@link import('./ldtkLevelEntries').getLdtkLevelEntries}
|
|
269
313
|
* (or simply {@link import('./LdtkMap').LdtkMap.levels} /
|
|
270
314
|
* {@link import('./LdtkMap').LdtkMap.getLevelByName}) to get "all levels,
|
|
@@ -275,8 +319,9 @@ export interface LdtkData {
|
|
|
275
319
|
* Worlds, present and non-empty only when the project has "Multi-Worlds"
|
|
276
320
|
* enabled in its advanced settings. Absent or empty for the (overwhelmingly
|
|
277
321
|
* common) single-world case, in which levels live directly in the root
|
|
278
|
-
* {@link levels} array instead. `defs` is NOT duplicated per-world
|
|
322
|
+
* {@link levels} array instead. `defs` is NOT duplicated per-world - it
|
|
279
323
|
* stays declared once at the document root regardless of this field.
|
|
280
324
|
*/
|
|
281
325
|
readonly worlds?: readonly LdtkWorldData[];
|
|
282
326
|
}
|
|
327
|
+
//# sourceMappingURL=LdtkData.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LdtkData.d.ts","sourceRoot":"","sources":["../../src/LdtkData.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAIpF,qDAAqD;AACrD,eAAO,MAAM,cAAc,IAAI,CAAC;AAChC,eAAO,MAAM,WAAW,IAAI,CAAC;AAC7B,eAAO,MAAM,WAAW,IAAI,CAAC;AAC7B,eAAO,MAAM,YAAY,IAAI,CAAC;AAE9B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,CAAC,aAAa,CAAC,EAAE,SAAS,mBAAmB,EAAE,CAAC;IACxD,qFAAqF;IACrF,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,mFAAmF;IACnF,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B;;;;;OAKG;IACH,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAC;IAClC,qFAAqF;IACrF,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAC;IAClC;;;;;OAKG;IACH,QAAQ,CAAC,eAAe,CAAC,EAAE,OAAO,CAAC;CACpC;AAED,4CAA4C;AAC5C,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,QAAQ,EAAE,SAAS,cAAc,EAAE,CAAC;IAC7C,QAAQ,CAAC,MAAM,EAAE,SAAS,YAAY,EAAE,CAAC;CAC1C;AAID,0CAA0C;AAC1C,MAAM,WAAW,QAAQ;IACvB,wDAAwD;IACxD,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;IACjC,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAC;IAClC,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAC;IAClC,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IACxB;;;;;;;;OAQG;IACH,QAAQ,CAAC,MAAM,EAAE,SAAS,SAAS,EAAE,CAAC;IACtC;;;;;;OAMG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,aAAa,EAAE,CAAC;CAC5C"}
|
package/dist/esm/LdtkData.js
CHANGED
|
@@ -1,18 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
* TypeScript types for the LDtk JSON format (version 1.5.x).
|
|
3
|
-
*
|
|
4
|
-
* These interfaces model the root LDtk JSON document as produced by the LDtk
|
|
5
|
-
* level editor. Only the fields consumed by the ExoJS runtime adapter are
|
|
6
|
-
* declared here; unknown fields are not stripped at parse time.
|
|
7
|
-
*
|
|
8
|
-
* @see https://ldtk.io/json/
|
|
9
|
-
*/
|
|
10
|
-
// ── Tile data ─────────────────────────────────────────────────────────────────
|
|
1
|
+
//#region src/LdtkData.ts
|
|
11
2
|
/** Flip-bit constants for {@link LdtkTileData.f}. */
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const
|
|
3
|
+
const LDTK_FLIP_NONE = 0;
|
|
4
|
+
const LDTK_FLIP_X = 1;
|
|
5
|
+
const LDTK_FLIP_Y = 2;
|
|
6
|
+
const LDTK_FLIP_XY = 3;
|
|
16
7
|
|
|
17
|
-
|
|
18
|
-
|
|
8
|
+
//#endregion
|
|
9
|
+
export { LDTK_FLIP_NONE, LDTK_FLIP_X, LDTK_FLIP_XY, LDTK_FLIP_Y };
|
|
10
|
+
//# sourceMappingURL=LdtkData.js.map
|
package/dist/esm/LdtkData.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LdtkData.js","sources":["../../../src/LdtkData.ts"],"sourcesContent":[null],"names":[],"mappings":"AAAA;;;;;;;;AAQG;AAMH;AAEA;AACO,MAAM,YAAY,GAAG;AACrB,MAAM,SAAS,GAAG;AAClB,MAAM,SAAS,GAAG;AAClB,MAAM,UAAU,GAAG;;;;"}
|
|
1
|
+
{"version":3,"file":"LdtkData.js","names":[],"sources":["../../src/LdtkData.ts"],"sourcesContent":["/**\n * TypeScript types for the LDtk JSON format (version 1.5.x).\n *\n * These interfaces model the root LDtk JSON document as produced by the LDtk\n * level editor. Only the fields consumed by the ExoJS runtime adapter are\n * declared here; unknown fields are not stripped at parse time.\n *\n * @see https://ldtk.io/json/\n */\n\nimport type { TilePropertyPoint, TilePropertyTileRef } from '@codexo/exojs-tilemap';\n\n// ── Tile data ─────────────────────────────────────────────────────────────────\n\n/** Flip-bit constants for {@link LdtkTileData.f}. */\nexport const LDTK_FLIP_NONE = 0;\nexport const LDTK_FLIP_X = 1;\nexport const LDTK_FLIP_Y = 2;\nexport const LDTK_FLIP_XY = 3;\n\n/** A single tile placed in a Tiles or AutoLayer layer instance. */\nexport interface LdtkTileData {\n /** Pixel position `[x, y]` of this tile within the layer. */\n readonly px: readonly [number, number];\n /** Source position `[x, y]` in the tileset image (top-left of the tile). */\n readonly src: readonly [number, number];\n /**\n * Flip bits: `0` = none, `1` = flipX, `2` = flipY, `3` = flipX + flipY.\n * Use {@link LDTK_FLIP_X} / {@link LDTK_FLIP_Y} constants for clarity.\n */\n readonly f: number;\n /** Local tile index in the owning tileset. */\n readonly t: number;\n /** Per-tile opacity in `[0, 1]`. Defaults to `1` when absent. */\n readonly a?: number;\n}\n\n// ── Entity data ───────────────────────────────────────────────────────────────\n\n/**\n * LDtk field types whose `__value` is a bare scalar (or `null`, when the\n * field has no value set).\n */\nexport type LdtkFieldScalarType = 'Int' | 'Float' | 'Bool' | 'String' | 'Multilines' | 'Color' | 'FilePath' | 'Enum';\n\n/**\n * Raw `__value` shape for a `Point`-typed field. Structurally identical to\n * {@link TilePropertyPoint} minus its `kind` tag, so the canonical shape is\n * reused directly rather than duplicated.\n */\nexport type LdtkFieldPointValue = Omit<TilePropertyPoint, 'kind'>;\n\n/**\n * Raw `__value` shape for an `EntityRef`-typed field: the referenced\n * entity's own iid plus LDtk's navigation context (owning layer/level/world).\n * Maps to {@link import('@codexo/exojs-tilemap').TilePropertyObjectRef} -\n * `entityIid` becomes `id`.\n */\nexport interface LdtkFieldEntityRefValue {\n readonly entityIid: string;\n readonly layerIid: string;\n readonly levelIid: string;\n readonly worldIid: string;\n}\n\n/**\n * Raw `__value` shape for a `Tile`-typed field. Structurally identical to\n * {@link TilePropertyTileRef} minus its `kind` tag, so the canonical shape is\n * reused directly rather than duplicated.\n */\nexport type LdtkFieldTileValue = Omit<TilePropertyTileRef, 'kind'>;\n\n/**\n * A field value on an entity or level instance, discriminated by `__type`.\n * `Array<T>` fields (e.g. `Array<Int>`, `Array<Point>`) carry a raw element\n * array whose per-element shape matches the corresponding non-array\n * `__value` shape above; see {@link import('./ldtkToTileMap').ldtkToTileMap}'s\n * field conversion for the exhaustive mapping into the canonical\n * {@link import('@codexo/exojs-tilemap').TilePropertyValue}.\n */\nexport type LdtkFieldInstance =\n | {\n readonly __identifier: string;\n readonly __type: LdtkFieldScalarType;\n readonly __value: string | number | boolean | null;\n }\n | {\n readonly __identifier: string;\n readonly __type: 'Point';\n readonly __value: LdtkFieldPointValue | null;\n }\n | {\n readonly __identifier: string;\n readonly __type: 'EntityRef';\n readonly __value: LdtkFieldEntityRefValue | null;\n }\n | {\n readonly __identifier: string;\n readonly __type: 'Tile';\n readonly __value: LdtkFieldTileValue | null;\n }\n | {\n readonly __identifier: string;\n readonly __type: `Array<${string}>`;\n readonly __value: readonly unknown[] | null;\n };\n\n/** An entity instance placed in an Entities layer. */\nexport interface LdtkEntityInstance {\n /** Entity definition identifier (class name). */\n readonly __identifier: string;\n /** Alias of `__identifier`, mirrors the entity definition type. */\n readonly __type: string;\n /**\n * Pixel position `[x, y]` of the entity's pivot-adjusted anchor - NOT the\n * top-left corner. Combine with {@link __pivot} to recover the bounding\n * box's top-left corner: `topLeftX = px[0] - width * __pivot[0]`.\n */\n readonly px: readonly [number, number];\n readonly width: number;\n readonly height: number;\n /**\n * Normalised `[x, y]` anchor point within the entity's bounding box, each\n * in `[0, 1]`. `[0, 0]` = top-left, `[0.5, 0.5]` = center, `[1, 1]` =\n * bottom-right. Determines how {@link px} relates to the bounding box.\n */\n readonly __pivot: readonly [number, number];\n readonly fieldInstances: readonly LdtkFieldInstance[];\n /** Globally unique instance id (UUID string). */\n readonly iid: string;\n /** UID of the entity definition this instance was created from. */\n readonly defUid: number;\n}\n\n// ── Layer instances ───────────────────────────────────────────────────────────\n\n/** Discriminant string for a layer instance type. */\nexport type LdtkLayerType = 'Tiles' | 'IntGrid' | 'Entities' | 'AutoLayer';\n\n/** A layer instance within a level. */\nexport interface LdtkLayerInstance {\n /** Layer definition identifier. */\n readonly __identifier: string;\n /** Layer type discriminant. */\n readonly __type: LdtkLayerType;\n /** Layer width in grid cells. */\n readonly __cWid: number;\n /** Layer height in grid cells. */\n readonly __cHei: number;\n /** Grid / tile size in pixels. */\n readonly __gridSize: number;\n /** UID of the layer definition. */\n readonly layerDefUid: number;\n /** UID of the parent level. */\n readonly levelId: number;\n readonly visible: boolean;\n /** Globally unique instance id (UUID string). */\n readonly iid: string;\n /**\n * UID of the tileset used by this layer, or `null` on a layer that draws no\n * tiles - LDtk writes the key either way.\n */\n readonly __tilesetDefUid?: number | null;\n /** Placed tiles for `Tiles` layer type. */\n readonly gridTiles?: readonly LdtkTileData[];\n /** Auto-computed tiles for `AutoLayer` (and `IntGrid` + auto-rules) layer types. */\n readonly autoLayerTiles?: readonly LdtkTileData[];\n /** Entity instances for `Entities` layer type. */\n readonly entityInstances?: readonly LdtkEntityInstance[];\n /**\n * Flat CSV array of IntGrid values for `IntGrid` layer type.\n * Index = `y * __cWid + x`. `0` = empty cell.\n */\n readonly intGridCsv?: readonly number[];\n /** Horizontal pixel offset applied to the layer. */\n readonly pxOffsetX?: number;\n /** Vertical pixel offset applied to the layer. */\n readonly pxOffsetY?: number;\n /** Layer opacity in `[0, 1]`. */\n readonly opacity?: number;\n}\n\n// ── Levels ────────────────────────────────────────────────────────────────────\n\n/**\n * One entry of a level's `__neighbours` array: an adjacency to another level,\n * plus the direction code LDtk assigned it.\n */\nexport interface LdtkLevelNeighbour {\n /** `iid` of the neighbouring level. */\n readonly levelIid: string;\n /**\n * Direction code: `\"n\"`, `\"s\"`, `\"e\"`, `\"w\"` for the cardinal sides, and\n * `\"<\"`, `\">\"`, `\"o\"` for the depth relations LDtk 1.x adds (lower depth,\n * greater depth, overlapping at the same depth). Mapped onto\n * {@link import('@codexo/exojs-tilemap').MapLevelSide} by\n * {@link import('./ldtkToMapWorld').ldtkToMapWorld}.\n */\n readonly dir: string;\n}\n\n/** A level in the LDtk world. */\nexport interface LdtkLevel {\n /** Human-readable level identifier (unique within the world). */\n readonly identifier: string;\n readonly uid: number;\n /** Globally unique instance id (UUID string). */\n readonly iid: string;\n /** World-space X position of the level's top-left corner in pixels. */\n readonly worldX: number;\n /** World-space Y position of the level's top-left corner in pixels. */\n readonly worldY: number;\n /** Level width in pixels. */\n readonly pxWid: number;\n /** Level height in pixels. */\n readonly pxHei: number;\n readonly bgColor?: string;\n /**\n * Layer instances in this level (top-to-bottom render order).\n * `null` when the level is stored in a separate `.ldtkl` file and has not\n * been loaded yet.\n */\n readonly layerInstances: readonly LdtkLayerInstance[] | null;\n readonly fieldInstances?: readonly LdtkFieldInstance[];\n /**\n * Relative path to this level's external `.ldtkl` file, or `null` when the\n * project does not save levels separately - LDtk writes the key either way.\n */\n readonly externalRelPath?: string | null;\n /**\n * Levels LDtk computed as adjacent to this one. Absent in documents written\n * before LDtk emitted the field, and empty for an isolated level.\n */\n readonly __neighbours?: readonly LdtkLevelNeighbour[] | null;\n}\n\n// ── Worlds ────────────────────────────────────────────────────────────────────\n\n/**\n * How a {@link LdtkWorldData}'s levels are spatially organised. `null` is a\n * valid LDtk value (unset), same as the other nullable enum-ish fields in\n * this file.\n */\nexport type LdtkWorldLayout = 'Free' | 'GridVania' | 'LinearHorizontal' | 'LinearVertical' | null;\n\n/**\n * A single world in a multi-world LDtk project (`root.worlds[]`, populated\n * when the project has \"Multi-Worlds\" enabled in its advanced settings).\n * Each world owns its own {@link levels}; `defs` (tilesets/layers/entity\n * definitions) is declared once at the document root and shared by every\n * world rather than duplicated per-world - see {@link LdtkData.defs}.\n */\nexport interface LdtkWorldData {\n /** Human-readable world identifier (unique within the project). */\n readonly identifier: string;\n /** Globally unique instance id (UUID string). */\n readonly iid: string;\n /** Width of the world grid in pixels. */\n readonly worldGridWidth: number;\n /** Height of the world grid in pixels. */\n readonly worldGridHeight: number;\n /** How this world's levels are spatially organised. */\n readonly worldLayout: LdtkWorldLayout;\n /** Levels belonging to this world, in document order. */\n readonly levels: readonly LdtkLevel[];\n}\n\n// ── Definitions ───────────────────────────────────────────────────────────────\n\n/** Tileset definition from `defs.tilesets`. */\nexport interface LdtkTilesetDef {\n readonly uid: number;\n /** Human-readable tileset identifier. */\n readonly identifier: string;\n /**\n * Relative path to the tileset atlas image.\n * `null` for internal / embedded tilesets with no image.\n */\n readonly relPath: string | null;\n /** Tile grid size (both width and height) in pixels. */\n readonly tileGridSize: number;\n /** Tileset image width in pixels. */\n readonly pxWid: number;\n /** Tileset image height in pixels. */\n readonly pxHei: number;\n /** Pixel spacing between tiles in the atlas. */\n readonly spacing?: number;\n /** Pixel padding (margin) around the atlas edges. */\n readonly padding?: number;\n}\n\n/** An IntGrid value definition (maps a raw int to a named, coloured entry). */\nexport interface LdtkIntGridValueDef {\n readonly value: number;\n readonly identifier: string | null;\n readonly color: string;\n}\n\n/** Layer definition from `defs.layers`. */\nexport interface LdtkLayerDef {\n readonly uid: number;\n readonly identifier: string;\n readonly type: LdtkLayerType;\n /** UID of the default tileset for this layer. `null` or absent = none. */\n readonly tilesetDefUid?: number | null;\n readonly gridSize: number;\n readonly intGridValues?: readonly LdtkIntGridValueDef[];\n /** Definition-level horizontal pixel offset, added to each layer instance offset. */\n readonly pxOffsetX?: number;\n /** Definition-level vertical pixel offset, added to each layer instance offset. */\n readonly pxOffsetY?: number;\n /**\n * Parallax horizontal factor, in `[-1, 1]`. `0` (the default) means \"no\n * parallax\" - the layer scrolls at normal camera speed, same as every\n * other layer. See {@link import('./ldtkToTileMap').ldtkToTileMap} for how\n * this is carried onto the runtime layer's `parallaxX`.\n */\n readonly parallaxFactorX?: number;\n /** Parallax vertical factor, in `[-1, 1]`. `0` (the default) means \"no parallax\". */\n readonly parallaxFactorY?: number;\n /**\n * Whether a non-zero parallax factor also scales this layer up/down to\n * simulate depth. Defaults to `true` (LDtk's own default) when absent.\n *\n * Converted to the runtime layer's uniform `parallaxScale` multiplier.\n */\n readonly parallaxScaling?: boolean;\n}\n\n/** Top-level definitions block (`defs`). */\nexport interface LdtkDefs {\n readonly tilesets: readonly LdtkTilesetDef[];\n readonly layers: readonly LdtkLayerDef[];\n}\n\n// ── Root document ─────────────────────────────────────────────────────────────\n\n/** Root LDtk JSON document (`*.ldtk`). */\nexport interface LdtkData {\n /** LDtk JSON format version string (e.g. `\"1.5.3\"`). */\n readonly jsonVersion: string;\n readonly worldGridWidth?: number;\n readonly worldGridHeight?: number;\n readonly defaultGridSize?: number;\n readonly bgColor?: string;\n readonly defs: LdtkDefs;\n /**\n * Levels not organised into worlds. Always populated for pre-multi-world\n * documents; kept EMPTY (per the LDtk spec's backward-compatibility rule)\n * when {@link worlds} is used instead - read levels via `worlds[].levels`\n * in that case, or use {@link import('./ldtkLevelEntries').getLdtkLevelEntries}\n * (or simply {@link import('./LdtkMap').LdtkMap.levels} /\n * {@link import('./LdtkMap').LdtkMap.getLevelByName}) to get \"all levels,\n * in order\" regardless of which shape the document uses.\n */\n readonly levels: readonly LdtkLevel[];\n /**\n * Worlds, present and non-empty only when the project has \"Multi-Worlds\"\n * enabled in its advanced settings. Absent or empty for the (overwhelmingly\n * common) single-world case, in which levels live directly in the root\n * {@link levels} array instead. `defs` is NOT duplicated per-world - it\n * stays declared once at the document root regardless of this field.\n */\n readonly worlds?: readonly LdtkWorldData[];\n}\n"],"mappings":";;AAeA,MAAa,iBAAiB;AAC9B,MAAa,cAAc;AAC3B,MAAa,cAAc;AAC3B,MAAa,eAAe"}
|
package/dist/esm/LdtkMap.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { TileMap } from '@codexo/exojs-tilemap';
|
|
1
|
+
import type { MapWorld, TileMap } from '@codexo/exojs-tilemap';
|
|
2
2
|
import type { LdtkData } from './LdtkData';
|
|
3
3
|
/**
|
|
4
4
|
* A parsed LDtk world document: holds the raw JSON data and the converted
|
|
@@ -8,7 +8,7 @@ import type { LdtkData } from './LdtkData';
|
|
|
8
8
|
* convertible to a format-independent `TileMap`; access them via
|
|
9
9
|
* {@link levels} (by document order) or by name via {@link getLevelByName}.
|
|
10
10
|
*
|
|
11
|
-
* Construction is cheap
|
|
11
|
+
* Construction is cheap - the runtime `TileMap[]` is supplied externally
|
|
12
12
|
* (built by {@link import('./ldtkToTileMap').ldtkToTileMap}). The map does
|
|
13
13
|
* **not** own tileset textures; those remain in the Loader cache.
|
|
14
14
|
*/
|
|
@@ -18,24 +18,42 @@ export declare class LdtkMap {
|
|
|
18
18
|
/** The raw parsed LDtk document. */
|
|
19
19
|
readonly data: LdtkData;
|
|
20
20
|
/**
|
|
21
|
-
* Runtime TileMaps
|
|
21
|
+
* Runtime TileMaps - one per LDtk level, in document order.
|
|
22
22
|
*
|
|
23
23
|
* The index here corresponds to
|
|
24
24
|
* {@link import('./ldtkLevelEntries').getLdtkLevelEntries}`(data)[i]`, not
|
|
25
|
-
* `data.levels[i]`
|
|
25
|
+
* `data.levels[i]` - the latter is empty for multi-world documents, where
|
|
26
26
|
* levels live under `data.worlds[].levels` instead. `loadLdtkMap` fully
|
|
27
27
|
* resolves external `.ldtkl` levels before conversion, so every entry here
|
|
28
28
|
* is always a fully converted `TileMap`.
|
|
29
29
|
*/
|
|
30
30
|
readonly levels: readonly TileMap[];
|
|
31
|
+
private _worlds?;
|
|
31
32
|
constructor(source: string, data: LdtkData, levels: readonly TileMap[]);
|
|
33
|
+
/**
|
|
34
|
+
* The document's world layout: level placement, bounds and neighbour graph,
|
|
35
|
+
* one {@link MapWorld} per LDtk world (exactly one for a single-world
|
|
36
|
+
* project). Built on first access and cached.
|
|
37
|
+
*
|
|
38
|
+
* This is metadata about *where* levels are, independent of the runtime maps
|
|
39
|
+
* in {@link levels}. Use it to navigate; use
|
|
40
|
+
* {@link import('./LdtkWorld').LdtkWorld} instead when levels should be
|
|
41
|
+
* loaded on demand rather than all at once.
|
|
42
|
+
*/
|
|
43
|
+
get worlds(): readonly MapWorld[];
|
|
44
|
+
/**
|
|
45
|
+
* The document's only world. Convenience for the single-world case; for a
|
|
46
|
+
* multi-world project this is the first world in document order and
|
|
47
|
+
* {@link worlds} is what to read instead.
|
|
48
|
+
*/
|
|
49
|
+
get world(): MapWorld;
|
|
32
50
|
/**
|
|
33
51
|
* Find a level's runtime {@link TileMap} by the LDtk level `identifier`,
|
|
34
52
|
* or `undefined` when no level with that name exists.
|
|
35
53
|
*
|
|
36
54
|
* Searches across {@link import('./ldtkLevelEntries').getLdtkLevelEntries}'s
|
|
37
55
|
* flattened level set rather than `data.levels` directly, so this works for
|
|
38
|
-
* both single-world and multi-world documents
|
|
56
|
+
* both single-world and multi-world documents - `data.levels` alone is
|
|
39
57
|
* empty for the latter.
|
|
40
58
|
*
|
|
41
59
|
* The lookup is O(n) in the number of levels.
|
|
@@ -45,7 +63,8 @@ export declare class LdtkMap {
|
|
|
45
63
|
* Destroy all owned runtime TileMaps.
|
|
46
64
|
*
|
|
47
65
|
* Is idempotent. Does NOT destroy tileset textures (Loader-owned) or any
|
|
48
|
-
* SceneNodes
|
|
66
|
+
* SceneNodes - the application is responsible for those.
|
|
49
67
|
*/
|
|
50
68
|
destroy(): void;
|
|
51
69
|
}
|
|
70
|
+
//# sourceMappingURL=LdtkMap.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LdtkMap.d.ts","sourceRoot":"","sources":["../../src/LdtkMap.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAE/D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAI3C;;;;;;;;;;;GAWG;AACH,qBAAa,OAAO;IAClB,6CAA6C;IAC7C,SAAgB,MAAM,EAAE,MAAM,CAAC;IAC/B,oCAAoC;IACpC,SAAgB,IAAI,EAAE,QAAQ,CAAC;IAC/B;;;;;;;;;OASG;IACH,SAAgB,MAAM,EAAE,SAAS,OAAO,EAAE,CAAC;IAE3C,OAAO,CAAC,OAAO,CAAC,CAAsB;gBAEnB,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,OAAO,EAAE;IAM7E;;;;;;;;;OASG;IACH,IAAW,MAAM,IAAI,SAAS,QAAQ,EAAE,CAGvC;IAED;;;;OAIG;IACH,IAAW,KAAK,IAAI,QAAQ,CAQ3B;IAED;;;;;;;;;;OAUG;IACI,cAAc,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS;IAM9D;;;;;OAKG;IACI,OAAO,IAAI,IAAI;CAKvB"}
|
package/dist/esm/LdtkMap.js
CHANGED
|
@@ -1,67 +1,92 @@
|
|
|
1
|
-
import { getLdtkLevelEntries } from
|
|
1
|
+
import { getLdtkLevelEntries } from "./ldtkLevelEntries.js";
|
|
2
|
+
import { ldtkToMapWorld } from "./ldtkToMapWorld.js";
|
|
2
3
|
|
|
4
|
+
//#region src/LdtkMap.ts
|
|
3
5
|
/**
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
6
|
+
* A parsed LDtk world document: holds the raw JSON data and the converted
|
|
7
|
+
* runtime {@link TileMap} for each level.
|
|
8
|
+
*
|
|
9
|
+
* `LdtkMap` is the parsed source model. Each LDtk level is independently
|
|
10
|
+
* convertible to a format-independent `TileMap`; access them via
|
|
11
|
+
* {@link levels} (by document order) or by name via {@link getLevelByName}.
|
|
12
|
+
*
|
|
13
|
+
* Construction is cheap - the runtime `TileMap[]` is supplied externally
|
|
14
|
+
* (built by {@link import('./ldtkToTileMap').ldtkToTileMap}). The map does
|
|
15
|
+
* **not** own tileset textures; those remain in the Loader cache.
|
|
16
|
+
*/
|
|
17
|
+
var LdtkMap = class {
|
|
18
|
+
/** Resolved URL this map was loaded from. */
|
|
19
|
+
source;
|
|
20
|
+
/** The raw parsed LDtk document. */
|
|
21
|
+
data;
|
|
22
|
+
/**
|
|
23
|
+
* Runtime TileMaps - one per LDtk level, in document order.
|
|
24
|
+
*
|
|
25
|
+
* The index here corresponds to
|
|
26
|
+
* {@link import('./ldtkLevelEntries').getLdtkLevelEntries}`(data)[i]`, not
|
|
27
|
+
* `data.levels[i]` - the latter is empty for multi-world documents, where
|
|
28
|
+
* levels live under `data.worlds[].levels` instead. `loadLdtkMap` fully
|
|
29
|
+
* resolves external `.ldtkl` levels before conversion, so every entry here
|
|
30
|
+
* is always a fully converted `TileMap`.
|
|
31
|
+
*/
|
|
32
|
+
levels;
|
|
33
|
+
_worlds;
|
|
34
|
+
constructor(source, data, levels) {
|
|
35
|
+
this.source = source;
|
|
36
|
+
this.data = data;
|
|
37
|
+
this.levels = levels;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* The document's world layout: level placement, bounds and neighbour graph,
|
|
41
|
+
* one {@link MapWorld} per LDtk world (exactly one for a single-world
|
|
42
|
+
* project). Built on first access and cached.
|
|
43
|
+
*
|
|
44
|
+
* This is metadata about *where* levels are, independent of the runtime maps
|
|
45
|
+
* in {@link levels}. Use it to navigate; use
|
|
46
|
+
* {@link import('./LdtkWorld').LdtkWorld} instead when levels should be
|
|
47
|
+
* loaded on demand rather than all at once.
|
|
48
|
+
*/
|
|
49
|
+
get worlds() {
|
|
50
|
+
this._worlds ??= ldtkToMapWorld(this.data);
|
|
51
|
+
return this._worlds;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* The document's only world. Convenience for the single-world case; for a
|
|
55
|
+
* multi-world project this is the first world in document order and
|
|
56
|
+
* {@link worlds} is what to read instead.
|
|
57
|
+
*/
|
|
58
|
+
get world() {
|
|
59
|
+
const [first] = this.worlds;
|
|
60
|
+
if (first === void 0) throw new Error(`LdtkMap: "${this.source}" declares no world.`);
|
|
61
|
+
return first;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Find a level's runtime {@link TileMap} by the LDtk level `identifier`,
|
|
65
|
+
* or `undefined` when no level with that name exists.
|
|
66
|
+
*
|
|
67
|
+
* Searches across {@link import('./ldtkLevelEntries').getLdtkLevelEntries}'s
|
|
68
|
+
* flattened level set rather than `data.levels` directly, so this works for
|
|
69
|
+
* both single-world and multi-world documents - `data.levels` alone is
|
|
70
|
+
* empty for the latter.
|
|
71
|
+
*
|
|
72
|
+
* The lookup is O(n) in the number of levels.
|
|
73
|
+
*/
|
|
74
|
+
getLevelByName(identifier) {
|
|
75
|
+
const index = getLdtkLevelEntries(this.data).findIndex((entry) => entry.level.identifier === identifier);
|
|
76
|
+
if (index === -1) return void 0;
|
|
77
|
+
return this.levels[index];
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Destroy all owned runtime TileMaps.
|
|
81
|
+
*
|
|
82
|
+
* Is idempotent. Does NOT destroy tileset textures (Loader-owned) or any
|
|
83
|
+
* SceneNodes - the application is responsible for those.
|
|
84
|
+
*/
|
|
85
|
+
destroy() {
|
|
86
|
+
for (const level of this.levels) level.destroy();
|
|
87
|
+
}
|
|
88
|
+
};
|
|
65
89
|
|
|
90
|
+
//#endregion
|
|
66
91
|
export { LdtkMap };
|
|
67
|
-
//# sourceMappingURL=LdtkMap.js.map
|
|
92
|
+
//# sourceMappingURL=LdtkMap.js.map
|
package/dist/esm/LdtkMap.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LdtkMap.js","sources":["
|
|
1
|
+
{"version":3,"file":"LdtkMap.js","names":[],"sources":["../../src/LdtkMap.ts"],"sourcesContent":["import type { MapWorld, TileMap } from '@codexo/exojs-tilemap';\n\nimport type { LdtkData } from './LdtkData';\nimport { getLdtkLevelEntries } from './ldtkLevelEntries';\nimport { ldtkToMapWorld } from './ldtkToMapWorld';\n\n/**\n * A parsed LDtk world document: holds the raw JSON data and the converted\n * runtime {@link TileMap} for each level.\n *\n * `LdtkMap` is the parsed source model. Each LDtk level is independently\n * convertible to a format-independent `TileMap`; access them via\n * {@link levels} (by document order) or by name via {@link getLevelByName}.\n *\n * Construction is cheap - the runtime `TileMap[]` is supplied externally\n * (built by {@link import('./ldtkToTileMap').ldtkToTileMap}). The map does\n * **not** own tileset textures; those remain in the Loader cache.\n */\nexport class LdtkMap {\n /** Resolved URL this map was loaded from. */\n public readonly source: string;\n /** The raw parsed LDtk document. */\n public readonly data: LdtkData;\n /**\n * Runtime TileMaps - one per LDtk level, in document order.\n *\n * The index here corresponds to\n * {@link import('./ldtkLevelEntries').getLdtkLevelEntries}`(data)[i]`, not\n * `data.levels[i]` - the latter is empty for multi-world documents, where\n * levels live under `data.worlds[].levels` instead. `loadLdtkMap` fully\n * resolves external `.ldtkl` levels before conversion, so every entry here\n * is always a fully converted `TileMap`.\n */\n public readonly levels: readonly TileMap[];\n\n private _worlds?: readonly MapWorld[];\n\n public constructor(source: string, data: LdtkData, levels: readonly TileMap[]) {\n this.source = source;\n this.data = data;\n this.levels = levels;\n }\n\n /**\n * The document's world layout: level placement, bounds and neighbour graph,\n * one {@link MapWorld} per LDtk world (exactly one for a single-world\n * project). Built on first access and cached.\n *\n * This is metadata about *where* levels are, independent of the runtime maps\n * in {@link levels}. Use it to navigate; use\n * {@link import('./LdtkWorld').LdtkWorld} instead when levels should be\n * loaded on demand rather than all at once.\n */\n public get worlds(): readonly MapWorld[] {\n this._worlds ??= ldtkToMapWorld(this.data);\n return this._worlds;\n }\n\n /**\n * The document's only world. Convenience for the single-world case; for a\n * multi-world project this is the first world in document order and\n * {@link worlds} is what to read instead.\n */\n public get world(): MapWorld {\n const [first] = this.worlds;\n\n if (first === undefined) {\n throw new Error(`LdtkMap: \"${this.source}\" declares no world.`);\n }\n\n return first;\n }\n\n /**\n * Find a level's runtime {@link TileMap} by the LDtk level `identifier`,\n * or `undefined` when no level with that name exists.\n *\n * Searches across {@link import('./ldtkLevelEntries').getLdtkLevelEntries}'s\n * flattened level set rather than `data.levels` directly, so this works for\n * both single-world and multi-world documents - `data.levels` alone is\n * empty for the latter.\n *\n * The lookup is O(n) in the number of levels.\n */\n public getLevelByName(identifier: string): TileMap | undefined {\n const index = getLdtkLevelEntries(this.data).findIndex(entry => entry.level.identifier === identifier);\n if (index === -1) return undefined;\n return this.levels[index];\n }\n\n /**\n * Destroy all owned runtime TileMaps.\n *\n * Is idempotent. Does NOT destroy tileset textures (Loader-owned) or any\n * SceneNodes - the application is responsible for those.\n */\n public destroy(): void {\n for (const level of this.levels) {\n level.destroy();\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAkBA,IAAa,UAAb,MAAqB;;CAEnB,AAAgB;;CAEhB,AAAgB;;;;;;;;;;;CAWhB,AAAgB;CAEhB,AAAQ;CAER,AAAO,YAAY,QAAgB,MAAgB,QAA4B;EAC7E,KAAK,SAAS;EACd,KAAK,OAAO;EACZ,KAAK,SAAS;CAChB;;;;;;;;;;;CAYA,IAAW,SAA8B;EACvC,KAAK,YAAY,eAAe,KAAK,IAAI;EACzC,OAAO,KAAK;CACd;;;;;;CAOA,IAAW,QAAkB;EAC3B,MAAM,CAAC,SAAS,KAAK;EAErB,IAAI,UAAU,QACZ,MAAM,IAAI,MAAM,aAAa,KAAK,OAAO,qBAAqB;EAGhE,OAAO;CACT;;;;;;;;;;;;CAaA,AAAO,eAAe,YAAyC;EAC7D,MAAM,QAAQ,oBAAoB,KAAK,IAAI,CAAC,CAAC,WAAU,UAAS,MAAM,MAAM,eAAe,UAAU;EACrG,IAAI,UAAU,IAAI,OAAO;EACzB,OAAO,KAAK,OAAO;CACrB;;;;;;;CAQA,AAAO,UAAgB;EACrB,KAAK,MAAM,SAAS,KAAK,QACvB,MAAM,QAAQ;CAElB;AACF"}
|