@codexo/exojs-tilemap-physics 0.17.0 → 0.19.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 +28 -67
- package/dist/esm/TileColliderStreamer.d.ts +3 -3
- package/dist/esm/TileColliderStreamer.d.ts.map +1 -1
- package/dist/esm/TileColliderStreamer.js +10 -9
- package/dist/esm/TileColliderStreamer.js.map +1 -1
- package/dist/esm/TilePhysicsBinding.d.ts +21 -0
- package/dist/esm/TilePhysicsBinding.d.ts.map +1 -0
- package/dist/esm/TilePhysicsBinding.js +35 -0
- package/dist/esm/TilePhysicsBinding.js.map +1 -0
- package/dist/esm/buildColliders.d.ts.map +1 -1
- package/dist/esm/index.js +2 -1
- package/dist/esm/material.d.ts +1 -1
- package/dist/esm/material.d.ts.map +1 -1
- package/dist/esm/objectLayer.d.ts +2 -2
- package/dist/esm/objectLayer.d.ts.map +1 -1
- package/dist/esm/objectLayer.js +9 -4
- package/dist/esm/objectLayer.js.map +1 -1
- package/dist/esm/outline.d.ts.map +1 -1
- package/dist/esm/public.d.ts +1 -0
- package/dist/esm/public.d.ts.map +1 -1
- package/package.json +11 -11
package/README.md
CHANGED
|
@@ -2,13 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
Static physics colliders from ExoJS tilemap collision geometry.
|
|
4
4
|
|
|
5
|
-
> A peer-dependency library on top of `@codexo/exojs`, `@codexo/exojs-tilemap`
|
|
6
|
-
> and `@codexo/exojs-physics` — construct its API directly. Importing it
|
|
7
|
-
> registers nothing.
|
|
5
|
+
> A peer-dependency library on top of `@codexo/exojs`, `@codexo/exojs-tilemap` and `@codexo/exojs-physics` — construct its API directly. Importing it registers nothing.
|
|
8
6
|
|
|
9
|
-
`@codexo/exojs-tilemap` never imports physics and `@codexo/exojs-physics` never
|
|
10
|
-
imports tilemap; this package is the seam between them, so both stay usable on
|
|
11
|
-
their own.
|
|
7
|
+
`@codexo/exojs-tilemap` never imports physics and `@codexo/exojs-physics` never imports tilemap; this package is the seam between them, so both stay usable on their own.
|
|
12
8
|
|
|
13
9
|
## Installation
|
|
14
10
|
|
|
@@ -18,9 +14,7 @@ npm install @codexo/exojs @codexo/exojs-tilemap @codexo/exojs-physics @codexo/ex
|
|
|
18
14
|
|
|
19
15
|
## Tile layers
|
|
20
16
|
|
|
21
|
-
`TileColliderStreamer` keeps a physics world's static tile colliders in sync
|
|
22
|
-
with a `TileLayer`: one static body per chunk-sized partition of the layer,
|
|
23
|
-
rebuilt when that partition is edited, destroyed when its chunk is evicted.
|
|
17
|
+
`TileColliderStreamer` keeps a physics world's static tile colliders in sync with a `TileLayer`: one static body per chunk-sized partition of the layer, rebuilt when that partition is edited, destroyed when its chunk is evicted.
|
|
24
18
|
|
|
25
19
|
```ts
|
|
26
20
|
import { PhysicsWorld } from '@codexo/exojs-physics';
|
|
@@ -32,24 +26,18 @@ const colliders = new TileColliderStreamer(world, groundLayer);
|
|
|
32
26
|
scene.systems.add({
|
|
33
27
|
update: delta => {
|
|
34
28
|
colliders.sync();
|
|
35
|
-
world.step(delta
|
|
29
|
+
world.step(delta);
|
|
36
30
|
},
|
|
37
31
|
});
|
|
38
32
|
```
|
|
39
33
|
|
|
40
|
-
`sync()` is cheap to call every frame: with no change since the last call it
|
|
41
|
-
returns immediately and does no work. It observes the layer through its public
|
|
42
|
-
revision counters, so it works with `ChunkStreamer`, a hand-rolled loader, or a
|
|
43
|
-
bounded layer that is fully resident.
|
|
34
|
+
`sync()` is cheap to call every frame: with no change since the last call it returns immediately and does no work. It observes the layer through its public revision counters, so it works with `ChunkStreamer`, a hand-rolled loader, or a bounded layer that is fully resident.
|
|
44
35
|
|
|
45
|
-
Call `destroy()` to remove every body the bridge created. Bodies it did not
|
|
46
|
-
create are untouched.
|
|
36
|
+
Call `destroy()` to remove every body the bridge created. Bodies it did not create are untouched.
|
|
47
37
|
|
|
48
38
|
## Collision authored per cell
|
|
49
39
|
|
|
50
|
-
Some editors author collision per grid cell rather than per tile - LDtk's
|
|
51
|
-
`IntGrid` is the common case. Pass a `cells` source and the bridge covers the
|
|
52
|
-
whole bounded layer, including partitions that hold no tiles at all:
|
|
40
|
+
Some editors author collision per grid cell rather than per tile - LDtk's `IntGrid` is the common case. Pass a `cells` source and the bridge covers the whole bounded layer, including partitions that hold no tiles at all:
|
|
53
41
|
|
|
54
42
|
```ts
|
|
55
43
|
import { createLdtkIntGridCellSource } from '@codexo/exojs-ldtk';
|
|
@@ -60,15 +48,9 @@ const colliders = new TileColliderStreamer(world, collisionLayer, {
|
|
|
60
48
|
});
|
|
61
49
|
```
|
|
62
50
|
|
|
63
|
-
A cell source is a plain `(tx, ty) => string | null`, so a procedural or
|
|
64
|
-
hand-rolled grid works the same way. The returned string is a classification,
|
|
65
|
-
never a meaning: it is the merge key for adjacent cells and it is what the
|
|
66
|
-
`material` resolver sees. Nothing in this package knows what `Solid` or `Water`
|
|
67
|
-
are supposed to do.
|
|
51
|
+
A cell source is a plain `(tx, ty) => string | null`, so a procedural or hand-rolled grid works the same way. The returned string is a classification, never a meaning: it is the merge key for adjacent cells and it is what the `material` resolver sees. Nothing in this package knows what `Solid` or `Water` are supposed to do.
|
|
68
52
|
|
|
69
|
-
The source is sampled while a partition is built and is expected to answer
|
|
70
|
-
identically for the lifetime of the bridge. Changing what it returns does not
|
|
71
|
-
invalidate colliders that already exist - rebuild by recreating the bridge.
|
|
53
|
+
The source is sampled while a partition is built and is expected to answer identically for the lifetime of the bridge. Changing what it returns does not invalidate colliders that already exist - rebuild by recreating the bridge.
|
|
72
54
|
|
|
73
55
|
## Object layers
|
|
74
56
|
|
|
@@ -86,6 +68,14 @@ for (const { object, body } of built) {
|
|
|
86
68
|
}
|
|
87
69
|
```
|
|
88
70
|
|
|
71
|
+
## Isometric presentation
|
|
72
|
+
|
|
73
|
+
Tile and object colliders use logical coordinates. Isometric logical cells are squares of side `tileHeight`; image-space tile collision shapes are inverse-projected before collider generation. Display layer offsets become logical translation vectors, and streamed collider bodies retain the same cell/chunk ownership rules. Orthogonal behavior is unchanged.
|
|
74
|
+
|
|
75
|
+
Create a `TilePhysicsBinding(body, node, map.projection)` explicitly and call `sync()` after physics updates, or `syncInterpolated(alpha)` with the fixed-step interpolation fraction. The node's parent must use map display coordinates. The binding only writes node position, owns nothing, and leaves sprite rotation/scale to the application; a projected logical rotation is not a rigid sprite rotation. Do not attach the same node through `PhysicsWorld.attach()`, which binds directly to unprojected world coordinates.
|
|
76
|
+
|
|
77
|
+
Object-layer `objects` remain logical geometry; `getDisplayObject()` is for rendering and must not be fed back into the collider builder. The Isometric Landscape example shows both representations.
|
|
78
|
+
|
|
89
79
|
## Geometry mapping
|
|
90
80
|
|
|
91
81
|
| Source | Collider |
|
|
@@ -99,32 +89,17 @@ for (const { object, body } of built) {
|
|
|
99
89
|
| Polyline | open chain; closed chain when its endpoints coincide |
|
|
100
90
|
| Point | nothing |
|
|
101
91
|
|
|
102
|
-
An ellipse maps to the capsule with the minor semi-axis as its radius and the
|
|
103
|
-
difference of the semi-axes as its spine. That capsule contains the ellipse and
|
|
104
|
-
is contained in the circumscribed circle, so it covers the source without a
|
|
105
|
-
tuning constant, and degenerates to a circle when the ellipse is round.
|
|
92
|
+
An ellipse maps to the capsule with the minor semi-axis as its radius and the difference of the semi-axes as its spine. That capsule contains the ellipse and is contained in the circumscribed circle, so it covers the source without a tuning constant, and degenerates to a circle when the ellipse is round.
|
|
106
93
|
|
|
107
94
|
## Region modes
|
|
108
95
|
|
|
109
|
-
`regionMode: 'boxes'` (the default) keeps merged rectangles as solid boxes. The
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
— neighbouring cells with different collision semantics, staircase profiles,
|
|
113
|
-
partial cells — adjacent boxes share an internal edge that a body sliding across
|
|
114
|
-
can catch on.
|
|
115
|
-
|
|
116
|
-
`regionMode: 'outline'` traces the boundary of each solid region into closed
|
|
117
|
-
one-sided chains, which have no internal edges at all. It removes intra-chunk
|
|
118
|
-
seams between adjacent cells that resolve to the same collision semantics;
|
|
119
|
-
boundaries between regions with different resolved semantics remain separate, as
|
|
120
|
-
do chunk boundaries. The trade-off is that a chain is a boundary, not an area:
|
|
121
|
-
queries inside the region find nothing, and a body spawned inside it falls
|
|
122
|
-
through.
|
|
96
|
+
`regionMode: 'boxes'` (the default) keeps merged rectangles as solid boxes. The region has an interior, so point queries, overlaps and sensors behave, and a body that starts inside solid tiles is pushed out. Where the merge cannot merge — neighbouring cells with different collision semantics, staircase profiles, partial cells — adjacent boxes share an internal edge that a body sliding across can catch on.
|
|
97
|
+
|
|
98
|
+
`regionMode: 'outline'` traces the boundary of each solid region into closed one-sided chains, which have no internal edges at all. It removes intra-chunk seams between adjacent cells that resolve to the same collision semantics; boundaries between regions with different resolved semantics remain separate, as do chunk boundaries. The trade-off is that a chain is a boundary, not an area: queries inside the region find nothing, and a body spawned inside it falls through.
|
|
123
99
|
|
|
124
100
|
## Materials
|
|
125
101
|
|
|
126
|
-
Friction, restitution, density, the sensor flag and the collision filter are
|
|
127
|
-
call-level defaults, optionally overridden per object:
|
|
102
|
+
Friction, restitution, density, the sensor flag and the collision filter are call-level defaults, optionally overridden per object:
|
|
128
103
|
|
|
129
104
|
```ts
|
|
130
105
|
new TileColliderStreamer(world, groundLayer, {
|
|
@@ -133,33 +108,19 @@ new TileColliderStreamer(world, groundLayer, {
|
|
|
133
108
|
});
|
|
134
109
|
```
|
|
135
110
|
|
|
136
|
-
The resolver is a build-time mapping, not a live rule: it runs only while a
|
|
137
|
-
chunk is being built or rebuilt. Changing what it would return has no effect
|
|
138
|
-
until the layer itself changes. An unrecognised `type` is not an error — it
|
|
139
|
-
reaches the resolver like any other and falls back to the defaults.
|
|
111
|
+
The resolver is a build-time mapping, not a live rule: it runs only while a chunk is being built or rebuilt. Changing what it would return has no effect until the layer itself changes. An unrecognised `type` is not an error — it reaches the resolver like any other and falls back to the defaults.
|
|
140
112
|
|
|
141
|
-
In `outline` mode the resolved material also decides what may share a boundary:
|
|
142
|
-
cells whose colliders would be indistinguishable are traced into one chain, and
|
|
143
|
-
cells that resolve differently keep their own.
|
|
113
|
+
In `outline` mode the resolved material also decides what may share a boundary: cells whose colliders would be indistinguishable are traced into one chain, and cells that resolve differently keep their own.
|
|
144
114
|
|
|
145
115
|
## Things to know before shipping a level
|
|
146
116
|
|
|
147
|
-
- **Merging never crosses a chunk boundary.** A solid run spanning two chunks is
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
- **A dynamic body resting on an evicted chunk falls.** Eviction is the chunk
|
|
151
|
-
source's decision; widen its unload radius if that matters.
|
|
152
|
-
- **Order is stable, part counts are not.** For a given layer and resident chunk
|
|
153
|
-
set the colliders are identical regardless of load order, and `bodies()`
|
|
154
|
-
iterates in `(cy, cx)` chunk order. The number of convex parts a concave
|
|
155
|
-
polygon decomposes into, and the exact rectangle decomposition of a merged
|
|
156
|
-
region, are not contractual.
|
|
117
|
+
- **Merging never crosses a chunk boundary.** A solid run spanning two chunks is at least two rectangles. That is what makes the result independent of the order chunks were loaded in.
|
|
118
|
+
- **A dynamic body resting on an evicted chunk falls.** Eviction is the chunk source's decision; widen its unload radius if that matters.
|
|
119
|
+
- **Order is stable, part counts are not.** For a given layer and resident chunk set the colliders are identical regardless of load order, and `bodies()` iterates in `(cy, cx)` chunk order. The number of convex parts a concave polygon decomposes into, and the exact rectangle decomposition of a merged region, are not contractual.
|
|
157
120
|
|
|
158
121
|
## Core compatibility
|
|
159
122
|
|
|
160
|
-
|
|
161
|
-
| ------------------------------- | --------------- |
|
|
162
|
-
| 0.15.x | 0.15.x |
|
|
123
|
+
This package follows the Core lockstep release line. Its Core, tilemap, and physics peer dependencies require the matching minor release.
|
|
163
124
|
|
|
164
125
|
## License
|
|
165
126
|
|
|
@@ -33,15 +33,15 @@ export interface TileColliderOptions extends ColliderDefaults {
|
|
|
33
33
|
* {@link import('@codexo/exojs-tilemap').ChunkStreamer}, a hand-rolled loader,
|
|
34
34
|
* or a fully resident bounded layer.
|
|
35
35
|
*
|
|
36
|
-
* Tick it from `
|
|
36
|
+
* Tick it from `preFrame`, before the frame's fixed steps run - not from
|
|
37
37
|
* `update`, which runs after them:
|
|
38
38
|
*
|
|
39
39
|
* ```ts
|
|
40
40
|
* const colliders = new TileColliderStreamer(world, layer);
|
|
41
|
-
* scene.systems.add({
|
|
41
|
+
* scene.systems.add({ preFrame: () => colliders.sync() });
|
|
42
42
|
* ```
|
|
43
43
|
*
|
|
44
|
-
* `SceneScope` runs `
|
|
44
|
+
* `SceneScope` runs `preFrame` once per frame, before any of that frame's
|
|
45
45
|
* fixed steps, and `update` after all of them. A chunk that becomes resident
|
|
46
46
|
* this frame needs its collider body built before the world steps over the
|
|
47
47
|
* hole, and a chunk evicted this frame must not keep its body for a whole
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TileColliderStreamer.d.ts","sourceRoot":"","sources":["../../src/TileColliderStreamer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,KAAK,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACvE,OAAO,KAAK,EAAqB,cAAc,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAKzG,OAAO,KAAK,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAEhE,gEAAgE;AAChE,MAAM,WAAW,mBAAoB,SAAQ,gBAAgB;IAC3D,uEAAuE;IACvE,UAAU,CAAC,EAAE,cAAc,CAAC;IAC5B;;;OAGG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,+DAA+D;IAC/D,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,aAAa,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC;IACpE;;;;;;;;OAQG;IACH,KAAK,CAAC,EAAE,cAAc,GAAG,SAAS,CAAC;CACpC;AAgCD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,qBAAa,oBAAoB;IAC/B,OAAO,CAA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AO,CAAC,QAAQ,CAAC,MAAM,CAAY;IACnC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAsB;IAC/C,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAmB;IAC7C,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAiB;IAE7C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAiC;IACxD,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAqB;IAE3C,OAAO,CAAC,cAAc,CAAM;IAC5B,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,UAAU,CAAS;IAE3B,YAAmB,KAAK,EAAE,YAAY,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,GAAE,mBAAwB,EAQ1F;IAED,uDAAuD;IACvD,IAAW,SAAS,IAAI,MAAM,CAQ7B;IAED;;;OAGG;IACK,MAAM,IAAI,gBAAgB,CAAC,WAAW,CAAC,CAM9C;IAED;;;;;;;OAOG;IACI,IAAI,IAAI,IAAI,CAgDlB;IAED;;;OAGG;IACI,OAAO,IAAI,IAAI,CAIrB;IAED,OAAO,CAAC,MAAM;IASd;;;;;OAKG;IACH,OAAO,CAAC,UAAU;IAqBlB,OAAO,CAAC,WAAW;CAuCpB"}
|
|
@@ -21,15 +21,15 @@ const blockExtent = (chunkExtent, layerExtent, start) => layerExtent === void 0
|
|
|
21
21
|
* {@link import('@codexo/exojs-tilemap').ChunkStreamer}, a hand-rolled loader,
|
|
22
22
|
* or a fully resident bounded layer.
|
|
23
23
|
*
|
|
24
|
-
* Tick it from `
|
|
24
|
+
* Tick it from `preFrame`, before the frame's fixed steps run - not from
|
|
25
25
|
* `update`, which runs after them:
|
|
26
26
|
*
|
|
27
27
|
* ```ts
|
|
28
28
|
* const colliders = new TileColliderStreamer(world, layer);
|
|
29
|
-
* scene.systems.add({
|
|
29
|
+
* scene.systems.add({ preFrame: () => colliders.sync() });
|
|
30
30
|
* ```
|
|
31
31
|
*
|
|
32
|
-
* `SceneScope` runs `
|
|
32
|
+
* `SceneScope` runs `preFrame` once per frame, before any of that frame's
|
|
33
33
|
* fixed steps, and `update` after all of them. A chunk that becomes resident
|
|
34
34
|
* this frame needs its collider body built before the world steps over the
|
|
35
35
|
* hole, and a chunk evicted this frame must not keep its body for a whole
|
|
@@ -171,15 +171,16 @@ var TileColliderStreamer = class {
|
|
|
171
171
|
...options.cells !== void 0 && { cells: options.cells }
|
|
172
172
|
});
|
|
173
173
|
if (geometry.rects.length === 0 && geometry.shapes.length === 0) return null;
|
|
174
|
-
const
|
|
175
|
-
const
|
|
174
|
+
const offset = layer.logicalOffset;
|
|
175
|
+
const x = startTx * layer.projection.logicalTileWidth + offset.x;
|
|
176
|
+
const y = startTy * layer.projection.logicalTileHeight + offset.y;
|
|
176
177
|
const colliders = buildTileColliders(geometry, {
|
|
177
178
|
x,
|
|
178
179
|
y,
|
|
179
|
-
tileWidth: layer.
|
|
180
|
-
tileHeight: layer.
|
|
181
|
-
layerOffsetX:
|
|
182
|
-
layerOffsetY:
|
|
180
|
+
tileWidth: layer.projection.logicalTileWidth,
|
|
181
|
+
tileHeight: layer.projection.logicalTileHeight,
|
|
182
|
+
layerOffsetX: offset.x,
|
|
183
|
+
layerOffsetY: offset.y,
|
|
183
184
|
regionMode: this._regionMode,
|
|
184
185
|
defaults: this._defaults,
|
|
185
186
|
material: options.material
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TileColliderStreamer.js","names":[],"sources":["../../src/TileColliderStreamer.ts"],"sourcesContent":["import { PhysicsBody, type PhysicsWorld } from '@codexo/exojs-physics';\nimport type { ReadonlyTileChunk, TileCellSource, TileLayer, TileMapObject } from '@codexo/exojs-tilemap';\nimport { buildTileCollisionGeometry } from '@codexo/exojs-tilemap';\n\nimport { buildTileColliders } from './buildColliders';\nimport { resolveDefaults, type ResolvedMaterial } from './material';\nimport type { ColliderDefaults, TileRegionMode } from './types';\n\n/** Options for a {@link TileColliderStreamer}. All optional. */\nexport interface TileColliderOptions extends ColliderDefaults {\n /** How solid whole-cell regions are represented. Default `'boxes'`. */\n regionMode?: TileRegionMode;\n /**\n * Merge adjacent whole-cell boxes sharing a `type` into larger rectangles.\n * Default `true`. Merging never crosses a chunk boundary.\n */\n merge?: boolean;\n /** Drop a source shape before any collider is built for it. */\n accept?: (object: TileMapObject, tx: number, ty: number) => boolean;\n /**\n * Per-cell collision classification, for layers whose collision is authored\n * per cell rather than per tile. On a bounded layer this makes the bridge\n * cover the whole layer, including partitions that hold no tiles at all.\n *\n * Sampled while a partition is built and expected to answer identically for\n * the lifetime of this bridge: changing what it returns does not invalidate\n * colliders that already exist. Rebuild by recreating the bridge.\n */\n cells?: TileCellSource | undefined;\n}\n\n/**\n * One collision build block: the deterministic spatial partition this bridge\n * may own a body for. A partition is not the same thing as tile residency - a\n * cell source covers partitions that hold no {@link ReadonlyTileChunk} at all,\n * and nothing here makes a non-resident chunk look resident.\n *\n * An entry with `body === null` is a cached empty result, not an absence: it\n * is what keeps an unrelated layer revision from re-walking every cell of\n * every empty partition.\n */\ninterface BlockEntry {\n readonly cx: number;\n readonly cy: number;\n /** The chunk the body was built from; `null` for a cell-only partition. A re-adopted chunk is a new one. */\n readonly chunk: ReadonlyTileChunk | null;\n readonly revision: number;\n /** `null` when the partition holds no collision geometry at all. */\n readonly body: PhysicsBody | null;\n}\n\nconst chunkKey = (cx: number, cy: number): string => `${cx},${cy}`;\n\n/**\n * Tile extent of a build block along one axis. Edge blocks of a bounded layer\n * are clipped, matching the dimensions the layer gives an edge chunk, so a\n * cell-only block never walks cells outside the layer.\n */\nconst blockExtent = (chunkExtent: number, layerExtent: number | undefined, start: number): number =>\n layerExtent === undefined ? chunkExtent : Math.min(chunkExtent, layerExtent - start);\n\n/**\n * Keeps a physics world's static tile colliders in sync with a\n * {@link TileLayer}: one static body per chunk-sized partition of the layer,\n * rebuilt when that partition changes, destroyed when it is evicted.\n *\n * The bridge owns every body it creates and nothing else. It observes the layer\n * through its public revision counters, so it works with any chunk source -\n * {@link import('@codexo/exojs-tilemap').ChunkStreamer}, a hand-rolled loader,\n * or a fully resident bounded layer.\n *\n * Tick it from `preUpdate`, before the frame's fixed steps run - not from\n * `update`, which runs after them:\n *\n * ```ts\n * const colliders = new TileColliderStreamer(world, layer);\n * scene.systems.add({ preUpdate: () => colliders.sync() });\n * ```\n *\n * `SceneScope` runs `preUpdate` once per frame, before any of that frame's\n * fixed steps, and `update` after all of them. A chunk that becomes resident\n * this frame needs its collider body built before the world steps over the\n * hole, and a chunk evicted this frame must not keep its body for a whole\n * extra frame of stepping - `update` gets both of those one step too late.\n * Wiring `sync()` into `fixedUpdate` instead (ordered before\n * {@link SystemOrder.Physics}) also works, and additionally re-syncs on\n * every fixed step within a frame rather than once per frame.\n *\n * Two consequences worth knowing before shipping a level:\n *\n * - Whole-cell merging never crosses a partition boundary, so a solid run\n * spanning two of them is at least two rectangles. This is what makes the\n * result independent of the order chunks were loaded in.\n * - A dynamic body resting on a chunk that gets evicted falls. Eviction is the\n * chunk source's decision; widen its unload radius if that matters.\n * - With {@link TileColliderOptions.cells}, a bounded layer's partitions are\n * all covered, resident or not - collision authored per cell does not depend\n * on tiles being placed.\n */\nexport class TileColliderStreamer {\n private readonly _world: PhysicsWorld;\n private readonly _layer: TileLayer;\n private readonly _options: TileColliderOptions;\n private readonly _defaults: ResolvedMaterial;\n private readonly _regionMode: TileRegionMode;\n\n private readonly _built = new Map<string, BlockEntry>();\n private readonly _seen = new Set<string>();\n\n private _layerRevision = -1;\n private _offsetX: number;\n private _offsetY: number;\n private _destroyed = false;\n\n public constructor(world: PhysicsWorld, layer: TileLayer, options: TileColliderOptions = {}) {\n this._world = world;\n this._layer = layer;\n this._options = options;\n this._defaults = resolveDefaults(options);\n this._regionMode = options.regionMode ?? 'boxes';\n this._offsetX = layer.offsetX;\n this._offsetY = layer.offsetY;\n }\n\n /** Number of bodies currently owned by this bridge. */\n public get bodyCount(): number {\n let count = 0;\n\n for (const entry of this._built.values()) {\n if (entry.body !== null) count++;\n }\n\n return count;\n }\n\n /**\n * The bodies this bridge owns, in `(cy, cx)` partition order - independent of\n * the order the chunks became resident in.\n */\n public *bodies(): IterableIterator<PhysicsBody> {\n const ordered = [...this._built.values()].sort((a, b) => a.cy - b.cy || a.cx - b.cx);\n\n for (const entry of ordered) {\n if (entry.body !== null) yield entry.body;\n }\n }\n\n /**\n * Bring the world's tile colliders up to date with the layer: build bodies\n * for newly resident chunks, rebuild edited ones, destroy evicted ones.\n *\n * Cheap to call every frame. With no change since the last call it performs\n * no work and allocates nothing. No-op once {@link destroy}ed or once the\n * layer is destroyed.\n */\n public sync(): void {\n if (this._destroyed || this._layer.destroyed) return;\n\n const layer = this._layer;\n const offsetChanged = layer.offsetX !== this._offsetX || layer.offsetY !== this._offsetY;\n\n if (!offsetChanged && layer.revision === this._layerRevision) return;\n\n if (offsetChanged) {\n // Geometry is emitted in layer pixel space, so a moved layer invalidates\n // every collider - and moving a layer does not bump its revision.\n this._clear();\n this._offsetX = layer.offsetX;\n this._offsetY = layer.offsetY;\n }\n\n const seen = this._seen;\n\n seen.clear();\n\n for (const chunk of layer.loadedChunks()) {\n this._syncBlock(chunk.cx, chunk.cy, chunk);\n }\n\n // A cell source covers the layer, not its residency: every partition of a\n // bounded layer is a build block, whether or not tiles were ever placed in\n // it. Without this the canonical case - collision authored per cell on a\n // layer that renders nothing - would produce no bodies at all.\n if (this._options.cells !== undefined) {\n const range = layer.chunkRange();\n\n if (range !== null) {\n for (let cy = range.minCy; cy <= range.maxCy; cy++) {\n for (let cx = range.minCx; cx <= range.maxCx; cx++) {\n this._syncBlock(cx, cy, layer.getChunk(cx, cy) ?? null);\n }\n }\n }\n }\n\n for (const [key, entry] of this._built) {\n if (seen.has(key)) continue;\n\n if (entry.body !== null) this._world.destroyBody(entry.body);\n this._built.delete(key);\n }\n\n this._layerRevision = layer.revision;\n }\n\n /**\n * Destroy every body this bridge created and stop responding to\n * {@link sync}. Bodies it did not create are untouched. Idempotent.\n */\n public destroy(): void {\n if (this._destroyed) return;\n this._destroyed = true;\n this._clear();\n }\n\n private _clear(): void {\n for (const entry of this._built.values()) {\n if (entry.body !== null) this._world.destroyBody(entry.body);\n }\n\n this._built.clear();\n this._layerRevision = -1;\n }\n\n /**\n * Reconcile one build block against what was built for it before. Skips\n * without sampling anything when neither the backing chunk nor its revision\n * moved - which is what keeps an empty cell-only block from re-walking its\n * cells on every unrelated layer change.\n */\n private _syncBlock(cx: number, cy: number, chunk: ReadonlyTileChunk | null): void {\n const key = chunkKey(cx, cy);\n\n if (this._seen.has(key)) return;\n\n this._seen.add(key);\n\n const entry = this._built.get(key);\n const revision = chunk?.revision ?? -1;\n\n if (entry?.chunk === chunk && entry.revision === revision) {\n return;\n }\n\n if (entry?.body != null) {\n this._world.destroyBody(entry.body);\n }\n\n this._built.set(key, { cx, cy, chunk, revision, body: this._buildBlock(cx, cy, chunk) });\n }\n\n private _buildBlock(cx: number, cy: number, chunk: ReadonlyTileChunk | null): PhysicsBody | null {\n const layer = this._layer;\n const options = this._options;\n const startTx = cx * layer.chunkWidth;\n const startTy = cy * layer.chunkHeight;\n const width = chunk?.width ?? blockExtent(layer.chunkWidth, layer.width, startTx);\n const height = chunk?.height ?? blockExtent(layer.chunkHeight, layer.height, startTy);\n const geometry = buildTileCollisionGeometry(layer, {\n region: { x: startTx, y: startTy, width, height },\n ...(options.merge !== undefined && { merge: options.merge }),\n ...(options.accept !== undefined && { accept: options.accept }),\n ...(options.cells !== undefined && { cells: options.cells }),\n });\n\n if (geometry.rects.length === 0 && geometry.shapes.length === 0) {\n return null;\n }\n\n const x = startTx * layer.tileWidth + layer.offsetX;\n const y = startTy * layer.tileHeight + layer.offsetY;\n const colliders = buildTileColliders(geometry, {\n x,\n y,\n tileWidth: layer.tileWidth,\n tileHeight: layer.tileHeight,\n layerOffsetX: layer.offsetX,\n layerOffsetY: layer.offsetY,\n regionMode: this._regionMode,\n defaults: this._defaults,\n material: options.material,\n });\n\n if (colliders.length === 0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,IAAI,YAAY;GAAE,MAAM;GAAU,UAAU;IAAE;IAAG;GAAE;GAAG;EAAU,CAAC,CAAC;CAC3F;AACF"}
|
|
1
|
+
{"version":3,"file":"TileColliderStreamer.js","names":[],"sources":["../../src/TileColliderStreamer.ts"],"sourcesContent":["import { PhysicsBody, type PhysicsWorld } from '@codexo/exojs-physics';\nimport type { ReadonlyTileChunk, TileCellSource, TileLayer, TileMapObject } from '@codexo/exojs-tilemap';\nimport { buildTileCollisionGeometry } from '@codexo/exojs-tilemap';\n\nimport { buildTileColliders } from './buildColliders';\nimport { resolveDefaults, type ResolvedMaterial } from './material';\nimport type { ColliderDefaults, TileRegionMode } from './types';\n\n/** Options for a {@link TileColliderStreamer}. All optional. */\nexport interface TileColliderOptions extends ColliderDefaults {\n /** How solid whole-cell regions are represented. Default `'boxes'`. */\n regionMode?: TileRegionMode;\n /**\n * Merge adjacent whole-cell boxes sharing a `type` into larger rectangles.\n * Default `true`. Merging never crosses a chunk boundary.\n */\n merge?: boolean;\n /** Drop a source shape before any collider is built for it. */\n accept?: (object: TileMapObject, tx: number, ty: number) => boolean;\n /**\n * Per-cell collision classification, for layers whose collision is authored\n * per cell rather than per tile. On a bounded layer this makes the bridge\n * cover the whole layer, including partitions that hold no tiles at all.\n *\n * Sampled while a partition is built and expected to answer identically for\n * the lifetime of this bridge: changing what it returns does not invalidate\n * colliders that already exist. Rebuild by recreating the bridge.\n */\n cells?: TileCellSource | undefined;\n}\n\n/**\n * One collision build block: the deterministic spatial partition this bridge\n * may own a body for. A partition is not the same thing as tile residency - a\n * cell source covers partitions that hold no {@link ReadonlyTileChunk} at all,\n * and nothing here makes a non-resident chunk look resident.\n *\n * An entry with `body === null` is a cached empty result, not an absence: it\n * is what keeps an unrelated layer revision from re-walking every cell of\n * every empty partition.\n */\ninterface BlockEntry {\n readonly cx: number;\n readonly cy: number;\n /** The chunk the body was built from; `null` for a cell-only partition. A re-adopted chunk is a new one. */\n readonly chunk: ReadonlyTileChunk | null;\n readonly revision: number;\n /** `null` when the partition holds no collision geometry at all. */\n readonly body: PhysicsBody | null;\n}\n\nconst chunkKey = (cx: number, cy: number): string => `${cx},${cy}`;\n\n/**\n * Tile extent of a build block along one axis. Edge blocks of a bounded layer\n * are clipped, matching the dimensions the layer gives an edge chunk, so a\n * cell-only block never walks cells outside the layer.\n */\nconst blockExtent = (chunkExtent: number, layerExtent: number | undefined, start: number): number =>\n layerExtent === undefined ? chunkExtent : Math.min(chunkExtent, layerExtent - start);\n\n/**\n * Keeps a physics world's static tile colliders in sync with a\n * {@link TileLayer}: one static body per chunk-sized partition of the layer,\n * rebuilt when that partition changes, destroyed when it is evicted.\n *\n * The bridge owns every body it creates and nothing else. It observes the layer\n * through its public revision counters, so it works with any chunk source -\n * {@link import('@codexo/exojs-tilemap').ChunkStreamer}, a hand-rolled loader,\n * or a fully resident bounded layer.\n *\n * Tick it from `preFrame`, before the frame's fixed steps run - not from\n * `update`, which runs after them:\n *\n * ```ts\n * const colliders = new TileColliderStreamer(world, layer);\n * scene.systems.add({ preFrame: () => colliders.sync() });\n * ```\n *\n * `SceneScope` runs `preFrame` once per frame, before any of that frame's\n * fixed steps, and `update` after all of them. A chunk that becomes resident\n * this frame needs its collider body built before the world steps over the\n * hole, and a chunk evicted this frame must not keep its body for a whole\n * extra frame of stepping - `update` gets both of those one step too late.\n * Wiring `sync()` into `fixedUpdate` instead (ordered before\n * {@link SystemOrder.Physics}) also works, and additionally re-syncs on\n * every fixed step within a frame rather than once per frame.\n *\n * Two consequences worth knowing before shipping a level:\n *\n * - Whole-cell merging never crosses a partition boundary, so a solid run\n * spanning two of them is at least two rectangles. This is what makes the\n * result independent of the order chunks were loaded in.\n * - A dynamic body resting on a chunk that gets evicted falls. Eviction is the\n * chunk source's decision; widen its unload radius if that matters.\n * - With {@link TileColliderOptions.cells}, a bounded layer's partitions are\n * all covered, resident or not - collision authored per cell does not depend\n * on tiles being placed.\n */\nexport class TileColliderStreamer {\n private readonly _world: PhysicsWorld;\n private readonly _layer: TileLayer;\n private readonly _options: TileColliderOptions;\n private readonly _defaults: ResolvedMaterial;\n private readonly _regionMode: TileRegionMode;\n\n private readonly _built = new Map<string, BlockEntry>();\n private readonly _seen = new Set<string>();\n\n private _layerRevision = -1;\n private _offsetX: number;\n private _offsetY: number;\n private _destroyed = false;\n\n public constructor(world: PhysicsWorld, layer: TileLayer, options: TileColliderOptions = {}) {\n this._world = world;\n this._layer = layer;\n this._options = options;\n this._defaults = resolveDefaults(options);\n this._regionMode = options.regionMode ?? 'boxes';\n this._offsetX = layer.offsetX;\n this._offsetY = layer.offsetY;\n }\n\n /** Number of bodies currently owned by this bridge. */\n public get bodyCount(): number {\n let count = 0;\n\n for (const entry of this._built.values()) {\n if (entry.body !== null) count++;\n }\n\n return count;\n }\n\n /**\n * The bodies this bridge owns, in `(cy, cx)` partition order - independent of\n * the order the chunks became resident in.\n */\n public *bodies(): IterableIterator<PhysicsBody> {\n const ordered = [...this._built.values()].sort((a, b) => a.cy - b.cy || a.cx - b.cx);\n\n for (const entry of ordered) {\n if (entry.body !== null) yield entry.body;\n }\n }\n\n /**\n * Bring the world's tile colliders up to date with the layer: build bodies\n * for newly resident chunks, rebuild edited ones, destroy evicted ones.\n *\n * Cheap to call every frame. With no change since the last call it performs\n * no work and allocates nothing. No-op once {@link destroy}ed or once the\n * layer is destroyed.\n */\n public sync(): void {\n if (this._destroyed || this._layer.destroyed) return;\n\n const layer = this._layer;\n const offsetChanged = layer.offsetX !== this._offsetX || layer.offsetY !== this._offsetY;\n\n if (!offsetChanged && layer.revision === this._layerRevision) return;\n\n if (offsetChanged) {\n // Geometry is emitted in layer pixel space, so a moved layer invalidates\n // every collider - and moving a layer does not bump its revision.\n this._clear();\n this._offsetX = layer.offsetX;\n this._offsetY = layer.offsetY;\n }\n\n const seen = this._seen;\n\n seen.clear();\n\n for (const chunk of layer.loadedChunks()) {\n this._syncBlock(chunk.cx, chunk.cy, chunk);\n }\n\n // A cell source covers the layer, not its residency: every partition of a\n // bounded layer is a build block, whether or not tiles were ever placed in\n // it. Without this the canonical case - collision authored per cell on a\n // layer that renders nothing - would produce no bodies at all.\n if (this._options.cells !== undefined) {\n const range = layer.chunkRange();\n\n if (range !== null) {\n for (let cy = range.minCy; cy <= range.maxCy; cy++) {\n for (let cx = range.minCx; cx <= range.maxCx; cx++) {\n this._syncBlock(cx, cy, layer.getChunk(cx, cy) ?? null);\n }\n }\n }\n }\n\n for (const [key, entry] of this._built) {\n if (seen.has(key)) continue;\n\n if (entry.body !== null) this._world.destroyBody(entry.body);\n this._built.delete(key);\n }\n\n this._layerRevision = layer.revision;\n }\n\n /**\n * Destroy every body this bridge created and stop responding to\n * {@link sync}. Bodies it did not create are untouched. Idempotent.\n */\n public destroy(): void {\n if (this._destroyed) return;\n this._destroyed = true;\n this._clear();\n }\n\n private _clear(): void {\n for (const entry of this._built.values()) {\n if (entry.body !== null) this._world.destroyBody(entry.body);\n }\n\n this._built.clear();\n this._layerRevision = -1;\n }\n\n /**\n * Reconcile one build block against what was built for it before. Skips\n * without sampling anything when neither the backing chunk nor its revision\n * moved - which is what keeps an empty cell-only block from re-walking its\n * cells on every unrelated layer change.\n */\n private _syncBlock(cx: number, cy: number, chunk: ReadonlyTileChunk | null): void {\n const key = chunkKey(cx, cy);\n\n if (this._seen.has(key)) return;\n\n this._seen.add(key);\n\n const entry = this._built.get(key);\n const revision = chunk?.revision ?? -1;\n\n if (entry?.chunk === chunk && entry.revision === revision) {\n return;\n }\n\n if (entry?.body != null) {\n this._world.destroyBody(entry.body);\n }\n\n this._built.set(key, { cx, cy, chunk, revision, body: this._buildBlock(cx, cy, chunk) });\n }\n\n private _buildBlock(cx: number, cy: number, chunk: ReadonlyTileChunk | null): PhysicsBody | null {\n const layer = this._layer;\n const options = this._options;\n const startTx = cx * layer.chunkWidth;\n const startTy = cy * layer.chunkHeight;\n const width = chunk?.width ?? blockExtent(layer.chunkWidth, layer.width, startTx);\n const height = chunk?.height ?? blockExtent(layer.chunkHeight, layer.height, startTy);\n const geometry = buildTileCollisionGeometry(layer, {\n region: { x: startTx, y: startTy, width, height },\n ...(options.merge !== undefined && { merge: options.merge }),\n ...(options.accept !== undefined && { accept: options.accept }),\n ...(options.cells !== undefined && { cells: options.cells }),\n });\n\n if (geometry.rects.length === 0 && geometry.shapes.length === 0) {\n return null;\n }\n\n const offset = layer.logicalOffset;\n const x = startTx * layer.projection.logicalTileWidth + offset.x;\n const y = startTy * layer.projection.logicalTileHeight + offset.y;\n const colliders = buildTileColliders(geometry, {\n x,\n y,\n tileWidth: layer.projection.logicalTileWidth,\n tileHeight: layer.projection.logicalTileHeight,\n layerOffsetX: offset.x,\n layerOffsetY: offset.y,\n regionMode: this._regionMode,\n defaults: this._defaults,\n material: options.material,\n });\n\n if (colliders.length === 0) {\n return null;\n }\n\n return this._world.add(new PhysicsBody({ type: 'static', position: { x, y }, colliders }));\n }\n}\n"],"mappings":";;;;;;AAmDA,MAAM,YAAY,IAAY,OAAuB,GAAG,GAAG,GAAG;;;;;;AAO9D,MAAM,eAAe,aAAqB,aAAiC,UACzE,gBAAgB,SAAY,cAAc,KAAK,IAAI,aAAa,cAAc,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwCrF,IAAa,uBAAb,MAAkC;CAChC,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CAEjB,AAAiB,yBAAS,IAAI,IAAwB;CACtD,AAAiB,wBAAQ,IAAI,IAAY;CAEzC,AAAQ,iBAAiB;CACzB,AAAQ;CACR,AAAQ;CACR,AAAQ,aAAa;CAErB,AAAO,YAAY,OAAqB,OAAkB,UAA+B,CAAC,GAAG;EAC3F,KAAK,SAAS;EACd,KAAK,SAAS;EACd,KAAK,WAAW;EAChB,KAAK,YAAY,gBAAgB,OAAO;EACxC,KAAK,cAAc,QAAQ,cAAc;EACzC,KAAK,WAAW,MAAM;EACtB,KAAK,WAAW,MAAM;CACxB;;CAGA,IAAW,YAAoB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QAAQ,OAAO;GAC7D,GAAI,QAAQ,UAAU,UAAa,EAAE,OAAO,QAAQ,MAAM;EAC5D,CAAC;EAED,IAAI,SAAS,MAAM,WAAW,KAAK,SAAS,OAAO,WAAW,GAC5D,OAAO;EAGT,MAAM,SAAS,MAAM;EACrB,MAAM,IAAI,UAAU,MAAM,WAAW,mBAAmB,OAAO;EAC/D,MAAM,IAAI,UAAU,MAAM,WAAW,oBAAoB,OAAO;EAChE,MAAM,YAAY,mBAAmB,UAAU;GAC7C;GACA;GACA,WAAW,MAAM,WAAW;GAC5B,YAAY,MAAM,WAAW;GAC7B,cAAc,OAAO;GACrB,cAAc,OAAO;GACrB,YAAY,KAAK;GACjB,UAAU,KAAK;GACf,UAAU,QAAQ;EACpB,CAAC;EAED,IAAI,UAAU,WAAW,GACvB,OAAO;EAGT,OAAO,KAAK,OAAO,IAAI,IAAI,YAAY;GAAE,MAAM;GAAU,UAAU;IAAE;IAAG;GAAE;GAAG;EAAU,CAAC,CAAC;CAC3F;AACF"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { SceneNode } from '@codexo/exojs';
|
|
2
|
+
import type { PhysicsBody } from '@codexo/exojs-physics';
|
|
3
|
+
import type { TileProjection } from '@codexo/exojs-tilemap';
|
|
4
|
+
/**
|
|
5
|
+
* Explicit presentation of a logical physics body through a tile projection.
|
|
6
|
+
* Call after stepping the world, or use syncInterpolated with the fixed-step
|
|
7
|
+
* interpolation fraction. The node's parent must use map display coordinates.
|
|
8
|
+
* Owns neither body nor node; does not register with the world. Sprite rotation
|
|
9
|
+
* and scale remain application-owned because projection is not a rigid rotation.
|
|
10
|
+
*/
|
|
11
|
+
export declare class TilePhysicsBinding {
|
|
12
|
+
readonly body: PhysicsBody;
|
|
13
|
+
readonly node: SceneNode;
|
|
14
|
+
readonly projection: TileProjection;
|
|
15
|
+
constructor(body: PhysicsBody, node: SceneNode, projection: TileProjection);
|
|
16
|
+
sync(): void;
|
|
17
|
+
/** Interpolates logical positions before projection; teleport semantics follow PhysicsBody. */
|
|
18
|
+
syncInterpolated(alpha: number): void;
|
|
19
|
+
private _sync;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=TilePhysicsBinding.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TilePhysicsBinding.d.ts","sourceRoot":"","sources":["../../src/TilePhysicsBinding.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAE5D;;;;;;GAMG;AACH,qBAAa,kBAAkB;aAEX,IAAI,EAAE,WAAW;aACjB,IAAI,EAAE,SAAS;aACf,UAAU,EAAE,cAAc;IAH5C,YACkB,IAAI,EAAE,WAAW,EACjB,IAAI,EAAE,SAAS,EACf,UAAU,EAAE,cAAc,EACxC;IAEG,IAAI,IAAI,IAAI,CAElB;IAED,+FAA+F;IACxF,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAG3C;IAED,OAAO,CAAC,KAAK;CAQd"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
//#region src/TilePhysicsBinding.ts
|
|
2
|
+
/**
|
|
3
|
+
* Explicit presentation of a logical physics body through a tile projection.
|
|
4
|
+
* Call after stepping the world, or use syncInterpolated with the fixed-step
|
|
5
|
+
* interpolation fraction. The node's parent must use map display coordinates.
|
|
6
|
+
* Owns neither body nor node; does not register with the world. Sprite rotation
|
|
7
|
+
* and scale remain application-owned because projection is not a rigid rotation.
|
|
8
|
+
*/
|
|
9
|
+
var TilePhysicsBinding = class {
|
|
10
|
+
body;
|
|
11
|
+
node;
|
|
12
|
+
projection;
|
|
13
|
+
constructor(body, node, projection) {
|
|
14
|
+
this.body = body;
|
|
15
|
+
this.node = node;
|
|
16
|
+
this.projection = projection;
|
|
17
|
+
}
|
|
18
|
+
sync() {
|
|
19
|
+
this._sync(this.body.x, this.body.y);
|
|
20
|
+
}
|
|
21
|
+
/** Interpolates logical positions before projection; teleport semantics follow PhysicsBody. */
|
|
22
|
+
syncInterpolated(alpha) {
|
|
23
|
+
const body = this.body;
|
|
24
|
+
this._sync(body.previousX + (body.x - body.previousX) * alpha, body.previousY + (body.y - body.previousY) * alpha);
|
|
25
|
+
}
|
|
26
|
+
_sync(x, y) {
|
|
27
|
+
const p = this.projection;
|
|
28
|
+
if (p.orientation === "isometric") this.node.setPosition(p.originX + (x - y) * p.tileWidth / (2 * p.tileHeight), p.originY + (x + y) / 2);
|
|
29
|
+
else this.node.setPosition(p.originX + x, p.originY + y);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
//#endregion
|
|
34
|
+
export { TilePhysicsBinding };
|
|
35
|
+
//# sourceMappingURL=TilePhysicsBinding.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TilePhysicsBinding.js","names":[],"sources":["../../src/TilePhysicsBinding.ts"],"sourcesContent":["import type { SceneNode } from '@codexo/exojs';\nimport type { PhysicsBody } from '@codexo/exojs-physics';\nimport type { TileProjection } from '@codexo/exojs-tilemap';\n\n/**\n * Explicit presentation of a logical physics body through a tile projection.\n * Call after stepping the world, or use syncInterpolated with the fixed-step\n * interpolation fraction. The node's parent must use map display coordinates.\n * Owns neither body nor node; does not register with the world. Sprite rotation\n * and scale remain application-owned because projection is not a rigid rotation.\n */\nexport class TilePhysicsBinding {\n public constructor(\n public readonly body: PhysicsBody,\n public readonly node: SceneNode,\n public readonly projection: TileProjection,\n ) {}\n\n public sync(): void {\n this._sync(this.body.x, this.body.y);\n }\n\n /** Interpolates logical positions before projection; teleport semantics follow PhysicsBody. */\n public syncInterpolated(alpha: number): void {\n const body = this.body;\n this._sync(body.previousX + (body.x - body.previousX) * alpha, body.previousY + (body.y - body.previousY) * alpha);\n }\n\n private _sync(x: number, y: number): void {\n const p = this.projection;\n if (p.orientation === 'isometric') {\n this.node.setPosition(p.originX + ((x - y) * p.tileWidth) / (2 * p.tileHeight), p.originY + (x + y) / 2);\n } else {\n this.node.setPosition(p.originX + x, p.originY + y);\n }\n }\n}\n"],"mappings":";;;;;;;;AAWA,IAAa,qBAAb,MAAgC;CAEZ;CACA;CACA;CAHlB,AAAO,YACL,AAAgB,MAChB,AAAgB,MAChB,AAAgB,YAChB;EAHgB;EACA;EACA;CACf;CAEH,AAAO,OAAa;EAClB,KAAK,MAAM,KAAK,KAAK,GAAG,KAAK,KAAK,CAAC;CACrC;;CAGA,AAAO,iBAAiB,OAAqB;EAC3C,MAAM,OAAO,KAAK;EAClB,KAAK,MAAM,KAAK,aAAa,KAAK,IAAI,KAAK,aAAa,OAAO,KAAK,aAAa,KAAK,IAAI,KAAK,aAAa,KAAK;CACnH;CAEA,AAAQ,MAAM,GAAW,GAAiB;EACxC,MAAM,IAAI,KAAK;EACf,IAAI,EAAE,gBAAgB,aACpB,KAAK,KAAK,YAAY,EAAE,WAAY,IAAI,KAAK,EAAE,aAAc,IAAI,EAAE,aAAa,EAAE,WAAW,IAAI,KAAK,CAAC;OAEvG,KAAK,KAAK,YAAY,EAAE,UAAU,GAAG,EAAE,UAAU,CAAC;CAEtD;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildColliders.d.ts","sourceRoot":"","sources":["../../src/buildColliders.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,SAAS,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAmD,KAAK,eAAe,EAAyB,MAAM,uBAAuB,CAAC;AACrI,OAAO,EAAE,UAAU,EAAE,KAAK,qBAAqB,EAAmD,KAAK,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAEpJ,OAAO,EAAe,KAAK,gBAAgB,EAAmB,MAAM,YAAY,CAAC;AAEjF,OAAO,KAAK,EAAE,4BAA4B,EAAE,cAAc,EAAE,MAAM,S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F,OAAO,EAAE,WAAW,EAAE,CAAC;AAEvB;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,aAAc,qBAAqB,WAAW,oBAAoB,KAAG,eAAe,EA6BlH,CAAC"}
|
package/dist/esm/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { buildObjectLayerColliders } from "./objectLayer.js";
|
|
2
2
|
import { TileColliderStreamer } from "./TileColliderStreamer.js";
|
|
3
|
+
import { TilePhysicsBinding } from "./TilePhysicsBinding.js";
|
|
3
4
|
|
|
4
|
-
export { TileColliderStreamer, buildObjectLayerColliders };
|
|
5
|
+
export { TileColliderStreamer, TilePhysicsBinding, buildObjectLayerColliders };
|
package/dist/esm/material.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export interface ResolvedMaterial {
|
|
|
11
11
|
/** Resolve the call-level defaults once, before any geometry is walked. */
|
|
12
12
|
export declare const resolveDefaults: (options: ColliderDefaults) => ResolvedMaterial;
|
|
13
13
|
/** Apply a resolver's overrides over already-resolved defaults. */
|
|
14
|
-
export declare const resolveMaterial: (defaults: ResolvedMaterial, resolver: ColliderDefaults[
|
|
14
|
+
export declare const resolveMaterial: (defaults: ResolvedMaterial, resolver: ColliderDefaults['material'], context: TileColliderContext) => ResolvedMaterial;
|
|
15
15
|
/**
|
|
16
16
|
* Identity of everything a chain collider can carry, used to decide which solid
|
|
17
17
|
* cells may be traced into a common outline.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"material.d.ts","sourceRoot":"","sources":["../../src/material.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,eAAe,EAAiB,MAAM,uBAAuB,CAAC;AAE5E,OAAO,KAAK,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAMrE,iFAAiF;AACjF,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,MAAM,EAAE,eAAe,CAAC;CAClC;AAED,2EAA2E;AAC3E,eAAO,MAAM,eAAe,
|
|
1
|
+
{"version":3,"file":"material.d.ts","sourceRoot":"","sources":["../../src/material.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,eAAe,EAAiB,MAAM,uBAAuB,CAAC;AAE5E,OAAO,KAAK,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAMrE,iFAAiF;AACjF,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,MAAM,EAAE,eAAe,CAAC;CAClC;AAED,2EAA2E;AAC3E,eAAO,MAAM,eAAe,YAAa,gBAAgB,KAAG,gBAU1D,CAAC;AAEH,mEAAmE;AACnE,eAAO,MAAM,eAAe,aAAc,gBAAgB,YAAY,gBAAgB,CAAC,UAAU,CAAC,WAAW,mBAAmB,KAAG,gBAkBlI,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,WAAW,aAAc,gBAAgB,KAAG,MACiG,CAAC"}
|
|
@@ -20,8 +20,8 @@ export interface ObjectCollider {
|
|
|
20
20
|
* them through the world. Use {@link import('./TileColliderStreamer').TileColliderStreamer}
|
|
21
21
|
* for tile layers, whose chunks come and go.
|
|
22
22
|
*
|
|
23
|
-
* The layer's
|
|
24
|
-
*
|
|
23
|
+
* The layer's display offset is converted to a logical translation. Isometric
|
|
24
|
+
* geometry remains in logical space; use TilePhysicsBinding for presentation. Objects with no collision geometry (points, tile and text objects) are
|
|
25
25
|
* skipped, as is any object the decomposition rejects - with a warning, not an
|
|
26
26
|
* exception.
|
|
27
27
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"objectLayer.d.ts","sourceRoot":"","sources":["../../src/objectLayer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,KAAK,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACvE,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAIxE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAEhD,qDAAqD;AACrD,MAAM,WAAW,qBAAsB,SAAQ,gBAAgB;IAC7D,8EAA8E;IAC9E,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,aAAa,KAAK,OAAO,CAAC;CAC7C;AAED,qEAAqE;AACrE,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC;IAC/B,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;CAC5B;AAED;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,yBAAyB,
|
|
1
|
+
{"version":3,"file":"objectLayer.d.ts","sourceRoot":"","sources":["../../src/objectLayer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,KAAK,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACvE,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAIxE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAEhD,qDAAqD;AACrD,MAAM,WAAW,qBAAsB,SAAQ,gBAAgB;IAC7D,8EAA8E;IAC9E,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,aAAa,KAAK,OAAO,CAAC;CAC7C;AAED,qEAAqE;AACrE,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC;IAC/B,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;CAC5B;AAED;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,yBAAyB,UAAW,YAAY,SAAS,WAAW,YAAW,qBAAqB,KAAQ,cAAc,EA4BtI,CAAC"}
|
package/dist/esm/objectLayer.js
CHANGED
|
@@ -12,8 +12,8 @@ import { PhysicsBody } from "@codexo/exojs-physics";
|
|
|
12
12
|
* them through the world. Use {@link import('./TileColliderStreamer').TileColliderStreamer}
|
|
13
13
|
* for tile layers, whose chunks come and go.
|
|
14
14
|
*
|
|
15
|
-
* The layer's
|
|
16
|
-
*
|
|
15
|
+
* The layer's display offset is converted to a logical translation. Isometric
|
|
16
|
+
* geometry remains in logical space; use TilePhysicsBinding for presentation. Objects with no collision geometry (points, tile and text objects) are
|
|
17
17
|
* skipped, as is any object the decomposition rejects - with a warning, not an
|
|
18
18
|
* exception.
|
|
19
19
|
*/
|
|
@@ -23,8 +23,13 @@ const buildObjectLayerColliders = (world, layer, options = {}) => {
|
|
|
23
23
|
const built = [];
|
|
24
24
|
for (const object of layer.objects) {
|
|
25
25
|
if (accept !== void 0 && !accept(object)) continue;
|
|
26
|
-
const
|
|
27
|
-
const
|
|
26
|
+
const p = layer.projection;
|
|
27
|
+
const offset = p === void 0 ? {
|
|
28
|
+
x: layer.offsetX,
|
|
29
|
+
y: layer.offsetY
|
|
30
|
+
} : p.pixelToLogical(p.originX + layer.offsetX, p.originY + layer.offsetY);
|
|
31
|
+
const x = object.x + offset.x;
|
|
32
|
+
const y = object.y + offset.y;
|
|
28
33
|
const material = resolveMaterial(defaults, options.material, {
|
|
29
34
|
type: object.type,
|
|
30
35
|
object
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"objectLayer.js","names":[],"sources":["../../src/objectLayer.ts"],"sourcesContent":["import { PhysicsBody, type PhysicsWorld } from '@codexo/exojs-physics';\nimport type { ObjectLayer, TileMapObject } from '@codexo/exojs-tilemap';\n\nimport { collidersForGeometry, objectLabel } from './buildColliders';\nimport { resolveDefaults, resolveMaterial } from './material';\nimport type { ColliderDefaults } from './types';\n\n/** Options for {@link buildObjectLayerColliders}. */\nexport interface ObjectColliderOptions extends ColliderDefaults {\n /** Drop an object before a body is built for it. Return `true` to keep it. */\n accept?: (object: TileMapObject) => boolean;\n}\n\n/** One static body built from one object, paired with its source. */\nexport interface ObjectCollider {\n readonly object: TileMapObject;\n readonly body: PhysicsBody;\n}\n\n/**\n * Build one static body per collision object in an object layer and add them to\n * `world`.\n *\n * An object layer is static data with no residency, so this is a one-shot\n * build with no lifecycle: the caller owns the returned bodies and destroys\n * them through the world. Use {@link import('./TileColliderStreamer').TileColliderStreamer}\n * for tile layers, whose chunks come and go.\n *\n * The layer's
|
|
1
|
+
{"version":3,"file":"objectLayer.js","names":[],"sources":["../../src/objectLayer.ts"],"sourcesContent":["import { PhysicsBody, type PhysicsWorld } from '@codexo/exojs-physics';\nimport type { ObjectLayer, TileMapObject } from '@codexo/exojs-tilemap';\n\nimport { collidersForGeometry, objectLabel } from './buildColliders';\nimport { resolveDefaults, resolveMaterial } from './material';\nimport type { ColliderDefaults } from './types';\n\n/** Options for {@link buildObjectLayerColliders}. */\nexport interface ObjectColliderOptions extends ColliderDefaults {\n /** Drop an object before a body is built for it. Return `true` to keep it. */\n accept?: (object: TileMapObject) => boolean;\n}\n\n/** One static body built from one object, paired with its source. */\nexport interface ObjectCollider {\n readonly object: TileMapObject;\n readonly body: PhysicsBody;\n}\n\n/**\n * Build one static body per collision object in an object layer and add them to\n * `world`.\n *\n * An object layer is static data with no residency, so this is a one-shot\n * build with no lifecycle: the caller owns the returned bodies and destroys\n * them through the world. Use {@link import('./TileColliderStreamer').TileColliderStreamer}\n * for tile layers, whose chunks come and go.\n *\n * The layer's display offset is converted to a logical translation. Isometric\n * geometry remains in logical space; use TilePhysicsBinding for presentation. Objects with no collision geometry (points, tile and text objects) are\n * skipped, as is any object the decomposition rejects - with a warning, not an\n * exception.\n */\nexport const buildObjectLayerColliders = (world: PhysicsWorld, layer: ObjectLayer, options: ObjectColliderOptions = {}): ObjectCollider[] => {\n const defaults = resolveDefaults(options);\n const accept = options.accept;\n const built: ObjectCollider[] = [];\n\n for (const object of layer.objects) {\n if (accept !== undefined && !accept(object)) {\n continue;\n }\n\n const p = layer.projection;\n const offset = p === undefined ? { x: layer.offsetX, y: layer.offsetY } : p.pixelToLogical(p.originX + layer.offsetX, p.originY + layer.offsetY);\n const x = object.x + offset.x;\n const y = object.y + offset.y;\n const material = resolveMaterial(defaults, options.material, { type: object.type, object });\n const colliders = collidersForGeometry({ ...object, x, y }, material, x, y, objectLabel(object));\n\n if (colliders.length === 0) {\n continue;\n }\n\n built.push({\n object,\n body: world.add(new PhysicsBody({ type: 'static', position: { x, y }, colliders })),\n });\n }\n\n return built;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAiCA,MAAa,6BAA6B,OAAqB,OAAoB,UAAiC,CAAC,MAAwB;CAC3I,MAAM,WAAW,gBAAgB,OAAO;CACxC,MAAM,SAAS,QAAQ;CACvB,MAAM,QAA0B,CAAC;CAEjC,KAAK,MAAM,UAAU,MAAM,SAAS;EAClC,IAAI,WAAW,UAAa,CAAC,OAAO,MAAM,GACxC;EAGF,MAAM,IAAI,MAAM;EAChB,MAAM,SAAS,MAAM,SAAY;GAAE,GAAG,MAAM;GAAS,GAAG,MAAM;EAAQ,IAAI,EAAE,eAAe,EAAE,UAAU,MAAM,SAAS,EAAE,UAAU,MAAM,OAAO;EAC/I,MAAM,IAAI,OAAO,IAAI,OAAO;EAC5B,MAAM,IAAI,OAAO,IAAI,OAAO;EAC5B,MAAM,WAAW,gBAAgB,UAAU,QAAQ,UAAU;GAAE,MAAM,OAAO;GAAM;EAAO,CAAC;EAC1F,MAAM,YAAY,qBAAqB;GAAE,GAAG;GAAQ;GAAG;EAAE,GAAG,UAAU,GAAG,GAAG,YAAY,MAAM,CAAC;EAE/F,IAAI,UAAU,WAAW,GACvB;EAGF,MAAM,KAAK;GACT;GACA,MAAM,MAAM,IAAI,IAAI,YAAY;IAAE,MAAM;IAAU,UAAU;KAAE;KAAG;IAAE;IAAG;GAAU,CAAC,CAAC;EACpF,CAAC;CACH;CAEA,OAAO;AACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"outline.d.ts","sourceRoot":"","sources":["../../src/outline.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAgK/C;;;;;;;;;;GAUG;AACH,eAAO,MAAM,iBAAiB,
|
|
1
|
+
{"version":3,"file":"outline.d.ts","sourceRoot":"","sources":["../../src/outline.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAgK/C;;;;;;;;;;GAUG;AACH,eAAO,MAAM,iBAAiB,gBAAiB,SAAS,MAAM,EAAE,KAAG,SAAS,EAAE,EA0D7E,CAAC"}
|
package/dist/esm/public.d.ts
CHANGED
|
@@ -2,5 +2,6 @@ export type { ObjectCollider, ObjectColliderOptions } from './objectLayer';
|
|
|
2
2
|
export { buildObjectLayerColliders } from './objectLayer';
|
|
3
3
|
export type { TileColliderOptions } from './TileColliderStreamer';
|
|
4
4
|
export { TileColliderStreamer } from './TileColliderStreamer';
|
|
5
|
+
export { TilePhysicsBinding } from './TilePhysicsBinding';
|
|
5
6
|
export type { ColliderDefaults, TileColliderContext, TileColliderMaterial, TileColliderMaterialResolver, TileRegionMode } from './types';
|
|
6
7
|
//# sourceMappingURL=public.d.ts.map
|
package/dist/esm/public.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"public.d.ts","sourceRoot":"","sources":["../../src/public.ts"],"names":[],"mappings":"AAIA,YAAY,EAAE,cAAc,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAC3E,OAAO,EAAE,yBAAyB,EAAE,MAAM,eAAe,CAAC;AAC1D,YAAY,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAClE,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,YAAY,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,4BAA4B,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC"}
|
|
1
|
+
{"version":3,"file":"public.d.ts","sourceRoot":"","sources":["../../src/public.ts"],"names":[],"mappings":"AAIA,YAAY,EAAE,cAAc,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAC3E,OAAO,EAAE,yBAAyB,EAAE,MAAM,eAAe,CAAC;AAC1D,YAAY,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAClE,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,YAAY,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,4BAA4B,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codexo/exojs-tilemap-physics",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.19.0",
|
|
4
4
|
"description": "Static physics colliders from ExoJS tilemap collision geometry.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -26,17 +26,17 @@
|
|
|
26
26
|
"LICENSE"
|
|
27
27
|
],
|
|
28
28
|
"peerDependencies": {
|
|
29
|
-
"@codexo/exojs": "0.
|
|
30
|
-
"@codexo/exojs-physics": "0.
|
|
31
|
-
"@codexo/exojs-tilemap": "0.
|
|
29
|
+
"@codexo/exojs": "0.19.x",
|
|
30
|
+
"@codexo/exojs-physics": "0.19.x",
|
|
31
|
+
"@codexo/exojs-tilemap": "0.19.x"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@codexo/exojs
|
|
35
|
-
"@codexo/exojs-
|
|
36
|
-
"@codexo/exojs-
|
|
37
|
-
"@codexo/exojs-tiled": "0.
|
|
38
|
-
"@codexo/exojs": "0.
|
|
39
|
-
"@codexo/exojs-
|
|
34
|
+
"@codexo/exojs": "0.19.0",
|
|
35
|
+
"@codexo/exojs-ldtk": "0.19.0",
|
|
36
|
+
"@codexo/exojs-physics": "0.19.0",
|
|
37
|
+
"@codexo/exojs-tiled": "0.19.0",
|
|
38
|
+
"@codexo/exojs-tilemap": "0.19.0",
|
|
39
|
+
"@codexo/exojs-config": "0.0.0"
|
|
40
40
|
},
|
|
41
41
|
"license": "MIT",
|
|
42
42
|
"publishConfig": {
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"scripts": {
|
|
46
46
|
"build": "tsx ../../scripts/build-extension.ts",
|
|
47
47
|
"build:dev": "tsx ../../scripts/build-extension.ts --dev",
|
|
48
|
-
"typecheck": "tsc --noEmit && tsc --noEmit -p tsconfig.test.json",
|
|
48
|
+
"typecheck": "exo-tsc --noEmit && exo-tsc --noEmit -p tsconfig.test.json",
|
|
49
49
|
"lint": "eslint \"src/**/*.ts\" \"test/**/*.ts\"",
|
|
50
50
|
"test": "vitest run --root ../.. --project=exojs-tilemap-physics"
|
|
51
51
|
}
|