@codexo/exojs-tiled 0.12.0 → 0.13.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 (45) hide show
  1. package/README.md +134 -71
  2. package/dist/esm/TiledLayer.d.ts +72 -0
  3. package/dist/esm/TiledLayer.js +117 -0
  4. package/dist/esm/TiledLayer.js.map +1 -0
  5. package/dist/esm/TiledMap.d.ts +57 -72
  6. package/dist/esm/TiledMap.js +251 -23
  7. package/dist/esm/TiledMap.js.map +1 -1
  8. package/dist/esm/TiledObject.d.ts +32 -0
  9. package/dist/esm/TiledObject.js +54 -0
  10. package/dist/esm/TiledObject.js.map +1 -0
  11. package/dist/esm/TiledTileset.d.ts +59 -0
  12. package/dist/esm/TiledTileset.js +70 -0
  13. package/dist/esm/TiledTileset.js.map +1 -0
  14. package/dist/esm/data.d.ts +217 -0
  15. package/dist/esm/gid.d.ts +13 -0
  16. package/dist/esm/gid.js +28 -0
  17. package/dist/esm/gid.js.map +1 -0
  18. package/dist/esm/index.js +8 -1
  19. package/dist/esm/index.js.map +1 -1
  20. package/dist/esm/loadTiledMap.d.ts +9 -0
  21. package/dist/esm/loadTiledMap.js +68 -0
  22. package/dist/esm/loadTiledMap.js.map +1 -0
  23. package/dist/esm/public.d.ts +42 -3
  24. package/dist/esm/register.js +7 -0
  25. package/dist/esm/register.js.map +1 -1
  26. package/dist/esm/tiledBuildInfo.js +2 -2
  27. package/dist/esm/tiledExtension.d.ts +10 -0
  28. package/dist/esm/tiledExtension.js +19 -48
  29. package/dist/esm/tiledExtension.js.map +1 -1
  30. package/dist/esm/tiledMapBinding.d.ts +19 -0
  31. package/dist/esm/tiledMapBinding.js +31 -0
  32. package/dist/esm/tiledMapBinding.js.map +1 -0
  33. package/dist/esm/tiledOptions.d.ts +31 -0
  34. package/dist/esm/tiledOptions.js +16 -0
  35. package/dist/esm/tiledOptions.js.map +1 -0
  36. package/dist/esm/tiledRuntimeMapBinding.d.ts +29 -0
  37. package/dist/esm/tiledRuntimeMapBinding.js +42 -0
  38. package/dist/esm/tiledRuntimeMapBinding.js.map +1 -0
  39. package/dist/esm/url.d.ts +18 -0
  40. package/dist/esm/url.js +41 -0
  41. package/dist/esm/url.js.map +1 -0
  42. package/dist/esm/validate.d.ts +49 -0
  43. package/dist/esm/validate.js +509 -0
  44. package/dist/esm/validate.js.map +1 -0
  45. package/package.json +11 -3
