@rpgjs/tiledmap 5.0.0-beta.2 → 5.0.0-beta.4

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,11 @@
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;
15
- }
16
- export {
17
- component as default
18
- };
1
+ import { prepareTiledPhysicsData } from "./index3.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 };
@@ -1,50 +1,21 @@
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;
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
+ }));
13
19
  }
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
- };
20
+ //#endregion
21
+ export { component as default };
package/dist/client.d.ts CHANGED
@@ -1,2 +1,3 @@
1
- declare const _default: any;
1
+ import { RpgClient } from '@rpgjs/client';
2
+ declare const _default: RpgClient;
2
3
  export default _default;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  export declare function provideTiledMap(options: {
2
2
  basePath: string;
3
3
  onLoadMap?: (map: string) => Promise<void>;
4
- }): any;
4
+ }): any[];
@@ -1,17 +1,15 @@
1
- import server from "./index2.js";
2
- import { createModule } from "@rpgjs/common";
1
+ import "./index2.js";
3
2
  import "./index3.js";
4
- const client = null;
5
- const provideLoadMap = null;
3
+ import server_default from "./index4.js";
4
+ import { createModule } from "@rpgjs/common";
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 };