@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.
- package/README.md +7 -163
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +12 -20
- package/dist/esm/ChunkSource.d.ts +0 -33
- package/dist/esm/ChunkSource.d.ts.map +0 -1
- package/dist/esm/ChunkStreamer.d.ts +0 -104
- package/dist/esm/ChunkStreamer.d.ts.map +0 -1
- package/dist/esm/ChunkStreamer.js +0 -229
- package/dist/esm/ChunkStreamer.js.map +0 -1
- package/dist/esm/ImageLayer.d.ts +0 -89
- package/dist/esm/ImageLayer.d.ts.map +0 -1
- package/dist/esm/ImageLayer.js +0 -74
- package/dist/esm/ImageLayer.js.map +0 -1
- package/dist/esm/ImageLayerNode.d.ts +0 -91
- package/dist/esm/ImageLayerNode.d.ts.map +0 -1
- package/dist/esm/ImageLayerNode.js +0 -210
- package/dist/esm/ImageLayerNode.js.map +0 -1
- package/dist/esm/MapObject.d.ts +0 -70
- package/dist/esm/MapObject.d.ts.map +0 -1
- package/dist/esm/MapObject.js +0 -34
- package/dist/esm/MapObject.js.map +0 -1
- package/dist/esm/MapObjectSpawner.d.ts +0 -133
- package/dist/esm/MapObjectSpawner.d.ts.map +0 -1
- package/dist/esm/MapObjectSpawner.js +0 -147
- package/dist/esm/MapObjectSpawner.js.map +0 -1
- package/dist/esm/MapSpawnSession.d.ts +0 -46
- package/dist/esm/MapSpawnSession.d.ts.map +0 -1
- package/dist/esm/MapSpawnSession.js +0 -88
- package/dist/esm/MapSpawnSession.js.map +0 -1
- package/dist/esm/MapWorld.d.ts +0 -134
- package/dist/esm/MapWorld.d.ts.map +0 -1
- package/dist/esm/MapWorld.js +0 -150
- package/dist/esm/MapWorld.js.map +0 -1
- package/dist/esm/MapWorldRuntime.d.ts +0 -180
- package/dist/esm/MapWorldRuntime.d.ts.map +0 -1
- package/dist/esm/MapWorldRuntime.js +0 -261
- package/dist/esm/MapWorldRuntime.js.map +0 -1
- package/dist/esm/ObjectLayer.d.ts +0 -379
- package/dist/esm/ObjectLayer.d.ts.map +0 -1
- package/dist/esm/ObjectLayer.js +0 -221
- package/dist/esm/ObjectLayer.js.map +0 -1
- package/dist/esm/SampledChunkSource.d.ts +0 -43
- package/dist/esm/SampledChunkSource.d.ts.map +0 -1
- package/dist/esm/SampledChunkSource.js +0 -48
- package/dist/esm/SampledChunkSource.js.map +0 -1
- package/dist/esm/TileAnimator.d.ts +0 -72
- package/dist/esm/TileAnimator.d.ts.map +0 -1
- package/dist/esm/TileAnimator.js +0 -158
- package/dist/esm/TileAnimator.js.map +0 -1
- package/dist/esm/TileChunk.d.ts +0 -103
- package/dist/esm/TileChunk.d.ts.map +0 -1
- package/dist/esm/TileChunk.js +0 -194
- package/dist/esm/TileChunk.js.map +0 -1
- package/dist/esm/TileChunkNode.d.ts +0 -2
- package/dist/esm/TileChunkNode.d.ts.map +0 -1
- package/dist/esm/TileChunkNode.js +0 -145
- package/dist/esm/TileChunkNode.js.map +0 -1
- package/dist/esm/TileLayer.d.ts +0 -286
- package/dist/esm/TileLayer.d.ts.map +0 -1
- package/dist/esm/TileLayer.js +0 -526
- package/dist/esm/TileLayer.js.map +0 -1
- package/dist/esm/TileLayerNode.d.ts +0 -129
- package/dist/esm/TileLayerNode.d.ts.map +0 -1
- package/dist/esm/TileLayerNode.js +0 -245
- package/dist/esm/TileLayerNode.js.map +0 -1
- package/dist/esm/TileMap.d.ts +0 -317
- package/dist/esm/TileMap.d.ts.map +0 -1
- package/dist/esm/TileMap.js +0 -406
- package/dist/esm/TileMap.js.map +0 -1
- package/dist/esm/TileMapBand.d.ts +0 -80
- package/dist/esm/TileMapBand.d.ts.map +0 -1
- package/dist/esm/TileMapBand.js +0 -155
- package/dist/esm/TileMapBand.js.map +0 -1
- package/dist/esm/TileMapNode.d.ts +0 -92
- package/dist/esm/TileMapNode.d.ts.map +0 -1
- package/dist/esm/TileMapNode.js +0 -134
- package/dist/esm/TileMapNode.js.map +0 -1
- package/dist/esm/TileMapView.d.ts +0 -248
- package/dist/esm/TileMapView.d.ts.map +0 -1
- package/dist/esm/TileMapView.js +0 -394
- package/dist/esm/TileMapView.js.map +0 -1
- package/dist/esm/TileProjection.d.ts +0 -59
- package/dist/esm/TileProjection.d.ts.map +0 -1
- package/dist/esm/TileProjection.js +0 -106
- package/dist/esm/TileProjection.js.map +0 -1
- package/dist/esm/TileSet.d.ts +0 -116
- package/dist/esm/TileSet.d.ts.map +0 -1
- package/dist/esm/TileSet.js +0 -168
- package/dist/esm/TileSet.js.map +0 -1
- package/dist/esm/WangSet.d.ts +0 -80
- package/dist/esm/WangSet.d.ts.map +0 -1
- package/dist/esm/WangSet.js +0 -73
- package/dist/esm/WangSet.js.map +0 -1
- package/dist/esm/WorkerSampledChunkSource.d.ts +0 -94
- package/dist/esm/WorkerSampledChunkSource.d.ts.map +0 -1
- package/dist/esm/WorkerSampledChunkSource.js +0 -113
- package/dist/esm/WorkerSampledChunkSource.js.map +0 -1
- package/dist/esm/autoTile.d.ts +0 -88
- package/dist/esm/autoTile.d.ts.map +0 -1
- package/dist/esm/autoTile.js +0 -173
- package/dist/esm/autoTile.js.map +0 -1
- package/dist/esm/chunkGeometry.d.ts +0 -2
- package/dist/esm/chunkGeometry.d.ts.map +0 -1
- package/dist/esm/chunkGeometry.js +0 -116
- package/dist/esm/chunkGeometry.js.map +0 -1
- package/dist/esm/index.d.ts +0 -2
- package/dist/esm/index.d.ts.map +0 -1
- package/dist/esm/index.js +0 -27
- package/dist/esm/nodeBounds.d.ts +0 -2
- package/dist/esm/nodeBounds.d.ts.map +0 -1
- package/dist/esm/nodeBounds.js +0 -40
- package/dist/esm/nodeBounds.js.map +0 -1
- package/dist/esm/pixelSnap.d.ts +0 -2
- package/dist/esm/pixelSnap.d.ts.map +0 -1
- package/dist/esm/pixelSnap.js +0 -21
- package/dist/esm/pixelSnap.js.map +0 -1
- package/dist/esm/projectObject.d.ts +0 -4
- package/dist/esm/projectObject.d.ts.map +0 -1
- package/dist/esm/projectObject.js +0 -87
- package/dist/esm/projectObject.js.map +0 -1
- package/dist/esm/public.d.ts +0 -48
- package/dist/esm/public.d.ts.map +0 -1
- package/dist/esm/tileCollision.d.ts +0 -190
- package/dist/esm/tileCollision.d.ts.map +0 -1
- package/dist/esm/tileCollision.js +0 -399
- package/dist/esm/tileCollision.js.map +0 -1
- package/dist/esm/tileWord.d.ts +0 -2
- package/dist/esm/tileWord.d.ts.map +0 -1
- package/dist/esm/tileWord.js +0 -16
- package/dist/esm/tileWord.js.map +0 -1
- package/dist/esm/tilemapExtension.d.ts +0 -20
- package/dist/esm/tilemapExtension.d.ts.map +0 -1
- package/dist/esm/tilemapExtension.js +0 -53
- package/dist/esm/tilemapExtension.js.map +0 -1
- package/dist/esm/tilemapSerializers.d.ts +0 -2
- package/dist/esm/tilemapSerializers.d.ts.map +0 -1
- package/dist/esm/tilemapSerializers.js +0 -54
- package/dist/esm/tilemapSerializers.js.map +0 -1
- package/dist/esm/types.d.ts +0 -231
- package/dist/esm/types.d.ts.map +0 -1
- package/dist/esm/types.js +0 -129
- package/dist/esm/types.js.map +0 -1
- package/dist/esm/webgl2/WebGl2TileChunkRenderer.d.ts +0 -2
- package/dist/esm/webgl2/WebGl2TileChunkRenderer.d.ts.map +0 -1
- package/dist/esm/webgl2/WebGl2TileChunkRenderer.js +0 -376
- package/dist/esm/webgl2/WebGl2TileChunkRenderer.js.map +0 -1
- package/dist/esm/webgl2/shaders/tile-chunk.frag.js +0 -6
- package/dist/esm/webgl2/shaders/tile-chunk.frag.js.map +0 -1
- package/dist/esm/webgl2/shaders/tile-chunk.vert.js +0 -6
- package/dist/esm/webgl2/shaders/tile-chunk.vert.js.map +0 -1
- package/dist/esm/webgpu/WebGpuTileChunkRenderer.d.ts +0 -2
- package/dist/esm/webgpu/WebGpuTileChunkRenderer.d.ts.map +0 -1
- package/dist/esm/webgpu/WebGpuTileChunkRenderer.js +0 -539
- package/dist/esm/webgpu/WebGpuTileChunkRenderer.js.map +0 -1
- package/dist/esm/webgpu/shaders/tile-chunk.wgsl.js +0 -6
- package/dist/esm/webgpu/shaders/tile-chunk.wgsl.js.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tilemapSerializers.js","names":[],"sources":["../../src/tilemapSerializers.ts"],"sourcesContent":["import type { NodeSerializer } from '@codexo/exojs';\nimport { PixelSnapMode } from '@codexo/exojs/renderer-sdk';\n\nimport { TileMap } from './TileMap';\nimport { TileMapNode } from './TileMapNode';\n\n// On-disk format: the mode is persisted as its NAME (readable JSON, robust\n// against enum renumbering), mapped to/from the numeric enum here.\nconst pixelSnapModeNames: Record<PixelSnapMode, string> = {\n [PixelSnapMode.None]: 'none',\n [PixelSnapMode.Position]: 'position',\n [PixelSnapMode.Geometry]: 'geometry',\n};\n\nconst pixelSnapModeFromName: Record<string, PixelSnapMode> = {\n none: PixelSnapMode.None,\n position: PixelSnapMode.Position,\n geometry: PixelSnapMode.Geometry,\n};\n\n/**\n * Scene serializer for {@link TileMapNode} - the convenience node that renders a\n * whole {@link TileMap}.\n *\n * Captures the **map reference** (its Loader source key) plus the render-only\n * `pixelSnapMode`; the per-layer / per-chunk nodes are derived from the map and\n * rebuilt on construction, so they are never written. The referenced `TileMap`\n * must be pre-loaded into the target Loader (e.g. `loader.load(Asset.type('tileMap', 'world.tmj'))`)\n * before deserialize - procedurally-built maps have no source key and cannot be\n * referenced.\n *\n * Standalone `TileLayerNode` / `TileMapBand` placement (the actor-interleaving\n * cases) is not yet covered.\n *\n * @internal - registered via {@link tilemapExtension}'s `serializers` binding.\n */\nexport const tileMapNodeSerializer: NodeSerializer<TileMapNode> = {\n write(node, ctx) {\n const out: Record<string, unknown> = {};\n const source = ctx.keyFor(node.map);\n\n if (source !== null) {\n out.map = source;\n }\n\n if (node.pixelSnapMode !== PixelSnapMode.None) {\n out.pixelSnapMode = pixelSnapModeNames[node.pixelSnapMode];\n }\n\n return out;\n },\n read(data, ctx) {\n const map = ctx.resolveAsset(data.map, TileMap);\n\n if (map === null) {\n throw new Error('TileMapNode deserialize requires its TileMap to be pre-loaded into the Loader (procedural maps have no source key).');\n }\n\n const node = new TileMapNode(map);\n\n if (typeof data.pixelSnapMode === 'string') {\n const mode = pixelSnapModeFromName[data.pixelSnapMode];\n\n if (mode !== undefined) {\n node.pixelSnapMode = mode;\n }\n }\n\n return node;\n },\n};\n"],"mappings":";;;;;AAQA,MAAM,qBAAoD;EACvD,cAAc,OAAO;EACrB,cAAc,WAAW;EACzB,cAAc,WAAW;AAC5B;AAEA,MAAM,wBAAuD;CAC3D,MAAM,cAAc;CACpB,UAAU,cAAc;CACxB,UAAU,cAAc;AAC1B;;;;;;;;;;;;;;;;;AAkBA,MAAa,wBAAqD;CAChE,MAAM,MAAM,KAAK;EACf,MAAM,MAA+B,CAAC;EACtC,MAAM,SAAS,IAAI,OAAO,KAAK,GAAG;EAElC,IAAI,WAAW,MACb,IAAI,MAAM;EAGZ,IAAI,KAAK,kBAAkB,cAAc,MACvC,IAAI,gBAAgB,mBAAmB,KAAK;EAG9C,OAAO;CACT;CACA,KAAK,MAAM,KAAK;EACd,MAAM,MAAM,IAAI,aAAa,KAAK,KAAK,OAAO;EAE9C,IAAI,QAAQ,MACV,MAAM,IAAI,MAAM,qHAAqH;EAGvI,MAAM,OAAO,IAAI,YAAY,GAAG;EAEhC,IAAI,OAAO,KAAK,kBAAkB,UAAU;GAC1C,MAAM,OAAO,sBAAsB,KAAK;GAExC,IAAI,SAAS,QACX,KAAK,gBAAgB;EAEzB;EAEA,OAAO;CACT;AACF"}
|
package/dist/esm/types.d.ts
DELETED
|
@@ -1,231 +0,0 @@
|
|
|
1
|
-
import type { TileMapObject } from './ObjectLayer';
|
|
2
|
-
import type { TileSet } from './TileSet';
|
|
3
|
-
/**
|
|
4
|
-
* Discriminant for the three structured, non-scalar {@link TilePropertyValue}
|
|
5
|
-
* variants: {@link TilePropertyPoint}, {@link TilePropertyObjectRef}, and
|
|
6
|
-
* {@link TilePropertyTileRef}.
|
|
7
|
-
*
|
|
8
|
-
* Modelled as a frozen string map (not a TS `enum`) so the values stay
|
|
9
|
-
* wire-stable, survive `verbatimModuleSyntax` (no emitted runtime helper),
|
|
10
|
-
* and follow the package convention for enum-like constants (see
|
|
11
|
-
* {@link import('./ObjectLayer').ObjectKind}).
|
|
12
|
-
* @stable
|
|
13
|
-
*/
|
|
14
|
-
export declare const TilePropertyKind: {
|
|
15
|
-
readonly Point: 'point';
|
|
16
|
-
readonly ObjectRef: 'objectRef';
|
|
17
|
-
readonly TileRef: 'tileRef';
|
|
18
|
-
};
|
|
19
|
-
/** Structured-value discriminant for {@link TilePropertyValue}. */
|
|
20
|
-
export type TilePropertyKind = (typeof TilePropertyKind)[keyof typeof TilePropertyKind];
|
|
21
|
-
/** A 2D point-valued tile property (e.g. an LDtk `Point` field). */
|
|
22
|
-
export interface TilePropertyPoint {
|
|
23
|
-
readonly kind: typeof TilePropertyKind.Point;
|
|
24
|
-
readonly cx: number;
|
|
25
|
-
readonly cy: number;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* A reference to another object/entity. `id` is the referenced object's
|
|
29
|
-
* identity - Tiled's numeric object id, or LDtk's `entityIid`. The extra
|
|
30
|
-
* fields are LDtk-only navigation context (`undefined` for Tiled-sourced
|
|
31
|
-
* refs) that lets a consumer resolve the reference without searching the
|
|
32
|
-
* whole level tree.
|
|
33
|
-
*/
|
|
34
|
-
export interface TilePropertyObjectRef {
|
|
35
|
-
readonly kind: typeof TilePropertyKind.ObjectRef;
|
|
36
|
-
readonly id: string | number;
|
|
37
|
-
readonly layerIid?: string;
|
|
38
|
-
readonly levelIid?: string;
|
|
39
|
-
readonly worldIid?: string;
|
|
40
|
-
}
|
|
41
|
-
/** A reference into a tileset region (e.g. an LDtk `Tile`-typed field). */
|
|
42
|
-
export interface TilePropertyTileRef {
|
|
43
|
-
readonly kind: typeof TilePropertyKind.TileRef;
|
|
44
|
-
readonly tilesetUid: number;
|
|
45
|
-
readonly x: number;
|
|
46
|
-
readonly y: number;
|
|
47
|
-
readonly w: number;
|
|
48
|
-
readonly h: number;
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Union of legal tile-property value types in the generic runtime.
|
|
52
|
-
* Format-neutral; adapters map their native property systems into this set -
|
|
53
|
-
* including the structured {@link TilePropertyPoint}, {@link TilePropertyObjectRef},
|
|
54
|
-
* and {@link TilePropertyTileRef} variants, arrays of any of the above, and
|
|
55
|
-
* nested property bags (e.g. Tiled `class`-typed properties).
|
|
56
|
-
* @advanced
|
|
57
|
-
*/
|
|
58
|
-
export type TilePropertyValue = null | boolean | number | string | TilePropertyPoint | TilePropertyObjectRef | TilePropertyTileRef | readonly TilePropertyValue[] | TileProperties;
|
|
59
|
-
/**
|
|
60
|
-
* An immutable, flat key-value bag of generic tile properties.
|
|
61
|
-
* Adapters copy and freeze source properties; the runtime never retains
|
|
62
|
-
* a caller-owned mutable object.
|
|
63
|
-
*
|
|
64
|
-
* Declared as an interface (not a `Record<...>` type alias) so it can
|
|
65
|
-
* mutually recurse with {@link TilePropertyValue} - a nested-bag member of
|
|
66
|
-
* that union - without TypeScript's "circularly references itself" alias
|
|
67
|
-
* restriction; structurally it behaves exactly like
|
|
68
|
-
* `Readonly<Record<string, TilePropertyValue>>`.
|
|
69
|
-
* @advanced
|
|
70
|
-
*/
|
|
71
|
-
export interface TileProperties {
|
|
72
|
-
readonly [key: string]: TilePropertyValue;
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Describes the orientation of a placed tile independent of source-format
|
|
76
|
-
* flip-bit encodings. The eight legal combinations map to the eight distinct
|
|
77
|
-
* 90°-rotation-and-flip states of a rectangular texture quad.
|
|
78
|
-
*
|
|
79
|
-
* Applying the transform at geometry-build time (reordering UV corners)
|
|
80
|
-
* avoids per-tile runtime cost and per-frame matrix allocation.
|
|
81
|
-
* @stable
|
|
82
|
-
*/
|
|
83
|
-
export interface TileTransform {
|
|
84
|
-
/** Horizontal flip (mirror left-right). */
|
|
85
|
-
readonly flipX: boolean;
|
|
86
|
-
/** Vertical flip (mirror top-bottom). */
|
|
87
|
-
readonly flipY: boolean;
|
|
88
|
-
/** Anti-diagonal flip (transpose of the UV axes). Combined with flips produces 90° rotations. */
|
|
89
|
-
readonly diagonal: boolean;
|
|
90
|
-
}
|
|
91
|
-
/** The identity transform: no flip, no diagonal. */
|
|
92
|
-
export declare const TILE_TRANSFORM_IDENTITY: Readonly<TileTransform>;
|
|
93
|
-
/**
|
|
94
|
-
* Opaque packed tile data stored in a {@link TileChunk}'s compact array.
|
|
95
|
-
* 0 means "empty cell". Any non-zero value encodes localTileId, tilesetIndex,
|
|
96
|
-
* and flip bits according to the bit-layout constants below.
|
|
97
|
-
*
|
|
98
|
-
* A `PackedTile` is **not** a source-format GID - it is a fully resolved
|
|
99
|
-
* internal compact representation. Use {@link packTile} / {@link unpackTile}
|
|
100
|
-
* to convert between packed form and a {@link ResolvedTile} if writing
|
|
101
|
-
* adapters.
|
|
102
|
-
*
|
|
103
|
-
* In public APIs, prefer {@link ResolvedTile} or null for queries.
|
|
104
|
-
* `PackedTile` is exposed as `@advanced` so `ReadonlyTileChunk.getRawAt()`
|
|
105
|
-
* has a self-documenting return type.
|
|
106
|
-
* @advanced
|
|
107
|
-
*/
|
|
108
|
-
export type PackedTile = number;
|
|
109
|
-
/** Bit width allocated to the local tile ID within a packed tile word. */
|
|
110
|
-
export declare const PACKED_LOCAL_BITS = 20;
|
|
111
|
-
/** Bit width allocated to the tileset index within a packed tile word. */
|
|
112
|
-
export declare const PACKED_TILESET_BITS = 9;
|
|
113
|
-
/** Bit width allocated to the transform/flip bits. */
|
|
114
|
-
export declare const PACKED_TRANSFORM_BITS = 3;
|
|
115
|
-
export declare const PACKED_LOCAL_MASK: number;
|
|
116
|
-
export declare const PACKED_TILESET_MASK: number;
|
|
117
|
-
export declare const PACKED_TRANSFORM_MASK: number;
|
|
118
|
-
export declare const PACKED_TILESET_SHIFT = 20;
|
|
119
|
-
export declare const PACKED_TRANSFORM_SHIFT: number;
|
|
120
|
-
/** Maximum tileset index representable in a packed tile. */
|
|
121
|
-
export declare const MAX_TILESET_INDEX: number;
|
|
122
|
-
/** Maximum local tile ID representable in a packed tile (1-based storage). */
|
|
123
|
-
export declare const MAX_LOCAL_TILE_ID: number;
|
|
124
|
-
/**
|
|
125
|
-
* Encode a tileset-local tile reference and transform into a packed word.
|
|
126
|
-
* The localTileId is stored as (localTileId + 1) so that a packed value of 0
|
|
127
|
-
* cleanly represents an empty cell, while tile 0 from tileset 0 with identity
|
|
128
|
-
* transform is stored as 1 (non-zero).
|
|
129
|
-
* Returns 0 for an empty cell.
|
|
130
|
-
*
|
|
131
|
-
* Public so chunk-provider authors (e.g. a format adapter or procedural
|
|
132
|
-
* generator) can build a {@link ChunkPayload}'s `tiles` array without
|
|
133
|
-
* duplicating this encoding.
|
|
134
|
-
* @advanced
|
|
135
|
-
*/
|
|
136
|
-
export declare const packTile: (tilesetIndex: number, localTileId: number, transform: TileTransform) => PackedTile;
|
|
137
|
-
/**
|
|
138
|
-
* Decode a packed word into its components.
|
|
139
|
-
* Returns null for an empty cell (packed === 0).
|
|
140
|
-
* @advanced
|
|
141
|
-
*/
|
|
142
|
-
export declare const unpackTile: (packed: PackedTile) => {
|
|
143
|
-
tilesetIndex: number;
|
|
144
|
-
localTileId: number;
|
|
145
|
-
transform: TileTransform;
|
|
146
|
-
} | null;
|
|
147
|
-
/**
|
|
148
|
-
* A fully resolved, format-independent tile reference returned by queries.
|
|
149
|
-
* Materialised on-demand from the packed storage; never stored as a per-cell
|
|
150
|
-
* heap object.
|
|
151
|
-
* @advanced
|
|
152
|
-
*/
|
|
153
|
-
export interface ResolvedTile {
|
|
154
|
-
/** The owning tileset (already resolved from source-format GID). */
|
|
155
|
-
readonly tileset: TileSet;
|
|
156
|
-
/** 0-based tile index within the tileset. */
|
|
157
|
-
readonly localTileId: number;
|
|
158
|
-
/** Orientation transform for this placed tile. */
|
|
159
|
-
readonly transform: TileTransform;
|
|
160
|
-
}
|
|
161
|
-
/**
|
|
162
|
-
* One frame of a tile animation: which local tile to show, and for how long.
|
|
163
|
-
* Mirrors Tiled's per-tile animation frame model.
|
|
164
|
-
* @advanced
|
|
165
|
-
*/
|
|
166
|
-
export interface TileAnimationFrame {
|
|
167
|
-
/** Local tile ID shown during this frame (within the tile's own tileset). */
|
|
168
|
-
readonly localTileId: number;
|
|
169
|
-
/** Frame duration in milliseconds. */
|
|
170
|
-
readonly duration: number;
|
|
171
|
-
}
|
|
172
|
-
/**
|
|
173
|
-
* Optional per-tile metadata in a {@link TileSet}. Sparse - only defined
|
|
174
|
-
* tiles carry a definition.
|
|
175
|
-
* @advanced
|
|
176
|
-
*/
|
|
177
|
-
export interface TileDefinition {
|
|
178
|
-
/** The local tile ID this definition belongs to. */
|
|
179
|
-
readonly localTileId: number;
|
|
180
|
-
/** Tile properties (copied and frozen by the tileset). */
|
|
181
|
-
readonly properties?: TileProperties;
|
|
182
|
-
/**
|
|
183
|
-
* Animation frame sequence for this tile, if animated. The frames are
|
|
184
|
-
* driven at runtime by a {@link import('./TileAnimator').TileAnimator};
|
|
185
|
-
* frame[0] is the tile's resting/base frame.
|
|
186
|
-
*/
|
|
187
|
-
readonly animation?: readonly TileAnimationFrame[];
|
|
188
|
-
/**
|
|
189
|
-
* Per-tile collision shapes sourced from the Tiled `objectgroup` on the tile.
|
|
190
|
-
* Shapes are in tile-local pixel space (origin = top-left of the tile cell).
|
|
191
|
-
* Only present when the source map defines collision geometry for this tile.
|
|
192
|
-
*/
|
|
193
|
-
readonly collision?: readonly TileMapObject[];
|
|
194
|
-
}
|
|
195
|
-
/** A signed chunk coordinate pair. */
|
|
196
|
-
export interface ChunkCoord {
|
|
197
|
-
readonly cx: number;
|
|
198
|
-
readonly cy: number;
|
|
199
|
-
}
|
|
200
|
-
/** Convert tile coordinates to chunk coordinates given a chunk size. */
|
|
201
|
-
export declare const tileToChunkCoord: (tx: number, ty: number, chunkW: number, chunkH: number) => ChunkCoord;
|
|
202
|
-
/** Convert tile coordinates to local-in-chunk coordinates. */
|
|
203
|
-
export declare const tileToLocalInChunk: (tx: number, ty: number, chunkW: number, chunkH: number) => {
|
|
204
|
-
lx: number;
|
|
205
|
-
ly: number;
|
|
206
|
-
};
|
|
207
|
-
/**
|
|
208
|
-
* Validate that a value is a finite, safe, positive integer.
|
|
209
|
-
* Used for dimensions, tile counts, chunk sizes.
|
|
210
|
-
*/
|
|
211
|
-
export declare const validatePositiveInteger: (value: number, label: string) => void;
|
|
212
|
-
/**
|
|
213
|
-
* Validate a non-negative finite integer.
|
|
214
|
-
*/
|
|
215
|
-
export declare const validateNonNegativeInteger: (value: number, label: string) => void;
|
|
216
|
-
/**
|
|
217
|
-
* Validate that a value is a finite integer (may be negative).
|
|
218
|
-
*/
|
|
219
|
-
export declare const validateInteger: (value: number, label: string) => void;
|
|
220
|
-
/**
|
|
221
|
-
* Validate a `width`/`height` pair that must be provided together (bounded)
|
|
222
|
-
* or omitted together (unbounded) - shared by {@link import('./TileLayer').TileLayer}
|
|
223
|
-
* and {@link import('./TileMap').TileMap}. When both are provided, each is
|
|
224
|
-
* validated as a positive integer via {@link validatePositiveInteger}.
|
|
225
|
-
*
|
|
226
|
-
* @param entityName Used in the paired-presence error message (e.g. `"TileLayer"`).
|
|
227
|
-
* @param fieldPrefix Used as the field-name prefix passed to {@link validatePositiveInteger} (e.g. `"layer"` for `"layer.width"`).
|
|
228
|
-
* @throws If exactly one of `width`/`height` is provided, or either is not a positive integer.
|
|
229
|
-
*/
|
|
230
|
-
export declare const validatePairedDimensions: (width: number | undefined, height: number | undefined, entityName: string, fieldPrefix: string) => void;
|
|
231
|
-
//# sourceMappingURL=types.d.ts.map
|
package/dist/esm/types.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA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CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAGlH,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,uBAAuB,UAAW,MAAM,SAAS,MAAM,KAAG,IAOtE,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,0BAA0B,UAAW,MAAM,SAAS,MAAM,KAAG,IAIzE,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,eAAe,UAAW,MAAM,SAAS,MAAM,KAAG,IAI9D,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,wBAAwB,UAAW,MAAM,GAAG,SAAS,UAAU,MAAM,GAAG,SAAS,cAAc,MAAM,eAAe,MAAM,KAAG,IAQzI,CAAC"}
|
package/dist/esm/types.js
DELETED
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
//#region src/types.ts
|
|
2
|
-
/**
|
|
3
|
-
* Discriminant for the three structured, non-scalar {@link TilePropertyValue}
|
|
4
|
-
* variants: {@link TilePropertyPoint}, {@link TilePropertyObjectRef}, and
|
|
5
|
-
* {@link TilePropertyTileRef}.
|
|
6
|
-
*
|
|
7
|
-
* Modelled as a frozen string map (not a TS `enum`) so the values stay
|
|
8
|
-
* wire-stable, survive `verbatimModuleSyntax` (no emitted runtime helper),
|
|
9
|
-
* and follow the package convention for enum-like constants (see
|
|
10
|
-
* {@link import('./ObjectLayer').ObjectKind}).
|
|
11
|
-
* @stable
|
|
12
|
-
*/
|
|
13
|
-
const TilePropertyKind = {
|
|
14
|
-
Point: "point",
|
|
15
|
-
ObjectRef: "objectRef",
|
|
16
|
-
TileRef: "tileRef"
|
|
17
|
-
};
|
|
18
|
-
/** The identity transform: no flip, no diagonal. */
|
|
19
|
-
const TILE_TRANSFORM_IDENTITY = Object.freeze({
|
|
20
|
-
flipX: false,
|
|
21
|
-
flipY: false,
|
|
22
|
-
diagonal: false
|
|
23
|
-
});
|
|
24
|
-
/** Bit width allocated to the local tile ID within a packed tile word. */
|
|
25
|
-
const PACKED_LOCAL_BITS = 20;
|
|
26
|
-
const PACKED_LOCAL_MASK = (1 << 20) - 1;
|
|
27
|
-
const PACKED_TILESET_MASK = 511 << 20;
|
|
28
|
-
const PACKED_TRANSFORM_MASK = 7 << 29;
|
|
29
|
-
const PACKED_TILESET_SHIFT = 20;
|
|
30
|
-
const PACKED_TRANSFORM_SHIFT = 29;
|
|
31
|
-
/** Maximum tileset index representable in a packed tile. */
|
|
32
|
-
const MAX_TILESET_INDEX = 511;
|
|
33
|
-
/** Maximum local tile ID representable in a packed tile (1-based storage). */
|
|
34
|
-
const MAX_LOCAL_TILE_ID = (1 << 20) - 2;
|
|
35
|
-
const TRANSFORM_FLIP_X = 1;
|
|
36
|
-
const TRANSFORM_FLIP_Y = 2;
|
|
37
|
-
const TRANSFORM_DIAGONAL = 4;
|
|
38
|
-
/**
|
|
39
|
-
* Encode a tileset-local tile reference and transform into a packed word.
|
|
40
|
-
* The localTileId is stored as (localTileId + 1) so that a packed value of 0
|
|
41
|
-
* cleanly represents an empty cell, while tile 0 from tileset 0 with identity
|
|
42
|
-
* transform is stored as 1 (non-zero).
|
|
43
|
-
* Returns 0 for an empty cell.
|
|
44
|
-
*
|
|
45
|
-
* Public so chunk-provider authors (e.g. a format adapter or procedural
|
|
46
|
-
* generator) can build a {@link ChunkPayload}'s `tiles` array without
|
|
47
|
-
* duplicating this encoding.
|
|
48
|
-
* @advanced
|
|
49
|
-
*/
|
|
50
|
-
const packTile = (tilesetIndex, localTileId, transform) => {
|
|
51
|
-
if (tilesetIndex < 0 || tilesetIndex > 511) throw new Error(`Tileset index ${tilesetIndex} exceeds maximum ${511}.`);
|
|
52
|
-
if (localTileId < 0 || localTileId > 1048574) throw new Error(`Local tile ID ${localTileId} exceeds maximum ${MAX_LOCAL_TILE_ID}.`);
|
|
53
|
-
let bits = 0;
|
|
54
|
-
if (transform.flipX) bits |= TRANSFORM_FLIP_X;
|
|
55
|
-
if (transform.flipY) bits |= TRANSFORM_FLIP_Y;
|
|
56
|
-
if (transform.diagonal) bits |= TRANSFORM_DIAGONAL;
|
|
57
|
-
return localTileId + 1 & PACKED_LOCAL_MASK | tilesetIndex << 20 & PACKED_TILESET_MASK | bits << 29 & PACKED_TRANSFORM_MASK;
|
|
58
|
-
};
|
|
59
|
-
/**
|
|
60
|
-
* Decode a packed word into its components.
|
|
61
|
-
* Returns null for an empty cell (packed === 0).
|
|
62
|
-
* @advanced
|
|
63
|
-
*/
|
|
64
|
-
const unpackTile = (packed) => {
|
|
65
|
-
if (packed === 0) return null;
|
|
66
|
-
const localTileId = (packed & PACKED_LOCAL_MASK) - 1;
|
|
67
|
-
const tilesetIndex = (packed & PACKED_TILESET_MASK) >>> 20;
|
|
68
|
-
const rawTransform = (packed & PACKED_TRANSFORM_MASK) >>> 29;
|
|
69
|
-
return {
|
|
70
|
-
tilesetIndex,
|
|
71
|
-
localTileId,
|
|
72
|
-
transform: {
|
|
73
|
-
flipX: !!(rawTransform & TRANSFORM_FLIP_X),
|
|
74
|
-
flipY: !!(rawTransform & TRANSFORM_FLIP_Y),
|
|
75
|
-
diagonal: !!(rawTransform & TRANSFORM_DIAGONAL)
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
};
|
|
79
|
-
/** Convert tile coordinates to chunk coordinates given a chunk size. */
|
|
80
|
-
const tileToChunkCoord = (tx, ty, chunkW, chunkH) => ({
|
|
81
|
-
cx: Math.floor(tx / chunkW),
|
|
82
|
-
cy: Math.floor(ty / chunkH)
|
|
83
|
-
});
|
|
84
|
-
/** Convert tile coordinates to local-in-chunk coordinates. */
|
|
85
|
-
const tileToLocalInChunk = (tx, ty, chunkW, chunkH) => ({
|
|
86
|
-
lx: (tx % chunkW + chunkW) % chunkW,
|
|
87
|
-
ly: (ty % chunkH + chunkH) % chunkH
|
|
88
|
-
});
|
|
89
|
-
/**
|
|
90
|
-
* Validate that a value is a finite, safe, positive integer.
|
|
91
|
-
* Used for dimensions, tile counts, chunk sizes.
|
|
92
|
-
*/
|
|
93
|
-
const validatePositiveInteger = (value, label) => {
|
|
94
|
-
if (!Number.isFinite(value) || !Number.isInteger(value) || value <= 0) throw new Error(`${label} must be a positive integer (got ${value}).`);
|
|
95
|
-
if (value > Number.MAX_SAFE_INTEGER) throw new Error(`${label} exceeds safe integer range (got ${value}).`);
|
|
96
|
-
};
|
|
97
|
-
/**
|
|
98
|
-
* Validate a non-negative finite integer.
|
|
99
|
-
*/
|
|
100
|
-
const validateNonNegativeInteger = (value, label) => {
|
|
101
|
-
if (!Number.isFinite(value) || !Number.isInteger(value) || value < 0) throw new Error(`${label} must be a non-negative integer (got ${value}).`);
|
|
102
|
-
};
|
|
103
|
-
/**
|
|
104
|
-
* Validate that a value is a finite integer (may be negative).
|
|
105
|
-
*/
|
|
106
|
-
const validateInteger = (value, label) => {
|
|
107
|
-
if (!Number.isFinite(value) || !Number.isInteger(value)) throw new Error(`${label} must be a finite integer (got ${value}).`);
|
|
108
|
-
};
|
|
109
|
-
/**
|
|
110
|
-
* Validate a `width`/`height` pair that must be provided together (bounded)
|
|
111
|
-
* or omitted together (unbounded) - shared by {@link import('./TileLayer').TileLayer}
|
|
112
|
-
* and {@link import('./TileMap').TileMap}. When both are provided, each is
|
|
113
|
-
* validated as a positive integer via {@link validatePositiveInteger}.
|
|
114
|
-
*
|
|
115
|
-
* @param entityName Used in the paired-presence error message (e.g. `"TileLayer"`).
|
|
116
|
-
* @param fieldPrefix Used as the field-name prefix passed to {@link validatePositiveInteger} (e.g. `"layer"` for `"layer.width"`).
|
|
117
|
-
* @throws If exactly one of `width`/`height` is provided, or either is not a positive integer.
|
|
118
|
-
*/
|
|
119
|
-
const validatePairedDimensions = (width, height, entityName, fieldPrefix) => {
|
|
120
|
-
if (width !== void 0 || height !== void 0) {
|
|
121
|
-
if (width === void 0 || height === void 0) throw new Error(`${entityName} width and height must both be provided (bounded) or both omitted (unbounded).`);
|
|
122
|
-
validatePositiveInteger(width, `${fieldPrefix}.width`);
|
|
123
|
-
validatePositiveInteger(height, `${fieldPrefix}.height`);
|
|
124
|
-
}
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
//#endregion
|
|
128
|
-
export { MAX_LOCAL_TILE_ID, PACKED_LOCAL_MASK, PACKED_TILESET_MASK, PACKED_TRANSFORM_MASK, TILE_TRANSFORM_IDENTITY, TilePropertyKind, packTile, tileToChunkCoord, tileToLocalInChunk, unpackTile, validateInteger, validateNonNegativeInteger, validatePairedDimensions, validatePositiveInteger };
|
|
129
|
-
//# sourceMappingURL=types.js.map
|
package/dist/esm/types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","names":[],"sources":["../../src/types.ts"],"sourcesContent":["import type { TileMapObject } from './ObjectLayer';\nimport type { TileSet } from './TileSet';\n\n// ── Properties ────────────────────────────────────────────────────────────\n\n/**\n * Discriminant for the three structured, non-scalar {@link TilePropertyValue}\n * variants: {@link TilePropertyPoint}, {@link TilePropertyObjectRef}, and\n * {@link TilePropertyTileRef}.\n *\n * Modelled as a frozen string map (not a TS `enum`) so the values stay\n * wire-stable, survive `verbatimModuleSyntax` (no emitted runtime helper),\n * and follow the package convention for enum-like constants (see\n * {@link import('./ObjectLayer').ObjectKind}).\n * @stable\n */\nexport const TilePropertyKind = {\n Point: 'point',\n ObjectRef: 'objectRef',\n TileRef: 'tileRef',\n} as const;\n\n/** Structured-value discriminant for {@link TilePropertyValue}. */\nexport type TilePropertyKind = (typeof TilePropertyKind)[keyof typeof TilePropertyKind];\n\n/** A 2D point-valued tile property (e.g. an LDtk `Point` field). */\nexport interface TilePropertyPoint {\n readonly kind: typeof TilePropertyKind.Point;\n readonly cx: number;\n readonly cy: number;\n}\n\n/**\n * A reference to another object/entity. `id` is the referenced object's\n * identity - Tiled's numeric object id, or LDtk's `entityIid`. The extra\n * fields are LDtk-only navigation context (`undefined` for Tiled-sourced\n * refs) that lets a consumer resolve the reference without searching the\n * whole level tree.\n */\nexport interface TilePropertyObjectRef {\n readonly kind: typeof TilePropertyKind.ObjectRef;\n readonly id: string | number;\n readonly layerIid?: string;\n readonly levelIid?: string;\n readonly worldIid?: string;\n}\n\n/** A reference into a tileset region (e.g. an LDtk `Tile`-typed field). */\nexport interface TilePropertyTileRef {\n readonly kind: typeof TilePropertyKind.TileRef;\n readonly tilesetUid: number;\n readonly x: number;\n readonly y: number;\n readonly w: number;\n readonly h: number;\n}\n\n/**\n * Union of legal tile-property value types in the generic runtime.\n * Format-neutral; adapters map their native property systems into this set -\n * including the structured {@link TilePropertyPoint}, {@link TilePropertyObjectRef},\n * and {@link TilePropertyTileRef} variants, arrays of any of the above, and\n * nested property bags (e.g. Tiled `class`-typed properties).\n * @advanced\n */\nexport type TilePropertyValue =\n null | boolean | number | string | TilePropertyPoint | TilePropertyObjectRef | TilePropertyTileRef | readonly TilePropertyValue[] | TileProperties;\n\n/**\n * An immutable, flat key-value bag of generic tile properties.\n * Adapters copy and freeze source properties; the runtime never retains\n * a caller-owned mutable object.\n *\n * Declared as an interface (not a `Record<...>` type alias) so it can\n * mutually recurse with {@link TilePropertyValue} - a nested-bag member of\n * that union - without TypeScript's \"circularly references itself\" alias\n * restriction; structurally it behaves exactly like\n * `Readonly<Record<string, TilePropertyValue>>`.\n * @advanced\n */\nexport interface TileProperties {\n readonly [key: string]: TilePropertyValue;\n}\n\n// ── Tile orientation / transform ──────────────────────────────────────────\n\n/**\n * Describes the orientation of a placed tile independent of source-format\n * flip-bit encodings. The eight legal combinations map to the eight distinct\n * 90°-rotation-and-flip states of a rectangular texture quad.\n *\n * Applying the transform at geometry-build time (reordering UV corners)\n * avoids per-tile runtime cost and per-frame matrix allocation.\n * @stable\n */\nexport interface TileTransform {\n /** Horizontal flip (mirror left-right). */\n readonly flipX: boolean;\n /** Vertical flip (mirror top-bottom). */\n readonly flipY: boolean;\n /** Anti-diagonal flip (transpose of the UV axes). Combined with flips produces 90° rotations. */\n readonly diagonal: boolean;\n}\n\n/** The identity transform: no flip, no diagonal. */\nexport const TILE_TRANSFORM_IDENTITY: Readonly<TileTransform> = Object.freeze({\n flipX: false,\n flipY: false,\n diagonal: false,\n});\n\n/**\n * Short string label for a {@link TileTransform} (debug / serialisation).\n * Returns one of the eight deterministic names, e.g. `\"flipX\"` or `\"diag+flipX+flipY\"`.\n * @internal\n */\nexport const tileTransformLabel = (t: TileTransform): string => {\n const parts: string[] = [];\n if (t.diagonal) parts.push('diag');\n if (t.flipX) parts.push('flipX');\n if (t.flipY) parts.push('flipY');\n return parts.length === 0 ? 'identity' : parts.join('+');\n};\n\n// ── Tile identity ─────────────────────────────────────────────────────────\n\n/**\n * Opaque packed tile data stored in a {@link TileChunk}'s compact array.\n * 0 means \"empty cell\". Any non-zero value encodes localTileId, tilesetIndex,\n * and flip bits according to the bit-layout constants below.\n *\n * A `PackedTile` is **not** a source-format GID - it is a fully resolved\n * internal compact representation. Use {@link packTile} / {@link unpackTile}\n * to convert between packed form and a {@link ResolvedTile} if writing\n * adapters.\n *\n * In public APIs, prefer {@link ResolvedTile} or null for queries.\n * `PackedTile` is exposed as `@advanced` so `ReadonlyTileChunk.getRawAt()`\n * has a self-documenting return type.\n * @advanced\n */\nexport type PackedTile = number;\n\n/** Bit width allocated to the local tile ID within a packed tile word. */\nexport const PACKED_LOCAL_BITS = 20;\n/** Bit width allocated to the tileset index within a packed tile word. */\nexport const PACKED_TILESET_BITS = 9;\n/** Bit width allocated to the transform/flip bits. */\nexport const PACKED_TRANSFORM_BITS = 3;\n\nexport const PACKED_LOCAL_MASK = (1 << PACKED_LOCAL_BITS) - 1;\nexport const PACKED_TILESET_MASK = ((1 << PACKED_TILESET_BITS) - 1) << PACKED_LOCAL_BITS;\nexport const PACKED_TRANSFORM_MASK = ((1 << PACKED_TRANSFORM_BITS) - 1) << (PACKED_LOCAL_BITS + PACKED_TILESET_BITS);\n\nexport const PACKED_TILESET_SHIFT = PACKED_LOCAL_BITS;\nexport const PACKED_TRANSFORM_SHIFT = PACKED_LOCAL_BITS + PACKED_TILESET_BITS;\n\n/** Maximum tileset index representable in a packed tile. */\nexport const MAX_TILESET_INDEX = (1 << PACKED_TILESET_BITS) - 1;\n/** Maximum local tile ID representable in a packed tile (1-based storage). */\nexport const MAX_LOCAL_TILE_ID = (1 << PACKED_LOCAL_BITS) - 2;\n\n// Transform bit-field values (bit 0 = flipX, bit 1 = flipY, bit 2 = diagonal).\nconst TRANSFORM_FLIP_X = 1 << 0;\nconst TRANSFORM_FLIP_Y = 1 << 1;\nconst TRANSFORM_DIAGONAL = 1 << 2;\n\n/**\n * Encode a tileset-local tile reference and transform into a packed word.\n * The localTileId is stored as (localTileId + 1) so that a packed value of 0\n * cleanly represents an empty cell, while tile 0 from tileset 0 with identity\n * transform is stored as 1 (non-zero).\n * Returns 0 for an empty cell.\n *\n * Public so chunk-provider authors (e.g. a format adapter or procedural\n * generator) can build a {@link ChunkPayload}'s `tiles` array without\n * duplicating this encoding.\n * @advanced\n */\nexport const packTile = (tilesetIndex: number, localTileId: number, transform: TileTransform): PackedTile => {\n if (tilesetIndex < 0 || tilesetIndex > MAX_TILESET_INDEX) {\n throw new Error(`Tileset index ${tilesetIndex} exceeds maximum ${MAX_TILESET_INDEX}.`);\n }\n if (localTileId < 0 || localTileId > MAX_LOCAL_TILE_ID) {\n throw new Error(`Local tile ID ${localTileId} exceeds maximum ${MAX_LOCAL_TILE_ID}.`);\n }\n let bits = 0;\n if (transform.flipX) bits |= TRANSFORM_FLIP_X;\n if (transform.flipY) bits |= TRANSFORM_FLIP_Y;\n if (transform.diagonal) bits |= TRANSFORM_DIAGONAL;\n // +1 so 0 means \"empty\" not \"tile 0 without transform\"\n const storedId = localTileId + 1;\n return (\n (storedId & PACKED_LOCAL_MASK) | ((tilesetIndex << PACKED_TILESET_SHIFT) & PACKED_TILESET_MASK) | ((bits << PACKED_TRANSFORM_SHIFT) & PACKED_TRANSFORM_MASK)\n );\n};\n\n/**\n * Decode a packed word into its components.\n * Returns null for an empty cell (packed === 0).\n * @advanced\n */\nexport const unpackTile = (\n packed: PackedTile,\n): {\n tilesetIndex: number;\n localTileId: number;\n transform: TileTransform;\n} | null => {\n if (packed === 0) return null;\n const storedId = packed & PACKED_LOCAL_MASK;\n // Undo the +1 offset applied during packTile.\n const localTileId = storedId - 1;\n const tilesetIndex = (packed & PACKED_TILESET_MASK) >>> PACKED_TILESET_SHIFT;\n const rawTransform = (packed & PACKED_TRANSFORM_MASK) >>> PACKED_TRANSFORM_SHIFT;\n return {\n tilesetIndex,\n localTileId,\n transform: {\n flipX: !!(rawTransform & TRANSFORM_FLIP_X),\n flipY: !!(rawTransform & TRANSFORM_FLIP_Y),\n diagonal: !!(rawTransform & TRANSFORM_DIAGONAL),\n },\n };\n};\n\n// ── Resolved tile reference (public query result) ─────────────────────────\n\n/**\n * A fully resolved, format-independent tile reference returned by queries.\n * Materialised on-demand from the packed storage; never stored as a per-cell\n * heap object.\n * @advanced\n */\nexport interface ResolvedTile {\n /** The owning tileset (already resolved from source-format GID). */\n readonly tileset: TileSet;\n /** 0-based tile index within the tileset. */\n readonly localTileId: number;\n /** Orientation transform for this placed tile. */\n readonly transform: TileTransform;\n}\n\n// ── Tile animation ────────────────────────────────────────────────────────\n\n/**\n * One frame of a tile animation: which local tile to show, and for how long.\n * Mirrors Tiled's per-tile animation frame model.\n * @advanced\n */\nexport interface TileAnimationFrame {\n /** Local tile ID shown during this frame (within the tile's own tileset). */\n readonly localTileId: number;\n /** Frame duration in milliseconds. */\n readonly duration: number;\n}\n\n// ── TileDefinition ────────────────────────────────────────────────────────\n\n/**\n * Optional per-tile metadata in a {@link TileSet}. Sparse - only defined\n * tiles carry a definition.\n * @advanced\n */\nexport interface TileDefinition {\n /** The local tile ID this definition belongs to. */\n readonly localTileId: number;\n /** Tile properties (copied and frozen by the tileset). */\n readonly properties?: TileProperties;\n /**\n * Animation frame sequence for this tile, if animated. The frames are\n * driven at runtime by a {@link import('./TileAnimator').TileAnimator};\n * frame[0] is the tile's resting/base frame.\n */\n readonly animation?: readonly TileAnimationFrame[];\n /**\n * Per-tile collision shapes sourced from the Tiled `objectgroup` on the tile.\n * Shapes are in tile-local pixel space (origin = top-left of the tile cell).\n * Only present when the source map defines collision geometry for this tile.\n */\n readonly collision?: readonly TileMapObject[];\n}\n\n// ── Chunk coordinate helpers ──────────────────────────────────────────────\n\n/** A signed chunk coordinate pair. */\nexport interface ChunkCoord {\n readonly cx: number;\n readonly cy: number;\n}\n\n/** Convert tile coordinates to chunk coordinates given a chunk size. */\nexport const tileToChunkCoord = (tx: number, ty: number, chunkW: number, chunkH: number): ChunkCoord => ({\n cx: Math.floor(tx / chunkW),\n cy: Math.floor(ty / chunkH),\n});\n\n/** Convert tile coordinates to local-in-chunk coordinates. */\nexport const tileToLocalInChunk = (tx: number, ty: number, chunkW: number, chunkH: number): { lx: number; ly: number } => ({\n lx: ((tx % chunkW) + chunkW) % chunkW,\n ly: ((ty % chunkH) + chunkH) % chunkH,\n});\n\n/**\n * Validate that a value is a finite, safe, positive integer.\n * Used for dimensions, tile counts, chunk sizes.\n */\nexport const validatePositiveInteger = (value: number, label: string): void => {\n if (!Number.isFinite(value) || !Number.isInteger(value) || value <= 0) {\n throw new Error(`${label} must be a positive integer (got ${value}).`);\n }\n if (value > Number.MAX_SAFE_INTEGER) {\n throw new Error(`${label} exceeds safe integer range (got ${value}).`);\n }\n};\n\n/**\n * Validate a non-negative finite integer.\n */\nexport const validateNonNegativeInteger = (value: number, label: string): void => {\n if (!Number.isFinite(value) || !Number.isInteger(value) || value < 0) {\n throw new Error(`${label} must be a non-negative integer (got ${value}).`);\n }\n};\n\n/**\n * Validate that a value is a finite integer (may be negative).\n */\nexport const validateInteger = (value: number, label: string): void => {\n if (!Number.isFinite(value) || !Number.isInteger(value)) {\n throw new Error(`${label} must be a finite integer (got ${value}).`);\n }\n};\n\n/**\n * Validate a `width`/`height` pair that must be provided together (bounded)\n * or omitted together (unbounded) - shared by {@link import('./TileLayer').TileLayer}\n * and {@link import('./TileMap').TileMap}. When both are provided, each is\n * validated as a positive integer via {@link validatePositiveInteger}.\n *\n * @param entityName Used in the paired-presence error message (e.g. `\"TileLayer\"`).\n * @param fieldPrefix Used as the field-name prefix passed to {@link validatePositiveInteger} (e.g. `\"layer\"` for `\"layer.width\"`).\n * @throws If exactly one of `width`/`height` is provided, or either is not a positive integer.\n */\nexport const validatePairedDimensions = (width: number | undefined, height: number | undefined, entityName: string, fieldPrefix: string): void => {\n if (width !== undefined || height !== undefined) {\n if (width === undefined || height === undefined) {\n throw new Error(`${entityName} width and height must both be provided (bounded) or both omitted (unbounded).`);\n }\n validatePositiveInteger(width, `${fieldPrefix}.width`);\n validatePositiveInteger(height, `${fieldPrefix}.height`);\n }\n};\n"],"mappings":";;;;;;;;;;;;AAgBA,MAAa,mBAAmB;CAC9B,OAAO;CACP,WAAW;CACX,SAAS;AACX;;AAqFA,MAAa,0BAAmD,OAAO,OAAO;CAC5E,OAAO;CACP,OAAO;CACP,UAAU;AACZ,CAAC;;AAmCD,MAAa,oBAAoB;AAMjC,MAAa,qBAAqB,WAA0B;AAC5D,MAAa,sBAAuB;AACpC,MAAa,wBAAyB,KAAsC;AAE5E,MAAa;AACb,MAAa,yBAAyB;;AAGtC,MAAa,oBAAoB;;AAEjC,MAAa,qBAAqB,WAA0B;AAG5D,MAAM,mBAAmB;AACzB,MAAM,mBAAmB;AACzB,MAAM,qBAAqB;;;;;;;;;;;;;AAc3B,MAAa,YAAY,cAAsB,aAAqB,cAAyC;CAC3G,IAAI,eAAe,KAAK,oBACtB,MAAM,IAAI,MAAM,iBAAiB,aAAa,uBAAqC,EAAE;CAEvF,IAAI,cAAc,KAAK,uBACrB,MAAM,IAAI,MAAM,iBAAiB,YAAY,mBAAmB,kBAAkB,EAAE;CAEtF,IAAI,OAAO;CACX,IAAI,UAAU,OAAO,QAAQ;CAC7B,IAAI,UAAU,OAAO,QAAQ;CAC7B,IAAI,UAAU,UAAU,QAAQ;CAGhC,OADiB,cAAc,IAEjB,oBAAuB,qBAAwC,sBAAyB,aAAkC;AAE1I;;;;;;AAOA,MAAa,cACX,WAKU;CACV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