@@ -0,0 +1,217 @@
1
+ /** A 2D point as written by Tiled (used for tile offsets and object shapes). */
2
+ export interface TiledPointData {
3
+ readonly x: number;
4
+ readonly y: number;
5
+ }
6
+ /** The `type` discriminant of a Tiled custom property. */
7
+ export type TiledPropertyType = 'string' | 'int' | 'float' | 'bool' | 'color' | 'file' | 'object' | 'class';
8
+ /**
9
+ * The value of a `class`-typed custom property: a nested map of member name
10
+ * to value, recursively allowing further `class` members.
11
+ */
12
+ export interface TiledClassPropertyValueData {
13
+ readonly [name: string]: string | number | boolean | TiledClassPropertyValueData;
14
+ }
15
+ /**
16
+ * One custom property entry as written by Tiled (`properties` arrays on
17
+ * maps, tilesets, tiles, layers and objects).
18
+ *
19
+ * - `string` / `color` / `file` → `value` is a `string`
20
+ * - `int` / `float` / `object` → `value` is a `number` (an `object` value is
21
+ * the referenced object's id)
22
+ * - `bool` → `value` is a `boolean`
23
+ * - `class` → `value` is a {@link TiledClassPropertyValueData}; `propertytype`
24
+ * names the class
25
+ */
26
+ export interface TiledPropertyData {
27
+ readonly name: string;
28
+ readonly type: TiledPropertyType;
29
+ readonly propertytype?: string;
30
+ readonly value: string | number | boolean | TiledClassPropertyValueData;
31
+ }
32
+ /** One frame of a tile's animation sequence. */
33
+ export interface TiledAnimationFrameData {
34
+ /** Local tile id (within the owning tileset) shown during this frame. */
35
+ readonly tileid: number;
36
+ /** Frame duration in milliseconds. */
37
+ readonly duration: number;
38
+ }
39
+ /**
40
+ * A per-tile definition within a tileset's `tiles` array. Sparse — only
41
+ * tiles carrying metadata (properties, animation, a collision objectgroup,
42
+ * or a collection-of-images source) appear here.
43
+ */
44
+ export interface TiledTileData {
45
+ /** Local tile id within the owning tileset. */
46
+ readonly id: number;
47
+ /** Tile class (`class`/`type` field depending on Tiled version). */
48
+ readonly type?: string;
49
+ readonly properties?: readonly TiledPropertyData[];
50
+ readonly animation?: readonly TiledAnimationFrameData[];
51
+ /** Per-tile collision shapes, structurally identical to an object layer. */
52
+ readonly objectgroup?: TiledObjectLayerData;
53
+ /** Collection-of-images tile source, relative to the tileset's location. */
54
+ readonly image?: string;
55
+ readonly imagewidth?: number;
56
+ readonly imageheight?: number;
57
+ }
58
+ /**
59
+ * A Tiled tileset, as the root of a standalone `.tsj` file or (minus
60
+ * `firstgid`) embedded inline in a map's `tilesets` array.
61
+ */
62
+ export interface TiledTilesetData {
63
+ readonly name: string;
64
+ readonly class?: string;
65
+ readonly tilewidth: number;
66
+ readonly tileheight: number;
67
+ readonly tilecount: number;
68
+ readonly columns: number;
69
+ readonly spacing?: number;
70
+ readonly margin?: number;
71
+ /** Single-image ("atlas") tileset source, relative to the tileset's location. Absent for collection-of-images tilesets. */
72
+ readonly image?: string;
73
+ readonly imagewidth?: number;
74
+ readonly imageheight?: number;
75
+ readonly tileoffset?: TiledPointData;
76
+ readonly objectalignment?: string;
77
+ readonly tiles?: readonly TiledTileData[];
78
+ readonly properties?: readonly TiledPropertyData[];
79
+ readonly tiledversion?: string;
80
+ readonly version?: string | number;
81
+ }
82
+ /** A map's `tilesets[]` entry referencing an external `.tsj` file by relative path. */
83
+ export interface TiledExternalTilesetRefData {
84
+ readonly firstgid: number;
85
+ readonly source: string;
86
+ }
87
+ /** A map's `tilesets[]` entry with the tileset embedded inline. */
88
+ export type TiledEmbeddedTilesetRefData = TiledTilesetData & {
89
+ readonly firstgid: number;
90
+ };
91
+ /** One entry of {@link TiledMapData.tilesets} — either external (`source`) or embedded. */
92
+ export type TiledTilesetRefData = TiledExternalTilesetRefData | TiledEmbeddedTilesetRefData;
93
+ /** Text rendering options for a `text` object (object layers). */
94
+ export interface TiledTextData {
95
+ readonly text: string;
96
+ readonly bold?: boolean;
97
+ readonly color?: string;
98
+ readonly fontfamily?: string;
99
+ readonly halign?: 'center' | 'right' | 'justify' | 'left';
100
+ readonly italic?: boolean;
101
+ readonly kerning?: boolean;
102
+ readonly pixelsize?: number;
103
+ readonly strikeout?: boolean;
104
+ readonly underline?: boolean;
105
+ readonly valign?: 'center' | 'bottom' | 'top';
106
+ readonly wrap?: boolean;
107
+ }
108
+ /**
109
+ * An object placed in an object layer (or a tile's collision `objectgroup`).
110
+ * The shape is determined by which of `point` / `ellipse` / `polygon` /
111
+ * `polyline` / `text` / `gid` is present; absent of all of these, the object
112
+ * is a plain rectangle.
113
+ */
114
+ export interface TiledObjectData {
115
+ readonly id: number;
116
+ readonly name: string;
117
+ /** Object class (empty string if unset). */
118
+ readonly type: string;
119
+ readonly x: number;
120
+ readonly y: number;
121
+ readonly width: number;
122
+ readonly height: number;
123
+ readonly rotation: number;
124
+ readonly visible: boolean;
125
+ /** Tile object reference; may carry flip/rotation flag bits in the high bits. */
126
+ readonly gid?: number;
127
+ readonly point?: boolean;
128
+ readonly ellipse?: boolean;
129
+ readonly polygon?: readonly TiledPointData[];
130
+ readonly polyline?: readonly TiledPointData[];
131
+ readonly text?: TiledTextData;
132
+ /** Path to a `.tx` object template this object was instantiated from. */
133
+ readonly template?: string;
134
+ readonly properties?: readonly TiledPropertyData[];
135
+ }
136
+ /** Fields shared by every layer type. */
137
+ export interface TiledLayerDataBase {
138
+ readonly id: number;
139
+ readonly name: string;
140
+ readonly class?: string;
141
+ readonly visible: boolean;
142
+ readonly opacity: number;
143
+ readonly x: number;
144
+ readonly y: number;
145
+ readonly offsetx?: number;
146
+ readonly offsety?: number;
147
+ readonly parallaxx?: number;
148
+ readonly parallaxy?: number;
149
+ readonly tintcolor?: string;
150
+ readonly properties?: readonly TiledPropertyData[];
151
+ }
152
+ /** A chunk of tile data within an infinite tile layer. */
153
+ export interface TiledChunkData {
154
+ readonly x: number;
155
+ readonly y: number;
156
+ readonly width: number;
157
+ readonly height: number;
158
+ readonly data: readonly number[];
159
+ }
160
+ /**
161
+ * A finite-map tile layer has `data` (a flat, row-major array of GIDs of
162
+ * length `width * height`). An infinite-map tile layer has `chunks` instead.
163
+ */
164
+ export interface TiledTileLayerData extends TiledLayerDataBase {
165
+ readonly type: 'tilelayer';
166
+ readonly width: number;
167
+ readonly height: number;
168
+ readonly data?: readonly number[];
169
+ readonly chunks?: readonly TiledChunkData[];
170
+ }
171
+ export interface TiledObjectLayerData extends TiledLayerDataBase {
172
+ readonly type: 'objectgroup';
173
+ readonly draworder?: 'topdown' | 'index';
174
+ readonly objects: readonly TiledObjectData[];
175
+ }
176
+ export interface TiledImageLayerData extends TiledLayerDataBase {
177
+ readonly type: 'imagelayer';
178
+ /** Image source, relative to the map's location. Empty string if unset. */
179
+ readonly image: string;
180
+ readonly repeatx?: boolean;
181
+ readonly repeaty?: boolean;
182
+ }
183
+ export interface TiledGroupLayerData extends TiledLayerDataBase {
184
+ readonly type: 'group';
185
+ readonly layers: readonly TiledLayerData[];
186
+ }
187
+ /** Discriminated union of all four Tiled layer types, keyed by `type`. */
188
+ export type TiledLayerData = TiledTileLayerData | TiledObjectLayerData | TiledImageLayerData | TiledGroupLayerData;
189
+ /** The orientation values Tiled may write for a map. */
190
+ export type TiledOrientation = 'orthogonal' | 'isometric' | 'staggered' | 'hexagonal';
191
+ /** The render-order values Tiled may write for an orthogonal map. */
192
+ export type TiledRenderOrder = 'right-down' | 'right-up' | 'left-down' | 'left-up';
193
+ /** The root of a `.tmj` map file. */
194
+ export interface TiledMapData {
195
+ readonly type: 'map';
196
+ readonly version: string | number;
197
+ readonly tiledversion?: string;
198
+ readonly class?: string;
199
+ readonly orientation: TiledOrientation;
200
+ readonly renderorder?: TiledRenderOrder;
201
+ /** Map width in tiles. */
202
+ readonly width: number;
203
+ /** Map height in tiles. */
204
+ readonly height: number;
205
+ /** Tile grid cell width in pixels. */
206
+ readonly tilewidth: number;
207
+ /** Tile grid cell height in pixels. */
208
+ readonly tileheight: number;
209
+ readonly infinite: boolean;
210
+ readonly compressionlevel?: number;
211
+ readonly nextlayerid?: number;
212
+ readonly nextobjectid?: number;
213
+ readonly backgroundcolor?: string;
214
+ readonly layers: readonly TiledLayerData[];
215
+ readonly tilesets: readonly TiledTilesetRefData[];
216
+ readonly properties?: readonly TiledPropertyData[];
217
+ }
@@ -0,0 +1,13 @@
1
+ export declare const TILED_FLIPPED_HORIZONTALLY_FLAG = 2147483648;
2
+ export declare const TILED_FLIPPED_VERTICALLY_FLAG = 1073741824;
3
+ export declare const TILED_FLIPPED_DIAGONALLY_FLAG = 536870912;
4
+ export declare const TILED_ROTATED_HEXAGONAL_120_FLAG = 268435456;
5
+ /**
6
+ * Strips the flip/rotation flag bits from a raw Tiled GID, returning the
7
+ * plain tileset-relative global tile id (0 = empty cell).
8
+ *
9
+ * GIDs may exceed `2^31` (the horizontal-flip flag alone is `2^31`), so the
10
+ * value is first coerced to an unsigned 32-bit integer via `>>> 0`.
11
+ * @internal
12
+ */
13
+ export declare function maskTiledGid(raw: number): number;
@@ -0,0 +1,28 @@
1
+ // Tiled GID flip-flag bits (TMJ tile-layer `data` / object `gid` values).
2
+ // The high four bits of a 32-bit GID encode flip/rotation state; the
3
+ // remaining 28 bits are the actual tileset-relative global tile id.
4
+ //
5
+ // These constants exist only to mask flip bits off before resolving a GID
6
+ // against a tileset's [firstgid, firstgid + tilecount) range during source
7
+ // validation. Converting flip bits into a runtime `TileTransform` is a C2
8
+ // (runtime conversion) concern and is intentionally not implemented here.
9
+ // @internal
10
+ const TILED_FLIPPED_HORIZONTALLY_FLAG = 0x80000000;
11
+ const TILED_FLIPPED_VERTICALLY_FLAG = 0x40000000;
12
+ const TILED_FLIPPED_DIAGONALLY_FLAG = 0x20000000;
13
+ /** Mask isolating the 28-bit tile id, clearing all four flip/rotation flag bits. */
14
+ const TILED_GID_MASK = 0x0fffffff;
15
+ /**
16
+ * Strips the flip/rotation flag bits from a raw Tiled GID, returning the
17
+ * plain tileset-relative global tile id (0 = empty cell).
18
+ *
19
+ * GIDs may exceed `2^31` (the horizontal-flip flag alone is `2^31`), so the
20
+ * value is first coerced to an unsigned 32-bit integer via `>>> 0`.
21
+ * @internal
22
+ */
23
+ function maskTiledGid(raw) {
24
+ return (raw >>> 0) & TILED_GID_MASK;
25
+ }
26
+
27
+ export { TILED_FLIPPED_DIAGONALLY_FLAG, TILED_FLIPPED_HORIZONTALLY_FLAG, TILED_FLIPPED_VERTICALLY_FLAG, maskTiledGid };
28
+ //# sourceMappingURL=gid.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gid.js","sources":["../../../src/gid.ts"],"sourcesContent":[null],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEO,MAAM,+BAA+B,GAAG;AACxC,MAAM,6BAA6B,GAAG;AACtC,MAAM,6BAA6B,GAAG;AAG7C;AACA,MAAM,cAAc,GAAG,UAAU;AAEjC;;;;;;;AAOG;AACG,SAAU,YAAY,CAAC,GAAW,EAAA;AACtC,IAAA,OAAO,CAAC,GAAG,KAAK,CAAC,IAAI,cAAc;AACrC;;;;"}
package/dist/esm/index.js CHANGED
@@ -1,4 +1,11 @@
1
- export { tiledExtension } from './tiledExtension.js';
2
1
  export { tiledBuildInfo } from './tiledBuildInfo.js';
