@flare-engine/tilemap 0.4.6 → 0.4.8
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 +1 -1
- package/dist/index.d.mts +35 -31
- package/dist/index.d.mts.map +1 -1
- package/dist/index.d.ts +35 -31
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +40 -27
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +40 -27
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @flare-engine/tilemap
|
|
2
2
|
|
|
3
|
-
Tiled `.tmj` and LDtk parsing + culled rendering + collider extraction. `parseTiled` / `parseLDtk` return a normalized `TilemapData`; `TilemapRenderer` owns its own `SpriteBatch` and only queues tiles inside the camera bounds; `drawInto(camera, batch)` queues into a caller-owned batch for single-flush z-ordering with sprites
|
|
3
|
+
Tiled `.tmj` and LDtk parsing + culled rendering + collider extraction. `parseTiled` / `parseLDtk` return a normalized `TilemapData`; `TilemapRenderer` owns its own `SpriteBatch` and only queues tiles inside the camera bounds; `drawInto(camera, batch, opts?)` queues into a caller-owned batch for single-flush z-ordering with sprites, honouring each layer's `opacity` and taking an optional shared `effect` / `alphaScale`; `extractColliders` produces collision shapes for `@flare-engine/physics`.
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|
package/dist/index.d.mts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { AABBShape } from "@flare-engine/physics";
|
|
2
|
-
import { Camera2D, SpriteBatch } from "@flare-engine/render";
|
|
2
|
+
import { AnySpriteEffect, Camera2D, SpriteBatch } from "@flare-engine/render";
|
|
3
3
|
import { Rect } from "@flare-engine/math";
|
|
4
4
|
import { SkImageLike } from "@flare-engine/assets";
|
|
5
|
-
//#region src/tilemap-data.d.ts
|
|
6
5
|
/** Low 29 bits of a Tiled GID — Tiled stores flip state in the high 3 bits. */
|
|
7
|
-
declare const GID_FLIP_MASK = 536870911;
|
|
6
|
+
export declare const GID_FLIP_MASK = 536870911;
|
|
8
7
|
/** Flip state encoded in the high bits of a Tiled GID. */
|
|
9
8
|
interface TileFlipFlags {
|
|
10
9
|
horizontal: boolean;
|
|
@@ -12,13 +11,13 @@ interface TileFlipFlags {
|
|
|
12
11
|
diagonal: boolean;
|
|
13
12
|
}
|
|
14
13
|
/** Strip the Tiled flip bits from a raw GID, returning the real global tile id. */
|
|
15
|
-
declare function stripGidFlags(gid: number): number;
|
|
14
|
+
export declare function stripGidFlags(gid: number): number;
|
|
16
15
|
/**
|
|
17
16
|
* Decode the Tiled flip bits encoded in the high bits of a raw GID.
|
|
18
17
|
* Note: `gid & 0x80000000` yields a negative Int32 when the bit is set;
|
|
19
18
|
* compare with `!== 0`, not `> 0`.
|
|
20
19
|
*/
|
|
21
|
-
declare function decodeGidFlags(gid: number): TileFlipFlags;
|
|
20
|
+
export declare function decodeGidFlags(gid: number): TileFlipFlags;
|
|
22
21
|
/** A layer of tiles in a grid. */
|
|
23
22
|
interface TileLayer {
|
|
24
23
|
readonly type: 'tile';
|
|
@@ -126,17 +125,15 @@ interface TilemapData {
|
|
|
126
125
|
properties: Record<string, unknown>;
|
|
127
126
|
}
|
|
128
127
|
/** Create an empty TilemapData. */
|
|
129
|
-
declare function createTilemapData(width: number, height: number, tileWidth: number, tileHeight: number): TilemapData;
|
|
128
|
+
export declare function createTilemapData(width: number, height: number, tileWidth: number, tileHeight: number): TilemapData;
|
|
130
129
|
/** Get a tile GID at a grid position from a tile layer. Returns 0 if out of bounds. */
|
|
131
|
-
declare function getTileAt(layer: TileLayer, col: number, row: number): number;
|
|
130
|
+
export declare function getTileAt(layer: TileLayer, col: number, row: number): number;
|
|
132
131
|
/** Get the tileset that owns a given GID. Handles Tiled flip bits in the high bits. */
|
|
133
|
-
declare function getTilesetForGid(tilesets: TilesetRef[], gid: number): TilesetRef | undefined;
|
|
132
|
+
export declare function getTilesetForGid(tilesets: TilesetRef[], gid: number): TilesetRef | undefined;
|
|
134
133
|
/** Compute the source rect in a tileset image for a given GID into `out`. Strips Tiled flip bits. Zero-alloc. */
|
|
135
|
-
declare function getTileSourceRectInto(tileset: TilesetRef, gid: number, out: Rect): Rect;
|
|
134
|
+
export declare function getTileSourceRectInto(tileset: TilesetRef, gid: number, out: Rect): Rect;
|
|
136
135
|
/** Compute the source rect in a tileset image for a given GID. Strips Tiled flip bits. */
|
|
137
|
-
declare function getTileSourceRect(tileset: TilesetRef, gid: number): Rect;
|
|
138
|
-
//#endregion
|
|
139
|
-
//#region src/ldtk-parser.d.ts
|
|
136
|
+
export declare function getTileSourceRect(tileset: TilesetRef, gid: number): Rect;
|
|
140
137
|
interface ParseLDtkOptions {
|
|
141
138
|
/** Predicate deciding whether an IntGrid value marks a solid cell. Default: value > 0. */
|
|
142
139
|
intGridSolid?: (value: number) => boolean;
|
|
@@ -157,30 +154,24 @@ interface LDtkEntity {
|
|
|
157
154
|
* Extract every LDtk entity from a parsed map as a flat, spawn-ready list —
|
|
158
155
|
* the LDtk-entity → ECS spawn convention. Walks all object layers; tile layers are skipped.
|
|
159
156
|
*/
|
|
160
|
-
declare function parseLDtkEntities(map: TilemapData): LDtkEntity[];
|
|
157
|
+
export declare function parseLDtkEntities(map: TilemapData): LDtkEntity[];
|
|
161
158
|
/**
|
|
162
159
|
* Parse an LDtk JSON project into an array of TilemapData (one per level).
|
|
163
160
|
* Returns all levels with their tile and entity layers.
|
|
164
161
|
* Throws TilemapParseError for unsupported formats (externalLevels, invalid input).
|
|
165
162
|
*/
|
|
166
|
-
declare function parseLDtk(json: unknown, options?: ParseLDtkOptions): TilemapData[];
|
|
167
|
-
//#endregion
|
|
168
|
-
//#region src/parse-error.d.ts
|
|
163
|
+
export declare function parseLDtk(json: unknown, options?: ParseLDtkOptions): TilemapData[];
|
|
169
164
|
/** Thrown by parseTiled/parseLDtk when a map uses an unsupported format or feature. */
|
|
170
|
-
declare class TilemapParseError extends Error {
|
|
165
|
+
export declare class TilemapParseError extends Error {
|
|
171
166
|
constructor(message: string);
|
|
172
167
|
}
|
|
173
|
-
//#endregion
|
|
174
|
-
//#region src/tiled-parser.d.ts
|
|
175
168
|
/**
|
|
176
169
|
* Parse a Tiled .tmj (JSON) map into TilemapData.
|
|
177
170
|
* Supports orthogonal maps with CSV tile layers and object layers.
|
|
178
171
|
* Throws TilemapParseError for unsupported formats (infinite, non-orthogonal,
|
|
179
172
|
* external tilesets, base64/compressed/chunked layer data).
|
|
180
173
|
*/
|
|
181
|
-
declare function parseTiled(json: unknown): TilemapData;
|
|
182
|
-
//#endregion
|
|
183
|
-
//#region src/tilemap-collider.d.ts
|
|
174
|
+
export declare function parseTiled(json: unknown): TilemapData;
|
|
184
175
|
/** A collision body extracted from a solid tile. */
|
|
185
176
|
interface TileCollider {
|
|
186
177
|
/** World position of the tile center. */
|
|
@@ -203,14 +194,24 @@ interface TileCollider {
|
|
|
203
194
|
* @param layerName Optional: only extract from this layer. If omitted, extracts from all tile layers.
|
|
204
195
|
* @returns Array of TileCollider bodies.
|
|
205
196
|
*/
|
|
206
|
-
declare function extractColliders(map: TilemapData, layerName?: string): TileCollider[];
|
|
207
|
-
|
|
208
|
-
|
|
197
|
+
export declare function extractColliders(map: TilemapData, layerName?: string): TileCollider[];
|
|
198
|
+
/**
|
|
199
|
+
* Per-draw options for `TilemapRenderer.drawInto` / `draw`.
|
|
200
|
+
*
|
|
201
|
+
* `effect` is set on every queued tile command. Batch runs key on the effect
|
|
202
|
+
* by reference, so one shared instance (e.g. an ambient `tint()`) keeps every
|
|
203
|
+
* tile — and any sprite drawn with the same instance — in a single run.
|
|
204
|
+
* `alphaScale` multiplies each layer's own `opacity` (default 1).
|
|
205
|
+
*/
|
|
206
|
+
interface TilemapDrawOptions {
|
|
207
|
+
effect?: AnySpriteEffect;
|
|
208
|
+
alphaScale?: number;
|
|
209
|
+
}
|
|
209
210
|
/**
|
|
210
211
|
* TilemapRenderer — draws a tilemap with viewport culling.
|
|
211
212
|
* Only tiles visible to the camera are submitted to the SpriteBatch.
|
|
212
213
|
*/
|
|
213
|
-
declare class TilemapRenderer {
|
|
214
|
+
export declare class TilemapRenderer {
|
|
214
215
|
/** The tilemap data to render. */
|
|
215
216
|
readonly map: TilemapData;
|
|
216
217
|
/** SpriteBatch used for batched tile rendering. */
|
|
@@ -228,16 +229,19 @@ declare class TilemapRenderer {
|
|
|
228
229
|
* Queue visible tile layers into a caller-owned `batch` using the camera for
|
|
229
230
|
* culling. Does NOT flush — the caller owns the single flush so tiles z-order
|
|
230
231
|
* under sprites. Zero-alloc: reuses the internal bounds buffer.
|
|
232
|
+
*
|
|
233
|
+
* Each tile's `alpha` is `layer.opacity * opts.alphaScale`; `opts.effect`
|
|
234
|
+
* is applied to every tile (see `TilemapDrawOptions`).
|
|
231
235
|
*/
|
|
232
|
-
drawInto(camera: Camera2D, batch: SpriteBatch): void;
|
|
236
|
+
drawInto(camera: Camera2D, batch: SpriteBatch, opts?: TilemapDrawOptions): void;
|
|
233
237
|
/**
|
|
234
238
|
* Draw visible tile layers using the camera for culling.
|
|
235
239
|
* Call `flush` on a callback to issue the actual draw calls.
|
|
236
|
-
* Delegates to `drawInto` so culling and queuing logic live in one place
|
|
240
|
+
* Delegates to `drawInto` so culling and queuing logic live in one place;
|
|
241
|
+
* `opts` is threaded through unchanged.
|
|
237
242
|
*/
|
|
238
|
-
draw(camera: Camera2D, flush: (batch: SpriteBatch) => void): void;
|
|
243
|
+
draw(camera: Camera2D, flush: (batch: SpriteBatch) => void, opts?: TilemapDrawOptions): void;
|
|
239
244
|
private _drawTileLayer;
|
|
240
245
|
}
|
|
241
|
-
|
|
242
|
-
export { GID_FLIP_MASK, type LDtkEntity, type MapLayer, type MapObject, type ObjectLayer, type ParseLDtkOptions, type TileCollider, type TileFlipFlags, type TileLayer, type TilemapData, TilemapParseError, TilemapRenderer, type TilesetRef, createTilemapData, decodeGidFlags, extractColliders, getTileAt, getTileSourceRect, getTileSourceRectInto, getTilesetForGid, parseLDtk, parseLDtkEntities, parseTiled, stripGidFlags };
|
|
246
|
+
export type { LDtkEntity, MapLayer, MapObject, ObjectLayer, ParseLDtkOptions, TileCollider, TileFlipFlags, TileLayer, TilemapData, TilemapDrawOptions, TilesetRef };
|
|
243
247
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/tilemap-data.ts","../src/ldtk-parser.ts","../src/parse-error.ts","../src/tiled-parser.ts","../src/tilemap-collider.ts","../src/tilemap-renderer.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/tilemap-data.ts","../src/ldtk-parser.ts","../src/parse-error.ts","../src/tiled-parser.ts","../src/tilemap-collider.ts","../src/tilemap-renderer.ts"],"mappings":";;;;;qBAGa;;UAOI;EACf;EACA;EACA;;;wBAIc,cAAc;;;;;;wBASd,eAAe,cAAc;;UAS5B;WACN;;EAET;;EAEA;;EAEA;;;;;;;;;;WAUS,OAAO;;EAEhB;;EAEA;;EAEA;EACA;;EAEA,YAAY;;;UAIG;;EAEf;;EAEA;;EAEA;;EAEA;EACA;;EAEA;EACA;;EAEA;;EAEA,YAAY;;;UAIG;WACN;;EAET;;EAEA,SAAS;;EAET;;EAEA;;EAEA,YAAY;;;KAIF,WAAW,YAAY;;UAGlB;;EAEf;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA,gBAAgB,YAAY;;EAE5B,YAAY;;;UAIG;;EAEf;;EAEA;;EAEA;;EAEA;;EAEA,QAAQ;;EAER,UAAU;;EAEV,YAAY;;;wBAIE,kBACd,eACA,gBACA,mBACA,qBACC;;wBAaa,UAAU,OAAO,WAAW,aAAa;;wBASzC,iBAAiB,UAAU,cAAc,cAAc;;wBAevD,sBAAsB,SAAS,YAAY,aAAa,KAAK,OAAO;;wBAYpE,kBAAkB,SAAS,YAAY,cAAc;UCvHpD;;EAEf,gBAAgB;;UAGD;;EAEf;;EAEA;EACA;;EAEA;EACA;;EAEA,QAAQ;;;;;;wBAOM,kBAAkB,KAAK,cAAc;;;;;;wBAuBrC,UAAU,eAAe,UAAS,mBAAwB;;qBC9H7D,0BAA0B;EACzB,YAAA;;;;;;;;wBC2GE,WAAW,gBAAgB;;UCvG1B;;EAEf;EACA;;EAEA,OAAO;;EAEP;;EAEA;;EAEA;;;;;;;;;;wBAWc,iBAAiB,KAAK,aAAa,qBAAqB;;;;;;;;;UCPvD;EACf,SAAS;EACT;;;;;;qBAOW;;WAEF,KAAK;;WAGL,OAAO;;UAGR;;UAGA;;UAGA;EAEI,YAAA,KAAK;;EAMjB,gBAAgB,qBAAqB,OAAO;;;;;;;;;EAY5C,SAAS,QAAQ,UAAU,OAAO,aAAa,OAAO;;;;;;;EA8BtD,KAAK,QAAQ,UAAU,QAAQ,OAAO,sBAAsB,OAAO;UAW3D"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { Rect } from "@flare-engine/math";
|
|
2
2
|
import { AABBShape } from "@flare-engine/physics";
|
|
3
3
|
import { SkImageLike } from "@flare-engine/assets";
|
|
4
|
-
import { Camera2D, SpriteBatch } from "@flare-engine/render";
|
|
5
|
-
//#region src/tilemap-data.d.ts
|
|
4
|
+
import { AnySpriteEffect, Camera2D, SpriteBatch } from "@flare-engine/render";
|
|
6
5
|
/** Low 29 bits of a Tiled GID — Tiled stores flip state in the high 3 bits. */
|
|
7
|
-
declare const GID_FLIP_MASK = 536870911;
|
|
6
|
+
export declare const GID_FLIP_MASK = 536870911;
|
|
8
7
|
/** Flip state encoded in the high bits of a Tiled GID. */
|
|
9
8
|
interface TileFlipFlags {
|
|
10
9
|
horizontal: boolean;
|
|
@@ -12,13 +11,13 @@ interface TileFlipFlags {
|
|
|
12
11
|
diagonal: boolean;
|
|
13
12
|
}
|
|
14
13
|
/** Strip the Tiled flip bits from a raw GID, returning the real global tile id. */
|
|
15
|
-
declare function stripGidFlags(gid: number): number;
|
|
14
|
+
export declare function stripGidFlags(gid: number): number;
|
|
16
15
|
/**
|
|
17
16
|
* Decode the Tiled flip bits encoded in the high bits of a raw GID.
|
|
18
17
|
* Note: `gid & 0x80000000` yields a negative Int32 when the bit is set;
|
|
19
18
|
* compare with `!== 0`, not `> 0`.
|
|
20
19
|
*/
|
|
21
|
-
declare function decodeGidFlags(gid: number): TileFlipFlags;
|
|
20
|
+
export declare function decodeGidFlags(gid: number): TileFlipFlags;
|
|
22
21
|
/** A layer of tiles in a grid. */
|
|
23
22
|
interface TileLayer {
|
|
24
23
|
readonly type: 'tile';
|
|
@@ -126,17 +125,15 @@ interface TilemapData {
|
|
|
126
125
|
properties: Record<string, unknown>;
|
|
127
126
|
}
|
|
128
127
|
/** Create an empty TilemapData. */
|
|
129
|
-
declare function createTilemapData(width: number, height: number, tileWidth: number, tileHeight: number): TilemapData;
|
|
128
|
+
export declare function createTilemapData(width: number, height: number, tileWidth: number, tileHeight: number): TilemapData;
|
|
130
129
|
/** Get a tile GID at a grid position from a tile layer. Returns 0 if out of bounds. */
|
|
131
|
-
declare function getTileAt(layer: TileLayer, col: number, row: number): number;
|
|
130
|
+
export declare function getTileAt(layer: TileLayer, col: number, row: number): number;
|
|
132
131
|
/** Get the tileset that owns a given GID. Handles Tiled flip bits in the high bits. */
|
|
133
|
-
declare function getTilesetForGid(tilesets: TilesetRef[], gid: number): TilesetRef | undefined;
|
|
132
|
+
export declare function getTilesetForGid(tilesets: TilesetRef[], gid: number): TilesetRef | undefined;
|
|
134
133
|
/** Compute the source rect in a tileset image for a given GID into `out`. Strips Tiled flip bits. Zero-alloc. */
|
|
135
|
-
declare function getTileSourceRectInto(tileset: TilesetRef, gid: number, out: Rect): Rect;
|
|
134
|
+
export declare function getTileSourceRectInto(tileset: TilesetRef, gid: number, out: Rect): Rect;
|
|
136
135
|
/** Compute the source rect in a tileset image for a given GID. Strips Tiled flip bits. */
|
|
137
|
-
declare function getTileSourceRect(tileset: TilesetRef, gid: number): Rect;
|
|
138
|
-
//#endregion
|
|
139
|
-
//#region src/ldtk-parser.d.ts
|
|
136
|
+
export declare function getTileSourceRect(tileset: TilesetRef, gid: number): Rect;
|
|
140
137
|
interface ParseLDtkOptions {
|
|
141
138
|
/** Predicate deciding whether an IntGrid value marks a solid cell. Default: value > 0. */
|
|
142
139
|
intGridSolid?: (value: number) => boolean;
|
|
@@ -157,30 +154,24 @@ interface LDtkEntity {
|
|
|
157
154
|
* Extract every LDtk entity from a parsed map as a flat, spawn-ready list —
|
|
158
155
|
* the LDtk-entity → ECS spawn convention. Walks all object layers; tile layers are skipped.
|
|
159
156
|
*/
|
|
160
|
-
declare function parseLDtkEntities(map: TilemapData): LDtkEntity[];
|
|
157
|
+
export declare function parseLDtkEntities(map: TilemapData): LDtkEntity[];
|
|
161
158
|
/**
|
|
162
159
|
* Parse an LDtk JSON project into an array of TilemapData (one per level).
|
|
163
160
|
* Returns all levels with their tile and entity layers.
|
|
164
161
|
* Throws TilemapParseError for unsupported formats (externalLevels, invalid input).
|
|
165
162
|
*/
|
|
166
|
-
declare function parseLDtk(json: unknown, options?: ParseLDtkOptions): TilemapData[];
|
|
167
|
-
//#endregion
|
|
168
|
-
//#region src/parse-error.d.ts
|
|
163
|
+
export declare function parseLDtk(json: unknown, options?: ParseLDtkOptions): TilemapData[];
|
|
169
164
|
/** Thrown by parseTiled/parseLDtk when a map uses an unsupported format or feature. */
|
|
170
|
-
declare class TilemapParseError extends Error {
|
|
165
|
+
export declare class TilemapParseError extends Error {
|
|
171
166
|
constructor(message: string);
|
|
172
167
|
}
|
|
173
|
-
//#endregion
|
|
174
|
-
//#region src/tiled-parser.d.ts
|
|
175
168
|
/**
|
|
176
169
|
* Parse a Tiled .tmj (JSON) map into TilemapData.
|
|
177
170
|
* Supports orthogonal maps with CSV tile layers and object layers.
|
|
178
171
|
* Throws TilemapParseError for unsupported formats (infinite, non-orthogonal,
|
|
179
172
|
* external tilesets, base64/compressed/chunked layer data).
|
|
180
173
|
*/
|
|
181
|
-
declare function parseTiled(json: unknown): TilemapData;
|
|
182
|
-
//#endregion
|
|
183
|
-
//#region src/tilemap-collider.d.ts
|
|
174
|
+
export declare function parseTiled(json: unknown): TilemapData;
|
|
184
175
|
/** A collision body extracted from a solid tile. */
|
|
185
176
|
interface TileCollider {
|
|
186
177
|
/** World position of the tile center. */
|
|
@@ -203,14 +194,24 @@ interface TileCollider {
|
|
|
203
194
|
* @param layerName Optional: only extract from this layer. If omitted, extracts from all tile layers.
|
|
204
195
|
* @returns Array of TileCollider bodies.
|
|
205
196
|
*/
|
|
206
|
-
declare function extractColliders(map: TilemapData, layerName?: string): TileCollider[];
|
|
207
|
-
|
|
208
|
-
|
|
197
|
+
export declare function extractColliders(map: TilemapData, layerName?: string): TileCollider[];
|
|
198
|
+
/**
|
|
199
|
+
* Per-draw options for `TilemapRenderer.drawInto` / `draw`.
|
|
200
|
+
*
|
|
201
|
+
* `effect` is set on every queued tile command. Batch runs key on the effect
|
|
202
|
+
* by reference, so one shared instance (e.g. an ambient `tint()`) keeps every
|
|
203
|
+
* tile — and any sprite drawn with the same instance — in a single run.
|
|
204
|
+
* `alphaScale` multiplies each layer's own `opacity` (default 1).
|
|
205
|
+
*/
|
|
206
|
+
interface TilemapDrawOptions {
|
|
207
|
+
effect?: AnySpriteEffect;
|
|
208
|
+
alphaScale?: number;
|
|
209
|
+
}
|
|
209
210
|
/**
|
|
210
211
|
* TilemapRenderer — draws a tilemap with viewport culling.
|
|
211
212
|
* Only tiles visible to the camera are submitted to the SpriteBatch.
|
|
212
213
|
*/
|
|
213
|
-
declare class TilemapRenderer {
|
|
214
|
+
export declare class TilemapRenderer {
|
|
214
215
|
/** The tilemap data to render. */
|
|
215
216
|
readonly map: TilemapData;
|
|
216
217
|
/** SpriteBatch used for batched tile rendering. */
|
|
@@ -228,16 +229,19 @@ declare class TilemapRenderer {
|
|
|
228
229
|
* Queue visible tile layers into a caller-owned `batch` using the camera for
|
|
229
230
|
* culling. Does NOT flush — the caller owns the single flush so tiles z-order
|
|
230
231
|
* under sprites. Zero-alloc: reuses the internal bounds buffer.
|
|
232
|
+
*
|
|
233
|
+
* Each tile's `alpha` is `layer.opacity * opts.alphaScale`; `opts.effect`
|
|
234
|
+
* is applied to every tile (see `TilemapDrawOptions`).
|
|
231
235
|
*/
|
|
232
|
-
drawInto(camera: Camera2D, batch: SpriteBatch): void;
|
|
236
|
+
drawInto(camera: Camera2D, batch: SpriteBatch, opts?: TilemapDrawOptions): void;
|
|
233
237
|
/**
|
|
234
238
|
* Draw visible tile layers using the camera for culling.
|
|
235
239
|
* Call `flush` on a callback to issue the actual draw calls.
|
|
236
|
-
* Delegates to `drawInto` so culling and queuing logic live in one place
|
|
240
|
+
* Delegates to `drawInto` so culling and queuing logic live in one place;
|
|
241
|
+
* `opts` is threaded through unchanged.
|
|
237
242
|
*/
|
|
238
|
-
draw(camera: Camera2D, flush: (batch: SpriteBatch) => void): void;
|
|
243
|
+
draw(camera: Camera2D, flush: (batch: SpriteBatch) => void, opts?: TilemapDrawOptions): void;
|
|
239
244
|
private _drawTileLayer;
|
|
240
245
|
}
|
|
241
|
-
|
|
242
|
-
export { GID_FLIP_MASK, type LDtkEntity, type MapLayer, type MapObject, type ObjectLayer, type ParseLDtkOptions, type TileCollider, type TileFlipFlags, type TileLayer, type TilemapData, TilemapParseError, TilemapRenderer, type TilesetRef, createTilemapData, decodeGidFlags, extractColliders, getTileAt, getTileSourceRect, getTileSourceRectInto, getTilesetForGid, parseLDtk, parseLDtkEntities, parseTiled, stripGidFlags };
|
|
246
|
+
export type { LDtkEntity, MapLayer, MapObject, ObjectLayer, ParseLDtkOptions, TileCollider, TileFlipFlags, TileLayer, TilemapData, TilemapDrawOptions, TilesetRef };
|
|
243
247
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/tilemap-data.ts","../src/ldtk-parser.ts","../src/parse-error.ts","../src/tiled-parser.ts","../src/tilemap-collider.ts","../src/tilemap-renderer.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/tilemap-data.ts","../src/ldtk-parser.ts","../src/parse-error.ts","../src/tiled-parser.ts","../src/tilemap-collider.ts","../src/tilemap-renderer.ts"],"mappings":";;;;;qBAGa;;UAOI;EACf;EACA;EACA;;;wBAIc,cAAc;;;;;;wBASd,eAAe,cAAc;;UAS5B;WACN;;EAET;;EAEA;;EAEA;;;;;;;;;;WAUS,OAAO;;EAEhB;;EAEA;;EAEA;EACA;;EAEA,YAAY;;;UAIG;;EAEf;;EAEA;;EAEA;;EAEA;EACA;;EAEA;EACA;;EAEA;;EAEA,YAAY;;;UAIG;WACN;;EAET;;EAEA,SAAS;;EAET;;EAEA;;EAEA,YAAY;;;KAIF,WAAW,YAAY;;UAGlB;;EAEf;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA,gBAAgB,YAAY;;EAE5B,YAAY;;;UAIG;;EAEf;;EAEA;;EAEA;;EAEA;;EAEA,QAAQ;;EAER,UAAU;;EAEV,YAAY;;;wBAIE,kBACd,eACA,gBACA,mBACA,qBACC;;wBAaa,UAAU,OAAO,WAAW,aAAa;;wBASzC,iBAAiB,UAAU,cAAc,cAAc;;wBAevD,sBAAsB,SAAS,YAAY,aAAa,KAAK,OAAO;;wBAYpE,kBAAkB,SAAS,YAAY,cAAc;UCvHpD;;EAEf,gBAAgB;;UAGD;;EAEf;;EAEA;EACA;;EAEA;EACA;;EAEA,QAAQ;;;;;;wBAOM,kBAAkB,KAAK,cAAc;;;;;;wBAuBrC,UAAU,eAAe,UAAS,mBAAwB;;qBC9H7D,0BAA0B;EACzB,YAAA;;;;;;;;wBC2GE,WAAW,gBAAgB;;UCvG1B;;EAEf;EACA;;EAEA,OAAO;;EAEP;;EAEA;;EAEA;;;;;;;;;;wBAWc,iBAAiB,KAAK,aAAa,qBAAqB;;;;;;;;;UCPvD;EACf,SAAS;EACT;;;;;;qBAOW;;WAEF,KAAK;;WAGL,OAAO;;UAGR;;UAGA;;UAGA;EAEI,YAAA,KAAK;;EAMjB,gBAAgB,qBAAqB,OAAO;;;;;;;;;EAY5C,SAAS,QAAQ,UAAU,OAAO,aAAa,OAAO;;;;;;;EA8BtD,KAAK,QAAQ,UAAU,QAAQ,OAAO,sBAAsB,OAAO;UAW3D"}
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
let _flare_engine_physics = require("@flare-engine/physics");
|
|
3
3
|
let _flare_engine_render = require("@flare-engine/render");
|
|
4
|
-
|
|
4
|
+
// src/parse-error.ts
|
|
5
5
|
/** Thrown by parseTiled/parseLDtk when a map uses an unsupported format or feature. */
|
|
6
6
|
var TilemapParseError = class extends Error {
|
|
7
7
|
constructor(message) {
|
|
@@ -9,13 +9,12 @@ var TilemapParseError = class extends Error {
|
|
|
9
9
|
this.name = "TilemapParseError";
|
|
10
10
|
}
|
|
11
11
|
};
|
|
12
|
-
|
|
13
|
-
//#region src/tilemap-data.ts
|
|
12
|
+
// src/tilemap-data.ts
|
|
14
13
|
/** Low 29 bits of a Tiled GID — Tiled stores flip state in the high 3 bits. */
|
|
15
14
|
const GID_FLIP_MASK = 536870911;
|
|
16
|
-
const FLIP_H = 2147483648;
|
|
17
|
-
const FLIP_V = 1073741824;
|
|
18
|
-
const FLIP_D = 536870912;
|
|
15
|
+
const FLIP_H$1 = 2147483648;
|
|
16
|
+
const FLIP_V$1 = 1073741824;
|
|
17
|
+
const FLIP_D$1 = 536870912;
|
|
19
18
|
/** Strip the Tiled flip bits from a raw GID, returning the real global tile id. */
|
|
20
19
|
function stripGidFlags(gid) {
|
|
21
20
|
return gid & GID_FLIP_MASK;
|
|
@@ -27,9 +26,9 @@ function stripGidFlags(gid) {
|
|
|
27
26
|
*/
|
|
28
27
|
function decodeGidFlags(gid) {
|
|
29
28
|
return {
|
|
30
|
-
horizontal: (gid & FLIP_H) !== 0,
|
|
31
|
-
vertical: (gid & FLIP_V) !== 0,
|
|
32
|
-
diagonal: (gid & FLIP_D) !== 0
|
|
29
|
+
horizontal: (gid & FLIP_H$1) !== 0,
|
|
30
|
+
vertical: (gid & FLIP_V$1) !== 0,
|
|
31
|
+
diagonal: (gid & FLIP_D$1) !== 0
|
|
33
32
|
};
|
|
34
33
|
}
|
|
35
34
|
/** Create an empty TilemapData. */
|
|
@@ -77,8 +76,7 @@ function getTileSourceRect(tileset, gid) {
|
|
|
77
76
|
height: 0
|
|
78
77
|
});
|
|
79
78
|
}
|
|
80
|
-
|
|
81
|
-
//#region src/ldtk-parser.ts
|
|
79
|
+
// src/ldtk-parser.ts
|
|
82
80
|
/**
|
|
83
81
|
* Extract every LDtk entity from a parsed map as a flat, spawn-ready list —
|
|
84
82
|
* the LDtk-entity → ECS spawn convention. Walks all object layers; tile layers are skipped.
|
|
@@ -250,8 +248,7 @@ function parseEntitiesLayer(layer) {
|
|
|
250
248
|
properties: {}
|
|
251
249
|
};
|
|
252
250
|
}
|
|
253
|
-
|
|
254
|
-
//#region src/tiled-parser.ts
|
|
251
|
+
// src/tiled-parser.ts
|
|
255
252
|
/** Convert Tiled properties array to a Record. */
|
|
256
253
|
function parseProperties(props) {
|
|
257
254
|
if (!props || props.length === 0) return {};
|
|
@@ -343,8 +340,7 @@ function parseObjectLayer(layer) {
|
|
|
343
340
|
properties: parseProperties(layer.properties)
|
|
344
341
|
};
|
|
345
342
|
}
|
|
346
|
-
|
|
347
|
-
//#region src/tilemap-collider.ts
|
|
343
|
+
// src/tilemap-collider.ts
|
|
348
344
|
/**
|
|
349
345
|
* Extract collision shapes from solid tiles in a tilemap.
|
|
350
346
|
* A tile is considered solid if its tileset marks the local tile ID as solid.
|
|
@@ -382,8 +378,11 @@ function extractFromLayer(layer, tilesets, tw, th, out) {
|
|
|
382
378
|
});
|
|
383
379
|
}
|
|
384
380
|
}
|
|
385
|
-
|
|
386
|
-
|
|
381
|
+
// src/tilemap-renderer.ts
|
|
382
|
+
const FLIP_H = 2147483648;
|
|
383
|
+
const FLIP_V = 1073741824;
|
|
384
|
+
const FLIP_D = 536870912;
|
|
385
|
+
const QUARTER_TURN = Math.PI / 2;
|
|
387
386
|
/**
|
|
388
387
|
* TilemapRenderer — draws a tilemap with viewport culling.
|
|
389
388
|
* Only tiles visible to the camera are submitted to the SpriteBatch.
|
|
@@ -421,26 +420,32 @@ var TilemapRenderer = class {
|
|
|
421
420
|
* Queue visible tile layers into a caller-owned `batch` using the camera for
|
|
422
421
|
* culling. Does NOT flush — the caller owns the single flush so tiles z-order
|
|
423
422
|
* under sprites. Zero-alloc: reuses the internal bounds buffer.
|
|
423
|
+
*
|
|
424
|
+
* Each tile's `alpha` is `layer.opacity * opts.alphaScale`; `opts.effect`
|
|
425
|
+
* is applied to every tile (see `TilemapDrawOptions`).
|
|
424
426
|
*/
|
|
425
|
-
drawInto(camera, batch) {
|
|
427
|
+
drawInto(camera, batch, opts) {
|
|
426
428
|
const bounds = camera.getBoundsInto(this._boundsBuf);
|
|
427
429
|
const tw = this.map.tileWidth;
|
|
428
430
|
const th = this.map.tileHeight;
|
|
431
|
+
const effect = opts?.effect;
|
|
432
|
+
const alphaScale = opts?.alphaScale ?? 1;
|
|
429
433
|
for (const layer of this.map.layers) {
|
|
430
434
|
if (layer.type !== "tile" || !layer.visible) continue;
|
|
431
|
-
this._drawTileLayer(layer, bounds.x, bounds.y, bounds.width, bounds.height, tw, th, batch);
|
|
435
|
+
this._drawTileLayer(layer, bounds.x, bounds.y, bounds.width, bounds.height, tw, th, batch, effect, layer.opacity * alphaScale);
|
|
432
436
|
}
|
|
433
437
|
}
|
|
434
438
|
/**
|
|
435
439
|
* Draw visible tile layers using the camera for culling.
|
|
436
440
|
* Call `flush` on a callback to issue the actual draw calls.
|
|
437
|
-
* Delegates to `drawInto` so culling and queuing logic live in one place
|
|
441
|
+
* Delegates to `drawInto` so culling and queuing logic live in one place;
|
|
442
|
+
* `opts` is threaded through unchanged.
|
|
438
443
|
*/
|
|
439
|
-
draw(camera, flush) {
|
|
440
|
-
this.drawInto(camera, this.batch);
|
|
444
|
+
draw(camera, flush, opts) {
|
|
445
|
+
this.drawInto(camera, this.batch, opts);
|
|
441
446
|
flush(this.batch);
|
|
442
447
|
}
|
|
443
|
-
_drawTileLayer(layer, viewX, viewY, viewW, viewH, tw, th, batch) {
|
|
448
|
+
_drawTileLayer(layer, viewX, viewY, viewW, viewH, tw, th, batch, effect, alpha) {
|
|
444
449
|
const offsetX = layer.offsetX;
|
|
445
450
|
const offsetY = layer.offsetY;
|
|
446
451
|
const startCol = Math.max(0, Math.floor((viewX - offsetX) / tw));
|
|
@@ -455,13 +460,21 @@ var TilemapRenderer = class {
|
|
|
455
460
|
const image = this._images.get(tileset.name);
|
|
456
461
|
if (!image) continue;
|
|
457
462
|
const src = getTileSourceRectInto(tileset, gid, this._srcBuf);
|
|
458
|
-
const
|
|
459
|
-
const
|
|
460
|
-
|
|
463
|
+
const h = (gid & FLIP_H) !== 0;
|
|
464
|
+
const v = (gid & FLIP_V) !== 0;
|
|
465
|
+
const d = (gid & FLIP_D) !== 0;
|
|
466
|
+
let flipX = h;
|
|
467
|
+
let flipY = v;
|
|
468
|
+
let rotation = 0;
|
|
469
|
+
if (d) {
|
|
470
|
+
rotation = !h && v ? -QUARTER_TURN : QUARTER_TURN;
|
|
471
|
+
flipX = h && v;
|
|
472
|
+
flipY = !h && !v;
|
|
473
|
+
}
|
|
474
|
+
batch.drawRaw(image, src.x, src.y, src.width, src.height, col * tw + offsetX + tw * .5, row * th + offsetY + th * .5, tw, th, effect, .5, .5, alpha, rotation, false, "normal", flipX, flipY);
|
|
461
475
|
}
|
|
462
476
|
}
|
|
463
477
|
};
|
|
464
|
-
//#endregion
|
|
465
478
|
exports.GID_FLIP_MASK = GID_FLIP_MASK;
|
|
466
479
|
exports.TilemapParseError = TilemapParseError;
|
|
467
480
|
exports.TilemapRenderer = TilemapRenderer;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["SpriteBatch"],"sources":["../src/parse-error.ts","../src/tilemap-data.ts","../src/ldtk-parser.ts","../src/tiled-parser.ts","../src/tilemap-collider.ts","../src/tilemap-renderer.ts"],"sourcesContent":["/** Thrown by parseTiled/parseLDtk when a map uses an unsupported format or feature. */\nexport class TilemapParseError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'TilemapParseError';\n }\n}\n","import type { Rect } from '@flare-engine/math';\n\n/** Low 29 bits of a Tiled GID — Tiled stores flip state in the high 3 bits. */\nexport const GID_FLIP_MASK = 0x1fffffff;\n\nconst FLIP_H = 0x80000000;\nconst FLIP_V = 0x40000000;\nconst FLIP_D = 0x20000000;\n\n/** Flip state encoded in the high bits of a Tiled GID. */\nexport interface TileFlipFlags {\n horizontal: boolean;\n vertical: boolean;\n diagonal: boolean;\n}\n\n/** Strip the Tiled flip bits from a raw GID, returning the real global tile id. */\nexport function stripGidFlags(gid: number): number {\n return gid & GID_FLIP_MASK;\n}\n\n/**\n * Decode the Tiled flip bits encoded in the high bits of a raw GID.\n * Note: `gid & 0x80000000` yields a negative Int32 when the bit is set;\n * compare with `!== 0`, not `> 0`.\n */\nexport function decodeGidFlags(gid: number): TileFlipFlags {\n return {\n horizontal: (gid & FLIP_H) !== 0,\n vertical: (gid & FLIP_V) !== 0,\n diagonal: (gid & FLIP_D) !== 0,\n };\n}\n\n/** A layer of tiles in a grid. */\nexport interface TileLayer {\n readonly type: 'tile';\n /** Layer name. */\n name: string;\n /** Grid width in tiles. */\n width: number;\n /** Grid height in tiles. */\n height: number;\n /**\n * Flat array of tile GIDs (row-major, length = width * height). `Uint32Array`,\n * not `Float32Array` — a 24-bit mantissa cannot hold Tiled's flip-bit GIDs\n * (`0x80000000` and up). This is a type decision for bulk numeric data per the\n * repo convention, not a measured perf change.\n *\n * `readonly` like `SolidGrid.solid`: the array cannot be swapped out from under a\n * parsed map, but its cells stay writable (`layer.tiles[i] = gid`).\n */\n readonly tiles: Uint32Array;\n /** Visibility flag. */\n visible: boolean;\n /** Opacity (0–1). */\n opacity: number;\n /** Layer offset in pixels. */\n offsetX: number;\n offsetY: number;\n /** Custom properties. */\n properties: Record<string, unknown>;\n}\n\n/** An object in an object layer. */\nexport interface MapObject {\n /** Object ID. */\n id: number;\n /** Object name. */\n name: string;\n /** Object type/class. */\n type: string;\n /** Position in pixels. */\n x: number;\n y: number;\n /** Size in pixels. */\n width: number;\n height: number;\n /** Rotation in degrees. */\n rotation: number;\n /** Custom properties. */\n properties: Record<string, unknown>;\n}\n\n/** A layer of objects. */\nexport interface ObjectLayer {\n readonly type: 'object';\n /** Layer name. */\n name: string;\n /** Objects in the layer. */\n objects: MapObject[];\n /** Visibility flag. */\n visible: boolean;\n /** Opacity (0–1). */\n opacity: number;\n /** Custom properties. */\n properties: Record<string, unknown>;\n}\n\n/** Union of layer types. */\nexport type MapLayer = TileLayer | ObjectLayer;\n\n/** Information about a tileset used in the map. */\nexport interface TilesetRef {\n /** First GID in this tileset. */\n firstGid: number;\n /** Tileset name. */\n name: string;\n /** Tile width in pixels. */\n tileWidth: number;\n /** Tile height in pixels. */\n tileHeight: number;\n /** Number of columns in the tileset image. */\n columns: number;\n /** Total tile count. */\n tileCount: number;\n /** Image source path (may need resolving). */\n image: string;\n /** Image width in pixels. */\n imageWidth: number;\n /** Image height in pixels. */\n imageHeight: number;\n /** Per-tile properties (indexed by local tile ID). */\n tileProperties: Map<number, Record<string, unknown>>;\n /** Tile IDs marked as solid/collision. */\n solidTiles: Set<number>;\n}\n\n/** Complete parsed tilemap data — format-independent. */\nexport interface TilemapData {\n /** Map width in tiles. */\n width: number;\n /** Map height in tiles. */\n height: number;\n /** Tile width in pixels. */\n tileWidth: number;\n /** Tile height in pixels. */\n tileHeight: number;\n /** All layers in order. */\n layers: MapLayer[];\n /** Tilesets referenced by this map. */\n tilesets: TilesetRef[];\n /** Custom map properties. */\n properties: Record<string, unknown>;\n}\n\n/** Create an empty TilemapData. */\nexport function createTilemapData(\n width: number,\n height: number,\n tileWidth: number,\n tileHeight: number,\n): TilemapData {\n return {\n width,\n height,\n tileWidth,\n tileHeight,\n layers: [],\n tilesets: [],\n properties: {},\n };\n}\n\n/** Get a tile GID at a grid position from a tile layer. Returns 0 if out of bounds. */\nexport function getTileAt(layer: TileLayer, col: number, row: number): number {\n if (col < 0 || col >= layer.width || row < 0 || row >= layer.height) return 0;\n // The `?? 0` is unreachable at runtime (the bounds check above guarantees an\n // in-range index into a hole-free Uint32Array) — it satisfies noUncheckedIndexedAccess,\n // which types every typed-array index read as `number | undefined`.\n return layer.tiles[row * layer.width + col] ?? 0;\n}\n\n/** Get the tileset that owns a given GID. Handles Tiled flip bits in the high bits. */\nexport function getTilesetForGid(tilesets: TilesetRef[], gid: number): TilesetRef | undefined {\n const id = gid & GID_FLIP_MASK;\n // Tilesets are ordered by firstGid; find the last one where firstGid <= id\n let result: TilesetRef | undefined;\n for (const ts of tilesets) {\n if (ts.firstGid <= id) {\n result = ts;\n } else {\n break;\n }\n }\n return result;\n}\n\n/** Compute the source rect in a tileset image for a given GID into `out`. Strips Tiled flip bits. Zero-alloc. */\nexport function getTileSourceRectInto(tileset: TilesetRef, gid: number, out: Rect): Rect {\n const localId = (gid & GID_FLIP_MASK) - tileset.firstGid;\n const col = localId % tileset.columns;\n const row = Math.floor(localId / tileset.columns);\n out.x = col * tileset.tileWidth;\n out.y = row * tileset.tileHeight;\n out.width = tileset.tileWidth;\n out.height = tileset.tileHeight;\n return out;\n}\n\n/** Compute the source rect in a tileset image for a given GID. Strips Tiled flip bits. */\nexport function getTileSourceRect(tileset: TilesetRef, gid: number): Rect {\n return getTileSourceRectInto(tileset, gid, { x: 0, y: 0, width: 0, height: 0 });\n}\n","import { TilemapParseError } from './parse-error.js';\nimport type { MapObject, ObjectLayer, TileLayer, TilemapData, TilesetRef } from './tilemap-data.js';\nimport { createTilemapData } from './tilemap-data.js';\n\n// ----- LDtk JSON types -----\n\ninterface LDtkFieldInstance {\n __identifier: string;\n __value: unknown;\n __type: string;\n}\n\ninterface LDtkEntityInstance {\n __identifier: string;\n __grid: [number, number];\n __pivot: [number, number];\n __tile?: { x: number; y: number; w: number; h: number };\n iid: string;\n width: number;\n height: number;\n px: [number, number];\n fieldInstances: LDtkFieldInstance[];\n}\n\ninterface LDtkTileInstance {\n px: [number, number];\n src: [number, number];\n f: number; // flip flags\n t: number; // tile ID\n}\n\ninterface LDtkLayerInstance {\n __identifier: string;\n __type: string;\n __cWid: number;\n __cHei: number;\n __gridSize: number;\n __tilesetDefUid?: number;\n __tilesetRelPath?: string;\n visible: boolean;\n __opacity: number;\n intGridCsv?: number[];\n // Real LDtk output always emits both arrays on every layer instance — only\n // one is ever populated per __type (an AutoLayer's gridTiles is always []).\n // Required (not optional) so a fixture omitting the unused one, as every\n // fixture here did before F057, cannot pass this module's own types.\n gridTiles: LDtkTileInstance[];\n autoLayerTiles: LDtkTileInstance[];\n entityInstances?: LDtkEntityInstance[];\n}\n\ninterface LDtkTilesetDef {\n uid: number;\n identifier: string;\n relPath: string;\n pxWid: number;\n pxHei: number;\n tileGridSize: number;\n __cWid: number;\n __cHei: number;\n}\n\ninterface LDtkLevel {\n identifier: string;\n uid: number;\n pxWid: number;\n pxHei: number;\n worldX: number;\n worldY: number;\n layerInstances?: LDtkLayerInstance[];\n fieldInstances?: LDtkFieldInstance[];\n}\n\ninterface LDtkJSON {\n defaultGridSize: number;\n externalLevels?: boolean;\n defs: {\n tilesets: LDtkTilesetDef[];\n };\n levels: LDtkLevel[];\n}\n\nexport interface ParseLDtkOptions {\n /** Predicate deciding whether an IntGrid value marks a solid cell. Default: value > 0. */\n intGridSolid?: (value: number) => boolean;\n}\n\nexport interface LDtkEntity {\n /** LDtk entity identifier (its type, e.g. \"Player\") — the key you switch on to decide what to spawn. */\n id: string;\n /** Entity position in pixels (LDtk px, pivot-adjusted per the parser convention). */\n x: number;\n y: number;\n /** Entity box size in pixels. */\n width: number;\n height: number;\n /** Custom field instances, keyed by field identifier. */\n fields: Record<string, unknown>;\n}\n\n/**\n * Extract every LDtk entity from a parsed map as a flat, spawn-ready list —\n * the LDtk-entity → ECS spawn convention. Walks all object layers; tile layers are skipped.\n */\nexport function parseLDtkEntities(map: TilemapData): LDtkEntity[] {\n const entities: LDtkEntity[] = [];\n for (const layer of map.layers) {\n if (layer.type !== 'object') continue;\n for (const obj of layer.objects) {\n entities.push({\n id: obj.type,\n x: obj.x,\n y: obj.y,\n width: obj.width,\n height: obj.height,\n fields: obj.properties,\n });\n }\n }\n return entities;\n}\n\n/**\n * Parse an LDtk JSON project into an array of TilemapData (one per level).\n * Returns all levels with their tile and entity layers.\n * Throws TilemapParseError for unsupported formats (externalLevels, invalid input).\n */\nexport function parseLDtk(json: unknown, options: ParseLDtkOptions = {}): TilemapData[] {\n if (\n !json ||\n typeof json !== 'object' ||\n !Array.isArray((json as Record<string, unknown>).levels) ||\n !(json as Record<string, unknown>).defs ||\n !Array.isArray(((json as Record<string, unknown>).defs as Record<string, unknown>).tilesets)\n ) {\n throw new TilemapParseError(\n 'parseLDtk: input is not an LDtk project JSON (missing defs.tilesets or levels).',\n );\n }\n\n const data = json as LDtkJSON;\n\n if (data.externalLevels === true) {\n throw new TilemapParseError(\n 'parseLDtk: projects with \"Save levels to separate files\" (externalLevels) are not supported. Disable it in LDtk ▸ Project settings and re-save.',\n );\n }\n\n const isSolid = options.intGridSolid ?? ((v) => v > 0);\n\n const tilesetDefs = new Map<number, LDtkTilesetDef>();\n for (const ts of data.defs.tilesets) {\n tilesetDefs.set(ts.uid, ts);\n }\n\n const results: TilemapData[] = [];\n\n for (const level of data.levels) {\n const gridSize = data.defaultGridSize;\n const mapWidth = Math.ceil(level.pxWid / gridSize);\n const mapHeight = Math.ceil(level.pxHei / gridSize);\n const map = createTilemapData(mapWidth, mapHeight, gridSize, gridSize);\n\n if (level.fieldInstances) {\n for (const field of level.fieldInstances) {\n map.properties[field.__identifier] = field.__value;\n }\n }\n\n // Pass 1: collect tile-layer tileset uids, sort ascending, assign deterministic firstGids.\n // Tilesets must be sorted by firstGid (ascending) for getTilesetForGid's early-break.\n const firstGidByUid = new Map<number, number>();\n let nextFirstGid = 1;\n\n if (level.layerInstances) {\n const usedTileUids = new Set<number>();\n for (const layerInst of level.layerInstances) {\n if (\n (layerInst.__type === 'Tiles' || layerInst.__type === 'AutoLayer') &&\n layerInst.__tilesetDefUid !== undefined\n ) {\n usedTileUids.add(layerInst.__tilesetDefUid);\n }\n }\n\n const sortedUids = Array.from(usedTileUids).sort((a, b) => a - b);\n for (const uid of sortedUids) {\n const def = tilesetDefs.get(uid);\n if (!def) continue;\n const columns = def.__cWid;\n const tileCount = def.__cWid * def.__cHei;\n firstGidByUid.set(uid, nextFirstGid);\n const ref: TilesetRef = {\n firstGid: nextFirstGid,\n name: def.identifier,\n tileWidth: def.tileGridSize,\n tileHeight: def.tileGridSize,\n columns,\n tileCount,\n image: def.relPath,\n imageWidth: def.pxWid,\n imageHeight: def.pxHei,\n tileProperties: new Map(),\n solidTiles: new Set(),\n };\n map.tilesets.push(ref);\n nextFirstGid += tileCount;\n }\n }\n\n // Pass 2: parse layers in reverse order (LDtk stores top-first; emit bottom-first).\n if (level.layerInstances) {\n for (let i = level.layerInstances.length - 1; i >= 0; i--) {\n const layerInst = level.layerInstances[i]!;\n\n if (layerInst.__type === 'IntGrid') {\n // IntGrid layers are treated as collision grids; IntGrid layers that also\n // carry auto-render tiles keep collision only (visual auto-tiles are M4 scope).\n const csv = layerInst.intGridCsv;\n const cellCount = layerInst.__cWid * layerInst.__cHei;\n const tiles = new Uint32Array(cellCount);\n const intFirstGid = nextFirstGid;\n let maxLocal = 0;\n let hasNonZero = false;\n const solidSet = new Set<number>();\n\n if (csv) {\n for (let j = 0; j < csv.length; j++) {\n const v = csv[j] ?? 0;\n if (v > 0) {\n hasNonZero = true;\n const localId = v - 1;\n if (localId > maxLocal) maxLocal = localId;\n tiles[j] = intFirstGid + localId;\n if (isSolid(v)) solidSet.add(localId);\n }\n }\n }\n\n if (hasNonZero) {\n const tileCount = maxLocal + 1;\n map.tilesets.push({\n firstGid: intFirstGid,\n name: layerInst.__identifier,\n tileWidth: layerInst.__gridSize,\n tileHeight: layerInst.__gridSize,\n columns: tileCount,\n tileCount,\n image: '',\n imageWidth: 0,\n imageHeight: 0,\n tileProperties: new Map(),\n solidTiles: solidSet,\n });\n nextFirstGid += tileCount;\n }\n\n map.layers.push({\n type: 'tile',\n name: layerInst.__identifier,\n width: layerInst.__cWid,\n height: layerInst.__cHei,\n tiles,\n visible: layerInst.visible,\n opacity: layerInst.__opacity,\n offsetX: 0,\n offsetY: 0,\n properties: {},\n });\n } else if (layerInst.__type === 'Tiles' || layerInst.__type === 'AutoLayer') {\n const firstGid = firstGidByUid.get(layerInst.__tilesetDefUid ?? -1) ?? 1;\n map.layers.push(parseTilesLayer(layerInst, mapWidth, mapHeight, gridSize, firstGid));\n } else if (layerInst.__type === 'Entities') {\n map.layers.push(parseEntitiesLayer(layerInst));\n }\n }\n }\n\n results.push(map);\n }\n\n return results;\n}\n\nfunction parseTilesLayer(\n layer: LDtkLayerInstance,\n mapWidth: number,\n mapHeight: number,\n gridSize: number,\n firstGid: number,\n): TileLayer {\n const tiles = new Uint32Array(mapWidth * mapHeight);\n // An AutoLayer's tiles live in autoLayerTiles; its gridTiles is always [].\n // `gridTiles ?? autoLayerTiles` picked the empty gridTiles for every\n // AutoLayer, since `??` only falls through on null/undefined, never on `[]`\n // — select by __type instead, which is the field LDtk itself keys on.\n const tileInstances = layer.__type === 'AutoLayer' ? layer.autoLayerTiles : layer.gridTiles;\n\n for (const ti of tileInstances) {\n const col = Math.floor(ti.px[0] / gridSize);\n const row = Math.floor(ti.px[1] / gridSize);\n if (col >= 0 && col < mapWidth && row >= 0 && row < mapHeight) {\n tiles[row * mapWidth + col] = firstGid + ti.t;\n }\n }\n\n return {\n type: 'tile',\n name: layer.__identifier,\n width: mapWidth,\n height: mapHeight,\n tiles,\n visible: layer.visible,\n opacity: layer.__opacity,\n offsetX: 0,\n offsetY: 0,\n properties: {},\n };\n}\n\nfunction parseEntitiesLayer(layer: LDtkLayerInstance): ObjectLayer {\n const objects: MapObject[] = (layer.entityInstances ?? []).map((ent, idx) => {\n const props: Record<string, unknown> = {};\n for (const field of ent.fieldInstances) {\n props[field.__identifier] = field.__value;\n }\n return {\n id: idx + 1,\n name: ent.__identifier,\n type: ent.__identifier,\n x: ent.px[0],\n y: ent.px[1],\n width: ent.width,\n height: ent.height,\n rotation: 0,\n properties: props,\n };\n });\n\n return {\n type: 'object',\n name: layer.__identifier,\n objects,\n visible: layer.visible,\n opacity: layer.__opacity,\n properties: {},\n };\n}\n","import { TilemapParseError } from './parse-error.js';\nimport type {\n MapLayer,\n MapObject,\n ObjectLayer,\n TileLayer,\n TilemapData,\n TilesetRef,\n} from './tilemap-data.js';\nimport { createTilemapData } from './tilemap-data.js';\n\n// ----- Tiled JSON types (.tmj format) -----\n\ninterface TiledProperty {\n name: string;\n type: string;\n value: unknown;\n}\n\ninterface TiledTileLayer {\n type: 'tilelayer';\n name: string;\n width: number;\n height: number;\n data: number[] | string;\n encoding?: string;\n compression?: string;\n chunks?: unknown[];\n visible: boolean;\n opacity: number;\n offsetx?: number;\n offsety?: number;\n properties?: TiledProperty[];\n}\n\ninterface TiledObject {\n id: number;\n name: string;\n type?: string;\n class?: string;\n x: number;\n y: number;\n width: number;\n height: number;\n rotation: number;\n properties?: TiledProperty[];\n}\n\ninterface TiledObjectLayer {\n type: 'objectgroup';\n name: string;\n objects: TiledObject[];\n visible: boolean;\n opacity: number;\n properties?: TiledProperty[];\n}\n\ntype TiledLayer = TiledTileLayer | TiledObjectLayer;\n\ninterface TiledTile {\n id: number;\n properties?: TiledProperty[];\n type?: string;\n class?: string;\n}\n\ninterface TiledTileset {\n firstgid: number;\n name: string;\n tilewidth: number;\n tileheight: number;\n columns: number;\n tilecount: number;\n image: string;\n imagewidth: number;\n imageheight: number;\n tiles?: TiledTile[];\n properties?: TiledProperty[];\n source?: string;\n}\n\ninterface TiledMapJSON {\n width: number;\n height: number;\n tilewidth: number;\n tileheight: number;\n orientation: string;\n infinite?: boolean;\n layers: TiledLayer[];\n tilesets: TiledTileset[];\n properties?: TiledProperty[];\n}\n\n/** Convert Tiled properties array to a Record. */\nfunction parseProperties(props?: TiledProperty[]): Record<string, unknown> {\n if (!props || props.length === 0) return {};\n const result: Record<string, unknown> = {};\n for (const p of props) {\n result[p.name] = p.value;\n }\n return result;\n}\n\n/**\n * Parse a Tiled .tmj (JSON) map into TilemapData.\n * Supports orthogonal maps with CSV tile layers and object layers.\n * Throws TilemapParseError for unsupported formats (infinite, non-orthogonal,\n * external tilesets, base64/compressed/chunked layer data).\n */\nexport function parseTiled(json: unknown): TilemapData {\n if (\n !json ||\n typeof json !== 'object' ||\n typeof (json as Record<string, unknown>).width !== 'number' ||\n typeof (json as Record<string, unknown>).height !== 'number' ||\n !Array.isArray((json as Record<string, unknown>).layers) ||\n !Array.isArray((json as Record<string, unknown>).tilesets)\n ) {\n throw new TilemapParseError(\n 'parseTiled: input is not a Tiled map JSON (missing width/height/layers/tilesets).',\n );\n }\n\n const data = json as TiledMapJSON;\n\n if (data.infinite === true) {\n throw new TilemapParseError(\n 'parseTiled: infinite maps are not supported. In Tiled: Map ▸ Map Properties ▸ set \"Infinite\" to false, then re-export.',\n );\n }\n if (data.orientation && data.orientation !== 'orthogonal') {\n throw new TilemapParseError(\n `parseTiled: orientation \"${data.orientation}\" is not supported — only orthogonal maps are supported.`,\n );\n }\n\n const map = createTilemapData(data.width, data.height, data.tilewidth, data.tileheight);\n map.properties = parseProperties(data.properties);\n\n // Parse tilesets\n for (const ts of data.tilesets) {\n if (ts.source !== undefined) {\n throw new TilemapParseError(\n `parseTiled: external tileset \"${ts.source}\" is not supported. Embed tilesets on export (Tiled ▸ Map ▸ \"Embed tilesets\") or run it through \\`flare tiled-to-flare\\` (which embeds tilesets by default).`,\n );\n }\n\n const tileProperties = new Map<number, Record<string, unknown>>();\n const solidTiles = new Set<number>();\n\n if (ts.tiles) {\n for (const tile of ts.tiles) {\n const props = parseProperties(tile.properties);\n if (Object.keys(props).length > 0) {\n tileProperties.set(tile.id, props);\n }\n // Mark as solid if it has a \"collision\" or \"solid\" property, or type/class is \"solid\"\n const tileType = tile.type ?? tile.class ?? '';\n if (tileType === 'solid' || props.solid === true || props.collision === true) {\n solidTiles.add(tile.id);\n }\n }\n }\n\n const ref: TilesetRef = {\n firstGid: ts.firstgid,\n name: ts.name,\n tileWidth: ts.tilewidth,\n tileHeight: ts.tileheight,\n columns: ts.columns,\n tileCount: ts.tilecount,\n image: ts.image,\n imageWidth: ts.imagewidth,\n imageHeight: ts.imageheight,\n tileProperties,\n solidTiles,\n };\n map.tilesets.push(ref);\n }\n\n // Sort tilesets by firstGid\n map.tilesets.sort((a, b) => a.firstGid - b.firstGid);\n\n // Parse layers\n for (const layer of data.layers) {\n map.layers.push(parseLayer(layer));\n }\n\n return map;\n}\n\nfunction parseLayer(layer: TiledLayer): MapLayer {\n if (layer.type === 'tilelayer') return parseTileLayer(layer);\n if (layer.type === 'objectgroup') return parseObjectLayer(layer);\n const l = layer as { type: string; name?: string };\n throw new TilemapParseError(\n `parseTiled: layer \"${l.name ?? ''}\" has unsupported type \"${l.type}\". Only tilelayer and objectgroup are supported — flatten group layers and remove image layers before export.`,\n );\n}\n\nfunction parseTileLayer(layer: TiledTileLayer): TileLayer {\n if (\n (layer.encoding !== undefined && layer.encoding !== 'csv') ||\n layer.compression !== undefined ||\n layer.chunks !== undefined\n ) {\n throw new TilemapParseError(\n 'parseTiled: base64/compressed/chunked (infinite) layer data is not supported. In Tiled export options set Tile Layer Format to \"CSV\".',\n );\n }\n if (typeof layer.data === 'string') {\n throw new TilemapParseError(\n 'parseTiled: base64/compressed/chunked (infinite) layer data is not supported. In Tiled export options set Tile Layer Format to \"CSV\".',\n );\n }\n // layer.data is number[] here — Uint32Array.from preserves flip-bit GIDs\n // (values up to 0xffffffff), unlike a Float32Array's 24-bit mantissa.\n return {\n type: 'tile',\n name: layer.name,\n width: layer.width,\n height: layer.height,\n tiles: Uint32Array.from(layer.data),\n visible: layer.visible,\n opacity: layer.opacity,\n offsetX: layer.offsetx ?? 0,\n offsetY: layer.offsety ?? 0,\n properties: parseProperties(layer.properties),\n };\n}\n\nfunction parseObjectLayer(layer: TiledObjectLayer): ObjectLayer {\n const objects: MapObject[] = layer.objects.map((obj) => ({\n id: obj.id,\n name: obj.name,\n type: obj.type ?? obj.class ?? '',\n x: obj.x,\n y: obj.y,\n width: obj.width,\n height: obj.height,\n rotation: obj.rotation,\n properties: parseProperties(obj.properties),\n }));\n\n return {\n type: 'object',\n name: layer.name,\n objects,\n visible: layer.visible,\n opacity: layer.opacity,\n properties: parseProperties(layer.properties),\n };\n}\n","import type { AABBShape } from '@flare-engine/physics';\nimport { AABB } from '@flare-engine/physics';\nimport type { TileLayer, TilemapData, TilesetRef } from './tilemap-data.js';\nimport { GID_FLIP_MASK, getTilesetForGid } from './tilemap-data.js';\n\n/** A collision body extracted from a solid tile. */\nexport interface TileCollider {\n /** World position of the tile center. */\n x: number;\n y: number;\n /** AABB collision shape. */\n shape: AABBShape;\n /** Grid column. */\n col: number;\n /** Grid row. */\n row: number;\n /** The tile GID (flip bits stripped — AABB is symmetric, downstream lookups want the real id). */\n gid: number;\n}\n\n/**\n * Extract collision shapes from solid tiles in a tilemap.\n * A tile is considered solid if its tileset marks the local tile ID as solid.\n *\n * @param map The parsed tilemap data.\n * @param layerName Optional: only extract from this layer. If omitted, extracts from all tile layers.\n * @returns Array of TileCollider bodies.\n */\nexport function extractColliders(map: TilemapData, layerName?: string): TileCollider[] {\n const colliders: TileCollider[] = [];\n const tw = map.tileWidth;\n const th = map.tileHeight;\n\n for (const layer of map.layers) {\n if (layer.type !== 'tile') continue;\n if (layerName !== undefined && layer.name !== layerName) continue;\n\n extractFromLayer(layer, map.tilesets, tw, th, colliders);\n }\n\n return colliders;\n}\n\nfunction extractFromLayer(\n layer: TileLayer,\n tilesets: TilesetRef[],\n tw: number,\n th: number,\n out: TileCollider[],\n): void {\n for (let row = 0; row < layer.height; row++) {\n for (let col = 0; col < layer.width; col++) {\n const gid = layer.tiles[row * layer.width + col] ?? 0;\n if (gid === 0) continue;\n\n const tileset = getTilesetForGid(tilesets, gid);\n if (!tileset) continue;\n\n const localId = (gid & GID_FLIP_MASK) - tileset.firstGid;\n if (!tileset.solidTiles.has(localId)) continue;\n\n out.push({\n x: col * tw + tw * 0.5 + layer.offsetX,\n y: row * th + th * 0.5 + layer.offsetY,\n shape: AABB(tw, th),\n col,\n row,\n gid: gid & GID_FLIP_MASK,\n });\n }\n }\n}\n","import type { SkImageLike } from '@flare-engine/assets';\nimport type { Rect } from '@flare-engine/math';\nimport type { Camera2D } from '@flare-engine/render';\nimport { SpriteBatch } from '@flare-engine/render';\nimport type { TileLayer, TilemapData } from './tilemap-data.js';\nimport { getTileAt, getTileSourceRectInto, getTilesetForGid } from './tilemap-data.js';\n\n/**\n * TilemapRenderer — draws a tilemap with viewport culling.\n * Only tiles visible to the camera are submitted to the SpriteBatch.\n */\nexport class TilemapRenderer {\n /** The tilemap data to render. */\n readonly map: TilemapData;\n\n /** SpriteBatch used for batched tile rendering. */\n readonly batch: SpriteBatch;\n\n /** Map from tileset name → SkImage. Set via setTilesetImage(). */\n private _images = new Map<string, SkImageLike>();\n\n /** Reusable bounds rect — avoids per-frame allocation from camera.getBounds(). */\n private _boundsBuf: Rect = { x: 0, y: 0, width: 0, height: 0 };\n\n /** Reusable source rect — avoids a per-tile allocation from getTileSourceRect. */\n private _srcBuf: Rect = { x: 0, y: 0, width: 0, height: 0 };\n\n constructor(map: TilemapData) {\n this.map = map;\n this.batch = new SpriteBatch();\n }\n\n /** Associate a loaded image with a tileset by name. */\n setTilesetImage(tilesetName: string, image: SkImageLike): void {\n this._images.set(tilesetName, image);\n }\n\n /**\n * Queue visible tile layers into a caller-owned `batch` using the camera for\n * culling. Does NOT flush — the caller owns the single flush so tiles z-order\n * under sprites. Zero-alloc: reuses the internal bounds buffer.\n */\n drawInto(camera: Camera2D, batch: SpriteBatch): void {\n const bounds = camera.getBoundsInto(this._boundsBuf);\n const tw = this.map.tileWidth;\n const th = this.map.tileHeight;\n\n for (const layer of this.map.layers) {\n if (layer.type !== 'tile' || !layer.visible) continue;\n this._drawTileLayer(layer, bounds.x, bounds.y, bounds.width, bounds.height, tw, th, batch);\n }\n }\n\n /**\n * Draw visible tile layers using the camera for culling.\n * Call `flush` on a callback to issue the actual draw calls.\n * Delegates to `drawInto` so culling and queuing logic live in one place.\n */\n draw(camera: Camera2D, flush: (batch: SpriteBatch) => void): void {\n this.drawInto(camera, this.batch);\n flush(this.batch);\n }\n\n // Flip rendering transforms (horizontal/vertical/diagonal) are a deferred\n // limitation — render-flip support is post-flip M10. Tileset resolution and\n // collider extraction are correct for flipped GIDs as of B8.\n private _drawTileLayer(\n layer: TileLayer,\n viewX: number,\n viewY: number,\n viewW: number,\n viewH: number,\n tw: number,\n th: number,\n batch: SpriteBatch,\n ): void {\n const offsetX = layer.offsetX;\n const offsetY = layer.offsetY;\n\n // Calculate visible tile range (clamped to layer bounds)\n const startCol = Math.max(0, Math.floor((viewX - offsetX) / tw));\n const startRow = Math.max(0, Math.floor((viewY - offsetY) / th));\n const endCol = Math.min(layer.width - 1, Math.floor((viewX - offsetX + viewW) / tw));\n const endRow = Math.min(layer.height - 1, Math.floor((viewY - offsetY + viewH) / th));\n\n for (let row = startRow; row <= endRow; row++) {\n for (let col = startCol; col <= endCol; col++) {\n const gid = getTileAt(layer, col, row);\n if (gid === 0) continue;\n\n const tileset = getTilesetForGid(this.map.tilesets, gid);\n if (!tileset) continue;\n\n const image = this._images.get(tileset.name);\n if (!image) continue;\n\n // Strips flip bits; writes into the reusable buffer, no per-tile allocation.\n const src = getTileSourceRectInto(tileset, gid, this._srcBuf);\n const dstX = col * tw + offsetX;\n const dstY = row * th + offsetY;\n\n batch.drawRaw(image, src.x, src.y, src.width, src.height, dstX, dstY, tw, th);\n }\n }\n }\n}\n"],"mappings":";;;;;AACA,IAAa,oBAAb,cAAuC,MAAM;CAC3C,YAAY,SAAiB;EAC3B,MAAM,OAAO;EACb,KAAK,OAAO;CACd;AACF;;;;ACHA,MAAa,gBAAgB;AAE7B,MAAM,SAAS;AACf,MAAM,SAAS;AACf,MAAM,SAAS;;AAUf,SAAgB,cAAc,KAAqB;CACjD,OAAO,MAAM;AACf;;;;;;AAOA,SAAgB,eAAe,KAA4B;CACzD,OAAO;EACL,aAAa,MAAM,YAAY;EAC/B,WAAW,MAAM,YAAY;EAC7B,WAAW,MAAM,YAAY;CAC/B;AACF;;AAmHA,SAAgB,kBACd,OACA,QACA,WACA,YACa;CACb,OAAO;EACL;EACA;EACA;EACA;EACA,QAAQ,CAAC;EACT,UAAU,CAAC;EACX,YAAY,CAAC;CACf;AACF;;AAGA,SAAgB,UAAU,OAAkB,KAAa,KAAqB;CAC5E,IAAI,MAAM,KAAK,OAAO,MAAM,SAAS,MAAM,KAAK,OAAO,MAAM,QAAQ,OAAO;CAI5E,OAAO,MAAM,MAAM,MAAM,MAAM,QAAQ,QAAQ;AACjD;;AAGA,SAAgB,iBAAiB,UAAwB,KAAqC;CAC5F,MAAM,KAAK,MAAM;CAEjB,IAAI;CACJ,KAAK,MAAM,MAAM,UACf,IAAI,GAAG,YAAY,IACjB,SAAS;MAET;CAGJ,OAAO;AACT;;AAGA,SAAgB,sBAAsB,SAAqB,KAAa,KAAiB;CACvF,MAAM,WAAW,MAAM,iBAAiB,QAAQ;CAChD,MAAM,MAAM,UAAU,QAAQ;CAC9B,MAAM,MAAM,KAAK,MAAM,UAAU,QAAQ,OAAO;CAChD,IAAI,IAAI,MAAM,QAAQ;CACtB,IAAI,IAAI,MAAM,QAAQ;CACtB,IAAI,QAAQ,QAAQ;CACpB,I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.ts","../src/tilemap-collider.ts","../src/tilemap-renderer.ts"],"sourcesContent":["/** Thrown by parseTiled/parseLDtk when a map uses an unsupported format or feature. */\nexport class TilemapParseError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'TilemapParseError';\n }\n}\n","import type { Rect } from '@flare-engine/math';\n\n/** Low 29 bits of a Tiled GID — Tiled stores flip state in the high 3 bits. */\nexport const GID_FLIP_MASK = 0x1fffffff;\n\nconst FLIP_H = 0x80000000;\nconst FLIP_V = 0x40000000;\nconst FLIP_D = 0x20000000;\n\n/** Flip state encoded in the high bits of a Tiled GID. */\nexport interface TileFlipFlags {\n horizontal: boolean;\n vertical: boolean;\n diagonal: boolean;\n}\n\n/** Strip the Tiled flip bits from a raw GID, returning the real global tile id. */\nexport function stripGidFlags(gid: number): number {\n return gid & GID_FLIP_MASK;\n}\n\n/**\n * Decode the Tiled flip bits encoded in the high bits of a raw GID.\n * Note: `gid & 0x80000000` yields a negative Int32 when the bit is set;\n * compare with `!== 0`, not `> 0`.\n */\nexport function decodeGidFlags(gid: number): TileFlipFlags {\n return {\n horizontal: (gid & FLIP_H) !== 0,\n vertical: (gid & FLIP_V) !== 0,\n diagonal: (gid & FLIP_D) !== 0,\n };\n}\n\n/** A layer of tiles in a grid. */\nexport interface TileLayer {\n readonly type: 'tile';\n /** Layer name. */\n name: string;\n /** Grid width in tiles. */\n width: number;\n /** Grid height in tiles. */\n height: number;\n /**\n * Flat array of tile GIDs (row-major, length = width * height). `Uint32Array`,\n * not `Float32Array` — a 24-bit mantissa cannot hold Tiled's flip-bit GIDs\n * (`0x80000000` and up). This is a type decision for bulk numeric data per the\n * repo convention, not a measured perf change.\n *\n * `readonly` like `SolidGrid.solid`: the array cannot be swapped out from under a\n * parsed map, but its cells stay writable (`layer.tiles[i] = gid`).\n */\n readonly tiles: Uint32Array;\n /** Visibility flag. */\n visible: boolean;\n /** Opacity (0–1). */\n opacity: number;\n /** Layer offset in pixels. */\n offsetX: number;\n offsetY: number;\n /** Custom properties. */\n properties: Record<string, unknown>;\n}\n\n/** An object in an object layer. */\nexport interface MapObject {\n /** Object ID. */\n id: number;\n /** Object name. */\n name: string;\n /** Object type/class. */\n type: string;\n /** Position in pixels. */\n x: number;\n y: number;\n /** Size in pixels. */\n width: number;\n height: number;\n /** Rotation in degrees. */\n rotation: number;\n /** Custom properties. */\n properties: Record<string, unknown>;\n}\n\n/** A layer of objects. */\nexport interface ObjectLayer {\n readonly type: 'object';\n /** Layer name. */\n name: string;\n /** Objects in the layer. */\n objects: MapObject[];\n /** Visibility flag. */\n visible: boolean;\n /** Opacity (0–1). */\n opacity: number;\n /** Custom properties. */\n properties: Record<string, unknown>;\n}\n\n/** Union of layer types. */\nexport type MapLayer = TileLayer | ObjectLayer;\n\n/** Information about a tileset used in the map. */\nexport interface TilesetRef {\n /** First GID in this tileset. */\n firstGid: number;\n /** Tileset name. */\n name: string;\n /** Tile width in pixels. */\n tileWidth: number;\n /** Tile height in pixels. */\n tileHeight: number;\n /** Number of columns in the tileset image. */\n columns: number;\n /** Total tile count. */\n tileCount: number;\n /** Image source path (may need resolving). */\n image: string;\n /** Image width in pixels. */\n imageWidth: number;\n /** Image height in pixels. */\n imageHeight: number;\n /** Per-tile properties (indexed by local tile ID). */\n tileProperties: Map<number, Record<string, unknown>>;\n /** Tile IDs marked as solid/collision. */\n solidTiles: Set<number>;\n}\n\n/** Complete parsed tilemap data — format-independent. */\nexport interface TilemapData {\n /** Map width in tiles. */\n width: number;\n /** Map height in tiles. */\n height: number;\n /** Tile width in pixels. */\n tileWidth: number;\n /** Tile height in pixels. */\n tileHeight: number;\n /** All layers in order. */\n layers: MapLayer[];\n /** Tilesets referenced by this map. */\n tilesets: TilesetRef[];\n /** Custom map properties. */\n properties: Record<string, unknown>;\n}\n\n/** Create an empty TilemapData. */\nexport function createTilemapData(\n width: number,\n height: number,\n tileWidth: number,\n tileHeight: number,\n): TilemapData {\n return {\n width,\n height,\n tileWidth,\n tileHeight,\n layers: [],\n tilesets: [],\n properties: {},\n };\n}\n\n/** Get a tile GID at a grid position from a tile layer. Returns 0 if out of bounds. */\nexport function getTileAt(layer: TileLayer, col: number, row: number): number {\n if (col < 0 || col >= layer.width || row < 0 || row >= layer.height) return 0;\n // The `?? 0` is unreachable at runtime (the bounds check above guarantees an\n // in-range index into a hole-free Uint32Array) — it satisfies noUncheckedIndexedAccess,\n // which types every typed-array index read as `number | undefined`.\n return layer.tiles[row * layer.width + col] ?? 0;\n}\n\n/** Get the tileset that owns a given GID. Handles Tiled flip bits in the high bits. */\nexport function getTilesetForGid(tilesets: TilesetRef[], gid: number): TilesetRef | undefined {\n const id = gid & GID_FLIP_MASK;\n // Tilesets are ordered by firstGid; find the last one where firstGid <= id\n let result: TilesetRef | undefined;\n for (const ts of tilesets) {\n if (ts.firstGid <= id) {\n result = ts;\n } else {\n break;\n }\n }\n return result;\n}\n\n/** Compute the source rect in a tileset image for a given GID into `out`. Strips Tiled flip bits. Zero-alloc. */\nexport function getTileSourceRectInto(tileset: TilesetRef, gid: number, out: Rect): Rect {\n const localId = (gid & GID_FLIP_MASK) - tileset.firstGid;\n const col = localId % tileset.columns;\n const row = Math.floor(localId / tileset.columns);\n out.x = col * tileset.tileWidth;\n out.y = row * tileset.tileHeight;\n out.width = tileset.tileWidth;\n out.height = tileset.tileHeight;\n return out;\n}\n\n/** Compute the source rect in a tileset image for a given GID. Strips Tiled flip bits. */\nexport function getTileSourceRect(tileset: TilesetRef, gid: number): Rect {\n return getTileSourceRectInto(tileset, gid, { x: 0, y: 0, width: 0, height: 0 });\n}\n","import { TilemapParseError } from './parse-error.js';\nimport type { MapObject, ObjectLayer, TileLayer, TilemapData, TilesetRef } from './tilemap-data.js';\nimport { createTilemapData } from './tilemap-data.js';\n\n// ----- LDtk JSON types -----\n\ninterface LDtkFieldInstance {\n __identifier: string;\n __value: unknown;\n __type: string;\n}\n\ninterface LDtkEntityInstance {\n __identifier: string;\n __grid: [number, number];\n __pivot: [number, number];\n __tile?: { x: number; y: number; w: number; h: number };\n iid: string;\n width: number;\n height: number;\n px: [number, number];\n fieldInstances: LDtkFieldInstance[];\n}\n\ninterface LDtkTileInstance {\n px: [number, number];\n src: [number, number];\n f: number; // flip flags\n t: number; // tile ID\n}\n\ninterface LDtkLayerInstance {\n __identifier: string;\n __type: string;\n __cWid: number;\n __cHei: number;\n __gridSize: number;\n __tilesetDefUid?: number;\n __tilesetRelPath?: string;\n visible: boolean;\n __opacity: number;\n intGridCsv?: number[];\n // Real LDtk output always emits both arrays on every layer instance — only\n // one is ever populated per __type (an AutoLayer's gridTiles is always []).\n // Required (not optional) so a fixture omitting the unused one, as every\n // fixture here did before F057, cannot pass this module's own types.\n gridTiles: LDtkTileInstance[];\n autoLayerTiles: LDtkTileInstance[];\n entityInstances?: LDtkEntityInstance[];\n}\n\ninterface LDtkTilesetDef {\n uid: number;\n identifier: string;\n relPath: string;\n pxWid: number;\n pxHei: number;\n tileGridSize: number;\n __cWid: number;\n __cHei: number;\n}\n\ninterface LDtkLevel {\n identifier: string;\n uid: number;\n pxWid: number;\n pxHei: number;\n worldX: number;\n worldY: number;\n layerInstances?: LDtkLayerInstance[];\n fieldInstances?: LDtkFieldInstance[];\n}\n\ninterface LDtkJSON {\n defaultGridSize: number;\n externalLevels?: boolean;\n defs: {\n tilesets: LDtkTilesetDef[];\n };\n levels: LDtkLevel[];\n}\n\nexport interface ParseLDtkOptions {\n /** Predicate deciding whether an IntGrid value marks a solid cell. Default: value > 0. */\n intGridSolid?: (value: number) => boolean;\n}\n\nexport interface LDtkEntity {\n /** LDtk entity identifier (its type, e.g. \"Player\") — the key you switch on to decide what to spawn. */\n id: string;\n /** Entity position in pixels (LDtk px, pivot-adjusted per the parser convention). */\n x: number;\n y: number;\n /** Entity box size in pixels. */\n width: number;\n height: number;\n /** Custom field instances, keyed by field identifier. */\n fields: Record<string, unknown>;\n}\n\n/**\n * Extract every LDtk entity from a parsed map as a flat, spawn-ready list —\n * the LDtk-entity → ECS spawn convention. Walks all object layers; tile layers are skipped.\n */\nexport function parseLDtkEntities(map: TilemapData): LDtkEntity[] {\n const entities: LDtkEntity[] = [];\n for (const layer of map.layers) {\n if (layer.type !== 'object') continue;\n for (const obj of layer.objects) {\n entities.push({\n id: obj.type,\n x: obj.x,\n y: obj.y,\n width: obj.width,\n height: obj.height,\n fields: obj.properties,\n });\n }\n }\n return entities;\n}\n\n/**\n * Parse an LDtk JSON project into an array of TilemapData (one per level).\n * Returns all levels with their tile and entity layers.\n * Throws TilemapParseError for unsupported formats (externalLevels, invalid input).\n */\nexport function parseLDtk(json: unknown, options: ParseLDtkOptions = {}): TilemapData[] {\n if (\n !json ||\n typeof json !== 'object' ||\n !Array.isArray((json as Record<string, unknown>).levels) ||\n !(json as Record<string, unknown>).defs ||\n !Array.isArray(((json as Record<string, unknown>).defs as Record<string, unknown>).tilesets)\n ) {\n throw new TilemapParseError(\n 'parseLDtk: input is not an LDtk project JSON (missing defs.tilesets or levels).',\n );\n }\n\n const data = json as LDtkJSON;\n\n if (data.externalLevels === true) {\n throw new TilemapParseError(\n 'parseLDtk: projects with \"Save levels to separate files\" (externalLevels) are not supported. Disable it in LDtk ▸ Project settings and re-save.',\n );\n }\n\n const isSolid = options.intGridSolid ?? ((v) => v > 0);\n\n const tilesetDefs = new Map<number, LDtkTilesetDef>();\n for (const ts of data.defs.tilesets) {\n tilesetDefs.set(ts.uid, ts);\n }\n\n const results: TilemapData[] = [];\n\n for (const level of data.levels) {\n const gridSize = data.defaultGridSize;\n const mapWidth = Math.ceil(level.pxWid / gridSize);\n const mapHeight = Math.ceil(level.pxHei / gridSize);\n const map = createTilemapData(mapWidth, mapHeight, gridSize, gridSize);\n\n if (level.fieldInstances) {\n for (const field of level.fieldInstances) {\n map.properties[field.__identifier] = field.__value;\n }\n }\n\n // Pass 1: collect tile-layer tileset uids, sort ascending, assign deterministic firstGids.\n // Tilesets must be sorted by firstGid (ascending) for getTilesetForGid's early-break.\n const firstGidByUid = new Map<number, number>();\n let nextFirstGid = 1;\n\n if (level.layerInstances) {\n const usedTileUids = new Set<number>();\n for (const layerInst of level.layerInstances) {\n if (\n (layerInst.__type === 'Tiles' || layerInst.__type === 'AutoLayer') &&\n layerInst.__tilesetDefUid !== undefined\n ) {\n usedTileUids.add(layerInst.__tilesetDefUid);\n }\n }\n\n const sortedUids = Array.from(usedTileUids).sort((a, b) => a - b);\n for (const uid of sortedUids) {\n const def = tilesetDefs.get(uid);\n if (!def) continue;\n const columns = def.__cWid;\n const tileCount = def.__cWid * def.__cHei;\n firstGidByUid.set(uid, nextFirstGid);\n const ref: TilesetRef = {\n firstGid: nextFirstGid,\n name: def.identifier,\n tileWidth: def.tileGridSize,\n tileHeight: def.tileGridSize,\n columns,\n tileCount,\n image: def.relPath,\n imageWidth: def.pxWid,\n imageHeight: def.pxHei,\n tileProperties: new Map(),\n solidTiles: new Set(),\n };\n map.tilesets.push(ref);\n nextFirstGid += tileCount;\n }\n }\n\n // Pass 2: parse layers in reverse order (LDtk stores top-first; emit bottom-first).\n if (level.layerInstances) {\n for (let i = level.layerInstances.length - 1; i >= 0; i--) {\n const layerInst = level.layerInstances[i]!;\n\n if (layerInst.__type === 'IntGrid') {\n // IntGrid layers are treated as collision grids; IntGrid layers that also\n // carry auto-render tiles keep collision only (visual auto-tiles are M4 scope).\n const csv = layerInst.intGridCsv;\n const cellCount = layerInst.__cWid * layerInst.__cHei;\n const tiles = new Uint32Array(cellCount);\n const intFirstGid = nextFirstGid;\n let maxLocal = 0;\n let hasNonZero = false;\n const solidSet = new Set<number>();\n\n if (csv) {\n for (let j = 0; j < csv.length; j++) {\n const v = csv[j] ?? 0;\n if (v > 0) {\n hasNonZero = true;\n const localId = v - 1;\n if (localId > maxLocal) maxLocal = localId;\n tiles[j] = intFirstGid + localId;\n if (isSolid(v)) solidSet.add(localId);\n }\n }\n }\n\n if (hasNonZero) {\n const tileCount = maxLocal + 1;\n map.tilesets.push({\n firstGid: intFirstGid,\n name: layerInst.__identifier,\n tileWidth: layerInst.__gridSize,\n tileHeight: layerInst.__gridSize,\n columns: tileCount,\n tileCount,\n image: '',\n imageWidth: 0,\n imageHeight: 0,\n tileProperties: new Map(),\n solidTiles: solidSet,\n });\n nextFirstGid += tileCount;\n }\n\n map.layers.push({\n type: 'tile',\n name: layerInst.__identifier,\n width: layerInst.__cWid,\n height: layerInst.__cHei,\n tiles,\n visible: layerInst.visible,\n opacity: layerInst.__opacity,\n offsetX: 0,\n offsetY: 0,\n properties: {},\n });\n } else if (layerInst.__type === 'Tiles' || layerInst.__type === 'AutoLayer') {\n const firstGid = firstGidByUid.get(layerInst.__tilesetDefUid ?? -1) ?? 1;\n map.layers.push(parseTilesLayer(layerInst, mapWidth, mapHeight, gridSize, firstGid));\n } else if (layerInst.__type === 'Entities') {\n map.layers.push(parseEntitiesLayer(layerInst));\n }\n }\n }\n\n results.push(map);\n }\n\n return results;\n}\n\nfunction parseTilesLayer(\n layer: LDtkLayerInstance,\n mapWidth: number,\n mapHeight: number,\n gridSize: number,\n firstGid: number,\n): TileLayer {\n const tiles = new Uint32Array(mapWidth * mapHeight);\n // An AutoLayer's tiles live in autoLayerTiles; its gridTiles is always [].\n // `gridTiles ?? autoLayerTiles` picked the empty gridTiles for every\n // AutoLayer, since `??` only falls through on null/undefined, never on `[]`\n // — select by __type instead, which is the field LDtk itself keys on.\n const tileInstances = layer.__type === 'AutoLayer' ? layer.autoLayerTiles : layer.gridTiles;\n\n for (const ti of tileInstances) {\n const col = Math.floor(ti.px[0] / gridSize);\n const row = Math.floor(ti.px[1] / gridSize);\n if (col >= 0 && col < mapWidth && row >= 0 && row < mapHeight) {\n tiles[row * mapWidth + col] = firstGid + ti.t;\n }\n }\n\n return {\n type: 'tile',\n name: layer.__identifier,\n width: mapWidth,\n height: mapHeight,\n tiles,\n visible: layer.visible,\n opacity: layer.__opacity,\n offsetX: 0,\n offsetY: 0,\n properties: {},\n };\n}\n\nfunction parseEntitiesLayer(layer: LDtkLayerInstance): ObjectLayer {\n const objects: MapObject[] = (layer.entityInstances ?? []).map((ent, idx) => {\n const props: Record<string, unknown> = {};\n for (const field of ent.fieldInstances) {\n props[field.__identifier] = field.__value;\n }\n return {\n id: idx + 1,\n name: ent.__identifier,\n type: ent.__identifier,\n x: ent.px[0],\n y: ent.px[1],\n width: ent.width,\n height: ent.height,\n rotation: 0,\n properties: props,\n };\n });\n\n return {\n type: 'object',\n name: layer.__identifier,\n objects,\n visible: layer.visible,\n opacity: layer.__opacity,\n properties: {},\n };\n}\n","import { TilemapParseError } from './parse-error.js';\nimport type {\n MapLayer,\n MapObject,\n ObjectLayer,\n TileLayer,\n TilemapData,\n TilesetRef,\n} from './tilemap-data.js';\nimport { createTilemapData } from './tilemap-data.js';\n\n// ----- Tiled JSON types (.tmj format) -----\n\ninterface TiledProperty {\n name: string;\n type: string;\n value: unknown;\n}\n\ninterface TiledTileLayer {\n type: 'tilelayer';\n name: string;\n width: number;\n height: number;\n data: number[] | string;\n encoding?: string;\n compression?: string;\n chunks?: unknown[];\n visible: boolean;\n opacity: number;\n offsetx?: number;\n offsety?: number;\n properties?: TiledProperty[];\n}\n\ninterface TiledObject {\n id: number;\n name: string;\n type?: string;\n class?: string;\n x: number;\n y: number;\n width: number;\n height: number;\n rotation: number;\n properties?: TiledProperty[];\n}\n\ninterface TiledObjectLayer {\n type: 'objectgroup';\n name: string;\n objects: TiledObject[];\n visible: boolean;\n opacity: number;\n properties?: TiledProperty[];\n}\n\ntype TiledLayer = TiledTileLayer | TiledObjectLayer;\n\ninterface TiledTile {\n id: number;\n properties?: TiledProperty[];\n type?: string;\n class?: string;\n}\n\ninterface TiledTileset {\n firstgid: number;\n name: string;\n tilewidth: number;\n tileheight: number;\n columns: number;\n tilecount: number;\n image: string;\n imagewidth: number;\n imageheight: number;\n tiles?: TiledTile[];\n properties?: TiledProperty[];\n source?: string;\n}\n\ninterface TiledMapJSON {\n width: number;\n height: number;\n tilewidth: number;\n tileheight: number;\n orientation: string;\n infinite?: boolean;\n layers: TiledLayer[];\n tilesets: TiledTileset[];\n properties?: TiledProperty[];\n}\n\n/** Convert Tiled properties array to a Record. */\nfunction parseProperties(props?: TiledProperty[]): Record<string, unknown> {\n if (!props || props.length === 0) return {};\n const result: Record<string, unknown> = {};\n for (const p of props) {\n result[p.name] = p.value;\n }\n return result;\n}\n\n/**\n * Parse a Tiled .tmj (JSON) map into TilemapData.\n * Supports orthogonal maps with CSV tile layers and object layers.\n * Throws TilemapParseError for unsupported formats (infinite, non-orthogonal,\n * external tilesets, base64/compressed/chunked layer data).\n */\nexport function parseTiled(json: unknown): TilemapData {\n if (\n !json ||\n typeof json !== 'object' ||\n typeof (json as Record<string, unknown>).width !== 'number' ||\n typeof (json as Record<string, unknown>).height !== 'number' ||\n !Array.isArray((json as Record<string, unknown>).layers) ||\n !Array.isArray((json as Record<string, unknown>).tilesets)\n ) {\n throw new TilemapParseError(\n 'parseTiled: input is not a Tiled map JSON (missing width/height/layers/tilesets).',\n );\n }\n\n const data = json as TiledMapJSON;\n\n if (data.infinite === true) {\n throw new TilemapParseError(\n 'parseTiled: infinite maps are not supported. In Tiled: Map ▸ Map Properties ▸ set \"Infinite\" to false, then re-export.',\n );\n }\n if (data.orientation && data.orientation !== 'orthogonal') {\n throw new TilemapParseError(\n `parseTiled: orientation \"${data.orientation}\" is not supported — only orthogonal maps are supported.`,\n );\n }\n\n const map = createTilemapData(data.width, data.height, data.tilewidth, data.tileheight);\n map.properties = parseProperties(data.properties);\n\n // Parse tilesets\n for (const ts of data.tilesets) {\n if (ts.source !== undefined) {\n throw new TilemapParseError(\n `parseTiled: external tileset \"${ts.source}\" is not supported. Embed tilesets on export (Tiled ▸ Map ▸ \"Embed tilesets\") or run it through \\`flare tiled-to-flare\\` (which embeds tilesets by default).`,\n );\n }\n\n const tileProperties = new Map<number, Record<string, unknown>>();\n const solidTiles = new Set<number>();\n\n if (ts.tiles) {\n for (const tile of ts.tiles) {\n const props = parseProperties(tile.properties);\n if (Object.keys(props).length > 0) {\n tileProperties.set(tile.id, props);\n }\n // Mark as solid if it has a \"collision\" or \"solid\" property, or type/class is \"solid\"\n const tileType = tile.type ?? tile.class ?? '';\n if (tileType === 'solid' || props.solid === true || props.collision === true) {\n solidTiles.add(tile.id);\n }\n }\n }\n\n const ref: TilesetRef = {\n firstGid: ts.firstgid,\n name: ts.name,\n tileWidth: ts.tilewidth,\n tileHeight: ts.tileheight,\n columns: ts.columns,\n tileCount: ts.tilecount,\n image: ts.image,\n imageWidth: ts.imagewidth,\n imageHeight: ts.imageheight,\n tileProperties,\n solidTiles,\n };\n map.tilesets.push(ref);\n }\n\n // Sort tilesets by firstGid\n map.tilesets.sort((a, b) => a.firstGid - b.firstGid);\n\n // Parse layers\n for (const layer of data.layers) {\n map.layers.push(parseLayer(layer));\n }\n\n return map;\n}\n\nfunction parseLayer(layer: TiledLayer): MapLayer {\n if (layer.type === 'tilelayer') return parseTileLayer(layer);\n if (layer.type === 'objectgroup') return parseObjectLayer(layer);\n const l = layer as { type: string; name?: string };\n throw new TilemapParseError(\n `parseTiled: layer \"${l.name ?? ''}\" has unsupported type \"${l.type}\". Only tilelayer and objectgroup are supported — flatten group layers and remove image layers before export.`,\n );\n}\n\nfunction parseTileLayer(layer: TiledTileLayer): TileLayer {\n if (\n (layer.encoding !== undefined && layer.encoding !== 'csv') ||\n layer.compression !== undefined ||\n layer.chunks !== undefined\n ) {\n throw new TilemapParseError(\n 'parseTiled: base64/compressed/chunked (infinite) layer data is not supported. In Tiled export options set Tile Layer Format to \"CSV\".',\n );\n }\n if (typeof layer.data === 'string') {\n throw new TilemapParseError(\n 'parseTiled: base64/compressed/chunked (infinite) layer data is not supported. In Tiled export options set Tile Layer Format to \"CSV\".',\n );\n }\n // layer.data is number[] here — Uint32Array.from preserves flip-bit GIDs\n // (values up to 0xffffffff), unlike a Float32Array's 24-bit mantissa.\n return {\n type: 'tile',\n name: layer.name,\n width: layer.width,\n height: layer.height,\n tiles: Uint32Array.from(layer.data),\n visible: layer.visible,\n opacity: layer.opacity,\n offsetX: layer.offsetx ?? 0,\n offsetY: layer.offsety ?? 0,\n properties: parseProperties(layer.properties),\n };\n}\n\nfunction parseObjectLayer(layer: TiledObjectLayer): ObjectLayer {\n const objects: MapObject[] = layer.objects.map((obj) => ({\n id: obj.id,\n name: obj.name,\n type: obj.type ?? obj.class ?? '',\n x: obj.x,\n y: obj.y,\n width: obj.width,\n height: obj.height,\n rotation: obj.rotation,\n properties: parseProperties(obj.properties),\n }));\n\n return {\n type: 'object',\n name: layer.name,\n objects,\n visible: layer.visible,\n opacity: layer.opacity,\n properties: parseProperties(layer.properties),\n };\n}\n","import type { AABBShape } from '@flare-engine/physics';\nimport { AABB } from '@flare-engine/physics';\nimport type { TileLayer, TilemapData, TilesetRef } from './tilemap-data.js';\nimport { GID_FLIP_MASK, getTilesetForGid } from './tilemap-data.js';\n\n/** A collision body extracted from a solid tile. */\nexport interface TileCollider {\n /** World position of the tile center. */\n x: number;\n y: number;\n /** AABB collision shape. */\n shape: AABBShape;\n /** Grid column. */\n col: number;\n /** Grid row. */\n row: number;\n /** The tile GID (flip bits stripped — AABB is symmetric, downstream lookups want the real id). */\n gid: number;\n}\n\n/**\n * Extract collision shapes from solid tiles in a tilemap.\n * A tile is considered solid if its tileset marks the local tile ID as solid.\n *\n * @param map The parsed tilemap data.\n * @param layerName Optional: only extract from this layer. If omitted, extracts from all tile layers.\n * @returns Array of TileCollider bodies.\n */\nexport function extractColliders(map: TilemapData, layerName?: string): TileCollider[] {\n const colliders: TileCollider[] = [];\n const tw = map.tileWidth;\n const th = map.tileHeight;\n\n for (const layer of map.layers) {\n if (layer.type !== 'tile') continue;\n if (layerName !== undefined && layer.name !== layerName) continue;\n\n extractFromLayer(layer, map.tilesets, tw, th, colliders);\n }\n\n return colliders;\n}\n\nfunction extractFromLayer(\n layer: TileLayer,\n tilesets: TilesetRef[],\n tw: number,\n th: number,\n out: TileCollider[],\n): void {\n for (let row = 0; row < layer.height; row++) {\n for (let col = 0; col < layer.width; col++) {\n const gid = layer.tiles[row * layer.width + col] ?? 0;\n if (gid === 0) continue;\n\n const tileset = getTilesetForGid(tilesets, gid);\n if (!tileset) continue;\n\n const localId = (gid & GID_FLIP_MASK) - tileset.firstGid;\n if (!tileset.solidTiles.has(localId)) continue;\n\n out.push({\n x: col * tw + tw * 0.5 + layer.offsetX,\n y: row * th + th * 0.5 + layer.offsetY,\n shape: AABB(tw, th),\n col,\n row,\n gid: gid & GID_FLIP_MASK,\n });\n }\n }\n}\n","import type { SkImageLike } from '@flare-engine/assets';\nimport type { Rect } from '@flare-engine/math';\nimport type { AnySpriteEffect, Camera2D } from '@flare-engine/render';\nimport { SpriteBatch } from '@flare-engine/render';\nimport type { TileLayer, TilemapData } from './tilemap-data.js';\nimport { getTileAt, getTileSourceRectInto, getTilesetForGid } from './tilemap-data.js';\n\n// Tiled GID flag bits (kept module-private; tilemap-data.ts owns the public mask).\nconst FLIP_H = 0x80000000;\nconst FLIP_V = 0x40000000;\nconst FLIP_D = 0x20000000;\nconst QUARTER_TURN = Math.PI / 2;\n\n/**\n * Per-draw options for `TilemapRenderer.drawInto` / `draw`.\n *\n * `effect` is set on every queued tile command. Batch runs key on the effect\n * by reference, so one shared instance (e.g. an ambient `tint()`) keeps every\n * tile — and any sprite drawn with the same instance — in a single run.\n * `alphaScale` multiplies each layer's own `opacity` (default 1).\n */\nexport interface TilemapDrawOptions {\n effect?: AnySpriteEffect;\n alphaScale?: number;\n}\n\n/**\n * TilemapRenderer — draws a tilemap with viewport culling.\n * Only tiles visible to the camera are submitted to the SpriteBatch.\n */\nexport class TilemapRenderer {\n /** The tilemap data to render. */\n readonly map: TilemapData;\n\n /** SpriteBatch used for batched tile rendering. */\n readonly batch: SpriteBatch;\n\n /** Map from tileset name → SkImage. Set via setTilesetImage(). */\n private _images = new Map<string, SkImageLike>();\n\n /** Reusable bounds rect — avoids per-frame allocation from camera.getBounds(). */\n private _boundsBuf: Rect = { x: 0, y: 0, width: 0, height: 0 };\n\n /** Reusable source rect — avoids a per-tile allocation from getTileSourceRect. */\n private _srcBuf: Rect = { x: 0, y: 0, width: 0, height: 0 };\n\n constructor(map: TilemapData) {\n this.map = map;\n this.batch = new SpriteBatch();\n }\n\n /** Associate a loaded image with a tileset by name. */\n setTilesetImage(tilesetName: string, image: SkImageLike): void {\n this._images.set(tilesetName, image);\n }\n\n /**\n * Queue visible tile layers into a caller-owned `batch` using the camera for\n * culling. Does NOT flush — the caller owns the single flush so tiles z-order\n * under sprites. Zero-alloc: reuses the internal bounds buffer.\n *\n * Each tile's `alpha` is `layer.opacity * opts.alphaScale`; `opts.effect`\n * is applied to every tile (see `TilemapDrawOptions`).\n */\n drawInto(camera: Camera2D, batch: SpriteBatch, opts?: TilemapDrawOptions): void {\n const bounds = camera.getBoundsInto(this._boundsBuf);\n const tw = this.map.tileWidth;\n const th = this.map.tileHeight;\n const effect = opts?.effect;\n const alphaScale = opts?.alphaScale ?? 1;\n\n for (const layer of this.map.layers) {\n if (layer.type !== 'tile' || !layer.visible) continue;\n this._drawTileLayer(\n layer,\n bounds.x,\n bounds.y,\n bounds.width,\n bounds.height,\n tw,\n th,\n batch,\n effect,\n layer.opacity * alphaScale,\n );\n }\n }\n\n /**\n * Draw visible tile layers using the camera for culling.\n * Call `flush` on a callback to issue the actual draw calls.\n * Delegates to `drawInto` so culling and queuing logic live in one place;\n * `opts` is threaded through unchanged.\n */\n draw(camera: Camera2D, flush: (batch: SpriteBatch) => void, opts?: TilemapDrawOptions): void {\n this.drawInto(camera, this.batch, opts);\n flush(this.batch);\n }\n\n // Tiled flip bits: H/V become the batch's flipX/flipY; the diagonal bit is a\n // quarter turn about the tile centre composed with the flip Tiled defines\n // (D+H = 90° CW, D+V = 90° CCW, D = flipY + CW, D+H+V = flipX + CW).\n // @flare-engine/render's flip draw path ignores `rotation` (see\n // SpriteDrawCommand.flipX), so D alone and D+H+V queue the right command\n // but draw without the turn until render composes the two.\n private _drawTileLayer(\n layer: TileLayer,\n viewX: number,\n viewY: number,\n viewW: number,\n viewH: number,\n tw: number,\n th: number,\n batch: SpriteBatch,\n effect: AnySpriteEffect | undefined,\n alpha: number,\n ): void {\n const offsetX = layer.offsetX;\n const offsetY = layer.offsetY;\n\n // Calculate visible tile range (clamped to layer bounds)\n const startCol = Math.max(0, Math.floor((viewX - offsetX) / tw));\n const startRow = Math.max(0, Math.floor((viewY - offsetY) / th));\n const endCol = Math.min(layer.width - 1, Math.floor((viewX - offsetX + viewW) / tw));\n const endRow = Math.min(layer.height - 1, Math.floor((viewY - offsetY + viewH) / th));\n\n for (let row = startRow; row <= endRow; row++) {\n for (let col = startCol; col <= endCol; col++) {\n const gid = getTileAt(layer, col, row);\n if (gid === 0) continue;\n\n const tileset = getTilesetForGid(this.map.tilesets, gid);\n if (!tileset) continue;\n\n const image = this._images.get(tileset.name);\n if (!image) continue;\n\n // Strips flip bits; writes into the reusable buffer, no per-tile allocation.\n const src = getTileSourceRectInto(tileset, gid, this._srcBuf);\n\n // Bit tests only — `gid & FLIP_H` is a negative Int32 when set, so compare to 0.\n const h = (gid & FLIP_H) !== 0;\n const v = (gid & FLIP_V) !== 0;\n const d = (gid & FLIP_D) !== 0;\n let flipX = h;\n let flipY = v;\n let rotation = 0;\n if (d) {\n rotation = !h && v ? -QUARTER_TURN : QUARTER_TURN;\n flipX = h && v;\n flipY = !h && !v;\n }\n\n // Centre anchor keeps a turned tile in its cell; the stored dstX/dstY\n // stay the cell's top-left. Positional slots — no per-tile object.\n batch.drawRaw(\n image,\n src.x,\n src.y,\n src.width,\n src.height,\n col * tw + offsetX + tw * 0.5,\n row * th + offsetY + th * 0.5,\n tw,\n th,\n effect,\n 0.5,\n 0.5,\n alpha,\n rotation,\n false,\n 'normal',\n flipX,\n flipY,\n );\n }\n }\n }\n}\n"],"mappings":";;;;;AACA,IAAa,oBAAb,cAAuC,MAAM;CAC3C,YAAY,SAAiB;EAC3B,MAAM,OAAO;EACb,KAAK,OAAO;CACd;AACF;;;ACHA,MAAa,gBAAgB;AAE7B,MAAMA,WAAS;AACf,M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ACA,UACA,OACA,UACA,OACA,KACF;EACF;CAEJ;AACF"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AABB } from "@flare-engine/physics";
|
|
2
2
|
import { SpriteBatch } from "@flare-engine/render";
|
|
3
|
-
|
|
3
|
+
// src/parse-error.ts
|
|
4
4
|
/** Thrown by parseTiled/parseLDtk when a map uses an unsupported format or feature. */
|
|
5
5
|
var TilemapParseError = class extends Error {
|
|
6
6
|
constructor(message) {
|
|
@@ -8,13 +8,12 @@ var TilemapParseError = class extends Error {
|
|
|
8
8
|
this.name = "TilemapParseError";
|
|
9
9
|
}
|
|
10
10
|
};
|
|
11
|
-
|
|
12
|
-
//#region src/tilemap-data.ts
|
|
11
|
+
// src/tilemap-data.ts
|
|
13
12
|
/** Low 29 bits of a Tiled GID — Tiled stores flip state in the high 3 bits. */
|
|
14
13
|
const GID_FLIP_MASK = 536870911;
|
|
15
|
-
const FLIP_H = 2147483648;
|
|
16
|
-
const FLIP_V = 1073741824;
|
|
17
|
-
const FLIP_D = 536870912;
|
|
14
|
+
const FLIP_H$1 = 2147483648;
|
|
15
|
+
const FLIP_V$1 = 1073741824;
|
|
16
|
+
const FLIP_D$1 = 536870912;
|
|
18
17
|
/** Strip the Tiled flip bits from a raw GID, returning the real global tile id. */
|
|
19
18
|
function stripGidFlags(gid) {
|
|
20
19
|
return gid & GID_FLIP_MASK;
|
|
@@ -26,9 +25,9 @@ function stripGidFlags(gid) {
|
|
|
26
25
|
*/
|
|
27
26
|
function decodeGidFlags(gid) {
|
|
28
27
|
return {
|
|
29
|
-
horizontal: (gid & FLIP_H) !== 0,
|
|
30
|
-
vertical: (gid & FLIP_V) !== 0,
|
|
31
|
-
diagonal: (gid & FLIP_D) !== 0
|
|
28
|
+
horizontal: (gid & FLIP_H$1) !== 0,
|
|
29
|
+
vertical: (gid & FLIP_V$1) !== 0,
|
|
30
|
+
diagonal: (gid & FLIP_D$1) !== 0
|
|
32
31
|
};
|
|
33
32
|
}
|
|
34
33
|
/** Create an empty TilemapData. */
|
|
@@ -76,8 +75,7 @@ function getTileSourceRect(tileset, gid) {
|
|
|
76
75
|
height: 0
|
|
77
76
|
});
|
|
78
77
|
}
|
|
79
|
-
|
|
80
|
-
//#region src/ldtk-parser.ts
|
|
78
|
+
// src/ldtk-parser.ts
|
|
81
79
|
/**
|
|
82
80
|
* Extract every LDtk entity from a parsed map as a flat, spawn-ready list —
|
|
83
81
|
* the LDtk-entity → ECS spawn convention. Walks all object layers; tile layers are skipped.
|
|
@@ -249,8 +247,7 @@ function parseEntitiesLayer(layer) {
|
|
|
249
247
|
properties: {}
|
|
250
248
|
};
|
|
251
249
|
}
|
|
252
|
-
|
|
253
|
-
//#region src/tiled-parser.ts
|
|
250
|
+
// src/tiled-parser.ts
|
|
254
251
|
/** Convert Tiled properties array to a Record. */
|
|
255
252
|
function parseProperties(props) {
|
|
256
253
|
if (!props || props.length === 0) return {};
|
|
@@ -342,8 +339,7 @@ function parseObjectLayer(layer) {
|
|
|
342
339
|
properties: parseProperties(layer.properties)
|
|
343
340
|
};
|
|
344
341
|
}
|
|
345
|
-
|
|
346
|
-
//#region src/tilemap-collider.ts
|
|
342
|
+
// src/tilemap-collider.ts
|
|
347
343
|
/**
|
|
348
344
|
* Extract collision shapes from solid tiles in a tilemap.
|
|
349
345
|
* A tile is considered solid if its tileset marks the local tile ID as solid.
|
|
@@ -381,8 +377,11 @@ function extractFromLayer(layer, tilesets, tw, th, out) {
|
|
|
381
377
|
});
|
|
382
378
|
}
|
|
383
379
|
}
|
|
384
|
-
|
|
385
|
-
|
|
380
|
+
// src/tilemap-renderer.ts
|
|
381
|
+
const FLIP_H = 2147483648;
|
|
382
|
+
const FLIP_V = 1073741824;
|
|
383
|
+
const FLIP_D = 536870912;
|
|
384
|
+
const QUARTER_TURN = Math.PI / 2;
|
|
386
385
|
/**
|
|
387
386
|
* TilemapRenderer — draws a tilemap with viewport culling.
|
|
388
387
|
* Only tiles visible to the camera are submitted to the SpriteBatch.
|
|
@@ -420,26 +419,32 @@ var TilemapRenderer = class {
|
|
|
420
419
|
* Queue visible tile layers into a caller-owned `batch` using the camera for
|
|
421
420
|
* culling. Does NOT flush — the caller owns the single flush so tiles z-order
|
|
422
421
|
* under sprites. Zero-alloc: reuses the internal bounds buffer.
|
|
422
|
+
*
|
|
423
|
+
* Each tile's `alpha` is `layer.opacity * opts.alphaScale`; `opts.effect`
|
|
424
|
+
* is applied to every tile (see `TilemapDrawOptions`).
|
|
423
425
|
*/
|
|
424
|
-
drawInto(camera, batch) {
|
|
426
|
+
drawInto(camera, batch, opts) {
|
|
425
427
|
const bounds = camera.getBoundsInto(this._boundsBuf);
|
|
426
428
|
const tw = this.map.tileWidth;
|
|
427
429
|
const th = this.map.tileHeight;
|
|
430
|
+
const effect = opts?.effect;
|
|
431
|
+
const alphaScale = opts?.alphaScale ?? 1;
|
|
428
432
|
for (const layer of this.map.layers) {
|
|
429
433
|
if (layer.type !== "tile" || !layer.visible) continue;
|
|
430
|
-
this._drawTileLayer(layer, bounds.x, bounds.y, bounds.width, bounds.height, tw, th, batch);
|
|
434
|
+
this._drawTileLayer(layer, bounds.x, bounds.y, bounds.width, bounds.height, tw, th, batch, effect, layer.opacity * alphaScale);
|
|
431
435
|
}
|
|
432
436
|
}
|
|
433
437
|
/**
|
|
434
438
|
* Draw visible tile layers using the camera for culling.
|
|
435
439
|
* Call `flush` on a callback to issue the actual draw calls.
|
|
436
|
-
* Delegates to `drawInto` so culling and queuing logic live in one place
|
|
440
|
+
* Delegates to `drawInto` so culling and queuing logic live in one place;
|
|
441
|
+
* `opts` is threaded through unchanged.
|
|
437
442
|
*/
|
|
438
|
-
draw(camera, flush) {
|
|
439
|
-
this.drawInto(camera, this.batch);
|
|
443
|
+
draw(camera, flush, opts) {
|
|
444
|
+
this.drawInto(camera, this.batch, opts);
|
|
440
445
|
flush(this.batch);
|
|
441
446
|
}
|
|
442
|
-
_drawTileLayer(layer, viewX, viewY, viewW, viewH, tw, th, batch) {
|
|
447
|
+
_drawTileLayer(layer, viewX, viewY, viewW, viewH, tw, th, batch, effect, alpha) {
|
|
443
448
|
const offsetX = layer.offsetX;
|
|
444
449
|
const offsetY = layer.offsetY;
|
|
445
450
|
const startCol = Math.max(0, Math.floor((viewX - offsetX) / tw));
|
|
@@ -454,13 +459,21 @@ var TilemapRenderer = class {
|
|
|
454
459
|
const image = this._images.get(tileset.name);
|
|
455
460
|
if (!image) continue;
|
|
456
461
|
const src = getTileSourceRectInto(tileset, gid, this._srcBuf);
|
|
457
|
-
const
|
|
458
|
-
const
|
|
459
|
-
|
|
462
|
+
const h = (gid & FLIP_H) !== 0;
|
|
463
|
+
const v = (gid & FLIP_V) !== 0;
|
|
464
|
+
const d = (gid & FLIP_D) !== 0;
|
|
465
|
+
let flipX = h;
|
|
466
|
+
let flipY = v;
|
|
467
|
+
let rotation = 0;
|
|
468
|
+
if (d) {
|
|
469
|
+
rotation = !h && v ? -QUARTER_TURN : QUARTER_TURN;
|
|
470
|
+
flipX = h && v;
|
|
471
|
+
flipY = !h && !v;
|
|
472
|
+
}
|
|
473
|
+
batch.drawRaw(image, src.x, src.y, src.width, src.height, col * tw + offsetX + tw * .5, row * th + offsetY + th * .5, tw, th, effect, .5, .5, alpha, rotation, false, "normal", flipX, flipY);
|
|
460
474
|
}
|
|
461
475
|
}
|
|
462
476
|
};
|
|
463
|
-
//#endregion
|
|
464
477
|
export { GID_FLIP_MASK, TilemapParseError, TilemapRenderer, createTilemapData, decodeGidFlags, extractColliders, getTileAt, getTileSourceRect, getTileSourceRectInto, getTilesetForGid, parseLDtk, parseLDtkEntities, parseTiled, stripGidFlags };
|
|
465
478
|
|
|
466
479
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/parse-error.ts","../src/tilemap-data.ts","../src/ldtk-parser.ts","../src/tiled-parser.ts","../src/tilemap-collider.ts","../src/tilemap-renderer.ts"],"sourcesContent":["/** Thrown by parseTiled/parseLDtk when a map uses an unsupported format or feature. */\nexport class TilemapParseError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'TilemapParseError';\n }\n}\n","import type { Rect } from '@flare-engine/math';\n\n/** Low 29 bits of a Tiled GID — Tiled stores flip state in the high 3 bits. */\nexport const GID_FLIP_MASK = 0x1fffffff;\n\nconst FLIP_H = 0x80000000;\nconst FLIP_V = 0x40000000;\nconst FLIP_D = 0x20000000;\n\n/** Flip state encoded in the high bits of a Tiled GID. */\nexport interface TileFlipFlags {\n horizontal: boolean;\n vertical: boolean;\n diagonal: boolean;\n}\n\n/** Strip the Tiled flip bits from a raw GID, returning the real global tile id. */\nexport function stripGidFlags(gid: number): number {\n return gid & GID_FLIP_MASK;\n}\n\n/**\n * Decode the Tiled flip bits encoded in the high bits of a raw GID.\n * Note: `gid & 0x80000000` yields a negative Int32 when the bit is set;\n * compare with `!== 0`, not `> 0`.\n */\nexport function decodeGidFlags(gid: number): TileFlipFlags {\n return {\n horizontal: (gid & FLIP_H) !== 0,\n vertical: (gid & FLIP_V) !== 0,\n diagonal: (gid & FLIP_D) !== 0,\n };\n}\n\n/** A layer of tiles in a grid. */\nexport interface TileLayer {\n readonly type: 'tile';\n /** Layer name. */\n name: string;\n /** Grid width in tiles. */\n width: number;\n /** Grid height in tiles. */\n height: number;\n /**\n * Flat array of tile GIDs (row-major, length = width * height). `Uint32Array`,\n * not `Float32Array` — a 24-bit mantissa cannot hold Tiled's flip-bit GIDs\n * (`0x80000000` and up). This is a type decision for bulk numeric data per the\n * repo convention, not a measured perf change.\n *\n * `readonly` like `SolidGrid.solid`: the array cannot be swapped out from under a\n * parsed map, but its cells stay writable (`layer.tiles[i] = gid`).\n */\n readonly tiles: Uint32Array;\n /** Visibility flag. */\n visible: boolean;\n /** Opacity (0–1). */\n opacity: number;\n /** Layer offset in pixels. */\n offsetX: number;\n offsetY: number;\n /** Custom properties. */\n properties: Record<string, unknown>;\n}\n\n/** An object in an object layer. */\nexport interface MapObject {\n /** Object ID. */\n id: number;\n /** Object name. */\n name: string;\n /** Object type/class. */\n type: string;\n /** Position in pixels. */\n x: number;\n y: number;\n /** Size in pixels. */\n width: number;\n height: number;\n /** Rotation in degrees. */\n rotation: number;\n /** Custom properties. */\n properties: Record<string, unknown>;\n}\n\n/** A layer of objects. */\nexport interface ObjectLayer {\n readonly type: 'object';\n /** Layer name. */\n name: string;\n /** Objects in the layer. */\n objects: MapObject[];\n /** Visibility flag. */\n visible: boolean;\n /** Opacity (0–1). */\n opacity: number;\n /** Custom properties. */\n properties: Record<string, unknown>;\n}\n\n/** Union of layer types. */\nexport type MapLayer = TileLayer | ObjectLayer;\n\n/** Information about a tileset used in the map. */\nexport interface TilesetRef {\n /** First GID in this tileset. */\n firstGid: number;\n /** Tileset name. */\n name: string;\n /** Tile width in pixels. */\n tileWidth: number;\n /** Tile height in pixels. */\n tileHeight: number;\n /** Number of columns in the tileset image. */\n columns: number;\n /** Total tile count. */\n tileCount: number;\n /** Image source path (may need resolving). */\n image: string;\n /** Image width in pixels. */\n imageWidth: number;\n /** Image height in pixels. */\n imageHeight: number;\n /** Per-tile properties (indexed by local tile ID). */\n tileProperties: Map<number, Record<string, unknown>>;\n /** Tile IDs marked as solid/collision. */\n solidTiles: Set<number>;\n}\n\n/** Complete parsed tilemap data — format-independent. */\nexport interface TilemapData {\n /** Map width in tiles. */\n width: number;\n /** Map height in tiles. */\n height: number;\n /** Tile width in pixels. */\n tileWidth: number;\n /** Tile height in pixels. */\n tileHeight: number;\n /** All layers in order. */\n layers: MapLayer[];\n /** Tilesets referenced by this map. */\n tilesets: TilesetRef[];\n /** Custom map properties. */\n properties: Record<string, unknown>;\n}\n\n/** Create an empty TilemapData. */\nexport function createTilemapData(\n width: number,\n height: number,\n tileWidth: number,\n tileHeight: number,\n): TilemapData {\n return {\n width,\n height,\n tileWidth,\n tileHeight,\n layers: [],\n tilesets: [],\n properties: {},\n };\n}\n\n/** Get a tile GID at a grid position from a tile layer. Returns 0 if out of bounds. */\nexport function getTileAt(layer: TileLayer, col: number, row: number): number {\n if (col < 0 || col >= layer.width || row < 0 || row >= layer.height) return 0;\n // The `?? 0` is unreachable at runtime (the bounds check above guarantees an\n // in-range index into a hole-free Uint32Array) — it satisfies noUncheckedIndexedAccess,\n // which types every typed-array index read as `number | undefined`.\n return layer.tiles[row * layer.width + col] ?? 0;\n}\n\n/** Get the tileset that owns a given GID. Handles Tiled flip bits in the high bits. */\nexport function getTilesetForGid(tilesets: TilesetRef[], gid: number): TilesetRef | undefined {\n const id = gid & GID_FLIP_MASK;\n // Tilesets are ordered by firstGid; find the last one where firstGid <= id\n let result: TilesetRef | undefined;\n for (const ts of tilesets) {\n if (ts.firstGid <= id) {\n result = ts;\n } else {\n break;\n }\n }\n return result;\n}\n\n/** Compute the source rect in a tileset image for a given GID into `out`. Strips Tiled flip bits. Zero-alloc. */\nexport function getTileSourceRectInto(tileset: TilesetRef, gid: number, out: Rect): Rect {\n const localId = (gid & GID_FLIP_MASK) - tileset.firstGid;\n const col = localId % tileset.columns;\n const row = Math.floor(localId / tileset.columns);\n out.x = col * tileset.tileWidth;\n out.y = row * tileset.tileHeight;\n out.width = tileset.tileWidth;\n out.height = tileset.tileHeight;\n return out;\n}\n\n/** Compute the source rect in a tileset image for a given GID. Strips Tiled flip bits. */\nexport function getTileSourceRect(tileset: TilesetRef, gid: number): Rect {\n return getTileSourceRectInto(tileset, gid, { x: 0, y: 0, width: 0, height: 0 });\n}\n","import { TilemapParseError } from './parse-error.js';\nimport type { MapObject, ObjectLayer, TileLayer, TilemapData, TilesetRef } from './tilemap-data.js';\nimport { createTilemapData } from './tilemap-data.js';\n\n// ----- LDtk JSON types -----\n\ninterface LDtkFieldInstance {\n __identifier: string;\n __value: unknown;\n __type: string;\n}\n\ninterface LDtkEntityInstance {\n __identifier: string;\n __grid: [number, number];\n __pivot: [number, number];\n __tile?: { x: number; y: number; w: number; h: number };\n iid: string;\n width: number;\n height: number;\n px: [number, number];\n fieldInstances: LDtkFieldInstance[];\n}\n\ninterface LDtkTileInstance {\n px: [number, number];\n src: [number, number];\n f: number; // flip flags\n t: number; // tile ID\n}\n\ninterface LDtkLayerInstance {\n __identifier: string;\n __type: string;\n __cWid: number;\n __cHei: number;\n __gridSize: number;\n __tilesetDefUid?: number;\n __tilesetRelPath?: string;\n visible: boolean;\n __opacity: number;\n intGridCsv?: number[];\n // Real LDtk output always emits both arrays on every layer instance — only\n // one is ever populated per __type (an AutoLayer's gridTiles is always []).\n // Required (not optional) so a fixture omitting the unused one, as every\n // fixture here did before F057, cannot pass this module's own types.\n gridTiles: LDtkTileInstance[];\n autoLayerTiles: LDtkTileInstance[];\n entityInstances?: LDtkEntityInstance[];\n}\n\ninterface LDtkTilesetDef {\n uid: number;\n identifier: string;\n relPath: string;\n pxWid: number;\n pxHei: number;\n tileGridSize: number;\n __cWid: number;\n __cHei: number;\n}\n\ninterface LDtkLevel {\n identifier: string;\n uid: number;\n pxWid: number;\n pxHei: number;\n worldX: number;\n worldY: number;\n layerInstances?: LDtkLayerInstance[];\n fieldInstances?: LDtkFieldInstance[];\n}\n\ninterface LDtkJSON {\n defaultGridSize: number;\n externalLevels?: boolean;\n defs: {\n tilesets: LDtkTilesetDef[];\n };\n levels: LDtkLevel[];\n}\n\nexport interface ParseLDtkOptions {\n /** Predicate deciding whether an IntGrid value marks a solid cell. Default: value > 0. */\n intGridSolid?: (value: number) => boolean;\n}\n\nexport interface LDtkEntity {\n /** LDtk entity identifier (its type, e.g. \"Player\") — the key you switch on to decide what to spawn. */\n id: string;\n /** Entity position in pixels (LDtk px, pivot-adjusted per the parser convention). */\n x: number;\n y: number;\n /** Entity box size in pixels. */\n width: number;\n height: number;\n /** Custom field instances, keyed by field identifier. */\n fields: Record<string, unknown>;\n}\n\n/**\n * Extract every LDtk entity from a parsed map as a flat, spawn-ready list —\n * the LDtk-entity → ECS spawn convention. Walks all object layers; tile layers are skipped.\n */\nexport function parseLDtkEntities(map: TilemapData): LDtkEntity[] {\n const entities: LDtkEntity[] = [];\n for (const layer of map.layers) {\n if (layer.type !== 'object') continue;\n for (const obj of layer.objects) {\n entities.push({\n id: obj.type,\n x: obj.x,\n y: obj.y,\n width: obj.width,\n height: obj.height,\n fields: obj.properties,\n });\n }\n }\n return entities;\n}\n\n/**\n * Parse an LDtk JSON project into an array of TilemapData (one per level).\n * Returns all levels with their tile and entity layers.\n * Throws TilemapParseError for unsupported formats (externalLevels, invalid input).\n */\nexport function parseLDtk(json: unknown, options: ParseLDtkOptions = {}): TilemapData[] {\n if (\n !json ||\n typeof json !== 'object' ||\n !Array.isArray((json as Record<string, unknown>).levels) ||\n !(json as Record<string, unknown>).defs ||\n !Array.isArray(((json as Record<string, unknown>).defs as Record<string, unknown>).tilesets)\n ) {\n throw new TilemapParseError(\n 'parseLDtk: input is not an LDtk project JSON (missing defs.tilesets or levels).',\n );\n }\n\n const data = json as LDtkJSON;\n\n if (data.externalLevels === true) {\n throw new TilemapParseError(\n 'parseLDtk: projects with \"Save levels to separate files\" (externalLevels) are not supported. Disable it in LDtk ▸ Project settings and re-save.',\n );\n }\n\n const isSolid = options.intGridSolid ?? ((v) => v > 0);\n\n const tilesetDefs = new Map<number, LDtkTilesetDef>();\n for (const ts of data.defs.tilesets) {\n tilesetDefs.set(ts.uid, ts);\n }\n\n const results: TilemapData[] = [];\n\n for (const level of data.levels) {\n const gridSize = data.defaultGridSize;\n const mapWidth = Math.ceil(level.pxWid / gridSize);\n const mapHeight = Math.ceil(level.pxHei / gridSize);\n const map = createTilemapData(mapWidth, mapHeight, gridSize, gridSize);\n\n if (level.fieldInstances) {\n for (const field of level.fieldInstances) {\n map.properties[field.__identifier] = field.__value;\n }\n }\n\n // Pass 1: collect tile-layer tileset uids, sort ascending, assign deterministic firstGids.\n // Tilesets must be sorted by firstGid (ascending) for getTilesetForGid's early-break.\n const firstGidByUid = new Map<number, number>();\n let nextFirstGid = 1;\n\n if (level.layerInstances) {\n const usedTileUids = new Set<number>();\n for (const layerInst of level.layerInstances) {\n if (\n (layerInst.__type === 'Tiles' || layerInst.__type === 'AutoLayer') &&\n layerInst.__tilesetDefUid !== undefined\n ) {\n usedTileUids.add(layerInst.__tilesetDefUid);\n }\n }\n\n const sortedUids = Array.from(usedTileUids).sort((a, b) => a - b);\n for (const uid of sortedUids) {\n const def = tilesetDefs.get(uid);\n if (!def) continue;\n const columns = def.__cWid;\n const tileCount = def.__cWid * def.__cHei;\n firstGidByUid.set(uid, nextFirstGid);\n const ref: TilesetRef = {\n firstGid: nextFirstGid,\n name: def.identifier,\n tileWidth: def.tileGridSize,\n tileHeight: def.tileGridSize,\n columns,\n tileCount,\n image: def.relPath,\n imageWidth: def.pxWid,\n imageHeight: def.pxHei,\n tileProperties: new Map(),\n solidTiles: new Set(),\n };\n map.tilesets.push(ref);\n nextFirstGid += tileCount;\n }\n }\n\n // Pass 2: parse layers in reverse order (LDtk stores top-first; emit bottom-first).\n if (level.layerInstances) {\n for (let i = level.layerInstances.length - 1; i >= 0; i--) {\n const layerInst = level.layerInstances[i]!;\n\n if (layerInst.__type === 'IntGrid') {\n // IntGrid layers are treated as collision grids; IntGrid layers that also\n // carry auto-render tiles keep collision only (visual auto-tiles are M4 scope).\n const csv = layerInst.intGridCsv;\n const cellCount = layerInst.__cWid * layerInst.__cHei;\n const tiles = new Uint32Array(cellCount);\n const intFirstGid = nextFirstGid;\n let maxLocal = 0;\n let hasNonZero = false;\n const solidSet = new Set<number>();\n\n if (csv) {\n for (let j = 0; j < csv.length; j++) {\n const v = csv[j] ?? 0;\n if (v > 0) {\n hasNonZero = true;\n const localId = v - 1;\n if (localId > maxLocal) maxLocal = localId;\n tiles[j] = intFirstGid + localId;\n if (isSolid(v)) solidSet.add(localId);\n }\n }\n }\n\n if (hasNonZero) {\n const tileCount = maxLocal + 1;\n map.tilesets.push({\n firstGid: intFirstGid,\n name: layerInst.__identifier,\n tileWidth: layerInst.__gridSize,\n tileHeight: layerInst.__gridSize,\n columns: tileCount,\n tileCount,\n image: '',\n imageWidth: 0,\n imageHeight: 0,\n tileProperties: new Map(),\n solidTiles: solidSet,\n });\n nextFirstGid += tileCount;\n }\n\n map.layers.push({\n type: 'tile',\n name: layerInst.__identifier,\n width: layerInst.__cWid,\n height: layerInst.__cHei,\n tiles,\n visible: layerInst.visible,\n opacity: layerInst.__opacity,\n offsetX: 0,\n offsetY: 0,\n properties: {},\n });\n } else if (layerInst.__type === 'Tiles' || layerInst.__type === 'AutoLayer') {\n const firstGid = firstGidByUid.get(layerInst.__tilesetDefUid ?? -1) ?? 1;\n map.layers.push(parseTilesLayer(layerInst, mapWidth, mapHeight, gridSize, firstGid));\n } else if (layerInst.__type === 'Entities') {\n map.layers.push(parseEntitiesLayer(layerInst));\n }\n }\n }\n\n results.push(map);\n }\n\n return results;\n}\n\nfunction parseTilesLayer(\n layer: LDtkLayerInstance,\n mapWidth: number,\n mapHeight: number,\n gridSize: number,\n firstGid: number,\n): TileLayer {\n const tiles = new Uint32Array(mapWidth * mapHeight);\n // An AutoLayer's tiles live in autoLayerTiles; its gridTiles is always [].\n // `gridTiles ?? autoLayerTiles` picked the empty gridTiles for every\n // AutoLayer, since `??` only falls through on null/undefined, never on `[]`\n // — select by __type instead, which is the field LDtk itself keys on.\n const tileInstances = layer.__type === 'AutoLayer' ? layer.autoLayerTiles : layer.gridTiles;\n\n for (const ti of tileInstances) {\n const col = Math.floor(ti.px[0] / gridSize);\n const row = Math.floor(ti.px[1] / gridSize);\n if (col >= 0 && col < mapWidth && row >= 0 && row < mapHeight) {\n tiles[row * mapWidth + col] = firstGid + ti.t;\n }\n }\n\n return {\n type: 'tile',\n name: layer.__identifier,\n width: mapWidth,\n height: mapHeight,\n tiles,\n visible: layer.visible,\n opacity: layer.__opacity,\n offsetX: 0,\n offsetY: 0,\n properties: {},\n };\n}\n\nfunction parseEntitiesLayer(layer: LDtkLayerInstance): ObjectLayer {\n const objects: MapObject[] = (layer.entityInstances ?? []).map((ent, idx) => {\n const props: Record<string, unknown> = {};\n for (const field of ent.fieldInstances) {\n props[field.__identifier] = field.__value;\n }\n return {\n id: idx + 1,\n name: ent.__identifier,\n type: ent.__identifier,\n x: ent.px[0],\n y: ent.px[1],\n width: ent.width,\n height: ent.height,\n rotation: 0,\n properties: props,\n };\n });\n\n return {\n type: 'object',\n name: layer.__identifier,\n objects,\n visible: layer.visible,\n opacity: layer.__opacity,\n properties: {},\n };\n}\n","import { TilemapParseError } from './parse-error.js';\nimport type {\n MapLayer,\n MapObject,\n ObjectLayer,\n TileLayer,\n TilemapData,\n TilesetRef,\n} from './tilemap-data.js';\nimport { createTilemapData } from './tilemap-data.js';\n\n// ----- Tiled JSON types (.tmj format) -----\n\ninterface TiledProperty {\n name: string;\n type: string;\n value: unknown;\n}\n\ninterface TiledTileLayer {\n type: 'tilelayer';\n name: string;\n width: number;\n height: number;\n data: number[] | string;\n encoding?: string;\n compression?: string;\n chunks?: unknown[];\n visible: boolean;\n opacity: number;\n offsetx?: number;\n offsety?: number;\n properties?: TiledProperty[];\n}\n\ninterface TiledObject {\n id: number;\n name: string;\n type?: string;\n class?: string;\n x: number;\n y: number;\n width: number;\n height: number;\n rotation: number;\n properties?: TiledProperty[];\n}\n\ninterface TiledObjectLayer {\n type: 'objectgroup';\n name: string;\n objects: TiledObject[];\n visible: boolean;\n opacity: number;\n properties?: TiledProperty[];\n}\n\ntype TiledLayer = TiledTileLayer | TiledObjectLayer;\n\ninterface TiledTile {\n id: number;\n properties?: TiledProperty[];\n type?: string;\n class?: string;\n}\n\ninterface TiledTileset {\n firstgid: number;\n name: string;\n tilewidth: number;\n tileheight: number;\n columns: number;\n tilecount: number;\n image: string;\n imagewidth: number;\n imageheight: number;\n tiles?: TiledTile[];\n properties?: TiledProperty[];\n source?: string;\n}\n\ninterface TiledMapJSON {\n width: number;\n height: number;\n tilewidth: number;\n tileheight: number;\n orientation: string;\n infinite?: boolean;\n layers: TiledLayer[];\n tilesets: TiledTileset[];\n properties?: TiledProperty[];\n}\n\n/** Convert Tiled properties array to a Record. */\nfunction parseProperties(props?: TiledProperty[]): Record<string, unknown> {\n if (!props || props.length === 0) return {};\n const result: Record<string, unknown> = {};\n for (const p of props) {\n result[p.name] = p.value;\n }\n return result;\n}\n\n/**\n * Parse a Tiled .tmj (JSON) map into TilemapData.\n * Supports orthogonal maps with CSV tile layers and object layers.\n * Throws TilemapParseError for unsupported formats (infinite, non-orthogonal,\n * external tilesets, base64/compressed/chunked layer data).\n */\nexport function parseTiled(json: unknown): TilemapData {\n if (\n !json ||\n typeof json !== 'object' ||\n typeof (json as Record<string, unknown>).width !== 'number' ||\n typeof (json as Record<string, unknown>).height !== 'number' ||\n !Array.isArray((json as Record<string, unknown>).layers) ||\n !Array.isArray((json as Record<string, unknown>).tilesets)\n ) {\n throw new TilemapParseError(\n 'parseTiled: input is not a Tiled map JSON (missing width/height/layers/tilesets).',\n );\n }\n\n const data = json as TiledMapJSON;\n\n if (data.infinite === true) {\n throw new TilemapParseError(\n 'parseTiled: infinite maps are not supported. In Tiled: Map ▸ Map Properties ▸ set \"Infinite\" to false, then re-export.',\n );\n }\n if (data.orientation && data.orientation !== 'orthogonal') {\n throw new TilemapParseError(\n `parseTiled: orientation \"${data.orientation}\" is not supported — only orthogonal maps are supported.`,\n );\n }\n\n const map = createTilemapData(data.width, data.height, data.tilewidth, data.tileheight);\n map.properties = parseProperties(data.properties);\n\n // Parse tilesets\n for (const ts of data.tilesets) {\n if (ts.source !== undefined) {\n throw new TilemapParseError(\n `parseTiled: external tileset \"${ts.source}\" is not supported. Embed tilesets on export (Tiled ▸ Map ▸ \"Embed tilesets\") or run it through \\`flare tiled-to-flare\\` (which embeds tilesets by default).`,\n );\n }\n\n const tileProperties = new Map<number, Record<string, unknown>>();\n const solidTiles = new Set<number>();\n\n if (ts.tiles) {\n for (const tile of ts.tiles) {\n const props = parseProperties(tile.properties);\n if (Object.keys(props).length > 0) {\n tileProperties.set(tile.id, props);\n }\n // Mark as solid if it has a \"collision\" or \"solid\" property, or type/class is \"solid\"\n const tileType = tile.type ?? tile.class ?? '';\n if (tileType === 'solid' || props.solid === true || props.collision === true) {\n solidTiles.add(tile.id);\n }\n }\n }\n\n const ref: TilesetRef = {\n firstGid: ts.firstgid,\n name: ts.name,\n tileWidth: ts.tilewidth,\n tileHeight: ts.tileheight,\n columns: ts.columns,\n tileCount: ts.tilecount,\n image: ts.image,\n imageWidth: ts.imagewidth,\n imageHeight: ts.imageheight,\n tileProperties,\n solidTiles,\n };\n map.tilesets.push(ref);\n }\n\n // Sort tilesets by firstGid\n map.tilesets.sort((a, b) => a.firstGid - b.firstGid);\n\n // Parse layers\n for (const layer of data.layers) {\n map.layers.push(parseLayer(layer));\n }\n\n return map;\n}\n\nfunction parseLayer(layer: TiledLayer): MapLayer {\n if (layer.type === 'tilelayer') return parseTileLayer(layer);\n if (layer.type === 'objectgroup') return parseObjectLayer(layer);\n const l = layer as { type: string; name?: string };\n throw new TilemapParseError(\n `parseTiled: layer \"${l.name ?? ''}\" has unsupported type \"${l.type}\". Only tilelayer and objectgroup are supported — flatten group layers and remove image layers before export.`,\n );\n}\n\nfunction parseTileLayer(layer: TiledTileLayer): TileLayer {\n if (\n (layer.encoding !== undefined && layer.encoding !== 'csv') ||\n layer.compression !== undefined ||\n layer.chunks !== undefined\n ) {\n throw new TilemapParseError(\n 'parseTiled: base64/compressed/chunked (infinite) layer data is not supported. In Tiled export options set Tile Layer Format to \"CSV\".',\n );\n }\n if (typeof layer.data === 'string') {\n throw new TilemapParseError(\n 'parseTiled: base64/compressed/chunked (infinite) layer data is not supported. In Tiled export options set Tile Layer Format to \"CSV\".',\n );\n }\n // layer.data is number[] here — Uint32Array.from preserves flip-bit GIDs\n // (values up to 0xffffffff), unlike a Float32Array's 24-bit mantissa.\n return {\n type: 'tile',\n name: layer.name,\n width: layer.width,\n height: layer.height,\n tiles: Uint32Array.from(layer.data),\n visible: layer.visible,\n opacity: layer.opacity,\n offsetX: layer.offsetx ?? 0,\n offsetY: layer.offsety ?? 0,\n properties: parseProperties(layer.properties),\n };\n}\n\nfunction parseObjectLayer(layer: TiledObjectLayer): ObjectLayer {\n const objects: MapObject[] = layer.objects.map((obj) => ({\n id: obj.id,\n name: obj.name,\n type: obj.type ?? obj.class ?? '',\n x: obj.x,\n y: obj.y,\n width: obj.width,\n height: obj.height,\n rotation: obj.rotation,\n properties: parseProperties(obj.properties),\n }));\n\n return {\n type: 'object',\n name: layer.name,\n objects,\n visible: layer.visible,\n opacity: layer.opacity,\n properties: parseProperties(layer.properties),\n };\n}\n","import type { AABBShape } from '@flare-engine/physics';\nimport { AABB } from '@flare-engine/physics';\nimport type { TileLayer, TilemapData, TilesetRef } from './tilemap-data.js';\nimport { GID_FLIP_MASK, getTilesetForGid } from './tilemap-data.js';\n\n/** A collision body extracted from a solid tile. */\nexport interface TileCollider {\n /** World position of the tile center. */\n x: number;\n y: number;\n /** AABB collision shape. */\n shape: AABBShape;\n /** Grid column. */\n col: number;\n /** Grid row. */\n row: number;\n /** The tile GID (flip bits stripped — AABB is symmetric, downstream lookups want the real id). */\n gid: number;\n}\n\n/**\n * Extract collision shapes from solid tiles in a tilemap.\n * A tile is considered solid if its tileset marks the local tile ID as solid.\n *\n * @param map The parsed tilemap data.\n * @param layerName Optional: only extract from this layer. If omitted, extracts from all tile layers.\n * @returns Array of TileCollider bodies.\n */\nexport function extractColliders(map: TilemapData, layerName?: string): TileCollider[] {\n const colliders: TileCollider[] = [];\n const tw = map.tileWidth;\n const th = map.tileHeight;\n\n for (const layer of map.layers) {\n if (layer.type !== 'tile') continue;\n if (layerName !== undefined && layer.name !== layerName) continue;\n\n extractFromLayer(layer, map.tilesets, tw, th, colliders);\n }\n\n return colliders;\n}\n\nfunction extractFromLayer(\n layer: TileLayer,\n tilesets: TilesetRef[],\n tw: number,\n th: number,\n out: TileCollider[],\n): void {\n for (let row = 0; row < layer.height; row++) {\n for (let col = 0; col < layer.width; col++) {\n const gid = layer.tiles[row * layer.width + col] ?? 0;\n if (gid === 0) continue;\n\n const tileset = getTilesetForGid(tilesets, gid);\n if (!tileset) continue;\n\n const localId = (gid & GID_FLIP_MASK) - tileset.firstGid;\n if (!tileset.solidTiles.has(localId)) continue;\n\n out.push({\n x: col * tw + tw * 0.5 + layer.offsetX,\n y: row * th + th * 0.5 + layer.offsetY,\n shape: AABB(tw, th),\n col,\n row,\n gid: gid & GID_FLIP_MASK,\n });\n }\n }\n}\n","import type { SkImageLike } from '@flare-engine/assets';\nimport type { Rect } from '@flare-engine/math';\nimport type { Camera2D } from '@flare-engine/render';\nimport { SpriteBatch } from '@flare-engine/render';\nimport type { TileLayer, TilemapData } from './tilemap-data.js';\nimport { getTileAt, getTileSourceRectInto, getTilesetForGid } from './tilemap-data.js';\n\n/**\n * TilemapRenderer — draws a tilemap with viewport culling.\n * Only tiles visible to the camera are submitted to the SpriteBatch.\n */\nexport class TilemapRenderer {\n /** The tilemap data to render. */\n readonly map: TilemapData;\n\n /** SpriteBatch used for batched tile rendering. */\n readonly batch: SpriteBatch;\n\n /** Map from tileset name → SkImage. Set via setTilesetImage(). */\n private _images = new Map<string, SkImageLike>();\n\n /** Reusable bounds rect — avoids per-frame allocation from camera.getBounds(). */\n private _boundsBuf: Rect = { x: 0, y: 0, width: 0, height: 0 };\n\n /** Reusable source rect — avoids a per-tile allocation from getTileSourceRect. */\n private _srcBuf: Rect = { x: 0, y: 0, width: 0, height: 0 };\n\n constructor(map: TilemapData) {\n this.map = map;\n this.batch = new SpriteBatch();\n }\n\n /** Associate a loaded image with a tileset by name. */\n setTilesetImage(tilesetName: string, image: SkImageLike): void {\n this._images.set(tilesetName, image);\n }\n\n /**\n * Queue visible tile layers into a caller-owned `batch` using the camera for\n * culling. Does NOT flush — the caller owns the single flush so tiles z-order\n * under sprites. Zero-alloc: reuses the internal bounds buffer.\n */\n drawInto(camera: Camera2D, batch: SpriteBatch): void {\n const bounds = camera.getBoundsInto(this._boundsBuf);\n const tw = this.map.tileWidth;\n const th = this.map.tileHeight;\n\n for (const layer of this.map.layers) {\n if (layer.type !== 'tile' || !layer.visible) continue;\n this._drawTileLayer(layer, bounds.x, bounds.y, bounds.width, bounds.height, tw, th, batch);\n }\n }\n\n /**\n * Draw visible tile layers using the camera for culling.\n * Call `flush` on a callback to issue the actual draw calls.\n * Delegates to `drawInto` so culling and queuing logic live in one place.\n */\n draw(camera: Camera2D, flush: (batch: SpriteBatch) => void): void {\n this.drawInto(camera, this.batch);\n flush(this.batch);\n }\n\n // Flip rendering transforms (horizontal/vertical/diagonal) are a deferred\n // limitation — render-flip support is post-flip M10. Tileset resolution and\n // collider extraction are correct for flipped GIDs as of B8.\n private _drawTileLayer(\n layer: TileLayer,\n viewX: number,\n viewY: number,\n viewW: number,\n viewH: number,\n tw: number,\n th: number,\n batch: SpriteBatch,\n ): void {\n const offsetX = layer.offsetX;\n const offsetY = layer.offsetY;\n\n // Calculate visible tile range (clamped to layer bounds)\n const startCol = Math.max(0, Math.floor((viewX - offsetX) / tw));\n const startRow = Math.max(0, Math.floor((viewY - offsetY) / th));\n const endCol = Math.min(layer.width - 1, Math.floor((viewX - offsetX + viewW) / tw));\n const endRow = Math.min(layer.height - 1, Math.floor((viewY - offsetY + viewH) / th));\n\n for (let row = startRow; row <= endRow; row++) {\n for (let col = startCol; col <= endCol; col++) {\n const gid = getTileAt(layer, col, row);\n if (gid === 0) continue;\n\n const tileset = getTilesetForGid(this.map.tilesets, gid);\n if (!tileset) continue;\n\n const image = this._images.get(tileset.name);\n if (!image) continue;\n\n // Strips flip bits; writes into the reusable buffer, no per-tile allocation.\n const src = getTileSourceRectInto(tileset, gid, this._srcBuf);\n const dstX = col * tw + offsetX;\n const dstY = row * th + offsetY;\n\n batch.drawRaw(image, src.x, src.y, src.width, src.height, dstX, dstY, tw, th);\n }\n }\n }\n}\n"],"mappings":";;;;AACA,IAAa,oBAAb,cAAuC,MAAM;CAC3C,YAAY,SAAiB;EAC3B,MAAM,OAAO;EACb,KAAK,OAAO;CACd;AACF;;;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,EAAE,CAAC;EAC/D,MAAM,WAAW,KAAK,IAAI,GAAG,KAAK,OAAO,QAAQ,WAAW,EAAE,CAAC;EAC/D,MAAM,SAAS,KAAK,IAAI,MAAM,QAAQ,GAAG,KAAK,OAAO,QAAQ,UAAU,SAAS,EAAE,CAAC;EACnF,MAAM,SAAS,KAAK,IAAI,MAAM,SAAS,GAAG,KAAK,OAAO,QAAQ,UAAU,SAAS,EAAE,CAAC;EAEpF,KAAK,IAAI,MAAM,UAAU,OAAO,QAAQ,OACtC,KAAK,IAAI,MAAM,UAAU,OAAO,QAAQ,OAAO;GAC7C,MAAM,MAAM,UAAU,OAAO,KAAK,GAAG;GACrC,IAAI,QAAQ,GAAG;GAEf,MAAM,UAAU,iBAAiB,KAAK,IAAI,UAAU,GAAG;GACvD,IAAI,CAAC,SAAS;GAEd,MAAM,QAAQ,KAAK,QAAQ,IAAI,QAAQ,IAAI;GAC3C,IAAI,CAAC,OAAO;GAGZ,MAAM,MAAM,sBAAsB,SAAS,KAAK,KAAK,OAAO;GAC5D,MAAM,OAAO,MAAM,KAAK;GACxB,MAAM,OAAO,MAAM,KAAK;GAExB,MAAM,QAAQ,OAAO,IAAI,GAAG,IAAI,GAAG,IAAI,OAAO,IAAI,QAAQ,MAAM,MAAM,IAAI,EAAE;EAC9E;CAEJ;AACF"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["FLIP_H","FLIP_V","FLIP_D"],"sources":["../src/parse-error.ts","../src/tilemap-data.ts","../src/ldtk-parser.ts","../src/tiled-parser.ts","../src/tilemap-collider.ts","../src/tilemap-renderer.ts"],"sourcesContent":["/** Thrown by parseTiled/parseLDtk when a map uses an unsupported format or feature. */\nexport class TilemapParseError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'TilemapParseError';\n }\n}\n","import type { Rect } from '@flare-engine/math';\n\n/** Low 29 bits of a Tiled GID — Tiled stores flip state in the high 3 bits. */\nexport const GID_FLIP_MASK = 0x1fffffff;\n\nconst FLIP_H = 0x80000000;\nconst FLIP_V = 0x40000000;\nconst FLIP_D = 0x20000000;\n\n/** Flip state encoded in the high bits of a Tiled GID. */\nexport interface TileFlipFlags {\n horizontal: boolean;\n vertical: boolean;\n diagonal: boolean;\n}\n\n/** Strip the Tiled flip bits from a raw GID, returning the real global tile id. */\nexport function stripGidFlags(gid: number): number {\n return gid & GID_FLIP_MASK;\n}\n\n/**\n * Decode the Tiled flip bits encoded in the high bits of a raw GID.\n * Note: `gid & 0x80000000` yields a negative Int32 when the bit is set;\n * compare with `!== 0`, not `> 0`.\n */\nexport function decodeGidFlags(gid: number): TileFlipFlags {\n return {\n horizontal: (gid & FLIP_H) !== 0,\n vertical: (gid & FLIP_V) !== 0,\n diagonal: (gid & FLIP_D) !== 0,\n };\n}\n\n/** A layer of tiles in a grid. */\nexport interface TileLayer {\n readonly type: 'tile';\n /** Layer name. */\n name: string;\n /** Grid width in tiles. */\n width: number;\n /** Grid height in tiles. */\n height: number;\n /**\n * Flat array of tile GIDs (row-major, length = width * height). `Uint32Array`,\n * not `Float32Array` — a 24-bit mantissa cannot hold Tiled's flip-bit GIDs\n * (`0x80000000` and up). This is a type decision for bulk numeric data per the\n * repo convention, not a measured perf change.\n *\n * `readonly` like `SolidGrid.solid`: the array cannot be swapped out from under a\n * parsed map, but its cells stay writable (`layer.tiles[i] = gid`).\n */\n readonly tiles: Uint32Array;\n /** Visibility flag. */\n visible: boolean;\n /** Opacity (0–1). */\n opacity: number;\n /** Layer offset in pixels. */\n offsetX: number;\n offsetY: number;\n /** Custom properties. */\n properties: Record<string, unknown>;\n}\n\n/** An object in an object layer. */\nexport interface MapObject {\n /** Object ID. */\n id: number;\n /** Object name. */\n name: string;\n /** Object type/class. */\n type: string;\n /** Position in pixels. */\n x: number;\n y: number;\n /** Size in pixels. */\n width: number;\n height: number;\n /** Rotation in degrees. */\n rotation: number;\n /** Custom properties. */\n properties: Record<string, unknown>;\n}\n\n/** A layer of objects. */\nexport interface ObjectLayer {\n readonly type: 'object';\n /** Layer name. */\n name: string;\n /** Objects in the layer. */\n objects: MapObject[];\n /** Visibility flag. */\n visible: boolean;\n /** Opacity (0–1). */\n opacity: number;\n /** Custom properties. */\n properties: Record<string, unknown>;\n}\n\n/** Union of layer types. */\nexport type MapLayer = TileLayer | ObjectLayer;\n\n/** Information about a tileset used in the map. */\nexport interface TilesetRef {\n /** First GID in this tileset. */\n firstGid: number;\n /** Tileset name. */\n name: string;\n /** Tile width in pixels. */\n tileWidth: number;\n /** Tile height in pixels. */\n tileHeight: number;\n /** Number of columns in the tileset image. */\n columns: number;\n /** Total tile count. */\n tileCount: number;\n /** Image source path (may need resolving). */\n image: string;\n /** Image width in pixels. */\n imageWidth: number;\n /** Image height in pixels. */\n imageHeight: number;\n /** Per-tile properties (indexed by local tile ID). */\n tileProperties: Map<number, Record<string, unknown>>;\n /** Tile IDs marked as solid/collision. */\n solidTiles: Set<number>;\n}\n\n/** Complete parsed tilemap data — format-independent. */\nexport interface TilemapData {\n /** Map width in tiles. */\n width: number;\n /** Map height in tiles. */\n height: number;\n /** Tile width in pixels. */\n tileWidth: number;\n /** Tile height in pixels. */\n tileHeight: number;\n /** All layers in order. */\n layers: MapLayer[];\n /** Tilesets referenced by this map. */\n tilesets: TilesetRef[];\n /** Custom map properties. */\n properties: Record<string, unknown>;\n}\n\n/** Create an empty TilemapData. */\nexport function createTilemapData(\n width: number,\n height: number,\n tileWidth: number,\n tileHeight: number,\n): TilemapData {\n return {\n width,\n height,\n tileWidth,\n tileHeight,\n layers: [],\n tilesets: [],\n properties: {},\n };\n}\n\n/** Get a tile GID at a grid position from a tile layer. Returns 0 if out of bounds. */\nexport function getTileAt(layer: TileLayer, col: number, row: number): number {\n if (col < 0 || col >= layer.width || row < 0 || row >= layer.height) return 0;\n // The `?? 0` is unreachable at runtime (the bounds check above guarantees an\n // in-range index into a hole-free Uint32Array) — it satisfies noUncheckedIndexedAccess,\n // which types every typed-array index read as `number | undefined`.\n return layer.tiles[row * layer.width + col] ?? 0;\n}\n\n/** Get the tileset that owns a given GID. Handles Tiled flip bits in the high bits. */\nexport function getTilesetForGid(tilesets: TilesetRef[], gid: number): TilesetRef | undefined {\n const id = gid & GID_FLIP_MASK;\n // Tilesets are ordered by firstGid; find the last one where firstGid <= id\n let result: TilesetRef | undefined;\n for (const ts of tilesets) {\n if (ts.firstGid <= id) {\n result = ts;\n } else {\n break;\n }\n }\n return result;\n}\n\n/** Compute the source rect in a tileset image for a given GID into `out`. Strips Tiled flip bits. Zero-alloc. */\nexport function getTileSourceRectInto(tileset: TilesetRef, gid: number, out: Rect): Rect {\n const localId = (gid & GID_FLIP_MASK) - tileset.firstGid;\n const col = localId % tileset.columns;\n const row = Math.floor(localId / tileset.columns);\n out.x = col * tileset.tileWidth;\n out.y = row * tileset.tileHeight;\n out.width = tileset.tileWidth;\n out.height = tileset.tileHeight;\n return out;\n}\n\n/** Compute the source rect in a tileset image for a given GID. Strips Tiled flip bits. */\nexport function getTileSourceRect(tileset: TilesetRef, gid: number): Rect {\n return getTileSourceRectInto(tileset, gid, { x: 0, y: 0, width: 0, height: 0 });\n}\n","import { TilemapParseError } from './parse-error.js';\nimport type { MapObject, ObjectLayer, TileLayer, TilemapData, TilesetRef } from './tilemap-data.js';\nimport { createTilemapData } from './tilemap-data.js';\n\n// ----- LDtk JSON types -----\n\ninterface LDtkFieldInstance {\n __identifier: string;\n __value: unknown;\n __type: string;\n}\n\ninterface LDtkEntityInstance {\n __identifier: string;\n __grid: [number, number];\n __pivot: [number, number];\n __tile?: { x: number; y: number; w: number; h: number };\n iid: string;\n width: number;\n height: number;\n px: [number, number];\n fieldInstances: LDtkFieldInstance[];\n}\n\ninterface LDtkTileInstance {\n px: [number, number];\n src: [number, number];\n f: number; // flip flags\n t: number; // tile ID\n}\n\ninterface LDtkLayerInstance {\n __identifier: string;\n __type: string;\n __cWid: number;\n __cHei: number;\n __gridSize: number;\n __tilesetDefUid?: number;\n __tilesetRelPath?: string;\n visible: boolean;\n __opacity: number;\n intGridCsv?: number[];\n // Real LDtk output always emits both arrays on every layer instance — only\n // one is ever populated per __type (an AutoLayer's gridTiles is always []).\n // Required (not optional) so a fixture omitting the unused one, as every\n // fixture here did before F057, cannot pass this module's own types.\n gridTiles: LDtkTileInstance[];\n autoLayerTiles: LDtkTileInstance[];\n entityInstances?: LDtkEntityInstance[];\n}\n\ninterface LDtkTilesetDef {\n uid: number;\n identifier: string;\n relPath: string;\n pxWid: number;\n pxHei: number;\n tileGridSize: number;\n __cWid: number;\n __cHei: number;\n}\n\ninterface LDtkLevel {\n identifier: string;\n uid: number;\n pxWid: number;\n pxHei: number;\n worldX: number;\n worldY: number;\n layerInstances?: LDtkLayerInstance[];\n fieldInstances?: LDtkFieldInstance[];\n}\n\ninterface LDtkJSON {\n defaultGridSize: number;\n externalLevels?: boolean;\n defs: {\n tilesets: LDtkTilesetDef[];\n };\n levels: LDtkLevel[];\n}\n\nexport interface ParseLDtkOptions {\n /** Predicate deciding whether an IntGrid value marks a solid cell. Default: value > 0. */\n intGridSolid?: (value: number) => boolean;\n}\n\nexport interface LDtkEntity {\n /** LDtk entity identifier (its type, e.g. \"Player\") — the key you switch on to decide what to spawn. */\n id: string;\n /** Entity position in pixels (LDtk px, pivot-adjusted per the parser convention). */\n x: number;\n y: number;\n /** Entity box size in pixels. */\n width: number;\n height: number;\n /** Custom field instances, keyed by field identifier. */\n fields: Record<string, unknown>;\n}\n\n/**\n * Extract every LDtk entity from a parsed map as a flat, spawn-ready list —\n * the LDtk-entity → ECS spawn convention. Walks all object layers; tile layers are skipped.\n */\nexport function parseLDtkEntities(map: TilemapData): LDtkEntity[] {\n const entities: LDtkEntity[] = [];\n for (const layer of map.layers) {\n if (layer.type !== 'object') continue;\n for (const obj of layer.objects) {\n entities.push({\n id: obj.type,\n x: obj.x,\n y: obj.y,\n width: obj.width,\n height: obj.height,\n fields: obj.properties,\n });\n }\n }\n return entities;\n}\n\n/**\n * Parse an LDtk JSON project into an array of TilemapData (one per level).\n * Returns all levels with their tile and entity layers.\n * Throws TilemapParseError for unsupported formats (externalLevels, invalid input).\n */\nexport function parseLDtk(json: unknown, options: ParseLDtkOptions = {}): TilemapData[] {\n if (\n !json ||\n typeof json !== 'object' ||\n !Array.isArray((json as Record<string, unknown>).levels) ||\n !(json as Record<string, unknown>).defs ||\n !Array.isArray(((json as Record<string, unknown>).defs as Record<string, unknown>).tilesets)\n ) {\n throw new TilemapParseError(\n 'parseLDtk: input is not an LDtk project JSON (missing defs.tilesets or levels).',\n );\n }\n\n const data = json as LDtkJSON;\n\n if (data.externalLevels === true) {\n throw new TilemapParseError(\n 'parseLDtk: projects with \"Save levels to separate files\" (externalLevels) are not supported. Disable it in LDtk ▸ Project settings and re-save.',\n );\n }\n\n const isSolid = options.intGridSolid ?? ((v) => v > 0);\n\n const tilesetDefs = new Map<number, LDtkTilesetDef>();\n for (const ts of data.defs.tilesets) {\n tilesetDefs.set(ts.uid, ts);\n }\n\n const results: TilemapData[] = [];\n\n for (const level of data.levels) {\n const gridSize = data.defaultGridSize;\n const mapWidth = Math.ceil(level.pxWid / gridSize);\n const mapHeight = Math.ceil(level.pxHei / gridSize);\n const map = createTilemapData(mapWidth, mapHeight, gridSize, gridSize);\n\n if (level.fieldInstances) {\n for (const field of level.fieldInstances) {\n map.properties[field.__identifier] = field.__value;\n }\n }\n\n // Pass 1: collect tile-layer tileset uids, sort ascending, assign deterministic firstGids.\n // Tilesets must be sorted by firstGid (ascending) for getTilesetForGid's early-break.\n const firstGidByUid = new Map<number, number>();\n let nextFirstGid = 1;\n\n if (level.layerInstances) {\n const usedTileUids = new Set<number>();\n for (const layerInst of level.layerInstances) {\n if (\n (layerInst.__type === 'Tiles' || layerInst.__type === 'AutoLayer') &&\n layerInst.__tilesetDefUid !== undefined\n ) {\n usedTileUids.add(layerInst.__tilesetDefUid);\n }\n }\n\n const sortedUids = Array.from(usedTileUids).sort((a, b) => a - b);\n for (const uid of sortedUids) {\n const def = tilesetDefs.get(uid);\n if (!def) continue;\n const columns = def.__cWid;\n const tileCount = def.__cWid * def.__cHei;\n firstGidByUid.set(uid, nextFirstGid);\n const ref: TilesetRef = {\n firstGid: nextFirstGid,\n name: def.identifier,\n tileWidth: def.tileGridSize,\n tileHeight: def.tileGridSize,\n columns,\n tileCount,\n image: def.relPath,\n imageWidth: def.pxWid,\n imageHeight: def.pxHei,\n tileProperties: new Map(),\n solidTiles: new Set(),\n };\n map.tilesets.push(ref);\n nextFirstGid += tileCount;\n }\n }\n\n // Pass 2: parse layers in reverse order (LDtk stores top-first; emit bottom-first).\n if (level.layerInstances) {\n for (let i = level.layerInstances.length - 1; i >= 0; i--) {\n const layerInst = level.layerInstances[i]!;\n\n if (layerInst.__type === 'IntGrid') {\n // IntGrid layers are treated as collision grids; IntGrid layers that also\n // carry auto-render tiles keep collision only (visual auto-tiles are M4 scope).\n const csv = layerInst.intGridCsv;\n const cellCount = layerInst.__cWid * layerInst.__cHei;\n const tiles = new Uint32Array(cellCount);\n const intFirstGid = nextFirstGid;\n let maxLocal = 0;\n let hasNonZero = false;\n const solidSet = new Set<number>();\n\n if (csv) {\n for (let j = 0; j < csv.length; j++) {\n const v = csv[j] ?? 0;\n if (v > 0) {\n hasNonZero = true;\n const localId = v - 1;\n if (localId > maxLocal) maxLocal = localId;\n tiles[j] = intFirstGid + localId;\n if (isSolid(v)) solidSet.add(localId);\n }\n }\n }\n\n if (hasNonZero) {\n const tileCount = maxLocal + 1;\n map.tilesets.push({\n firstGid: intFirstGid,\n name: layerInst.__identifier,\n tileWidth: layerInst.__gridSize,\n tileHeight: layerInst.__gridSize,\n columns: tileCount,\n tileCount,\n image: '',\n imageWidth: 0,\n imageHeight: 0,\n tileProperties: new Map(),\n solidTiles: solidSet,\n });\n nextFirstGid += tileCount;\n }\n\n map.layers.push({\n type: 'tile',\n name: layerInst.__identifier,\n width: layerInst.__cWid,\n height: layerInst.__cHei,\n tiles,\n visible: layerInst.visible,\n opacity: layerInst.__opacity,\n offsetX: 0,\n offsetY: 0,\n properties: {},\n });\n } else if (layerInst.__type === 'Tiles' || layerInst.__type === 'AutoLayer') {\n const firstGid = firstGidByUid.get(layerInst.__tilesetDefUid ?? -1) ?? 1;\n map.layers.push(parseTilesLayer(layerInst, mapWidth, mapHeight, gridSize, firstGid));\n } else if (layerInst.__type === 'Entities') {\n map.layers.push(parseEntitiesLayer(layerInst));\n }\n }\n }\n\n results.push(map);\n }\n\n return results;\n}\n\nfunction parseTilesLayer(\n layer: LDtkLayerInstance,\n mapWidth: number,\n mapHeight: number,\n gridSize: number,\n firstGid: number,\n): TileLayer {\n const tiles = new Uint32Array(mapWidth * mapHeight);\n // An AutoLayer's tiles live in autoLayerTiles; its gridTiles is always [].\n // `gridTiles ?? autoLayerTiles` picked the empty gridTiles for every\n // AutoLayer, since `??` only falls through on null/undefined, never on `[]`\n // — select by __type instead, which is the field LDtk itself keys on.\n const tileInstances = layer.__type === 'AutoLayer' ? layer.autoLayerTiles : layer.gridTiles;\n\n for (const ti of tileInstances) {\n const col = Math.floor(ti.px[0] / gridSize);\n const row = Math.floor(ti.px[1] / gridSize);\n if (col >= 0 && col < mapWidth && row >= 0 && row < mapHeight) {\n tiles[row * mapWidth + col] = firstGid + ti.t;\n }\n }\n\n return {\n type: 'tile',\n name: layer.__identifier,\n width: mapWidth,\n height: mapHeight,\n tiles,\n visible: layer.visible,\n opacity: layer.__opacity,\n offsetX: 0,\n offsetY: 0,\n properties: {},\n };\n}\n\nfunction parseEntitiesLayer(layer: LDtkLayerInstance): ObjectLayer {\n const objects: MapObject[] = (layer.entityInstances ?? []).map((ent, idx) => {\n const props: Record<string, unknown> = {};\n for (const field of ent.fieldInstances) {\n props[field.__identifier] = field.__value;\n }\n return {\n id: idx + 1,\n name: ent.__identifier,\n type: ent.__identifier,\n x: ent.px[0],\n y: ent.px[1],\n width: ent.width,\n height: ent.height,\n rotation: 0,\n properties: props,\n };\n });\n\n return {\n type: 'object',\n name: layer.__identifier,\n objects,\n visible: layer.visible,\n opacity: layer.__opacity,\n properties: {},\n };\n}\n","import { TilemapParseError } from './parse-error.js';\nimport type {\n MapLayer,\n MapObject,\n ObjectLayer,\n TileLayer,\n TilemapData,\n TilesetRef,\n} from './tilemap-data.js';\nimport { createTilemapData } from './tilemap-data.js';\n\n// ----- Tiled JSON types (.tmj format) -----\n\ninterface TiledProperty {\n name: string;\n type: string;\n value: unknown;\n}\n\ninterface TiledTileLayer {\n type: 'tilelayer';\n name: string;\n width: number;\n height: number;\n data: number[] | string;\n encoding?: string;\n compression?: string;\n chunks?: unknown[];\n visible: boolean;\n opacity: number;\n offsetx?: number;\n offsety?: number;\n properties?: TiledProperty[];\n}\n\ninterface TiledObject {\n id: number;\n name: string;\n type?: string;\n class?: string;\n x: number;\n y: number;\n width: number;\n height: number;\n rotation: number;\n properties?: TiledProperty[];\n}\n\ninterface TiledObjectLayer {\n type: 'objectgroup';\n name: string;\n objects: TiledObject[];\n visible: boolean;\n opacity: number;\n properties?: TiledProperty[];\n}\n\ntype TiledLayer = TiledTileLayer | TiledObjectLayer;\n\ninterface TiledTile {\n id: number;\n properties?: TiledProperty[];\n type?: string;\n class?: string;\n}\n\ninterface TiledTileset {\n firstgid: number;\n name: string;\n tilewidth: number;\n tileheight: number;\n columns: number;\n tilecount: number;\n image: string;\n imagewidth: number;\n imageheight: number;\n tiles?: TiledTile[];\n properties?: TiledProperty[];\n source?: string;\n}\n\ninterface TiledMapJSON {\n width: number;\n height: number;\n tilewidth: number;\n tileheight: number;\n orientation: string;\n infinite?: boolean;\n layers: TiledLayer[];\n tilesets: TiledTileset[];\n properties?: TiledProperty[];\n}\n\n/** Convert Tiled properties array to a Record. */\nfunction parseProperties(props?: TiledProperty[]): Record<string, unknown> {\n if (!props || props.length === 0) return {};\n const result: Record<string, unknown> = {};\n for (const p of props) {\n result[p.name] = p.value;\n }\n return result;\n}\n\n/**\n * Parse a Tiled .tmj (JSON) map into TilemapData.\n * Supports orthogonal maps with CSV tile layers and object layers.\n * Throws TilemapParseError for unsupported formats (infinite, non-orthogonal,\n * external tilesets, base64/compressed/chunked layer data).\n */\nexport function parseTiled(json: unknown): TilemapData {\n if (\n !json ||\n typeof json !== 'object' ||\n typeof (json as Record<string, unknown>).width !== 'number' ||\n typeof (json as Record<string, unknown>).height !== 'number' ||\n !Array.isArray((json as Record<string, unknown>).layers) ||\n !Array.isArray((json as Record<string, unknown>).tilesets)\n ) {\n throw new TilemapParseError(\n 'parseTiled: input is not a Tiled map JSON (missing width/height/layers/tilesets).',\n );\n }\n\n const data = json as TiledMapJSON;\n\n if (data.infinite === true) {\n throw new TilemapParseError(\n 'parseTiled: infinite maps are not supported. In Tiled: Map ▸ Map Properties ▸ set \"Infinite\" to false, then re-export.',\n );\n }\n if (data.orientation && data.orientation !== 'orthogonal') {\n throw new TilemapParseError(\n `parseTiled: orientation \"${data.orientation}\" is not supported — only orthogonal maps are supported.`,\n );\n }\n\n const map = createTilemapData(data.width, data.height, data.tilewidth, data.tileheight);\n map.properties = parseProperties(data.properties);\n\n // Parse tilesets\n for (const ts of data.tilesets) {\n if (ts.source !== undefined) {\n throw new TilemapParseError(\n `parseTiled: external tileset \"${ts.source}\" is not supported. Embed tilesets on export (Tiled ▸ Map ▸ \"Embed tilesets\") or run it through \\`flare tiled-to-flare\\` (which embeds tilesets by default).`,\n );\n }\n\n const tileProperties = new Map<number, Record<string, unknown>>();\n const solidTiles = new Set<number>();\n\n if (ts.tiles) {\n for (const tile of ts.tiles) {\n const props = parseProperties(tile.properties);\n if (Object.keys(props).length > 0) {\n tileProperties.set(tile.id, props);\n }\n // Mark as solid if it has a \"collision\" or \"solid\" property, or type/class is \"solid\"\n const tileType = tile.type ?? tile.class ?? '';\n if (tileType === 'solid' || props.solid === true || props.collision === true) {\n solidTiles.add(tile.id);\n }\n }\n }\n\n const ref: TilesetRef = {\n firstGid: ts.firstgid,\n name: ts.name,\n tileWidth: ts.tilewidth,\n tileHeight: ts.tileheight,\n columns: ts.columns,\n tileCount: ts.tilecount,\n image: ts.image,\n imageWidth: ts.imagewidth,\n imageHeight: ts.imageheight,\n tileProperties,\n solidTiles,\n };\n map.tilesets.push(ref);\n }\n\n // Sort tilesets by firstGid\n map.tilesets.sort((a, b) => a.firstGid - b.firstGid);\n\n // Parse layers\n for (const layer of data.layers) {\n map.layers.push(parseLayer(layer));\n }\n\n return map;\n}\n\nfunction parseLayer(layer: TiledLayer): MapLayer {\n if (layer.type === 'tilelayer') return parseTileLayer(layer);\n if (layer.type === 'objectgroup') return parseObjectLayer(layer);\n const l = layer as { type: string; name?: string };\n throw new TilemapParseError(\n `parseTiled: layer \"${l.name ?? ''}\" has unsupported type \"${l.type}\". Only tilelayer and objectgroup are supported — flatten group layers and remove image layers before export.`,\n );\n}\n\nfunction parseTileLayer(layer: TiledTileLayer): TileLayer {\n if (\n (layer.encoding !== undefined && layer.encoding !== 'csv') ||\n layer.compression !== undefined ||\n layer.chunks !== undefined\n ) {\n throw new TilemapParseError(\n 'parseTiled: base64/compressed/chunked (infinite) layer data is not supported. In Tiled export options set Tile Layer Format to \"CSV\".',\n );\n }\n if (typeof layer.data === 'string') {\n throw new TilemapParseError(\n 'parseTiled: base64/compressed/chunked (infinite) layer data is not supported. In Tiled export options set Tile Layer Format to \"CSV\".',\n );\n }\n // layer.data is number[] here — Uint32Array.from preserves flip-bit GIDs\n // (values up to 0xffffffff), unlike a Float32Array's 24-bit mantissa.\n return {\n type: 'tile',\n name: layer.name,\n width: layer.width,\n height: layer.height,\n tiles: Uint32Array.from(layer.data),\n visible: layer.visible,\n opacity: layer.opacity,\n offsetX: layer.offsetx ?? 0,\n offsetY: layer.offsety ?? 0,\n properties: parseProperties(layer.properties),\n };\n}\n\nfunction parseObjectLayer(layer: TiledObjectLayer): ObjectLayer {\n const objects: MapObject[] = layer.objects.map((obj) => ({\n id: obj.id,\n name: obj.name,\n type: obj.type ?? obj.class ?? '',\n x: obj.x,\n y: obj.y,\n width: obj.width,\n height: obj.height,\n rotation: obj.rotation,\n properties: parseProperties(obj.properties),\n }));\n\n return {\n type: 'object',\n name: layer.name,\n objects,\n visible: layer.visible,\n opacity: layer.opacity,\n properties: parseProperties(layer.properties),\n };\n}\n","import type { AABBShape } from '@flare-engine/physics';\nimport { AABB } from '@flare-engine/physics';\nimport type { TileLayer, TilemapData, TilesetRef } from './tilemap-data.js';\nimport { GID_FLIP_MASK, getTilesetForGid } from './tilemap-data.js';\n\n/** A collision body extracted from a solid tile. */\nexport interface TileCollider {\n /** World position of the tile center. */\n x: number;\n y: number;\n /** AABB collision shape. */\n shape: AABBShape;\n /** Grid column. */\n col: number;\n /** Grid row. */\n row: number;\n /** The tile GID (flip bits stripped — AABB is symmetric, downstream lookups want the real id). */\n gid: number;\n}\n\n/**\n * Extract collision shapes from solid tiles in a tilemap.\n * A tile is considered solid if its tileset marks the local tile ID as solid.\n *\n * @param map The parsed tilemap data.\n * @param layerName Optional: only extract from this layer. If omitted, extracts from all tile layers.\n * @returns Array of TileCollider bodies.\n */\nexport function extractColliders(map: TilemapData, layerName?: string): TileCollider[] {\n const colliders: TileCollider[] = [];\n const tw = map.tileWidth;\n const th = map.tileHeight;\n\n for (const layer of map.layers) {\n if (layer.type !== 'tile') continue;\n if (layerName !== undefined && layer.name !== layerName) continue;\n\n extractFromLayer(layer, map.tilesets, tw, th, colliders);\n }\n\n return colliders;\n}\n\nfunction extractFromLayer(\n layer: TileLayer,\n tilesets: TilesetRef[],\n tw: number,\n th: number,\n out: TileCollider[],\n): void {\n for (let row = 0; row < layer.height; row++) {\n for (let col = 0; col < layer.width; col++) {\n const gid = layer.tiles[row * layer.width + col] ?? 0;\n if (gid === 0) continue;\n\n const tileset = getTilesetForGid(tilesets, gid);\n if (!tileset) continue;\n\n const localId = (gid & GID_FLIP_MASK) - tileset.firstGid;\n if (!tileset.solidTiles.has(localId)) continue;\n\n out.push({\n x: col * tw + tw * 0.5 + layer.offsetX,\n y: row * th + th * 0.5 + layer.offsetY,\n shape: AABB(tw, th),\n col,\n row,\n gid: gid & GID_FLIP_MASK,\n });\n }\n }\n}\n","import type { SkImageLike } from '@flare-engine/assets';\nimport type { Rect } from '@flare-engine/math';\nimport type { AnySpriteEffect, Camera2D } from '@flare-engine/render';\nimport { SpriteBatch } from '@flare-engine/render';\nimport type { TileLayer, TilemapData } from './tilemap-data.js';\nimport { getTileAt, getTileSourceRectInto, getTilesetForGid } from './tilemap-data.js';\n\n// Tiled GID flag bits (kept module-private; tilemap-data.ts owns the public mask).\nconst FLIP_H = 0x80000000;\nconst FLIP_V = 0x40000000;\nconst FLIP_D = 0x20000000;\nconst QUARTER_TURN = Math.PI / 2;\n\n/**\n * Per-draw options for `TilemapRenderer.drawInto` / `draw`.\n *\n * `effect` is set on every queued tile command. Batch runs key on the effect\n * by reference, so one shared instance (e.g. an ambient `tint()`) keeps every\n * tile — and any sprite drawn with the same instance — in a single run.\n * `alphaScale` multiplies each layer's own `opacity` (default 1).\n */\nexport interface TilemapDrawOptions {\n effect?: AnySpriteEffect;\n alphaScale?: number;\n}\n\n/**\n * TilemapRenderer — draws a tilemap with viewport culling.\n * Only tiles visible to the camera are submitted to the SpriteBatch.\n */\nexport class TilemapRenderer {\n /** The tilemap data to render. */\n readonly map: TilemapData;\n\n /** SpriteBatch used for batched tile rendering. */\n readonly batch: SpriteBatch;\n\n /** Map from tileset name → SkImage. Set via setTilesetImage(). */\n private _images = new Map<string, SkImageLike>();\n\n /** Reusable bounds rect — avoids per-frame allocation from camera.getBounds(). */\n private _boundsBuf: Rect = { x: 0, y: 0, width: 0, height: 0 };\n\n /** Reusable source rect — avoids a per-tile allocation from getTileSourceRect. */\n private _srcBuf: Rect = { x: 0, y: 0, width: 0, height: 0 };\n\n constructor(map: TilemapData) {\n this.map = map;\n this.batch = new SpriteBatch();\n }\n\n /** Associate a loaded image with a tileset by name. */\n setTilesetImage(tilesetName: string, image: SkImageLike): void {\n this._images.set(tilesetName, image);\n }\n\n /**\n * Queue visible tile layers into a caller-owned `batch` using the camera for\n * culling. Does NOT flush — the caller owns the single flush so tiles z-order\n * under sprites. Zero-alloc: reuses the internal bounds buffer.\n *\n * Each tile's `alpha` is `layer.opacity * opts.alphaScale`; `opts.effect`\n * is applied to every tile (see `TilemapDrawOptions`).\n */\n drawInto(camera: Camera2D, batch: SpriteBatch, opts?: TilemapDrawOptions): void {\n const bounds = camera.getBoundsInto(this._boundsBuf);\n const tw = this.map.tileWidth;\n const th = this.map.tileHeight;\n const effect = opts?.effect;\n const alphaScale = opts?.alphaScale ?? 1;\n\n for (const layer of this.map.layers) {\n if (layer.type !== 'tile' || !layer.visible) continue;\n this._drawTileLayer(\n layer,\n bounds.x,\n bounds.y,\n bounds.width,\n bounds.height,\n tw,\n th,\n batch,\n effect,\n layer.opacity * alphaScale,\n );\n }\n }\n\n /**\n * Draw visible tile layers using the camera for culling.\n * Call `flush` on a callback to issue the actual draw calls.\n * Delegates to `drawInto` so culling and queuing logic live in one place;\n * `opts` is threaded through unchanged.\n */\n draw(camera: Camera2D, flush: (batch: SpriteBatch) => void, opts?: TilemapDrawOptions): void {\n this.drawInto(camera, this.batch, opts);\n flush(this.batch);\n }\n\n // Tiled flip bits: H/V become the batch's flipX/flipY; the diagonal bit is a\n // quarter turn about the tile centre composed with the flip Tiled defines\n // (D+H = 90° CW, D+V = 90° CCW, D = flipY + CW, D+H+V = flipX + CW).\n // @flare-engine/render's flip draw path ignores `rotation` (see\n // SpriteDrawCommand.flipX), so D alone and D+H+V queue the right command\n // but draw without the turn until render composes the two.\n private _drawTileLayer(\n layer: TileLayer,\n viewX: number,\n viewY: number,\n viewW: number,\n viewH: number,\n tw: number,\n th: number,\n batch: SpriteBatch,\n effect: AnySpriteEffect | undefined,\n alpha: number,\n ): void {\n const offsetX = layer.offsetX;\n const offsetY = layer.offsetY;\n\n // Calculate visible tile range (clamped to layer bounds)\n const startCol = Math.max(0, Math.floor((viewX - offsetX) / tw));\n const startRow = Math.max(0, Math.floor((viewY - offsetY) / th));\n const endCol = Math.min(layer.width - 1, Math.floor((viewX - offsetX + viewW) / tw));\n const endRow = Math.min(layer.height - 1, Math.floor((viewY - offsetY + viewH) / th));\n\n for (let row = startRow; row <= endRow; row++) {\n for (let col = startCol; col <= endCol; col++) {\n const gid = getTileAt(layer, col, row);\n if (gid === 0) continue;\n\n const tileset = getTilesetForGid(this.map.tilesets, gid);\n if (!tileset) continue;\n\n const image = this._images.get(tileset.name);\n if (!image) continue;\n\n // Strips flip bits; writes into the reusable buffer, no per-tile allocation.\n const src = getTileSourceRectInto(tileset, gid, this._srcBuf);\n\n // Bit tests only — `gid & FLIP_H` is a negative Int32 when set, so compare to 0.\n const h = (gid & FLIP_H) !== 0;\n const v = (gid & FLIP_V) !== 0;\n const d = (gid & FLIP_D) !== 0;\n let flipX = h;\n let flipY = v;\n let rotation = 0;\n if (d) {\n rotation = !h && v ? -QUARTER_TURN : QUARTER_TURN;\n flipX = h && v;\n flipY = !h && !v;\n }\n\n // Centre anchor keeps a turned tile in its cell; the stored dstX/dstY\n // stay the cell's top-left. Positional slots — no per-tile object.\n batch.drawRaw(\n image,\n src.x,\n src.y,\n src.width,\n src.height,\n col * tw + offsetX + tw * 0.5,\n row * th + offsetY + th * 0.5,\n tw,\n th,\n effect,\n 0.5,\n 0.5,\n alpha,\n rotation,\n false,\n 'normal',\n flipX,\n flipY,\n );\n }\n }\n }\n}\n"],"mappings":";;;;AACA,IAAa,oBAAb,cAAuC,MAAM;CAC3C,YAAY,SAAiB;EAC3B,MAAM,OAAO;EACb,KAAK,OAAO;CACd;AACF;;;ACHA,MAAa,gBAAgB;AAE7B,MAAMA,WAAS;AACf,MAAMC,WAAS;AACf,MAAMC,WAAS;;AAUf,SAAgB,cAAc,KAAqB;CACjD,OAAO,MAAM;AACf;;;;;;AAOA,SAAgB,eAAe,KAA4B;CACzD,OAAO;EACL,aAAa,MAAMF,cAAY;EAC/B,WAAW,MAAMC,cAAY;EAC7B,WAAW,MAAMC,cAAY;CAC/B;AACF;;AAmHA,SAAgB,kBACd,OACA,QACA,WACA,YACa;CACb,OAAO;EACL;EACA;EACA;EACA;EACA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AAQ,UAAU,SAAS,EAAE,CAAC;EACnF,MAAM,SAAS,KAAK,IAAI,MAAM,SAAS,GAAG,KAAK,OAAO,QAAQ,UAAU,SAAS,EAAE,CAAC;EAEpF,KAAK,IAAI,MAAM,UAAU,OAAO,QAAQ,OACtC,KAAK,IAAI,MAAM,UAAU,OAAO,QAAQ,OAAO;GAC7C,MAAM,MAAM,UAAU,OAAO,KAAK,GAAG;GACrC,IAAI,QAAQ,GAAG;GAEf,MAAM,UAAU,iBAAiB,KAAK,IAAI,UAAU,GAAG;GACvD,IAAI,CAAC,SAAS;GAEd,MAAM,QAAQ,KAAK,QAAQ,IAAI,QAAQ,IAAI;GAC3C,IAAI,CAAC,OAAO;GAGZ,MAAM,MAAM,sBAAsB,SAAS,KAAK,KAAK,OAAO;GAG5D,MAAM,KAAK,MAAM,YAAY;GAC7B,MAAM,KAAK,MAAM,YAAY;GAC7B,MAAM,KAAK,MAAM,YAAY;GAC7B,IAAI,QAAQ;GACZ,IAAI,QAAQ;GACZ,IAAI,WAAW;GACf,IAAI,GAAG;IACL,WAAW,CAAC,KAAK,IAAI,CAAC,eAAe;IACrC,QAAQ,KAAK;IACb,QAAQ,CAAC,KAAK,CAAC;GACjB;GAIA,MAAM,QACJ,OACA,IAAI,GACJ,IAAI,GACJ,IAAI,OACJ,IAAI,QACJ,MAAM,KAAK,UAAU,KAAK,IAC1B,MAAM,KAAK,UAAU,KAAK,IAC1B,IACA,IACA,QACA,IACA,IACA,OACA,UACA,OACA,UACA,OACA,KACF;EACF;CAEJ;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flare-engine/tilemap",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.8",
|
|
4
4
|
"description": "Tiled/LDtk parser, culled tilemap renderer",
|
|
5
5
|
"keywords": ["flare-engine", "tilemap", "tiled", "ldtk"],
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -37,10 +37,10 @@
|
|
|
37
37
|
"typecheck": "tsc --noEmit"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@flare-engine/assets": "^0.4.
|
|
41
|
-
"@flare-engine/math": "^0.4.
|
|
42
|
-
"@flare-engine/physics": "^0.4.
|
|
43
|
-
"@flare-engine/render": "^0.4.
|
|
40
|
+
"@flare-engine/assets": "^0.4.8",
|
|
41
|
+
"@flare-engine/math": "^0.4.8",
|
|
42
|
+
"@flare-engine/physics": "^0.4.8",
|
|
43
|
+
"@flare-engine/render": "^0.4.8"
|
|
44
44
|
},
|
|
45
45
|
"engines": {
|
|
46
46
|
"node": ">=20"
|