@rpgjs/tiledmap 5.0.0-alpha.4 → 5.0.0-alpha.5

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.
@@ -13,7 +13,10 @@ function provideTiledMap(options) {
13
13
  },
14
14
  (_a = provideLoadMap) == null ? void 0 : _a(async (map) => {
15
15
  const response = await fetch(`${options.basePath}/${map}.tmx`);
16
- const mapData = (await response.text()).replace(/source="([^"]+)"/g, `source="${options.basePath}/$1"`);
16
+ const mapData = (await response.text()).replace(
17
+ /source="([^"]+)"/g,
18
+ `source="${options.basePath}/$1"`
19
+ );
17
20
  const parser = new TiledParser(mapData);
18
21
  const parsedMap = parser.parseMap();
19
22
  const tilesets = [];
@@ -31,12 +34,23 @@ function provideTiledMap(options) {
31
34
  });
32
35
  }
33
36
  parsedMap.tilesets = tilesets;
37
+ const events = [
38
+ {
39
+ "event": eval("function Event(options = {}) {\n return {\n async onInit() {\n this.setGraphic('male')\n //new BattleAi(this)\n },\n \n async onAction(player) {\n await player.showText('Comment vas tu ?')\n },\n\n async onChanges(player) {\n },\n\n async onPlayerTouch(player) {\n }\n }\n}"),
40
+ "x": 200,
41
+ "y": 200
42
+ }
43
+ ];
34
44
  const obj = {
35
45
  data: mapData,
36
46
  component,
37
47
  parsedMap,
48
+ events,
38
49
  id: map
39
50
  };
51
+ if (options.onLoadMap) {
52
+ await options.onLoadMap(map);
53
+ }
40
54
  return obj;
41
55
  })
42
56
  ]);
@@ -4,8 +4,7 @@ import { TiledMap } from "@canvasengine/presets";
4
4
  function component($$props) {
5
5
  useProps($$props);
6
6
  const defineProps = useDefineProps($$props);
7
- var _a = defineProps(), data = _a.data;
8
- _a.children;
7
+ var data = defineProps().data;
9
8
  var map = signal(data());
10
9
  let $this = h(Container, null, h(TiledMap, { map, basePath: "map", createLayersPerTilesZ: true, objectLayer: () => h(EventLayerComponent) }));
11
10
  return $this;
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export declare function provideTiledMap(options: {
2
2
  basePath: string;
3
+ onLoadMap?: (map: string) => Promise<void>;
3
4
  }): any;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rpgjs/tiledmap",
3
- "version": "5.0.0-alpha.4",
3
+ "version": "5.0.0-alpha.5",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "exports": {
@@ -24,11 +24,11 @@
24
24
  "peerDependencies": {
25
25
  "canvasengine": "2.0.0-beta.21",
26
26
  "@canvasengine/presets": "2.0.0-beta.21",
27
- "@rpgjs/common": "5.0.0-alpha.4",
28
- "@rpgjs/server": "5.0.0-alpha.4",
29
- "@rpgjs/client": "5.0.0-alpha.4",
30
- "@rpgjs/tiled": "5.0.0-alpha.4",
31
- "@rpgjs/vite": "5.0.0-alpha.4"
27
+ "@rpgjs/common": "5.0.0-alpha.5",
28
+ "@rpgjs/server": "5.0.0-alpha.5",
29
+ "@rpgjs/client": "5.0.0-alpha.5",
30
+ "@rpgjs/tiled": "5.0.0-alpha.5",
31
+ "@rpgjs/vite": "5.0.0-alpha.5"
32
32
  },
33
33
  "publishConfig": {
34
34
  "access": "public"
package/src/index.ts CHANGED
@@ -7,6 +7,7 @@ import Tiled from "./tiled.ce";
7
7
 
8
8
  export function provideTiledMap(options: {
9
9
  basePath: string;
10
+ onLoadMap?: (map: string) => Promise<void>;
10
11
  }) {
11
12
  return createModule("TiledMap", [
12
13
  {
@@ -14,33 +15,50 @@ export function provideTiledMap(options: {
14
15
  client,
15
16
  },
16
17
  provideLoadMap?.(async (map) => {
17
- 'use client';
18
- const response = await fetch(`${options.basePath}/${map}.tmx`)
19
- const mapData = (await response.text()).replace(/source="([^"]+)"/g, `source="${options.basePath}/$1"`)
18
+ "use client";
19
+ const response = await fetch(`${options.basePath}/${map}.tmx`);
20
+ const mapData = (await response.text()).replace(
21
+ /source="([^"]+)"/g,
22
+ `source="${options.basePath}/$1"`
23
+ );
20
24
  const parser = new TiledParser(mapData);
21
25
  const parsedMap = parser.parseMap();
22
- const tilesets: any = []
26
+ const tilesets: any = [];
23
27
  for (let tileset of parsedMap.tilesets) {
24
28
  const response = await fetch(`${tileset.source}`);
25
29
  const tilesetData = await response.text();
26
30
  const parser = new TiledParser(tilesetData);
27
31
  const parsedTileset = parser.parseTileset();
28
- parsedTileset.image.source = `${options.basePath}/${parsedTileset.image.source}`
32
+ parsedTileset.image.source = `${options.basePath}/${parsedTileset.image.source}`;
29
33
  // Preserve firstgid from the original tileset reference
30
34
  tilesets.push({
31
- ...tileset, // Preserve original properties including firstgid
32
- ...parsedTileset // Merge with parsed tileset data
33
- })
35
+ ...tileset, // Preserve original properties including firstgid
36
+ ...parsedTileset, // Merge with parsed tileset data
37
+ });
34
38
  }
35
- parsedMap.tilesets = tilesets
36
-
39
+ parsedMap.tilesets = tilesets;
40
+
41
+ const events = [
42
+ {
43
+ "event": eval("function Event(options = {}) {\n return {\n async onInit() {\n this.setGraphic('male')\n //new BattleAi(this)\n },\n \n async onAction(player) {\n await player.showText('Comment vas tu ?')\n },\n\n async onChanges(player) {\n },\n\n async onPlayerTouch(player) {\n }\n }\n}"),
44
+ "x": 200,
45
+ "y": 200
46
+ }
47
+ ]
48
+
37
49
  const obj = {
38
- data: mapData,
39
- component: Tiled,
40
- parsedMap,
41
- id: map
42
- }
43
- return obj
50
+ data: mapData,
51
+ component: Tiled,
52
+ parsedMap,
53
+ events,
54
+ id: map,
55
+ };
56
+
57
+ if (options.onLoadMap) {
58
+ await options.onLoadMap(map);
59
+ }
60
+
61
+ return obj;
44
62
  }),
45
63
  ]);
46
64
  }
package/src/tiled.ce CHANGED
@@ -7,7 +7,7 @@
7
7
  import { TiledMap } from "@canvasengine/presets";
8
8
  import { signal } from "canvasengine";
9
9
 
10
- const { data, children } = defineProps()
10
+ const { data } = defineProps()
11
11
 
12
12
  const map = signal(data())
13
13
  </script>