2
+ export { tiledExtension } from './tiledExtension.js';
3
+ export { tiledMapBinding } from './tiledMapBinding.js';
4
+ export { tiledRuntimeMapBinding } from './tiledRuntimeMapBinding.js';
5
+ export { TILE_TRANSFORM_IDENTITY, TileLayer, TileLayerNode, TileMap, TileMapBand, TileMapNode, TileMapView, TileSet, tilemapExtension } from '@codexo/exojs-tilemap';
6
+ export { TiledGroupLayer, TiledImageLayer, TiledLayer, TiledObjectLayer, TiledTileLayer, createTiledLayer } from './TiledLayer.js';
3
7
  export { TiledMap } from './TiledMap.js';
8
+ export { TiledObject } from './TiledObject.js';
9
+ export { TiledTileset } from './TiledTileset.js';
10
+ export { TiledFormatError } from './validate.js';
4
11
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;"}
@@ -0,0 +1,9 @@
1
+ import { type AssetLoaderContext } from '@codexo/exojs';
2
+ import { TiledMap } from './TiledMap';
3
+ /**
4
+ * Loads and resolves a Tiled map: fetches and validates the `.tmj`, resolves
5
+ * each tileset (external `.tsj` or embedded) and its image(s), and returns
6
+ * the assembled, GID-validated {@link TiledMap}.
7
+ * @internal
8
+ */
9
+ export declare function loadTiledMap(source: string, context: AssetLoaderContext): Promise<TiledMap>;
@@ -0,0 +1,68 @@
1
+ import { Texture } from '@codexo/exojs';
2
+ import { TiledMap } from './TiledMap.js';
3
+ import { TiledTileset } from './TiledTileset.js';
4
+ import { resolveTiledUrl } from './url.js';
5
+ import { validateTiledMapData, validateTiledTilesetFileData } from './validate.js';
6
+
7
+ /**
8
+ * Resolves and loads the image(s) referenced by a tileset: the atlas
9
+ * `image` (if present) and any collection-of-images per-tile `image`
10
+ * entries, relative to `baseUrl` (the resolved location of the file the
11
+ * tileset data came from — the `.tmj` for an embedded tileset, the `.tsj`
12
+ * for an external one).
13
+ *
14
+ * Textures are loaded via `context.loader`, which deduplicates concurrent
15
+ * and repeated loads of the same normalized URL.
16
+ */
17
+ async function loadTiledTilesetResources(data, baseUrl, context, source) {
18
+ let imageUrl;
19
+ let texture;
20
+ if (data.image !== undefined) {
21
+ imageUrl = resolveTiledUrl(data.image, baseUrl);
22
+ texture = await context.loader.load(Texture, imageUrl);
23
+ }
24
+ let tileTextures;
25
+ if (data.tiles !== undefined) {
26
+ for (const tile of data.tiles) {
27
+ if (tile.image === undefined) {
28
+ continue;
29
+ }
30
+ const tileImageUrl = resolveTiledUrl(tile.image, baseUrl);
31
+ const tileTexture = await context.loader.load(Texture, tileImageUrl);
32
+ tileTextures ??= new Map();
33
+ tileTextures.set(tile.id, tileTexture);
34
+ }
35
+ }
36
+ return { source, imageUrl, texture, tileTextures };
37
+ }
38
+ /**
39
+ * Resolves one `tilesets[]` entry of a `.tmj` file to a {@link TiledTileset}:
40
+ * fetches and validates the external `.tsj` if `ref.source` is set, or uses
41
+ * the embedded tileset data directly, then resolves and loads its image(s).
42
+ */
43
+ async function loadTiledTileset(ref, mapSource, context) {
44
+ if ('source' in ref) {
45
+ const tsjUrl = resolveTiledUrl(ref.source, mapSource);
46
+ const raw = await context.fetchJson(tsjUrl);
47
+ const data = validateTiledTilesetFileData(raw, tsjUrl);
48
+ const resources = await loadTiledTilesetResources(data, tsjUrl, context, tsjUrl);
49
+ return new TiledTileset(data, ref.firstgid, resources);
50
+ }
51
+ const resources = await loadTiledTilesetResources(ref, mapSource, context);
52
+ return new TiledTileset(ref, ref.firstgid, resources);
53
+ }
54
+ /**
55
+ * Loads and resolves a Tiled map: fetches and validates the `.tmj`, resolves
56
+ * each tileset (external `.tsj` or embedded) and its image(s), and returns
57
+ * the assembled, GID-validated {@link TiledMap}.
58
+ * @internal
59
+ */
60
+ async function loadTiledMap(source, context) {
61
+ const raw = await context.fetchJson(source);
62
+ const data = validateTiledMapData(raw, source);
63
+ const tilesets = await Promise.all(data.tilesets.map(ref => loadTiledTileset(ref, source, context)));
64
+ return new TiledMap(source, data, tilesets);
65
+ }
66
+
67
+ export { loadTiledMap };
68
+ //# sourceMappingURL=loadTiledMap.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loadTiledMap.js","sources":["../../../src/loadTiledMap.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;AAQA;;;;;;;;;AASG;AACH,eAAe,yBAAyB,CAAC,IAAsB,EAAE,OAAe,EAAE,OAA2B,EAAE,MAAe,EAAA;AAC5H,IAAA,IAAI,QAA4B;AAChC,IAAA,IAAI,OAA4B;AAEhC,IAAA,IAAI,IAAI,CAAC,KAAK,KAA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C,QAAQ,EAAE,SAAS,CAAC;IACxD;IAEA,MAAM,SAAS,GAAG,MAAM,yBAAyB,CAAC,GAAG,EAAE,SAAS,EAAE,OAAO,CAAC;IAE1E,OAAO,IAAI,YAAY,CAAC,GAAG,EAAE,GAAG,CAAC,QAAQ,EAAE,SAAS,CAAC;AACvD;AAEA;;;;;AAKG;AACI,eAAe,YAAY,CAAC,MAAc,EAAE,OAA2B,EAAA;IAC5E,MAAM,GAAG,GAAG,MAAM,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC;IAC3C,MAAM,IAAI,GAAG,oBAAoB,CAAC,GAAG,EAAE,MAAM,CAAC;IAC9C,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,IAAI,gBAAgB,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IAEpG,OAAO,IAAI,QAAQ,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ,CAAC;AAC7C;;;;"}
@@ -1,6 +1,45 @@
1
- export type { Extension, AssetBinding, AssetHandler, AssetLoadRequest } from '@codexo/exojs/extensions';
2
- export { tiledExtension } from './tiledExtension';
1
+ export { type TiledLoadOptions } from './tiledOptions';
2
+ export type { AssetBinding, AssetHandler, AssetLoadRequest, Extension } from '@codexo/exojs/extensions';
3
3
  export type { TiledBuildInfo } from './tiledBuildInfo';
