@debuffjp/tilemap 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +41 -2
- package/dist/collide.d.ts +40 -0
- package/dist/collide.d.ts.map +1 -0
- package/dist/collide.js +94 -0
- package/dist/collide.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/ldtk.d.ts +93 -0
- package/dist/ldtk.d.ts.map +1 -0
- package/dist/ldtk.js +105 -0
- package/dist/ldtk.js.map +1 -0
- package/dist/tiled.d.ts +88 -0
- package/dist/tiled.d.ts.map +1 -0
- package/dist/tiled.js +129 -0
- package/dist/tiled.js.map +1 -0
- package/dist/tilemap.d.ts +142 -0
- package/dist/tilemap.d.ts.map +1 -0
- package/dist/tilemap.js +269 -0
- package/dist/tilemap.js.map +1 -0
- package/package.json +47 -4
package/README.md
CHANGED
|
@@ -1,3 +1,42 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @debuffjp/tilemap
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Tilemaps for debuff: culled, batched rendering through `draw`, tile collision, and importers for [Tiled](https://www.mapeditor.org/) and [LDtk](https://ldtk.io/).
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import { fromTiled } from "@debuffjp/tilemap";
|
|
7
|
+
|
|
8
|
+
const map = fromTiled(assets.json("level1"), { image: (path) => assets.image("tiles") });
|
|
9
|
+
const player = { x: 32, y: 32, w: 12, h: 14 };
|
|
10
|
+
|
|
11
|
+
// update(dt)
|
|
12
|
+
const hit = map.move(player, vx * dt, vy * dt);
|
|
13
|
+
if (hit.onGround) vy = 0;
|
|
14
|
+
|
|
15
|
+
// render(draw)
|
|
16
|
+
draw.withCamera(game.camera, () => map.draw(draw, { camera: game.camera }));
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Building maps
|
|
20
|
+
|
|
21
|
+
- **Tiled** (`.tmj`): `fromTiled(json, { image, tilesets? })`. Orthogonal maps, CSV or uncompressed Base64, infinite maps, layer groups (offsets, opacity, parallax), flip and rotation flags, external tilesets, object layers.
|
|
22
|
+
- **LDtk** (`.ldtk`): `fromLdtk(project, { level?, image, intGrid? })`. Tiles, AutoLayer (stacked tiles become extra layers), IntGrid collision, entities and level fields.
|
|
23
|
+
- **In code**: `new Tilemap({ width, height, tileWidth, tileHeight, tilesets, layers })`, then `map.set(layer, col, row, id)`. Useful for procedural levels.
|
|
24
|
+
|
|
25
|
+
## Collision
|
|
26
|
+
|
|
27
|
+
| Source | Becomes |
|
|
28
|
+
| --- | --- |
|
|
29
|
+
| Tiled tile property `solid` / `collides` | solid |
|
|
30
|
+
| Tiled tile property `oneWay` | one-way (solid from above) |
|
|
31
|
+
| Tiled layer property `collision: true` | every tile in the layer is solid |
|
|
32
|
+
| LDtk IntGrid value | solid; values named `oneWay`, `one_way` or `platform` are one-way; override with `intGrid` |
|
|
33
|
+
| Code | `map.setCollision(col, row, Collision.Solid)` |
|
|
34
|
+
|
|
35
|
+
`map.move(body, dx, dy, { dropThrough? })` moves an `{ x, y, w, h }` box, resolving X then Y. It splits fast moves into tile-sized steps so nothing tunnels, and returns `onGround`, `hitCeiling`, `hitLeft`, `hitRight`. `map.edges` controls which map borders are solid (default: sides solid, top and bottom open).
|
|
36
|
+
|
|
37
|
+
## API
|
|
38
|
+
|
|
39
|
+
- `map.draw(draw, { camera?, layers? })`: draws only tiles in view, applies parallax, no per-tile allocation
|
|
40
|
+
- `map.get / set / tileAt`, `map.tileProperties(id)`, `map.objects(layer)`, `map.properties`
|
|
41
|
+
- `map.collisionAt(col, row)`, `map.collideFrom(layers, { everyTile? })`, `overlapsSolid(map, body)`
|
|
42
|
+
- The asset pipeline loads `.tmj`, `.tsj` and `.ldtk` files as JSON
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { type Tilemap } from "./tilemap.js";
|
|
2
|
+
/** An axis-aligned box in world pixels; `x, y` is the top-left corner. */
|
|
3
|
+
export interface Body {
|
|
4
|
+
x: number;
|
|
5
|
+
y: number;
|
|
6
|
+
w: number;
|
|
7
|
+
h: number;
|
|
8
|
+
}
|
|
9
|
+
export interface MoveResult {
|
|
10
|
+
/** Blocked while moving horizontally. */
|
|
11
|
+
hitX: boolean;
|
|
12
|
+
/** Blocked while moving vertically. */
|
|
13
|
+
hitY: boolean;
|
|
14
|
+
/** Landed on something (solid or one-way) while moving down. */
|
|
15
|
+
onGround: boolean;
|
|
16
|
+
/** Hit a ceiling while moving up. */
|
|
17
|
+
hitCeiling: boolean;
|
|
18
|
+
/** Hit a wall on the left or right. */
|
|
19
|
+
hitLeft: boolean;
|
|
20
|
+
hitRight: boolean;
|
|
21
|
+
}
|
|
22
|
+
export interface MoveOptions {
|
|
23
|
+
/** Pass through one-way platforms (e.g. while holding down to drop). */
|
|
24
|
+
dropThrough?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* How far (in pixels) a falling body may already be inside a one-way tile and still land on it, snapping
|
|
27
|
+
* up to its top. Set it to the platform art's thickness so a jump that visually reaches the plank catches it.
|
|
28
|
+
* Default 0.
|
|
29
|
+
*/
|
|
30
|
+
oneWayTolerance?: number;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Move a body through the map, stopping at solid tiles. X then Y are resolved separately, and long
|
|
34
|
+
* moves are split into tile-sized sub-steps so fast bodies never tunnel. One-way tiles only block a
|
|
35
|
+
* body moving down whose bottom started at or above the tile's top (plus `oneWayTolerance`). Mutates `body.x/y`.
|
|
36
|
+
*/
|
|
37
|
+
export declare function move(map: Tilemap, body: Body, dx: number, dy: number, options?: MoveOptions): MoveResult;
|
|
38
|
+
/** True if a body overlaps any solid tile (e.g. to check whether it can stand up). */
|
|
39
|
+
export declare function overlapsSolid(map: Tilemap, body: Body): boolean;
|
|
40
|
+
//# sourceMappingURL=collide.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collide.d.ts","sourceRoot":"","sources":["../src/collide.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,KAAK,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvD,0EAA0E;AAC1E,MAAM,WAAW,IAAI;IACnB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACX;AAED,MAAM,WAAW,UAAU;IACzB,yCAAyC;IACzC,IAAI,EAAE,OAAO,CAAC;IACd,uCAAuC;IACvC,IAAI,EAAE,OAAO,CAAC;IACd,gEAAgE;IAChE,QAAQ,EAAE,OAAO,CAAC;IAClB,qCAAqC;IACrC,UAAU,EAAE,OAAO,CAAC;IACpB,uCAAuC;IACvC,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,WAAW,WAAW;IAC1B,wEAAwE;IACxE,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB;;;;OAIG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAID;;;;GAIG;AACH,wBAAgB,IAAI,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,OAAO,GAAE,WAAgB,GAAG,UAAU,CAS5G;AAgED,sFAAsF;AACtF,wBAAgB,aAAa,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,GAAG,OAAO,CAQ/D"}
|
package/dist/collide.js
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { Collision } from "./tilemap.js";
|
|
2
|
+
const EPS = 1e-6;
|
|
3
|
+
/**
|
|
4
|
+
* Move a body through the map, stopping at solid tiles. X then Y are resolved separately, and long
|
|
5
|
+
* moves are split into tile-sized sub-steps so fast bodies never tunnel. One-way tiles only block a
|
|
6
|
+
* body moving down whose bottom started at or above the tile's top (plus `oneWayTolerance`). Mutates `body.x/y`.
|
|
7
|
+
*/
|
|
8
|
+
export function move(map, body, dx, dy, options = {}) {
|
|
9
|
+
const result = { hitX: false, hitY: false, onGround: false, hitCeiling: false, hitLeft: false, hitRight: false };
|
|
10
|
+
const stepsX = Math.max(1, Math.ceil(Math.abs(dx) / map.tileWidth));
|
|
11
|
+
const stepX = dx / stepsX;
|
|
12
|
+
for (let i = 0; i < stepsX && !result.hitX; i++)
|
|
13
|
+
moveX(map, body, stepX, result);
|
|
14
|
+
const stepsY = Math.max(1, Math.ceil(Math.abs(dy) / map.tileHeight));
|
|
15
|
+
const stepY = dy / stepsY;
|
|
16
|
+
for (let i = 0; i < stepsY && !result.hitY; i++)
|
|
17
|
+
moveY(map, body, stepY, result, options);
|
|
18
|
+
return result;
|
|
19
|
+
}
|
|
20
|
+
function moveX(map, body, dx, result) {
|
|
21
|
+
if (dx === 0)
|
|
22
|
+
return;
|
|
23
|
+
const { tileWidth: tw, tileHeight: th } = map;
|
|
24
|
+
const top = Math.floor(body.y / th);
|
|
25
|
+
const bottom = Math.floor((body.y + body.h - EPS) / th);
|
|
26
|
+
if (dx > 0) {
|
|
27
|
+
const edge = body.x + body.w + dx;
|
|
28
|
+
const col = Math.floor((edge - EPS) / tw);
|
|
29
|
+
for (let row = top; row <= bottom; row++) {
|
|
30
|
+
if (map.collisionAt(col, row) === Collision.Solid) {
|
|
31
|
+
body.x = col * tw - body.w;
|
|
32
|
+
result.hitX = result.hitRight = true;
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
const edge = body.x + dx;
|
|
39
|
+
const col = Math.floor(edge / tw);
|
|
40
|
+
for (let row = top; row <= bottom; row++) {
|
|
41
|
+
if (map.collisionAt(col, row) === Collision.Solid) {
|
|
42
|
+
body.x = (col + 1) * tw;
|
|
43
|
+
result.hitX = result.hitLeft = true;
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
body.x += dx;
|
|
49
|
+
}
|
|
50
|
+
function moveY(map, body, dy, result, options) {
|
|
51
|
+
if (dy === 0)
|
|
52
|
+
return;
|
|
53
|
+
const { tileWidth: tw, tileHeight: th } = map;
|
|
54
|
+
const left = Math.floor(body.x / tw);
|
|
55
|
+
const right = Math.floor((body.x + body.w - EPS) / tw);
|
|
56
|
+
if (dy > 0) {
|
|
57
|
+
const bottom = body.y + body.h;
|
|
58
|
+
const row = Math.floor((bottom + dy - EPS) / th);
|
|
59
|
+
const rowTop = row * th;
|
|
60
|
+
for (let col = left; col <= right; col++) {
|
|
61
|
+
const kind = map.collisionAt(col, row);
|
|
62
|
+
const blocks = kind === Collision.Solid ||
|
|
63
|
+
(kind === Collision.OneWay && !options.dropThrough && bottom <= rowTop + (options.oneWayTolerance ?? 0) + EPS);
|
|
64
|
+
if (blocks) {
|
|
65
|
+
body.y = rowTop - body.h;
|
|
66
|
+
result.hitY = result.onGround = true;
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
const row = Math.floor((body.y + dy) / th);
|
|
73
|
+
for (let col = left; col <= right; col++) {
|
|
74
|
+
if (map.collisionAt(col, row) === Collision.Solid) {
|
|
75
|
+
body.y = (row + 1) * th;
|
|
76
|
+
result.hitY = result.hitCeiling = true;
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
body.y += dy;
|
|
82
|
+
}
|
|
83
|
+
/** True if a body overlaps any solid tile (e.g. to check whether it can stand up). */
|
|
84
|
+
export function overlapsSolid(map, body) {
|
|
85
|
+
const { tileWidth: tw, tileHeight: th } = map;
|
|
86
|
+
for (let row = Math.floor(body.y / th); row <= Math.floor((body.y + body.h - EPS) / th); row++) {
|
|
87
|
+
for (let col = Math.floor(body.x / tw); col <= Math.floor((body.x + body.w - EPS) / tw); col++) {
|
|
88
|
+
if (map.collisionAt(col, row) === Collision.Solid)
|
|
89
|
+
return true;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=collide.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collide.js","sourceRoot":"","sources":["../src/collide.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAgB,MAAM,cAAc,CAAC;AAmCvD,MAAM,GAAG,GAAG,IAAI,CAAC;AAEjB;;;;GAIG;AACH,MAAM,UAAU,IAAI,CAAC,GAAY,EAAE,IAAU,EAAE,EAAU,EAAE,EAAU,EAAE,OAAO,GAAgB,EAAE;IAC9F,MAAM,MAAM,GAAe,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC;IAC7H,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC;IACpE,MAAM,KAAK,GAAG,EAAE,GAAG,MAAM,CAAC;IAC1B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,EAAE;QAAE,KAAK,CAAC,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;IACjF,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC;IACrE,MAAM,KAAK,GAAG,EAAE,GAAG,M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,IAAI,EAAE,CAAC;AACf,CAAC;AAED,sFAAsF;AACtF,MAAM,UAAU,aAAa,CAAC,GAAY,EAAE,IAAU;IACpD,MAAM,EAAE,SAAS,EAAE,EAAE,EAAE,UAAU,EAAE,EAAE,EAAE,GAAG,GAAG,CAAC;IAC9C,KAAK,IAAI,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,GAAG,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,GAAG,GAAG,CAAC,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,EAAE,CAAC;QAC/F,KAAK,IAAI,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,GAAG,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,GAAG,GAAG,CAAC,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,EAAE,CAAC;YAC/F,IAAI,GAAG,CAAC,WAAW,CAAC,GAAG,EAAE,GAAG,CAAC,KAAK,SAAS,CAAC,KAAK;gBAAE,OAAO,IAAI,CAAC;QACjE,CAAC;IACH,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { type Body, type MoveOptions, type MoveResult, move, overlapsSolid } from "./collide.js";
|
|
2
|
+
export { type FromLdtkOptions, fromLdtk, type LdtkProject, type LdtkTilesetDef } from "./ldtk.js";
|
|
3
|
+
export { type FromTiledOptions, fromTiled, type TiledMap, type TiledTileset } from "./tiled.js";
|
|
4
|
+
export { Collision, FLIP_D, FLIP_H, FLIP_V, type ImageRegion, type MapObject, type TileLayer, type TileLayerDrawOptions, Tilemap, type TilemapOptions, type Tileset, } from "./tilemap.js";
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,IAAI,EAAE,KAAK,WAAW,EAAE,KAAK,UAAU,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AACjG,OAAO,EAAE,KAAK,eAAe,EAAE,QAAQ,EAAE,KAAK,WAAW,EAAE,KAAK,cAAc,EAAE,MAAM,WAAW,CAAC;AAClG,OAAO,EAAE,KAAK,gBAAgB,EAAE,SAAS,EAAE,KAAK,QAAQ,EAAE,KAAK,YAAY,EAAE,MAAM,YAAY,CAAC;AAChG,OAAO,EACL,SAAS,EACT,MAAM,EACN,MAAM,EACN,MAAM,EACN,KAAK,WAAW,EAChB,KAAK,SAAS,EACd,KAAK,SAAS,EACd,KAAK,oBAAoB,EACzB,OAAO,EACP,KAAK,cAAc,EACnB,KAAK,OAAO,GACb,MAAM,cAAc,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgD,IAAI,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AACjG,OAAO,EAAwB,QAAQ,EAAyC,MAAM,WAAW,CAAC;AAClG,OAAO,EAAyB,SAAS,EAAoC,MAAM,YAAY,CAAC;AAChG,OAAO,EACL,SAAS,EACT,MAAM,EACN,MAAM,EACN,MAAM,EAKN,OAAO,GAGR,MAAM,cAAc,CAAC"}
|
package/dist/ldtk.d.ts
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import type { TextureSource } from "@debuffjp/core";
|
|
2
|
+
import { type ImageRegion, Tilemap } from "./tilemap.js";
|
|
3
|
+
interface LdtkTile {
|
|
4
|
+
px: [number, number];
|
|
5
|
+
src: [number, number];
|
|
6
|
+
/** Bit 0: flip X, bit 1: flip Y. */
|
|
7
|
+
f: number;
|
|
8
|
+
t: number;
|
|
9
|
+
}
|
|
10
|
+
interface LdtkField {
|
|
11
|
+
__identifier: string;
|
|
12
|
+
__value: unknown;
|
|
13
|
+
}
|
|
14
|
+
interface LdtkLayerInstance {
|
|
15
|
+
__identifier: string;
|
|
16
|
+
__type: "IntGrid" | "Entities" | "Tiles" | "AutoLayer";
|
|
17
|
+
__cWid: number;
|
|
18
|
+
__cHei: number;
|
|
19
|
+
__gridSize: number;
|
|
20
|
+
__opacity: number;
|
|
21
|
+
__pxTotalOffsetX: number;
|
|
22
|
+
__pxTotalOffsetY: number;
|
|
23
|
+
__tilesetDefUid: number | null;
|
|
24
|
+
layerDefUid: number;
|
|
25
|
+
visible: boolean;
|
|
26
|
+
intGridCsv: number[];
|
|
27
|
+
gridTiles: LdtkTile[];
|
|
28
|
+
autoLayerTiles: LdtkTile[];
|
|
29
|
+
entityInstances: {
|
|
30
|
+
__identifier: string;
|
|
31
|
+
iid: string;
|
|
32
|
+
px: [number, number];
|
|
33
|
+
__pivot: [number, number];
|
|
34
|
+
width: number;
|
|
35
|
+
height: number;
|
|
36
|
+
fieldInstances: LdtkField[];
|
|
37
|
+
}[];
|
|
38
|
+
}
|
|
39
|
+
export interface LdtkTilesetDef {
|
|
40
|
+
uid: number;
|
|
41
|
+
identifier: string;
|
|
42
|
+
relPath: string | null;
|
|
43
|
+
pxWid: number;
|
|
44
|
+
pxHei: number;
|
|
45
|
+
tileGridSize: number;
|
|
46
|
+
spacing: number;
|
|
47
|
+
padding: number;
|
|
48
|
+
customData?: {
|
|
49
|
+
tileId: number;
|
|
50
|
+
data: string;
|
|
51
|
+
}[];
|
|
52
|
+
enumTags?: {
|
|
53
|
+
enumValueId: string;
|
|
54
|
+
tileIds: number[];
|
|
55
|
+
}[];
|
|
56
|
+
}
|
|
57
|
+
interface LdtkLevel {
|
|
58
|
+
identifier: string;
|
|
59
|
+
pxWid: number;
|
|
60
|
+
pxHei: number;
|
|
61
|
+
fieldInstances: LdtkField[];
|
|
62
|
+
layerInstances: LdtkLayerInstance[] | null;
|
|
63
|
+
externalRelPath?: string | null;
|
|
64
|
+
}
|
|
65
|
+
export interface LdtkProject {
|
|
66
|
+
defs: {
|
|
67
|
+
tilesets: LdtkTilesetDef[];
|
|
68
|
+
layers: {
|
|
69
|
+
uid: number;
|
|
70
|
+
identifier: string;
|
|
71
|
+
intGridValues?: {
|
|
72
|
+
value: number;
|
|
73
|
+
identifier: string | null;
|
|
74
|
+
}[];
|
|
75
|
+
}[];
|
|
76
|
+
};
|
|
77
|
+
levels: LdtkLevel[];
|
|
78
|
+
}
|
|
79
|
+
export interface FromLdtkOptions {
|
|
80
|
+
/** Level identifier (e.g. "Level_0"). Default: the first level. */
|
|
81
|
+
level?: string;
|
|
82
|
+
/** Resolve a tileset's relative image path to a loaded image. */
|
|
83
|
+
image: (relPath: string, tileset: LdtkTilesetDef) => TextureSource | ImageRegion;
|
|
84
|
+
/**
|
|
85
|
+
* Collision from IntGrid layers. By default every non-zero IntGrid value is solid, except values whose
|
|
86
|
+
* identifier is "oneWay", "one_way" or "platform", which are one-way. Override per value here.
|
|
87
|
+
*/
|
|
88
|
+
intGrid?: Record<number, "solid" | "oneWay" | "none">;
|
|
89
|
+
}
|
|
90
|
+
/** Build a `Tilemap` from one level of an LDtk project. */
|
|
91
|
+
export declare function fromLdtk(project: LdtkProject, options: FromLdtkOptions): Tilemap;
|
|
92
|
+
export {};
|
|
93
|
+
//# sourceMappingURL=ldtk.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ldtk.d.ts","sourceRoot":"","sources":["../src/ldtk.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAA6B,KAAK,WAAW,EAAkB,OAAO,EAAgB,MAAM,cAAc,CAAC;AAGlH,UAAU,QAAQ;IAChB,EAAE,EAAE,CAAC,MAAM,EAAE,MAAM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,CAAC,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,eAAe,GAAG,OAAO,CAyFhF"}
|
package/dist/ldtk.js
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { Collision, FLIP_H, FLIP_V, Tilemap } from "./tilemap.js";
|
|
2
|
+
const ONE_WAY_NAMES = new Set(["oneway", "one_way", "platform"]);
|
|
3
|
+
/** Build a `Tilemap` from one level of an LDtk project. */
|
|
4
|
+
export function fromLdtk(project, options) {
|
|
5
|
+
const level = options.level ? project.levels.find((l) => l.identifier === options.level) : project.levels[0];
|
|
6
|
+
if (!level)
|
|
7
|
+
throw new Error(`LDtk level "${options.level}" not found. Levels: ${project.levels.map((l) => l.identifier).join(", ")}`);
|
|
8
|
+
if (!level.layerInstances) {
|
|
9
|
+
throw new Error(`LDtk level "${level.identifier}" is stored externally (${level.externalRelPath}). Disable "Save levels to separate files" or load that file`);
|
|
10
|
+
}
|
|
11
|
+
const instances = level.layerInstances;
|
|
12
|
+
const grid = instances.find((l) => l.__type !== "Entities")?.__gridSize ?? 16;
|
|
13
|
+
const width = Math.ceil(level.pxWid / grid);
|
|
14
|
+
const height = Math.ceil(level.pxHei / grid);
|
|
15
|
+
// Give each LDtk tileset a contiguous id range, in definition order.
|
|
16
|
+
let nextId = 1;
|
|
17
|
+
const firstIds = new Map();
|
|
18
|
+
const tilesets = [];
|
|
19
|
+
for (const def of project.defs.tilesets) {
|
|
20
|
+
if (!def.relPath)
|
|
21
|
+
continue; // embedded atlases (e.g. LDtk icons) have no image
|
|
22
|
+
const columns = Math.floor((def.pxWid - def.padding * 2 + def.spacing) / (def.tileGridSize + def.spacing));
|
|
23
|
+
const rows = Math.floor((def.pxHei - def.padding * 2 + def.spacing) / (def.tileGridSize + def.spacing));
|
|
24
|
+
const properties = {};
|
|
25
|
+
for (const { tileId, data } of def.customData ?? [])
|
|
26
|
+
properties[tileId] = { ...properties[tileId], data };
|
|
27
|
+
for (const { enumValueId, tileIds } of def.enumTags ?? []) {
|
|
28
|
+
for (const id of tileIds)
|
|
29
|
+
properties[id] = { ...properties[id], [enumValueId]: true };
|
|
30
|
+
}
|
|
31
|
+
firstIds.set(def.uid, nextId);
|
|
32
|
+
tilesets.push({
|
|
33
|
+
firstId: nextId,
|
|
34
|
+
image: options.image(def.relPath, def),
|
|
35
|
+
tileWidth: def.tileGridSize,
|
|
36
|
+
tileHeight: def.tileGridSize,
|
|
37
|
+
columns,
|
|
38
|
+
count: columns * rows,
|
|
39
|
+
margin: def.padding,
|
|
40
|
+
spacing: def.spacing,
|
|
41
|
+
properties,
|
|
42
|
+
});
|
|
43
|
+
nextId += columns * rows;
|
|
44
|
+
}
|
|
45
|
+
const map = new Tilemap({ width, height, tileWidth: grid, tileHeight: grid, tilesets, layers: [] });
|
|
46
|
+
map.properties = Object.fromEntries(level.fieldInstances.map((f) => [f.__identifier, f.__value]));
|
|
47
|
+
// LDtk lists layers top-most first; draw order is bottom-most first.
|
|
48
|
+
for (const inst of [...instances].reverse()) {
|
|
49
|
+
const common = { visible: inst.visible, opacity: inst.__opacity, offsetX: inst.__pxTotalOffsetX, offsetY: inst.__pxTotalOffsetY };
|
|
50
|
+
if (inst.__type === "Entities") {
|
|
51
|
+
map.objectLayers.set(inst.__identifier, inst.entityInstances.map((e, i) => ({
|
|
52
|
+
id: i + 1,
|
|
53
|
+
name: e.__identifier,
|
|
54
|
+
type: e.__identifier,
|
|
55
|
+
x: e.px[0] - e.__pivot[0] * e.width + inst.__pxTotalOffsetX,
|
|
56
|
+
y: e.px[1] - e.__pivot[1] * e.height + inst.__pxTotalOffsetY,
|
|
57
|
+
width: e.width,
|
|
58
|
+
height: e.height,
|
|
59
|
+
properties: { iid: e.iid, ...Object.fromEntries(e.fieldInstances.map((f) => [f.__identifier, f.__value])) },
|
|
60
|
+
})));
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
if (inst.__type === "IntGrid")
|
|
64
|
+
applyIntGrid(map, project, inst, grid, options);
|
|
65
|
+
const tiles = inst.__type === "Tiles" ? inst.gridTiles : inst.autoLayerTiles;
|
|
66
|
+
if (!tiles.length)
|
|
67
|
+
continue;
|
|
68
|
+
if (inst.__gridSize !== grid)
|
|
69
|
+
throw new Error(`LDtk layer "${inst.__identifier}" uses a ${inst.__gridSize}px grid; all tile layers must use ${grid}px`);
|
|
70
|
+
const firstId = inst.__tilesetDefUid === null ? undefined : firstIds.get(inst.__tilesetDefUid);
|
|
71
|
+
if (firstId === undefined)
|
|
72
|
+
continue;
|
|
73
|
+
// Auto-layer rules can stack tiles in one cell; extra tiles go to overflow layers drawn above.
|
|
74
|
+
const stacks = [];
|
|
75
|
+
for (const tile of tiles) {
|
|
76
|
+
const index = Math.floor(tile.px[1] / grid) * width + Math.floor(tile.px[0] / grid);
|
|
77
|
+
const id = (firstId + tile.t) | (tile.f & 1 ? FLIP_H : 0) | (tile.f & 2 ? FLIP_V : 0);
|
|
78
|
+
let target = stacks.find((s) => s[index] === 0);
|
|
79
|
+
if (!target) {
|
|
80
|
+
target = new Uint32Array(width * height);
|
|
81
|
+
stacks.push(target);
|
|
82
|
+
}
|
|
83
|
+
target[index] = id >>> 0;
|
|
84
|
+
}
|
|
85
|
+
stacks.forEach((data, i) => {
|
|
86
|
+
map.addLayer(i === 0 ? inst.__identifier : `${inst.__identifier}#${i + 1}`, { data, ...common });
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
return map;
|
|
90
|
+
}
|
|
91
|
+
function applyIntGrid(map, project, inst, grid, options) {
|
|
92
|
+
if (inst.__gridSize !== grid)
|
|
93
|
+
throw new Error(`LDtk IntGrid "${inst.__identifier}" uses a ${inst.__gridSize}px grid; expected ${grid}px`);
|
|
94
|
+
const def = project.defs.layers.find((l) => l.uid === inst.layerDefUid);
|
|
95
|
+
const names = new Map((def?.intGridValues ?? []).map((v) => [v.value, (v.identifier ?? "").toLowerCase()]));
|
|
96
|
+
inst.intGridCsv.forEach((value, i) => {
|
|
97
|
+
if (value === 0)
|
|
98
|
+
return;
|
|
99
|
+
const rule = options.intGrid?.[value] ?? (ONE_WAY_NAMES.has(names.get(value) ?? "") ? "oneWay" : "solid");
|
|
100
|
+
if (rule === "none")
|
|
101
|
+
return;
|
|
102
|
+
map.setCollision(i % inst.__cWid, Math.floor(i / inst.__cWid), rule === "oneWay" ? Collision.OneWay : Collision.Solid);
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=ldtk.js.map
|
package/dist/ldtk.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ldtk.js","sourceRoot":"","sources":["../src/ldtk.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,EAAoC,OAAO,EAAgB,MAAM,cAAc,CAAC;AA+ElH,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC,CAAC,QAAQ,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC,CAAC;AAEjE,2DAA2D;AAC3D,MAAM,UAAU,QAAQ,CAAC,OAAoB,EAAE,OAAwB;IACrE,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,KAAK,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAC7G,IAAI,CAAC,KAAK;QAAE,MAAM,IAAI,KAAK,CAAC,eAAe,OAAO,CAAC,KAAK,wBAAwB,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACtI,IAAI,CAAC,KAAK,CAAC,cAAc,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CACb,eAAe,KAAK,CAAC,UAAU,2BAA2B,KAAK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AAE,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,UAAU,IAAI,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,CAAC;IAC5G,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE;QACnC,IAAI,KAAK,KAAK,CAAC;YAAE,OAAO;QACxB,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;QAC1G,IAAI,IAAI,KAAK,MAAM;YAAE,OAAO;QAC5B,GAAG,CAAC,YAAY,CAAC,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,EAAE,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IACzH,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/dist/tiled.d.ts
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import type { TextureSource } from "@debuffjp/core";
|
|
2
|
+
import { type ImageRegion, Tilemap } from "./tilemap.js";
|
|
3
|
+
interface TiledProperty {
|
|
4
|
+
name: string;
|
|
5
|
+
type?: string;
|
|
6
|
+
value: unknown;
|
|
7
|
+
}
|
|
8
|
+
interface TiledChunk {
|
|
9
|
+
x: number;
|
|
10
|
+
y: number;
|
|
11
|
+
width: number;
|
|
12
|
+
height: number;
|
|
13
|
+
data: number[] | string;
|
|
14
|
+
}
|
|
15
|
+
interface TiledLayer {
|
|
16
|
+
type: "tilelayer" | "objectgroup" | "group" | "imagelayer";
|
|
17
|
+
name: string;
|
|
18
|
+
visible?: boolean;
|
|
19
|
+
opacity?: number;
|
|
20
|
+
offsetx?: number;
|
|
21
|
+
offsety?: number;
|
|
22
|
+
parallaxx?: number;
|
|
23
|
+
parallaxy?: number;
|
|
24
|
+
width?: number;
|
|
25
|
+
height?: number;
|
|
26
|
+
data?: number[] | string;
|
|
27
|
+
chunks?: TiledChunk[];
|
|
28
|
+
encoding?: "csv" | "base64";
|
|
29
|
+
compression?: string;
|
|
30
|
+
objects?: {
|
|
31
|
+
id: number;
|
|
32
|
+
name?: string;
|
|
33
|
+
type?: string;
|
|
34
|
+
class?: string;
|
|
35
|
+
x: number;
|
|
36
|
+
y: number;
|
|
37
|
+
width?: number;
|
|
38
|
+
height?: number;
|
|
39
|
+
gid?: number;
|
|
40
|
+
properties?: TiledProperty[];
|
|
41
|
+
}[];
|
|
42
|
+
layers?: TiledLayer[];
|
|
43
|
+
properties?: TiledProperty[];
|
|
44
|
+
}
|
|
45
|
+
export interface TiledTileset {
|
|
46
|
+
firstgid?: number;
|
|
47
|
+
source?: string;
|
|
48
|
+
name?: string;
|
|
49
|
+
image?: string;
|
|
50
|
+
columns?: number;
|
|
51
|
+
tilecount?: number;
|
|
52
|
+
tilewidth?: number;
|
|
53
|
+
tileheight?: number;
|
|
54
|
+
margin?: number;
|
|
55
|
+
spacing?: number;
|
|
56
|
+
tiles?: {
|
|
57
|
+
id: number;
|
|
58
|
+
properties?: TiledProperty[];
|
|
59
|
+
type?: string;
|
|
60
|
+
class?: string;
|
|
61
|
+
}[];
|
|
62
|
+
}
|
|
63
|
+
export interface TiledMap {
|
|
64
|
+
width: number;
|
|
65
|
+
height: number;
|
|
66
|
+
tilewidth: number;
|
|
67
|
+
tileheight: number;
|
|
68
|
+
infinite?: boolean;
|
|
69
|
+
orientation?: string;
|
|
70
|
+
layers: TiledLayer[];
|
|
71
|
+
tilesets: TiledTileset[];
|
|
72
|
+
properties?: TiledProperty[];
|
|
73
|
+
}
|
|
74
|
+
export interface FromTiledOptions {
|
|
75
|
+
/** Resolve a tileset image path (as written in the map or tileset) to a loaded image. */
|
|
76
|
+
image: (path: string, tileset: TiledTileset) => TextureSource | ImageRegion;
|
|
77
|
+
/** External tilesets (`.tsj`) by the `source` path the map references. */
|
|
78
|
+
tilesets?: Record<string, TiledTileset>;
|
|
79
|
+
/**
|
|
80
|
+
* Collision. By default: tiles with a `solid`/`collides`/`oneWay` property in any layer, plus every
|
|
81
|
+
* tile in layers whose `collision` property is true. Pass layer names to use those layers instead.
|
|
82
|
+
*/
|
|
83
|
+
collisionLayers?: string[];
|
|
84
|
+
}
|
|
85
|
+
/** Build a `Tilemap` from a Tiled JSON map (`.tmj` / `.json`). Orthogonal maps only. */
|
|
86
|
+
export declare function fromTiled(map: TiledMap, options: FromTiledOptions): Tilemap;
|
|
87
|
+
export {};
|
|
88
|
+
//# sourceMappingURL=tiled.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tiled.d.ts","sourceRoot":"","sources":["../src/tiled.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,KAAK,WAAW,EAAkB,OAAO,EAAgB,MAAM,cAAc,CAAC;AAGvF,UAAU,aAAa;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,OAAO,CAAC;CAChB;AACD,UAAU,UAAU;IAClB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC;CACzB;AACD,UAAU,UAAU;IAClB,IAAI,EAAE,WAAW,GAAG,aAAa,GAAG,OAAO,GAAG,YAAY,CAAC;IAC3D,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,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EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,UAAU,CAAC,EAAE,aAAa,EAAE,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;CACvF;AACD,MAAM,WAAW,QAAQ;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,UAAU,EAAE,CAAC;IACrB,QAAQ,EAAE,YAAY,EAAE,CAAC;IACzB,UAAU,CAAC,EAAE,aAAa,EAAE,CAAC;CAC9B;AAED,MAAM,WAAW,gBAAgB;IAC/B,yFAAyF;IACzF,KAAK,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,KAAK,aAAa,GAAG,WAAW,CAAC;IAC5E,0EAA0E;IAC1E,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IACxC;;;OAGG;IACH,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;CAC5B;AAED,wFAAwF;AACxF,wBAAgB,SAAS,CAAC,GAAG,EAAE,QAAQ,EAAE,OAAO,EAAE,gBAAgB,GAAG,OAAO,CA0F3E"}
|
package/dist/tiled.js
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { Tilemap } from "./tilemap.js";
|
|
2
|
+
/** Build a `Tilemap` from a Tiled JSON map (`.tmj` / `.json`). Orthogonal maps only. */
|
|
3
|
+
export function fromTiled(map, options) {
|
|
4
|
+
if (map.orientation && map.orientation !== "orthogonal") {
|
|
5
|
+
throw new Error(`Tiled map orientation "${map.orientation}" isn't supported yet; use orthogonal`);
|
|
6
|
+
}
|
|
7
|
+
const tilesets = map.tilesets.map((ref) => {
|
|
8
|
+
const external = ref.source ? options.tilesets?.[ref.source] : undefined;
|
|
9
|
+
const ts = external ? { ...external, ...(ref.firstgid === undefined ? {} : { firstgid: ref.firstgid }) } : ref;
|
|
10
|
+
if (ref.source && !options.tilesets?.[ref.source]) {
|
|
11
|
+
throw new Error(`External tileset "${ref.source}" not provided. Pass it in options.tilesets["${ref.source}"]`);
|
|
12
|
+
}
|
|
13
|
+
if (!ts.image)
|
|
14
|
+
throw new Error(`Tileset "${ts.name ?? ref.source}" has no image. Image-collection tilesets aren't supported yet`);
|
|
15
|
+
const properties = {};
|
|
16
|
+
for (const tile of ts.tiles ?? []) {
|
|
17
|
+
const props = toProps(tile.properties);
|
|
18
|
+
const kind = tile.class ?? tile.type;
|
|
19
|
+
if (kind)
|
|
20
|
+
props.class = kind;
|
|
21
|
+
properties[tile.id] = props;
|
|
22
|
+
}
|
|
23
|
+
return {
|
|
24
|
+
firstId: ts.firstgid ?? 1,
|
|
25
|
+
image: options.image(ts.image, ts),
|
|
26
|
+
tileWidth: ts.tilewidth ?? map.tilewidth,
|
|
27
|
+
tileHeight: ts.tileheight ?? map.tileheight,
|
|
28
|
+
columns: ts.columns ?? 1,
|
|
29
|
+
count: ts.tilecount ?? 0,
|
|
30
|
+
margin: ts.margin ?? 0,
|
|
31
|
+
spacing: ts.spacing ?? 0,
|
|
32
|
+
properties,
|
|
33
|
+
};
|
|
34
|
+
});
|
|
35
|
+
const flat = flatten(map.layers);
|
|
36
|
+
// Infinite maps store chunks; find their bounds so the map becomes a finite grid.
|
|
37
|
+
let minX = 0;
|
|
38
|
+
let minY = 0;
|
|
39
|
+
let width = map.width;
|
|
40
|
+
let height = map.height;
|
|
41
|
+
if (map.infinite) {
|
|
42
|
+
const chunks = flat.flatMap((l) => l.layer.chunks ?? []);
|
|
43
|
+
if (chunks.length) {
|
|
44
|
+
minX = Math.min(...chunks.map((c) => c.x));
|
|
45
|
+
minY = Math.min(...chunks.map((c) => c.y));
|
|
46
|
+
width = Math.max(...chunks.map((c) => c.x + c.width)) - minX;
|
|
47
|
+
height = Math.max(...chunks.map((c) => c.y + c.height)) - minY;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
const result = new Tilemap({ width, height, tileWidth: map.tilewidth, tileHeight: map.tileheight, tilesets, layers: [] });
|
|
51
|
+
result.properties = toProps(map.properties);
|
|
52
|
+
const shiftX = -minX * map.tilewidth;
|
|
53
|
+
const shiftY = -minY * map.tileheight;
|
|
54
|
+
const collisionByProperty = [];
|
|
55
|
+
for (const { layer, offsetX, offsetY, opacity, parallaxX, parallaxY, visible } of flat) {
|
|
56
|
+
if (layer.type === "tilelayer") {
|
|
57
|
+
const data = new Uint32Array(width * height);
|
|
58
|
+
const blit = (src, x0, y0, w, h) => {
|
|
59
|
+
const cells = decode(src, layer);
|
|
60
|
+
for (let r = 0; r < h; r++)
|
|
61
|
+
for (let c = 0; c < w; c++)
|
|
62
|
+
data[(y0 + r) * width + (x0 + c)] = cells[r * w + c] ?? 0;
|
|
63
|
+
};
|
|
64
|
+
if (layer.chunks)
|
|
65
|
+
for (const c of layer.chunks)
|
|
66
|
+
blit(c.data, c.x - minX, c.y - minY, c.width, c.height);
|
|
67
|
+
else if (layer.data)
|
|
68
|
+
blit(layer.data, 0, 0, layer.width ?? width, layer.height ?? height);
|
|
69
|
+
result.addLayer(layer.name, { data, visible, opacity, parallaxX, parallaxY, offsetX, offsetY });
|
|
70
|
+
if (toProps(layer.properties).collision === true)
|
|
71
|
+
collisionByProperty.push(layer.name);
|
|
72
|
+
}
|
|
73
|
+
else if (layer.type === "objectgroup") {
|
|
74
|
+
result.objectLayers.set(layer.name, (layer.objects ?? []).map((o) => ({
|
|
75
|
+
id: o.id,
|
|
76
|
+
name: o.name ?? "",
|
|
77
|
+
type: o.class ?? o.type ?? "",
|
|
78
|
+
x: o.x + offsetX + shiftX,
|
|
79
|
+
// Tile objects are anchored bottom-left in Tiled; normalise everything to top-left.
|
|
80
|
+
y: o.y + offsetY + shiftY - (o.gid ? (o.height ?? 0) : 0),
|
|
81
|
+
width: o.width ?? 0,
|
|
82
|
+
height: o.height ?? 0,
|
|
83
|
+
properties: { ...toProps(o.properties), ...(o.gid ? { gid: o.gid } : {}) },
|
|
84
|
+
})));
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if (options.collisionLayers)
|
|
88
|
+
result.collideFrom(options.collisionLayers);
|
|
89
|
+
else {
|
|
90
|
+
result.collideFrom(result.layers.map((l) => l.name));
|
|
91
|
+
if (collisionByProperty.length)
|
|
92
|
+
result.collideFrom(collisionByProperty, { everyTile: true });
|
|
93
|
+
}
|
|
94
|
+
return result;
|
|
95
|
+
}
|
|
96
|
+
/** Flatten groups, combining offsets, opacity, parallax and visibility. */
|
|
97
|
+
function flatten(layers, parent) {
|
|
98
|
+
return layers.flatMap((layer) => {
|
|
99
|
+
const own = {
|
|
100
|
+
offsetX: (parent?.offsetX ?? 0) + (layer.offsetx ?? 0),
|
|
101
|
+
offsetY: (parent?.offsetY ?? 0) + (layer.offsety ?? 0),
|
|
102
|
+
opacity: (parent?.opacity ?? 1) * (layer.opacity ?? 1),
|
|
103
|
+
parallaxX: (parent?.parallaxX ?? 1) * (layer.parallaxx ?? 1),
|
|
104
|
+
parallaxY: (parent?.parallaxY ?? 1) * (layer.parallaxy ?? 1),
|
|
105
|
+
visible: (parent?.visible ?? true) && (layer.visible ?? true),
|
|
106
|
+
};
|
|
107
|
+
return layer.type === "group" ? flatten(layer.layers ?? [], own) : [{ layer, ...own }];
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
function decode(src, layer) {
|
|
111
|
+
if (Array.isArray(src))
|
|
112
|
+
return src;
|
|
113
|
+
if (layer.compression) {
|
|
114
|
+
throw new Error(`Tile layer "${layer.name}" uses ${layer.compression} compression. Export with CSV or uncompressed Base64`);
|
|
115
|
+
}
|
|
116
|
+
const bytes = Uint8Array.from(atob(src), (c) => c.charCodeAt(0));
|
|
117
|
+
const view = new DataView(bytes.buffer);
|
|
118
|
+
const out = new Uint32Array(bytes.length / 4);
|
|
119
|
+
for (let i = 0; i < out.length; i++)
|
|
120
|
+
out[i] = view.getUint32(i * 4, true);
|
|
121
|
+
return out;
|
|
122
|
+
}
|
|
123
|
+
function toProps(props) {
|
|
124
|
+
const out = {};
|
|
125
|
+
for (const p of props ?? [])
|
|
126
|
+
out[p.name] = p.value;
|
|
127
|
+
return out;
|
|
128
|
+
}
|
|
129
|
+
//# sourceMappingURL=tiled.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tiled.js","sourceRoot":"","sources":["../src/tiled.ts"],"names":[],"mappings":"AACA,OAAO,EAAoC,OAAO,EAAgB,MAAM,cAAc,CAAC;AAkFvF,wFAAwF;AACxF,MAAM,UAAU,SAAS,CAAC,GAAa,EAAE,OAAyB;IAChE,IAAI,GAAG,CAAC,WAAW,IAAI,GAAG,CAAC,WAAW,KAAK,YAAY,EAAE,CAAC;QACxD,MAAM,IAAI,KAAK,CAAC,0BAA0B,GAAG,CAAC,WAAW,uCAAuC,CAAC,CAAC;IACpG,CAAC;IACD,MAAM,QAAQ,GAAG,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,GAAG,EAAW,EAAE;QACjD,MAAM,QAAQ,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QACzE,MAAM,EAAE,GAAiB,QAAQ,CAAC,CAAC,CAAC,EAAE,GAAG,QAAQ,EAAE,GAAG,CAAC,GAAG,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,GAAG,CAAC,QAAQ,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC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AC,EAAE;QAAE,GAAG,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,CAAC;IAC1E,OAAO,GAAG,CAAC;AACb,CAAC;AAED,SAAS,OAAO,CAAC,KAAuB;IACtC,MAAM,GAAG,GAA4B,EAAE,CAAC;IACxC,KAAK,MAAM,CAAC,IAAI,KAAK,IAAI,EAAE;QAAE,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC;IACnD,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import type { Draw, TextureSource } from "@debuffjp/core";
|
|
2
|
+
import { type Body, type MoveOptions, type MoveResult } from "./collide.js";
|
|
3
|
+
/** Tile flip/rotation flags stored in the top bits of a tile id (Tiled's convention). */
|
|
4
|
+
export declare const FLIP_H = 2147483648;
|
|
5
|
+
export declare const FLIP_V = 1073741824;
|
|
6
|
+
export declare const FLIP_D = 536870912;
|
|
7
|
+
/** Collision kinds in the collision grid. `OneWay` is solid only from above (jump-through platforms). */
|
|
8
|
+
export declare const Collision: {
|
|
9
|
+
readonly None: 0;
|
|
10
|
+
readonly Solid: 1;
|
|
11
|
+
readonly OneWay: 2;
|
|
12
|
+
};
|
|
13
|
+
export type Collision = (typeof Collision)[keyof typeof Collision];
|
|
14
|
+
/** An image region, e.g. from `assets.frame(id)` when the tileset image was packed into an atlas. */
|
|
15
|
+
export interface ImageRegion {
|
|
16
|
+
image: TextureSource;
|
|
17
|
+
x: number;
|
|
18
|
+
y: number;
|
|
19
|
+
}
|
|
20
|
+
export interface Tileset {
|
|
21
|
+
/** First tile id (gid) this tileset covers. Tile id 0 always means "empty". */
|
|
22
|
+
firstId: number;
|
|
23
|
+
/** The tileset image, or a region of an atlas holding it. */
|
|
24
|
+
image: TextureSource | ImageRegion;
|
|
25
|
+
tileWidth: number;
|
|
26
|
+
tileHeight: number;
|
|
27
|
+
columns: number;
|
|
28
|
+
count: number;
|
|
29
|
+
margin?: number;
|
|
30
|
+
spacing?: number;
|
|
31
|
+
/** Per local tile index: custom properties (e.g. `solid`, `oneWay`). */
|
|
32
|
+
properties?: Record<number, Record<string, unknown>>;
|
|
33
|
+
}
|
|
34
|
+
export interface TileLayer {
|
|
35
|
+
name: string;
|
|
36
|
+
/** Tile ids row-major, width × height; 0 = empty. High bits carry FLIP_* flags. */
|
|
37
|
+
data: Uint32Array;
|
|
38
|
+
visible: boolean;
|
|
39
|
+
opacity: number;
|
|
40
|
+
/** Scroll factor relative to the camera; 1 = world space, 0 = fixed to the screen. */
|
|
41
|
+
parallaxX: number;
|
|
42
|
+
parallaxY: number;
|
|
43
|
+
offsetX: number;
|
|
44
|
+
offsetY: number;
|
|
45
|
+
}
|
|
46
|
+
export interface MapObject {
|
|
47
|
+
id: number;
|
|
48
|
+
name: string;
|
|
49
|
+
/** Tiled class/type or LDtk entity identifier. */
|
|
50
|
+
type: string;
|
|
51
|
+
x: number;
|
|
52
|
+
y: number;
|
|
53
|
+
width: number;
|
|
54
|
+
height: number;
|
|
55
|
+
properties: Record<string, unknown>;
|
|
56
|
+
}
|
|
57
|
+
export interface TilemapOptions {
|
|
58
|
+
/** Size in tiles. */
|
|
59
|
+
width: number;
|
|
60
|
+
height: number;
|
|
61
|
+
tileWidth: number;
|
|
62
|
+
tileHeight: number;
|
|
63
|
+
tilesets?: Tileset[];
|
|
64
|
+
/** Layer names to create empty, in draw order. Default ["main"]. */
|
|
65
|
+
layers?: string[];
|
|
66
|
+
}
|
|
67
|
+
export interface TileLayerDrawOptions {
|
|
68
|
+
/** Draw only these layers, by name. Default: every visible layer. */
|
|
69
|
+
layers?: readonly string[];
|
|
70
|
+
/** Cull to this camera's view and apply layer parallax. Draw inside `draw.withCamera(camera, ...)`. */
|
|
71
|
+
camera?: {
|
|
72
|
+
x: number;
|
|
73
|
+
y: number;
|
|
74
|
+
zoom: number;
|
|
75
|
+
width: number;
|
|
76
|
+
height: number;
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* A grid of tile layers, tilesets, object layers and a collision grid. Build one in code, or import
|
|
81
|
+
* with `fromTiled` / `fromLDtk`. Positions are in pixels (world units); tile coordinates are columns/rows.
|
|
82
|
+
*/
|
|
83
|
+
export declare class Tilemap {
|
|
84
|
+
readonly width: number;
|
|
85
|
+
readonly height: number;
|
|
86
|
+
readonly tileWidth: number;
|
|
87
|
+
readonly tileHeight: number;
|
|
88
|
+
readonly tilesets: Tileset[];
|
|
89
|
+
readonly layers: TileLayer[];
|
|
90
|
+
readonly objectLayers: Map<string, MapObject[]>;
|
|
91
|
+
/** One `Collision` value per cell. */
|
|
92
|
+
readonly collision: Uint8Array;
|
|
93
|
+
/** Map-level custom properties. */
|
|
94
|
+
properties: Record<string, unknown>;
|
|
95
|
+
/** Which map edges block movement. Default: solid sides, open top and bottom (so bodies can fall into pits). */
|
|
96
|
+
edges: {
|
|
97
|
+
left: boolean;
|
|
98
|
+
right: boolean;
|
|
99
|
+
top: boolean;
|
|
100
|
+
bottom: boolean;
|
|
101
|
+
};
|
|
102
|
+
/** Frame per tile id (without flags), built lazily. */
|
|
103
|
+
private readonly frames;
|
|
104
|
+
/** Reused per tile so drawing doesn't allocate. */
|
|
105
|
+
private readonly spriteOptions;
|
|
106
|
+
constructor(options: TilemapOptions);
|
|
107
|
+
/** Width and height in pixels. */
|
|
108
|
+
get pixelWidth(): number;
|
|
109
|
+
get pixelHeight(): number;
|
|
110
|
+
addLayer(name: string, init?: Partial<Omit<TileLayer, "name">>): TileLayer;
|
|
111
|
+
layer(name: string): TileLayer | undefined;
|
|
112
|
+
/** Objects in an object layer (spawn points, triggers, entities). */
|
|
113
|
+
objects(layer: string): MapObject[];
|
|
114
|
+
inBounds(col: number, row: number): boolean;
|
|
115
|
+
/** Tile id (with flags) at a cell, 0 if empty or out of bounds. */
|
|
116
|
+
get(layer: string, col: number, row: number): number;
|
|
117
|
+
set(layer: string, col: number, row: number, id: number): void;
|
|
118
|
+
/** Tile id at a world position. */
|
|
119
|
+
tileAt(layer: string, x: number, y: number): number;
|
|
120
|
+
/** Custom properties of a tile id, from its tileset. */
|
|
121
|
+
tileProperties(id: number): Record<string, unknown> | undefined;
|
|
122
|
+
collisionAt(col: number, row: number): Collision;
|
|
123
|
+
setCollision(col: number, row: number, kind: Collision): void;
|
|
124
|
+
/**
|
|
125
|
+
* Fill the collision grid from tile data: cells in `layers` whose tile has a truthy `solid` / `oneWay`
|
|
126
|
+
* property (or every non-empty cell, with `everyTile`) become solid / one-way.
|
|
127
|
+
*/
|
|
128
|
+
collideFrom(layers: readonly string[], options?: {
|
|
129
|
+
everyTile?: boolean;
|
|
130
|
+
}): this;
|
|
131
|
+
/** Move a body through the map with tile collision. See {@link move}. */
|
|
132
|
+
move(body: Body, dx: number, dy: number, options?: MoveOptions): MoveResult;
|
|
133
|
+
/**
|
|
134
|
+
* Draw tile layers. With a camera, only tiles in view are drawn and parallax is applied; call it
|
|
135
|
+
* inside `draw.withCamera(camera, ...)`. Allocation-free per tile.
|
|
136
|
+
*/
|
|
137
|
+
draw(draw: Draw, options?: TileLayerDrawOptions): void;
|
|
138
|
+
private requireLayer;
|
|
139
|
+
private tilesetFor;
|
|
140
|
+
private frame;
|
|
141
|
+
}
|
|
142
|
+
//# sourceMappingURL=tilemap.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tilemap.d.ts","sourceRoot":"","sources":["../src/tilemap.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAS,aAAa,EAAE,MAAM,gBAAgB,CAAC;AACjE,OAAO,EAAE,KAAK,IAAI,EAAE,KAAK,WAAW,EAAE,KAAK,UAAU,EAAQ,MAAM,cAAc,CAAC;AAElF,yFAAyF;AACzF,eAAO,MAAM,MAAM,aAAa,CAAC;AACjC,eAAO,MAAM,MAAM,aAAa,CAAC;AACjC,eAAO,MAAM,MAAM,YA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EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,GAAG,IAAI,CAE5D;IAED;;;OAGG;IACH,WAAW,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,EAAE,OAAO,GAAE;QAAE,SAAS,CAAC,EAAE,OAAO,CAAA;KAAO,GAAG,IAAI,CAYlF;IAED,yEAAyE;IACzE,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,UAAU,CAE1E;IAID;;;OAGG;IACH,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,GAAE,oBAAyB,GAAG,IAAI,CAuCzD;IAID,OAAO,CAAC,YAAY;IAMpB,OAAO,CAAC,UAAU;IASlB,OAAO,CAAC,KAAK;CAqBd"}
|
package/dist/tilemap.js
ADDED
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
import { move } from "./collide.js";
|
|
2
|
+
/** Tile flip/rotation flags stored in the top bits of a tile id (Tiled's convention). */
|
|
3
|
+
export const FLIP_H = 0x80000000;
|
|
4
|
+
export const FLIP_V = 0x40000000;
|
|
5
|
+
export const FLIP_D = 0x20000000;
|
|
6
|
+
const ID_MASK = 0x1fffffff;
|
|
7
|
+
/** Collision kinds in the collision grid. `OneWay` is solid only from above (jump-through platforms). */
|
|
8
|
+
export const Collision = { None: 0, Solid: 1, OneWay: 2 };
|
|
9
|
+
/**
|
|
10
|
+
* A grid of tile layers, tilesets, object layers and a collision grid. Build one in code, or import
|
|
11
|
+
* with `fromTiled` / `fromLDtk`. Positions are in pixels (world units); tile coordinates are columns/rows.
|
|
12
|
+
*/
|
|
13
|
+
export class Tilemap {
|
|
14
|
+
width;
|
|
15
|
+
height;
|
|
16
|
+
tileWidth;
|
|
17
|
+
tileHeight;
|
|
18
|
+
tilesets;
|
|
19
|
+
layers = [];
|
|
20
|
+
objectLayers = new Map();
|
|
21
|
+
/** One `Collision` value per cell. */
|
|
22
|
+
collision;
|
|
23
|
+
/** Map-level custom properties. */
|
|
24
|
+
properties = {};
|
|
25
|
+
/** Which map edges block movement. Default: solid sides, open top and bottom (so bodies can fall into pits). */
|
|
26
|
+
edges = { left: true, right: true, top: false, bottom: false };
|
|
27
|
+
/** Frame per tile id (without flags), built lazily. */
|
|
28
|
+
frames = [];
|
|
29
|
+
/** Reused per tile so drawing doesn't allocate. */
|
|
30
|
+
spriteOptions = {
|
|
31
|
+
origin: [0.5, 0.5],
|
|
32
|
+
flipX: false,
|
|
33
|
+
flipY: false,
|
|
34
|
+
rotation: 0,
|
|
35
|
+
alpha: 1,
|
|
36
|
+
};
|
|
37
|
+
constructor(options) {
|
|
38
|
+
this.width = options.width;
|
|
39
|
+
this.height = options.height;
|
|
40
|
+
this.tileWidth = options.tileWidth;
|
|
41
|
+
this.tileHeight = options.tileHeight;
|
|
42
|
+
this.tilesets = [...(options.tilesets ?? [])].sort((a, b) => a.firstId - b.firstId);
|
|
43
|
+
this.collision = new Uint8Array(this.width * this.height);
|
|
44
|
+
for (const name of options.layers ?? ["main"])
|
|
45
|
+
this.addLayer(name);
|
|
46
|
+
}
|
|
47
|
+
/** Width and height in pixels. */
|
|
48
|
+
get pixelWidth() {
|
|
49
|
+
return this.width * this.tileWidth;
|
|
50
|
+
}
|
|
51
|
+
get pixelHeight() {
|
|
52
|
+
return this.height * this.tileHeight;
|
|
53
|
+
}
|
|
54
|
+
addLayer(name, init = {}) {
|
|
55
|
+
if (this.layer(name))
|
|
56
|
+
throw new Error(`Tile layer "${name}" already exists`);
|
|
57
|
+
const layer = {
|
|
58
|
+
name,
|
|
59
|
+
data: init.data ?? new Uint32Array(this.width * this.height),
|
|
60
|
+
visible: init.visible ?? true,
|
|
61
|
+
opacity: init.opacity ?? 1,
|
|
62
|
+
parallaxX: init.parallaxX ?? 1,
|
|
63
|
+
parallaxY: init.parallaxY ?? 1,
|
|
64
|
+
offsetX: init.offsetX ?? 0,
|
|
65
|
+
offsetY: init.offsetY ?? 0,
|
|
66
|
+
};
|
|
67
|
+
if (layer.data.length !== this.width * this.height) {
|
|
68
|
+
throw new Error(`Tile layer "${name}" has ${layer.data.length} cells; expected ${this.width * this.height}`);
|
|
69
|
+
}
|
|
70
|
+
this.layers.push(layer);
|
|
71
|
+
return layer;
|
|
72
|
+
}
|
|
73
|
+
layer(name) {
|
|
74
|
+
return this.layers.find((l) => l.name === name);
|
|
75
|
+
}
|
|
76
|
+
/** Objects in an object layer (spawn points, triggers, entities). */
|
|
77
|
+
objects(layer) {
|
|
78
|
+
return this.objectLayers.get(layer) ?? [];
|
|
79
|
+
}
|
|
80
|
+
// ---- cells -------------------------------------------------------------------------------------
|
|
81
|
+
inBounds(col, row) {
|
|
82
|
+
return col >= 0 && row >= 0 && col < this.width && row < this.height;
|
|
83
|
+
}
|
|
84
|
+
/** Tile id (with flags) at a cell, 0 if empty or out of bounds. */
|
|
85
|
+
get(layer, col, row) {
|
|
86
|
+
if (!this.inBounds(col, row))
|
|
87
|
+
return 0;
|
|
88
|
+
return this.requireLayer(layer).data[row * this.width + col] ?? 0;
|
|
89
|
+
}
|
|
90
|
+
set(layer, col, row, id) {
|
|
91
|
+
if (!this.inBounds(col, row))
|
|
92
|
+
return;
|
|
93
|
+
this.requireLayer(layer).data[row * this.width + col] = id >>> 0;
|
|
94
|
+
}
|
|
95
|
+
/** Tile id at a world position. */
|
|
96
|
+
tileAt(layer, x, y) {
|
|
97
|
+
return this.get(layer, Math.floor(x / this.tileWidth), Math.floor(y / this.tileHeight));
|
|
98
|
+
}
|
|
99
|
+
/** Custom properties of a tile id, from its tileset. */
|
|
100
|
+
tileProperties(id) {
|
|
101
|
+
const gid = id & ID_MASK;
|
|
102
|
+
const ts = this.tilesetFor(gid);
|
|
103
|
+
return ts?.properties?.[gid - ts.firstId];
|
|
104
|
+
}
|
|
105
|
+
// ---- collision ---------------------------------------------------------------------------------
|
|
106
|
+
collisionAt(col, row) {
|
|
107
|
+
if (col < 0)
|
|
108
|
+
return this.edges.left ? Collision.Solid : Collision.None;
|
|
109
|
+
if (col >= this.width)
|
|
110
|
+
return this.edges.right ? Collision.Solid : Collision.None;
|
|
111
|
+
if (row < 0)
|
|
112
|
+
return this.edges.top ? Collision.Solid : Collision.None;
|
|
113
|
+
if (row >= this.height)
|
|
114
|
+
return this.edges.bottom ? Collision.Solid : Collision.None;
|
|
115
|
+
return (this.collision[row * this.width + col] ?? 0);
|
|
116
|
+
}
|
|
117
|
+
setCollision(col, row, kind) {
|
|
118
|
+
if (this.inBounds(col, row))
|
|
119
|
+
this.collision[row * this.width + col] = kind;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Fill the collision grid from tile data: cells in `layers` whose tile has a truthy `solid` / `oneWay`
|
|
123
|
+
* property (or every non-empty cell, with `everyTile`) become solid / one-way.
|
|
124
|
+
*/
|
|
125
|
+
collideFrom(layers, options = {}) {
|
|
126
|
+
for (const name of layers) {
|
|
127
|
+
const { data } = this.requireLayer(name);
|
|
128
|
+
for (let i = 0; i < data.length; i++) {
|
|
129
|
+
const id = data[i] ?? 0;
|
|
130
|
+
if ((id & ID_MASK) === 0)
|
|
131
|
+
continue;
|
|
132
|
+
const props = this.tileProperties(id);
|
|
133
|
+
if (props?.oneWay)
|
|
134
|
+
this.collision[i] = Collision.OneWay;
|
|
135
|
+
else if (options.everyTile || props?.solid || props?.collides)
|
|
136
|
+
this.collision[i] = Collision.Solid;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return this;
|
|
140
|
+
}
|
|
141
|
+
/** Move a body through the map with tile collision. See {@link move}. */
|
|
142
|
+
move(body, dx, dy, options) {
|
|
143
|
+
return move(this, body, dx, dy, options);
|
|
144
|
+
}
|
|
145
|
+
// ---- rendering ---------------------------------------------------------------------------------
|
|
146
|
+
/**
|
|
147
|
+
* Draw tile layers. With a camera, only tiles in view are drawn and parallax is applied; call it
|
|
148
|
+
* inside `draw.withCamera(camera, ...)`. Allocation-free per tile.
|
|
149
|
+
*/
|
|
150
|
+
draw(draw, options = {}) {
|
|
151
|
+
const { tileWidth: tw, tileHeight: th } = this;
|
|
152
|
+
const cam = options.camera;
|
|
153
|
+
const o = this.spriteOptions;
|
|
154
|
+
const baseAlpha = draw.alpha;
|
|
155
|
+
for (const layer of this.layers) {
|
|
156
|
+
if (options.layers ? !options.layers.includes(layer.name) : !layer.visible)
|
|
157
|
+
continue;
|
|
158
|
+
// Parallax: shift the layer by the part of the camera motion it should not follow.
|
|
159
|
+
const px = cam ? cam.x * (1 - layer.parallaxX) : 0;
|
|
160
|
+
const py = cam ? cam.y * (1 - layer.parallaxY) : 0;
|
|
161
|
+
const ox = layer.offsetX + px;
|
|
162
|
+
const oy = layer.offsetY + py;
|
|
163
|
+
let c0 = 0;
|
|
164
|
+
let r0 = 0;
|
|
165
|
+
let c1 = this.width - 1;
|
|
166
|
+
let r1 = this.height - 1;
|
|
167
|
+
if (cam) {
|
|
168
|
+
const hw = cam.width / 2 / cam.zoom;
|
|
169
|
+
const hh = cam.height / 2 / cam.zoom;
|
|
170
|
+
c0 = Math.max(0, Math.floor((cam.x - hw - ox) / tw));
|
|
171
|
+
r0 = Math.max(0, Math.floor((cam.y - hh - oy) / th));
|
|
172
|
+
c1 = Math.min(this.width - 1, Math.floor((cam.x + hw - ox) / tw));
|
|
173
|
+
r1 = Math.min(this.height - 1, Math.floor((cam.y + hh - oy) / th));
|
|
174
|
+
}
|
|
175
|
+
draw.alpha = baseAlpha * layer.opacity;
|
|
176
|
+
const { data } = layer;
|
|
177
|
+
for (let row = r0; row <= r1; row++) {
|
|
178
|
+
for (let col = c0; col <= c1; col++) {
|
|
179
|
+
const raw = data[row * this.width + col] ?? 0;
|
|
180
|
+
const gid = raw & ID_MASK;
|
|
181
|
+
if (gid === 0)
|
|
182
|
+
continue;
|
|
183
|
+
const frame = this.frame(gid);
|
|
184
|
+
if (!frame)
|
|
185
|
+
continue;
|
|
186
|
+
applyFlips(o, raw);
|
|
187
|
+
draw.sprite(frame, col * tw + tw / 2 + ox, row * th + th / 2 + oy, o);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
draw.alpha = baseAlpha;
|
|
192
|
+
}
|
|
193
|
+
// ---- internals ---------------------------------------------------------------------------------
|
|
194
|
+
requireLayer(name) {
|
|
195
|
+
const layer = this.layer(name);
|
|
196
|
+
if (!layer)
|
|
197
|
+
throw new Error(`Unknown tile layer "${name}". Layers: ${this.layers.map((l) => l.name).join(", ") || "none"}`);
|
|
198
|
+
return layer;
|
|
199
|
+
}
|
|
200
|
+
tilesetFor(gid) {
|
|
201
|
+
let found;
|
|
202
|
+
for (const ts of this.tilesets) {
|
|
203
|
+
if (ts.firstId <= gid)
|
|
204
|
+
found = ts;
|
|
205
|
+
else
|
|
206
|
+
break;
|
|
207
|
+
}
|
|
208
|
+
return found && gid - found.firstId < found.count ? found : undefined;
|
|
209
|
+
}
|
|
210
|
+
frame(gid) {
|
|
211
|
+
let f = this.frames[gid];
|
|
212
|
+
if (f)
|
|
213
|
+
return f;
|
|
214
|
+
const ts = this.tilesetFor(gid);
|
|
215
|
+
if (!ts)
|
|
216
|
+
return undefined;
|
|
217
|
+
const local = gid - ts.firstId;
|
|
218
|
+
const margin = ts.margin ?? 0;
|
|
219
|
+
const spacing = ts.spacing ?? 0;
|
|
220
|
+
const col = local % ts.columns;
|
|
221
|
+
const row = Math.floor(local / ts.columns);
|
|
222
|
+
const region = "image" in ts.image ? ts.image : { image: ts.image, x: 0, y: 0 };
|
|
223
|
+
f = {
|
|
224
|
+
image: region.image,
|
|
225
|
+
x: region.x + margin + col * (ts.tileWidth + spacing),
|
|
226
|
+
y: region.y + margin + row * (ts.tileHeight + spacing),
|
|
227
|
+
w: ts.tileWidth,
|
|
228
|
+
h: ts.tileHeight,
|
|
229
|
+
};
|
|
230
|
+
this.frames[gid] = f;
|
|
231
|
+
return f;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Tiled flip flags → sprite rotation/flips. Tiled applies the diagonal flip (transpose) first, then
|
|
236
|
+
* horizontal, then vertical; expressed as rotate-then-flip that gives this table.
|
|
237
|
+
*/
|
|
238
|
+
function applyFlips(o, raw) {
|
|
239
|
+
const h = (raw & FLIP_H) !== 0;
|
|
240
|
+
const v = (raw & FLIP_V) !== 0;
|
|
241
|
+
if ((raw & FLIP_D) === 0) {
|
|
242
|
+
o.rotation = 0;
|
|
243
|
+
o.flipX = h;
|
|
244
|
+
o.flipY = v;
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
// Diagonal: transpose = rotate 90° then flip Y; combine with H/V.
|
|
248
|
+
if (h && v) {
|
|
249
|
+
o.rotation = Math.PI / 2;
|
|
250
|
+
o.flipX = true;
|
|
251
|
+
o.flipY = false;
|
|
252
|
+
}
|
|
253
|
+
else if (h) {
|
|
254
|
+
o.rotation = Math.PI / 2;
|
|
255
|
+
o.flipX = false;
|
|
256
|
+
o.flipY = false;
|
|
257
|
+
}
|
|
258
|
+
else if (v) {
|
|
259
|
+
o.rotation = -Math.PI / 2;
|
|
260
|
+
o.flipX = false;
|
|
261
|
+
o.flipY = false;
|
|
262
|
+
}
|
|
263
|
+
else {
|
|
264
|
+
o.rotation = Math.PI / 2;
|
|
265
|
+
o.flipX = false;
|
|
266
|
+
o.flipY = true;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
//# sourceMappingURL=tilemap.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tilemap.js","sourceRoot":"","sources":["../src/tilemap.ts"],"names":[],"mappings":"AACA,OAAO,EAAgD,IAAI,EAAE,MAAM,cAAc,CAAC;AAElF,yFAAyF;AACzF,MAAM,CAAC,MAAM,MAAM,GAAG,UAAU,CAAC;AACjC,MAAM,CAAC,MAAM,MAAM,GAAG,UAAU,CAAC;AACjC,MAAM,CAAC,MAAM,MAAM,GAAG,UAAU,CAAC;AACjC,MAAM,OAAO,GAAG,UAAU,CAAC;AAE3B,yGAAyG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ChB,CAAC,CAAC,KAAK,GAAG,IAAI,CAAC;IACjB,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,49 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@debuffjp/tilemap",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Tilemaps for debuff: culled batched rendering, tile collision, Tiled and LDtk import",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"game",
|
|
7
|
+
"gamedev",
|
|
8
|
+
"tilemap",
|
|
9
|
+
"tiled",
|
|
10
|
+
"ldtk",
|
|
11
|
+
"collision",
|
|
12
|
+
"debuff"
|
|
13
|
+
],
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"homepage": "https://debuff.jp",
|
|
16
|
+
"bugs": "https://github.com/debuffjp/debuff/issues",
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/debuffjp/debuff.git",
|
|
20
|
+
"directory": "packages/tilemap"
|
|
21
|
+
},
|
|
22
|
+
"type": "module",
|
|
23
|
+
"sideEffects": false,
|
|
24
|
+
"main": "./dist/index.js",
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"exports": {
|
|
27
|
+
".": {
|
|
28
|
+
"types": "./dist/index.d.ts",
|
|
29
|
+
"default": "./dist/index.js"
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"files": [
|
|
33
|
+
"dist",
|
|
34
|
+
"README.md"
|
|
35
|
+
],
|
|
36
|
+
"scripts": {
|
|
37
|
+
"build": "tsc -b"
|
|
38
|
+
},
|
|
39
|
+
"peerDependencies": {
|
|
40
|
+
"@debuffjp/core": "0.1.0"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@debuffjp/core": "0.1.0"
|
|
44
|
+
},
|
|
45
|
+
"publishConfig": {
|
|
46
|
+
"access": "public",
|
|
47
|
+
"provenance": false
|
|
48
|
+
}
|
|
49
|
+
}
|