@rpgjs/tiledmap 5.0.0-beta.1 → 5.0.0-beta.11

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.
@@ -1,18 +1,64 @@
1
- import { useProps, useDefineProps, signal, effect, h, Container } from "canvasengine";
2
- import { EventLayerComponent } from "@rpgjs/client";
3
- import { TiledMap } from "@canvasengine/presets";
4
- function component($$props) {
5
- useProps($$props);
6
- const defineProps = useDefineProps($$props);
7
- var _a = defineProps(), data = _a.data, params = _a.params;
8
- var map = signal(data());
9
- var basePath = signal(params().basePath);
10
- effect(function() {
11
- map.set(data());
12
- });
13
- let $this = h(Container, null, h(TiledMap, { map, basePath, createLayersPerTilesZ: true, objectLayer: () => h(EventLayerComponent) }));
14
- return $this;
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));
15
16
  }
16
- export {
17
- component as default
18
- };
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 };
@@ -1,50 +1,11 @@
1
- import { MapClass } from "./index3.js";
2
- const TILED_HITBOX_ID_PREFIX = "__tiled_collision__:";
3
- function prepareTiledPhysicsData(mapData, map) {
4
- if (!mapData?.parsedMap) {
5
- return;
6
- }
7
- const tiledMap = new MapClass(mapData.parsedMap);
8
- map.tiled = tiledMap;
9
- const tiledHitboxes = collectBlockedTileHitboxes(tiledMap);
10
- mapData.hitboxes = mergeTiledHitboxes(mapData.hitboxes, tiledHitboxes);
11
- mapData.width = tiledMap.widthPx;
12
- mapData.height = tiledMap.heightPx;
13
- }
14
- function collectBlockedTileHitboxes(tiledMap) {
15
- const hitboxes = [];
16
- const mapWidth = tiledMap.width;
17
- const mapHeight = tiledMap.height;
18
- const tileWidth = tiledMap.tilewidth;
19
- const tileHeight = tiledMap.tileheight;
20
- for (let y = 0; y < mapHeight; y++) {
21
- for (let x = 0; x < mapWidth; x++) {
22
- const tileInfo = tiledMap.getTileByPosition(x * tileWidth, y * tileHeight, [0, 0], {
23
- populateTiles: true
24
- });
25
- if (tileInfo.hasCollision) {
26
- hitboxes.push({
27
- id: createTiledHitboxId(x, y),
28
- x: x * tileWidth,
29
- y: y * tileHeight,
30
- width: tileWidth,
31
- height: tileHeight
32
- });
33
- }
34
- }
35
- }
36
- return hitboxes;
37
- }
38
- function mergeTiledHitboxes(existingHitboxes, tiledHitboxes) {
39
- const preservedHitboxes = Array.isArray(existingHitboxes) ? existingHitboxes.filter((hitbox) => !isGeneratedTiledHitbox(hitbox)) : [];
40
- return [...preservedHitboxes, ...tiledHitboxes];
41
- }
42
- function isGeneratedTiledHitbox(hitbox) {
43
- return typeof hitbox?.id === "string" && hitbox.id.startsWith(TILED_HITBOX_ID_PREFIX);
44
- }
45
- function createTiledHitboxId(x, y) {
46
- return `${TILED_HITBOX_ID_PREFIX}${x},${y}`;
47
- }
48
- export {
49
- prepareTiledPhysicsData
50
- };
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 {};
@@ -0,0 +1,4 @@
1
+ export declare function provideTiledMap(options: {
2
+ basePath: string;
3
+ onLoadMap?: (map: string) => Promise<void>;
4
+ }): any[];
@@ -1,17 +1,15 @@
1
- import server from "./index2.js";
1
+ import "./index2.js";
2
+ import "./index4.js";
3
+ import server_default from "./index5.js";
2
4
  import { createModule } from "@rpgjs/common";
3
- import "./index3.js";
4
- const client = null;
5
- const provideLoadMap = null;
5
+ //#region src/index.ts
6
+ var client = null;
7
+ var provideLoadMap = null;
6
8
  function provideTiledMap(options) {
7
- return createModule("TiledMap", [
8
- {
9
- server,
10
- client
11
- },
12
- provideLoadMap?.()
13
- ]);
9
+ return createModule("TiledMap", [{
10
+ server: server_default,
11
+ client
12
+ }, provideLoadMap?.()]);
14
13
  }
15
- export {
16
- provideTiledMap
17
- };
14
+ //#endregion
15
+ export { provideTiledMap };