4
4
  export { tiledBuildInfo } from './tiledBuildInfo';
5
+ export { tiledExtension } from './tiledExtension';
6
+ export { tiledMapBinding } from './tiledMapBinding';
7
+ export { tiledRuntimeMapBinding } from './tiledRuntimeMapBinding';
8
+ export type { ChunkCoord, PackedTile, ReadonlyTileChunk, ResolvedTile, TileDefinition, TileLayerNodeOptions, TileLayerOptions, TileLayerSelector, TileMapBandDefinition, TileMapNodeOptions, TileMapOptions, TileMapViewOptions, TileProperties, TilePropertyValue, TileSetOptions, TileTransform, } from '@codexo/exojs-tilemap';
9
+ export { TILE_TRANSFORM_IDENTITY, TileLayer, TileLayerNode, TileMap, TileMapBand, tilemapExtension, TileMapNode, TileMapView, TileSet, } from '@codexo/exojs-tilemap';
10
+ export type { TiledAnimationFrameData, TiledChunkData, TiledClassPropertyValueData, TiledEmbeddedTilesetRefData, TiledExternalTilesetRefData, TiledGroupLayerData, TiledImageLayerData, TiledLayerData, TiledLayerDataBase, TiledMapData, TiledObjectData, TiledObjectLayerData, TiledOrientation, TiledPointData, TiledPropertyData, TiledPropertyType, TiledRenderOrder, TiledTextData, TiledTileData, TiledTileLayerData, TiledTilesetData, TiledTilesetRefData, } from './data';
11
+ export type { TiledLayerType } from './TiledLayer';
12
+ export { createTiledLayer, TiledGroupLayer, TiledImageLayer, TiledLayer, TiledObjectLayer, TiledTileLayer, } from './TiledLayer';
5
13
  export { TiledMap } from './TiledMap';
