@rpgjs/tiledmap 5.0.0-alpha.9 → 5.0.0-beta.10
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/CHANGELOG.md +38 -0
- package/LICENSE +19 -0
- package/dist/client/client.d.ts +3 -0
- package/dist/client/compat.d.ts +19 -0
- package/dist/{index.d.ts → client/index.d.ts} +1 -1
- package/dist/client/index.js +35 -48
- package/dist/client/index2.js +3998 -6
- package/dist/client/index3.js +120 -4641
- package/dist/client/index4.js +64 -15
- package/dist/client/index5.js +11 -0
- package/dist/client/index6.js +22 -0
- package/dist/client/physics.d.ts +7 -0
- package/dist/server/compat.d.ts +19 -0
- package/dist/server/index.d.ts +4 -0
- package/dist/server/index.js +12 -14
- package/dist/server/index2.js +3997 -93
- package/dist/server/index3.js +131 -5232
- package/dist/server/index4.js +93 -0
- package/dist/server/index5.js +15 -0
- package/dist/server/physics.d.ts +7 -0
- package/dist/server/server.d.ts +54 -0
- package/package.json +11 -11
- package/src/client.ts +9 -3
- package/src/compat.ts +221 -0
- package/src/index.ts +5 -1
- package/src/physics.spec.ts +285 -0
- package/src/physics.ts +171 -0
- package/src/server.ts +45 -152
- package/src/tiled.ce +5 -1
- package/dist/client.d.ts +0 -2
- package/dist/server.d.ts +0 -65
package/dist/client/index4.js
CHANGED
|
@@ -1,15 +1,64 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
1
|
+
import { MapClass } from "./index2.js";
|
|
2
|
+
import { applyTiledMapCompat } from "./index3.js";
|
|
3
|
+
//#region src/physics.ts
|
|
4
|
+
var TILED_HITBOX_ID_PREFIX = "__tiled_collision__:";
|
|
5
|
+
var START_POSITION_NAME = "start";
|
|
6
|
+
function prepareTiledPhysicsData(mapData, map) {
|
|
7
|
+
if (!mapData?.parsedMap) return;
|
|
8
|
+
const tiledMap = new MapClass(mapData.parsedMap);
|
|
9
|
+
map.tiled = tiledMap;
|
|
10
|
+
applyTiledMapCompat(map, mapData.parsedMap);
|
|
11
|
+
const tiledHitboxes = collectBlockedTileHitboxes(tiledMap);
|
|
12
|
+
mapData.hitboxes = mergeTiledHitboxes(mapData.hitboxes, tiledHitboxes);
|
|
13
|
+
mapData.width = tiledMap.widthPx;
|
|
14
|
+
mapData.height = tiledMap.heightPx;
|
|
15
|
+
mapData.positions = mergeTiledPositions(mapData.positions, collectTiledPointPositions(mapData.parsedMap.objects));
|
|
16
|
+
}
|
|
17
|
+
function collectTiledPointPositions(objects) {
|
|
18
|
+
if (!Array.isArray(objects)) return {};
|
|
19
|
+
const positions = {};
|
|
20
|
+
for (const obj of objects) {
|
|
21
|
+
if (!obj?.point || typeof obj.x !== "number" || typeof obj.y !== "number") continue;
|
|
22
|
+
if (typeof obj.name === "string" && obj.name.length > 0) positions[obj.name] = {
|
|
23
|
+
x: obj.x,
|
|
24
|
+
y: obj.y
|
|
25
|
+
};
|
|
26
|
+
if (!positions[START_POSITION_NAME] && (obj.class === START_POSITION_NAME || obj.type === START_POSITION_NAME)) positions[START_POSITION_NAME] = {
|
|
27
|
+
x: obj.x,
|
|
28
|
+
y: obj.y
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
return positions;
|
|
32
|
+
}
|
|
33
|
+
function mergeTiledPositions(existingPositions, tiledPositions) {
|
|
34
|
+
return {
|
|
35
|
+
...existingPositions && typeof existingPositions === "object" ? existingPositions : {},
|
|
36
|
+
...tiledPositions
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function collectBlockedTileHitboxes(tiledMap) {
|
|
40
|
+
const hitboxes = [];
|
|
41
|
+
const mapWidth = tiledMap.width;
|
|
42
|
+
const mapHeight = tiledMap.height;
|
|
43
|
+
const tileWidth = tiledMap.tilewidth;
|
|
44
|
+
const tileHeight = tiledMap.tileheight;
|
|
45
|
+
for (let y = 0; y < mapHeight; y++) for (let x = 0; x < mapWidth; x++) if (tiledMap.getTileByPosition(x * tileWidth, y * tileHeight, [0, 0], { populateTiles: true }).hasCollision) hitboxes.push({
|
|
46
|
+
id: createTiledHitboxId(x, y),
|
|
47
|
+
x: x * tileWidth,
|
|
48
|
+
y: y * tileHeight,
|
|
49
|
+
width: tileWidth,
|
|
50
|
+
height: tileHeight
|
|
51
|
+
});
|
|
52
|
+
return hitboxes;
|
|
53
|
+
}
|
|
54
|
+
function mergeTiledHitboxes(existingHitboxes, tiledHitboxes) {
|
|
55
|
+
return [...Array.isArray(existingHitboxes) ? existingHitboxes.filter((hitbox) => !isGeneratedTiledHitbox(hitbox)) : [], ...tiledHitboxes];
|
|
56
|
+
}
|
|
57
|
+
function isGeneratedTiledHitbox(hitbox) {
|
|
58
|
+
return typeof hitbox?.id === "string" && hitbox.id.startsWith(TILED_HITBOX_ID_PREFIX);
|
|
59
|
+
}
|
|
60
|
+
function createTiledHitboxId(x, y) {
|
|
61
|
+
return `${TILED_HITBOX_ID_PREFIX}${x},${y}`;
|
|
62
|
+
}
|
|
63
|
+
//#endregion
|
|
64
|
+
export { prepareTiledPhysicsData };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { prepareTiledPhysicsData } from "./index4.js";
|
|
2
|
+
import { defineModule } from "@rpgjs/common";
|
|
3
|
+
//#region src/client.ts
|
|
4
|
+
var client_default = defineModule({
|
|
5
|
+
componentAnimations: [],
|
|
6
|
+
sceneMap: { onPhysicsInit(map, context) {
|
|
7
|
+
prepareTiledPhysicsData(context?.mapData, map);
|
|
8
|
+
} }
|
|
9
|
+
});
|
|
10
|
+
//#endregion
|
|
11
|
+
export { client_default as default };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { EventLayerComponent } from "@rpgjs/client";
|
|
2
|
+
import { Container, effect, h, signal, useDefineProps, useProps } from "canvasengine";
|
|
3
|
+
import { TiledMap } from "@canvasengine/presets";
|
|
4
|
+
//#region src/tiled.ce
|
|
5
|
+
function component($$props) {
|
|
6
|
+
useProps($$props);
|
|
7
|
+
const { data, params } = useDefineProps($$props)();
|
|
8
|
+
const map = signal(data());
|
|
9
|
+
const basePath = signal(params().basePath);
|
|
10
|
+
effect(() => {
|
|
11
|
+
map.set(data());
|
|
12
|
+
});
|
|
13
|
+
return h(Container, null, h(TiledMap, {
|
|
14
|
+
map,
|
|
15
|
+
basePath,
|
|
16
|
+
createLayersPerTilesZ: true,
|
|
17
|
+
objectLayer: () => h(EventLayerComponent)
|
|
18
|
+
}));
|
|
19
|
+
}
|
|
20
|
+
var __ce_component = component;
|
|
21
|
+
//#endregion
|
|
22
|
+
export { __ce_component as default };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { MapClass } from '@canvasengine/tiled';
|
|
2
|
+
type AnyMap = {
|
|
3
|
+
tiled?: MapClass;
|
|
4
|
+
[key: string]: any;
|
|
5
|
+
};
|
|
6
|
+
type ParsedTiledMap = {
|
|
7
|
+
width?: number;
|
|
8
|
+
height?: number;
|
|
9
|
+
tilewidth?: number;
|
|
10
|
+
tileheight?: number;
|
|
11
|
+
layers?: any[];
|
|
12
|
+
tilesets?: any[];
|
|
13
|
+
[key: string]: any;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Adds v4-style map helpers backed by CanvasEngine Tiled.
|
|
17
|
+
*/
|
|
18
|
+
export declare function applyTiledMapCompat(map: AnyMap, parsedMap: ParsedTiledMap): void;
|
|
19
|
+
export {};
|
package/dist/server/index.js
CHANGED
|
@@ -1,17 +1,15 @@
|
|
|
1
|
-
import
|
|
1
|
+
import "./index2.js";
|
|
2
|
+
import "./index4.js";
|
|
3
|
+
import server_default from "./index5.js";
|
|
2
4
|
import { createModule } from "@rpgjs/common";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
//#region src/index.ts
|
|
6
|
+
var client = null;
|
|
7
|
+
var provideLoadMap = null;
|
|
6
8
|
function provideTiledMap(options) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
},
|
|
12
|
-
provideLoadMap == null ? void 0 : provideLoadMap()
|
|
13
|
-
]);
|
|
9
|
+
return createModule("TiledMap", [{
|
|
10
|
+
server: server_default,
|
|
11
|
+
client
|
|
12
|
+
}, provideLoadMap?.()]);
|
|
14
13
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
};
|
|
14
|
+
//#endregion
|
|
15
|
+
export { provideTiledMap };
|