6
- export type { TiledLayer, TiledMapData, TiledObject, TiledProperty, TiledTileset } from './TiledMap';
14
+ export { TiledObject } from './TiledObject';
15
+ export type { TiledTilesetResources } from './TiledTileset';
16
+ export { TiledTileset } from './TiledTileset';
17
+ export { TiledFormatError } from './validate';
18
+ import type { TileMap } from '@codexo/exojs-tilemap';
19
+ import type { TiledMap } from './TiledMap';
20
+ declare module '@codexo/exojs' {
21
+ interface ExtensionTypeMap {
22
+ /** `.tmj` path-only loads resolve to the generic runtime {@link TileMap}. */
23
+ tmj: TileMap;
24
+ }
25
+ interface ExtensionTokenTypeMap {
26
+ /** The advanced parsed-source token is also accepted for `.tmj`: `load(TiledMap, 'world.tmj')`. */
27
+ tmj: TiledMap;
28
+ }
29
+ interface AssetDefinitions {
30
+ tileMap: {
31
+ resource: TileMap;
32
+ config: {
33
+ source: string;
34
+ format?: 'tiled';
35
+ };
36
+ };
37
+ tiledMap: {
38
+ resource: TiledMap;
39
+ config: {
40
+ source: string;
41
+ format?: 'tiled';
42
+ };
43
+ };
44
+ }
45
+ }
@@ -1,7 +1,14 @@
1
1
  import { ExtensionRegistry } from '@codexo/exojs/extensions';
2
2
  import { tiledExtension } from './tiledExtension.js';
3
3
  export { tiledBuildInfo } from './tiledBuildInfo.js';
4
+ export { tiledMapBinding } from './tiledMapBinding.js';
5
+ export { tiledRuntimeMapBinding } from './tiledRuntimeMapBinding.js';
6
+ export { TILE_TRANSFORM_IDENTITY, TileLayer, TileLayerNode, TileMap, TileMapBand, TileMapNode, TileMapView, TileSet, tilemapExtension } from '@codexo/exojs-tilemap';
7
+ export { TiledGroupLayer, TiledImageLayer, TiledLayer, TiledObjectLayer, TiledTileLayer, createTiledLayer } from './TiledLayer.js';
4
8
  export { TiledMap } from './TiledMap.js';
9
+ export { TiledObject } from './TiledObject.js';
10
+ export { TiledTileset } from './TiledTileset.js';
11
+ export { TiledFormatError } from './validate.js';
5
12
 
6
13
  // @codexo/exojs-tiled/register — explicit registration entry.
7
14
  // Importing this entry registers the default tiledExtension descriptor
@@ -1 +1 @@
1
- {"version":3,"file":"register.js","sources":["../../../src/register.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;AAAA;AACA;AACA;AACA;AACA;AAMA,iBAAiB,CAAC,QAAQ,CAAC,cAAc,CAAC;;;;"}
1
+ {"version":3,"file":"register.js","sources":["../../../src/register.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AAMA,iBAAiB,CAAC,QAAQ,CAAC,cAAc,CAAC;;;;"}
@@ -1,6 +1,6 @@
1
1
  const tiledBuildInfo = Object.freeze({
2
- version: "0.12.0",
3
- revision: "599bc56",
2
+ version: "0.13.0",
3
+ revision: "83ebf7f",
4
4
  development: false,
5
5
  });
6
6
 
@@ -1,6 +1,16 @@
1
1
  import type { Extension } from '@codexo/exojs/extensions';
2
2
  /**
3
3
  * Default immutable Tiled extension descriptor.
4
+ *
5
+ * Registers two asset bindings:
6
+ * - {@link tiledRuntimeMapBinding} — `loader.load(TileMap, 'world.tmj')` →
7
+ * returns a format-independent runtime {@link TileMap} (common case).
8
+ * - {@link tiledMapBinding} — `loader.load(TiledMap, 'world.tmj')` →
9
+ * returns the raw parsed {@link TiledMap} source model (advanced/diagnostic).
10
+ *
11
+ * Depends on {@link tilemapExtension} so that snapshot construction always
12
+ * materialises the generic tilemap runtime before the Tiled adapter.
13
+ *
4
14
  * Use with `ApplicationOptions.extensions` or call
5
15
  * `import '@codexo/exojs-tiled/register'` for global auto-registration.
6
16
  */
@@ -1,59 +1,30 @@
1
- import { Texture } from '@codexo/exojs';
2
- import { TiledMap } from './TiledMap.js';
1
+ import { tilemapExtension } from '@codexo/exojs-tilemap';
2
+ import { tiledMapBinding } from './tiledMapBinding.js';
3
+ import { tiledRuntimeMapBinding } from './tiledRuntimeMapBinding.js';
3
4
 
4
- /**
5
- * Resolve a tileset image reference relative to the map's source path.
6
- * `new URL(ref, source)` only works when `source` is an absolute URL; the
7
- * loader is frequently called with relative paths, so fall back to a synthetic
8
- * base and strip it.
9
- */
10
- function resolveRelative(ref, source) {
11
- try {
12
- return new URL(ref, source).href;
13
- }
14
- catch {
15
- const base = 'https://exojs.invalid/';
16
- return new URL(ref, base + source.replace(/^\/+/, '')).href.slice(base.length);
17
- }
18
- }
19
- const tiledBinding = {
20
- type: TiledMap,
21
- typeNames: ['tiledMap'],
22
- extensions: ['tmj'],
23
- create(loader) {
24
- return {
25
- async load({ source }, context) {
26
- const data = await context.fetchJson(source);
27
- if (!data || typeof data !== 'object' || !Array.isArray(data.tilesets)) {
28
- throw new Error(`TiledMap: invalid or unsupported map file at "${source}".`);
29
- }
30
- if (data.infinite === true) {
31
- throw new Error(`TiledMap: infinite maps are not supported (at "${source}").`);
32
- }
33
- if (data.orientation !== undefined && data.orientation !== 'orthogonal') {
34
- throw new Error(`TiledMap: only orthogonal orientation is supported (got "${data.orientation}" at "${source}").`);
35
- }
36
- // Load tileset textures. Sub-assets are owned by the Loader cache —
37
- // TiledMap must NOT destroy them.
38
- const tilesetTextures = (await Promise.all(data.tilesets
39
- .filter(ts => ts.image !== undefined)
40
- .map(ts => loader.load(Texture, resolveRelative(ts.image, source)))));
41
- return new TiledMap(data, tilesetTextures);
42
- },
43
- destroy() {
44
- // This handler holds no loader-local resources.
45
- },
46
- };
47
- },
48
- };
49
5
  /**
50
6
  * Default immutable Tiled extension descriptor.
7
+ *
8
+ * Registers two asset bindings:
9
+ * - {@link tiledRuntimeMapBinding} — `loader.load(TileMap, 'world.tmj')` →
10
+ * returns a format-independent runtime {@link TileMap} (common case).
11
+ * - {@link tiledMapBinding} — `loader.load(TiledMap, 'world.tmj')` →
12
+ * returns the raw parsed {@link TiledMap} source model (advanced/diagnostic).
13
+ *
14
+ * Depends on {@link tilemapExtension} so that snapshot construction always
15
+ * materialises the generic tilemap runtime before the Tiled adapter.
16
+ *
51
17
  * Use with `ApplicationOptions.extensions` or call
52
18
  * `import '@codexo/exojs-tiled/register'` for global auto-registration.
53
19
  */
54
20
  const tiledExtension = Object.freeze({
55
21
  id: '@codexo/exojs-tiled',
56
- assets: [tiledBinding],
22
+ dependencies: [tilemapExtension],
23
+ // Localized erasure cast: typed bindings (Options=TiledLoadOptions) meet the
24
+ // untyped Extension.assets contract here. Runtime behavior is unaffected —
25
+ // materializeAssetBindings calls create() and bindAsset() correctly regardless
26
+ // of the erased Options type.
27
+ assets: [tiledRuntimeMapBinding, tiledMapBinding],
57
28
  });
58
29
 
59
30
  export { tiledExtension };
@@ -1 +1 @@
1
- {"version":3,"file":"tiledExtension.js","sources":["../../../src/tiledExtension.ts"],"sourcesContent":[null],"names":[],"mappings":";;;AAMA;;;;;AAKG;AACH,SAAS,eAAe,CAAC,GAAW,EAAE,MAAc,EAAA;AAClD,IAAA,IAAI;QACF,OAAO,IAAI,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,IAAI;IAClC;AAAE,IAAA,MAAM;QACN,MAAM,IAAI,GAAG,wBAAwB;QACrC,OAAO,IAAI,GAAG,CAAC,GAAG,EAAE,IAAI,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CA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AA,OAAO,IAAI,QAAQ,CAAC,IAAI,EAAE,eAAe,CAAC;YAC5C,CAAC;YACD,OAAO,GAAA;;YAEP,CAAC;SACF;IACH,CAAC;CACF;AAED;;;;AAIG;AACI,MAAM,cAAc,GAAc,MAAM,CAAC,MAAM,CAAC;AACrD,IAAA,EAAE,EAAE,qBAAqB;IACzB,MAAM,EAAE,CAAC,YAAY,CAAC;AACvB,CAAA;;;;"}
1
+ {"version":3,"file":"tiledExtension.js","sources":["../../../src/tiledExtension.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAMA;;;;;;;;;;;;;;AAcG;AACI,MAAM,cAAc,GAAc,MAAM,CAAC,MAAM,CAAC;AACrD,IAAA,EAAE,EAAE,qBAAqB;IACzB,YAAY,EAAE,CAAC,gBAAgB,CAAC;;;;;AAKhC,IAAA,MAAM,EAAE,CAAC,sBAAsB,EAAE,eAAe,CAA8B;AAC/E,CAAA;;;;"}
@@ -0,0 +1,19 @@
1
+ import { TiledMap } from './TiledMap';
2
+ import { type TiledLoadOptions } from './tiledOptions';
3
+ /**
4
+ * Declarative asset binding for {@link TiledMap}.
5
+ *
6
+ * Token-only: `loader.load(TiledMap, 'world.tmj')` resolves through this
7
+ * binding, but no `extensions` are claimed, so a plain
8
+ * `loader.load('world.tmj')` does not resolve to `TiledMap`. The `.tmj`
9
+ * extension (and generic `.json` Tiled loading) is reserved for the
10
+ * format-independent `TileMap` runtime asset binding.
11
+ */
12
+ export declare const tiledMapBinding: {
13
+ type: typeof TiledMap;
14
+ typeNames: string[];
15
+ create(): {
16
+ getIdentityKey(req: import("@codexo/exojs").AssetLoadRequest<TiledLoadOptions>): string;
17
+ load(req: import("@codexo/exojs").AssetLoadRequest<TiledLoadOptions>, ctx: import("@codexo/exojs").AssetLoaderContext): Promise<TiledMap>;
18
+ };
19
+ };
@@ -0,0 +1,31 @@
1
+ import { loadTiledMap } from './loadTiledMap.js';
2
+ import { TiledMap } from './TiledMap.js';
3
+ import { resolveTiledOptions } from './tiledOptions.js';
4
+
5
+ /**
6
+ * Declarative asset binding for {@link TiledMap}.
7
+ *
8
+ * Token-only: `loader.load(TiledMap, 'world.tmj')` resolves through this
9
+ * binding, but no `extensions` are claimed, so a plain
10
+ * `loader.load('world.tmj')` does not resolve to `TiledMap`. The `.tmj`
11
+ * extension (and generic `.json` Tiled loading) is reserved for the
12
+ * format-independent `TileMap` runtime asset binding.
13
+ */
14
+ const tiledMapBinding = {
15
+ type: TiledMap,
16
+ typeNames: ['tiledMap'],
17
+ create() {
18
+ return {
19
+ getIdentityKey(req) {
20
+ const o = resolveTiledOptions(req.options);
21
+ return `${req.source}|${o.format}`;
22
+ },
23
+ async load(req, ctx) {
24
+ return loadTiledMap(req.source, ctx);
25
+ },
26
+ };
27
+ },
28
+ };
29
+
30
+ export { tiledMapBinding };
31
+ //# sourceMappingURL=tiledMapBinding.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tiledMapBinding.js","sources":["../../../src/tiledMapBinding.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAMA;;;;;;;;AAQG;AACI,MAAM,eAAe,GAAG;AAC7B,IAAA,IAAI,EAAE,QAAQ;IACd,SAAS,EAAE,CAAC,UAAU,CAAC;IACvB,MAAM,GAAA;QACJ,OAAO;AACL,YAAA,cAAc,CAAC,GAAG,EAAA;gBAChB,MAAM,CAAC,GAAG,mBAAmB,CAAC,GAAG,CAAC,OAAO,CAAC;gBAC1C,OAAO,CAAA,EAAG,GAAG,CAAC,MAAM,IAAI,CAAC,CAAC,MAAM,CAAA,CAAE;YACpC,CAAC;AACD,YAAA,MAAM,IAAI,CAAC,GAAG,EAAE,GAAG,EAAA;gBACjB,OAAO,YAAY,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC;YACtC,CAAC;SACiD;IACtD,CAAC;;;;;"}
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Options accepted by both the runtime (`TileMap`) and source (`TiledMap`)
3
+ * asset bindings when loading a Tiled map.
4
+ * @advanced
5
+ */
6
+ export interface TiledLoadOptions {
7
+ /**
8
+ * Explicit format hint for ambiguous file extensions.
9
+ *
10
+ * `.tmj`/`.tsj` paths are recognised by extension and need no hint. Provide
11
+ * `format: 'tiled'` when loading Tiled map data from a generic `.json` path:
12
+ * `loader.load(TileMap, 'world.json', { format: 'tiled' })`. `'tiled'` is the
13
+ * only accepted value, so a foreign format (e.g. `'ldtk'`) is a compile error
14
+ * rather than a silent runtime fall-through.
15
+ *
16
+ * The hint participates in the asset identity key, so the same source loaded
17
+ * under different (future) formats resolves to distinct cache entries.
18
+ */
19
+ readonly format?: 'tiled';
20
+ }
21
+ /**
22
+ * Applies defaults and returns a normalized options object.
23
+ *
24
+ * Tiled parsing is unconditionally strict: {@link validateTiledMapData} throws
25
+ * a `TiledFormatError` on any malformed *known* field and silently preserves
26
+ * unknown fields. There is intentionally no `strict` toggle — a permissive
27
+ * parse mode is a potential v0.14 follow-up, not part of v0.13.
28
+ */
29
+ export declare function resolveTiledOptions(options: TiledLoadOptions | undefined): {
30
+ format: 'tiled';
31
+ };