@rpgjs/client 5.0.0-alpha.10 → 5.0.0-alpha.3

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.
Files changed (115) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/dist/Game/EffectManager.d.ts +5 -0
  3. package/dist/RpgClient.d.ts +68 -99
  4. package/dist/RpgClientEngine.d.ts +4 -86
  5. package/dist/components/effects/index.d.ts +4 -0
  6. package/dist/components/index.d.ts +1 -2
  7. package/dist/index.d.ts +1 -1
  8. package/dist/index.js +1 -2
  9. package/dist/index.js.map +1 -1
  10. package/dist/index10.js +1 -1
  11. package/dist/index11.js +4 -4
  12. package/dist/index11.js.map +1 -1
  13. package/dist/index12.js +2 -6
  14. package/dist/index12.js.map +1 -1
  15. package/dist/index13.js +2 -2
  16. package/dist/index13.js.map +1 -1
  17. package/dist/index14.js +35 -95
  18. package/dist/index14.js.map +1 -1
  19. package/dist/index15.js +186 -45
  20. package/dist/index15.js.map +1 -1
  21. package/dist/index16.js +5 -187
  22. package/dist/index16.js.map +1 -1
  23. package/dist/index17.js +383 -5
  24. package/dist/index17.js.map +1 -1
  25. package/dist/index18.js +28 -384
  26. package/dist/index18.js.map +1 -1
  27. package/dist/index19.js +17 -24
  28. package/dist/index19.js.map +1 -1
  29. package/dist/index2.js +25 -147
  30. package/dist/index2.js.map +1 -1
  31. package/dist/index20.js +2413 -16
  32. package/dist/index20.js.map +1 -1
  33. package/dist/index21.js +88 -2395
  34. package/dist/index21.js.map +1 -1
  35. package/dist/index22.js +103 -108
  36. package/dist/index22.js.map +1 -1
  37. package/dist/index23.js +57 -95
  38. package/dist/index23.js.map +1 -1
  39. package/dist/index24.js +12 -62
  40. package/dist/index24.js.map +1 -1
  41. package/dist/index25.js +37 -18
  42. package/dist/index25.js.map +1 -1
  43. package/dist/index26.js +3 -25
  44. package/dist/index26.js.map +1 -1
  45. package/dist/index27.js +314 -87
  46. package/dist/index27.js.map +1 -1
  47. package/dist/index28.js +21 -37
  48. package/dist/index28.js.map +1 -1
  49. package/dist/index29.js +9 -3
  50. package/dist/index29.js.map +1 -1
  51. package/dist/index3.js +2 -2
  52. package/dist/index30.js +6 -317
  53. package/dist/index30.js.map +1 -1
  54. package/dist/index31.js +171 -24
  55. package/dist/index31.js.map +1 -1
  56. package/dist/index32.js +497 -7
  57. package/dist/index32.js.map +1 -1
  58. package/dist/index33.js +9 -8
  59. package/dist/index33.js.map +1 -1
  60. package/dist/index34.js +4400 -9
  61. package/dist/index34.js.map +1 -1
  62. package/dist/index35.js +85 -4397
  63. package/dist/index35.js.map +1 -1
  64. package/dist/index36.js +55 -310
  65. package/dist/index36.js.map +1 -1
  66. package/dist/index37.js +15 -169
  67. package/dist/index37.js.map +1 -1
  68. package/dist/index38.js +15 -496
  69. package/dist/index38.js.map +1 -1
  70. package/dist/index4.js +5 -18
  71. package/dist/index4.js.map +1 -1
  72. package/dist/index5.js +1 -2
  73. package/dist/index5.js.map +1 -1
  74. package/dist/index6.js +1 -1
  75. package/dist/index7.js +2 -10
  76. package/dist/index7.js.map +1 -1
  77. package/dist/index8.js +6 -24
  78. package/dist/index8.js.map +1 -1
  79. package/dist/index9.js +2 -2
  80. package/dist/presets/index.d.ts +0 -102
  81. package/dist/services/loadMap.d.ts +2 -123
  82. package/dist/services/mmorpg.d.ts +3 -7
  83. package/package.json +12 -14
  84. package/src/Game/{AnimationManager.ts → EffectManager.ts} +2 -2
  85. package/src/Game/Object.ts +0 -69
  86. package/src/RpgClient.ts +67 -101
  87. package/src/RpgClientEngine.ts +24 -159
  88. package/src/components/character.ce +33 -74
  89. package/src/components/{animations → effects}/animation.ce +5 -3
  90. package/src/components/{animations → effects}/index.ts +1 -1
  91. package/src/components/index.ts +1 -2
  92. package/src/components/scenes/draw-map.ce +23 -6
  93. package/src/components/scenes/element-map.ce +23 -0
  94. package/src/components/scenes/event-layer.ce +3 -3
  95. package/src/core/setup.ts +0 -2
  96. package/src/index.ts +1 -1
  97. package/src/module.ts +5 -23
  98. package/src/presets/index.ts +1 -5
  99. package/src/services/loadMap.ts +2 -131
  100. package/src/services/mmorpg.ts +4 -20
  101. package/tsconfig.json +1 -1
  102. package/vite.config.ts +1 -1
  103. package/dist/Game/AnimationManager.d.ts +0 -8
  104. package/dist/components/animations/index.d.ts +0 -4
  105. package/dist/index39.js +0 -61
  106. package/dist/index39.js.map +0 -1
  107. package/dist/index40.js +0 -20
  108. package/dist/index40.js.map +0 -1
  109. package/dist/index41.js +0 -82
  110. package/dist/index41.js.map +0 -1
  111. package/dist/presets/animation.d.ts +0 -31
  112. package/dist/presets/lpc.d.ts +0 -89
  113. package/src/presets/animation.ts +0 -46
  114. package/src/presets/lpc.ts +0 -108
  115. /package/src/components/{animations → effects}/hit.ce +0 -0
package/dist/index7.js CHANGED
@@ -1,4 +1,4 @@
1
- import { inject } from './index16.js';
1
+ import { inject } from './index15.js';
2
2
  import { UpdateMapToken } from '@rpgjs/common';
3
3
 
4
4
  const LoadMapToken = "LoadMapToken";
@@ -6,9 +6,6 @@ class LoadMapService {
6
6
  constructor(context, options) {
7
7
  this.context = context;
8
8
  this.options = options;
9
- if (context["side"] === "server") {
10
- return;
11
- }
12
9
  this.updateMapService = inject(context, UpdateMapToken);
13
10
  }
14
11
  async load(mapId) {
@@ -21,12 +18,7 @@ function provideLoadMap(options) {
21
18
  return [
22
19
  {
23
20
  provide: UpdateMapToken,
24
- useFactory: (context) => {
25
- if (context["side"] === "client") {
26
- console.warn("UpdateMapToken is not overridden");
27
- }
28
- return;
29
- }
21
+ useFactory: (context) => console.warn("UpdateMapToken is not overridden")
30
22
  },
31
23
  {
32
24
  provide: LoadMapToken,
@@ -1 +1 @@
1
- {"version":3,"file":"index7.js","sources":["../src/services/loadMap.ts"],"sourcesContent":["import { Context, inject } from \"@signe/di\";\nimport { UpdateMapToken, UpdateMapService } from \"@rpgjs/common\";\n\nexport const LoadMapToken = 'LoadMapToken'\n\n/**\n * Represents the structure of map data that should be returned by the load map callback.\n * This interface defines all the properties that can be provided when loading a custom map.\n * \n * @interface MapData\n */\ntype MapData = {\n /** Raw map data that will be passed to the map component */\n data: any;\n /** CanvasEngine component that will render the map */\n component: any;\n /** Optional map width in pixels, used for viewport calculations */\n width?: number;\n /** Optional map height in pixels, used for viewport calculations */\n height?: number;\n /** Optional map events data (NPCs, interactive objects, etc.) */\n events?: any;\n /** Optional map identifier, defaults to the mapId parameter if not provided */\n id?: string;\n}\n\n/**\n * Callback function type for loading map data.\n * This function receives a map ID and should return either a MapData object directly\n * or a Promise that resolves to a MapData object.\n * \n * @callback LoadMapOptions\n * @param {string} mapId - The identifier of the map to load\n * @returns {Promise<MapData> | MapData} The map data object or a promise resolving to it\n */\nexport type LoadMapOptions = (mapId: string) => Promise<MapData> | MapData \n\nexport class LoadMapService {\n private updateMapService: UpdateMapService;\n\n constructor(private context: Context, private options: LoadMapOptions) {\n if (context['side'] === 'server') {\n return\n }\n this.updateMapService = inject(context, UpdateMapToken);\n }\n\n async load(mapId: string) {\n const map = await this.options(mapId.replace('map-', ''))\n await this.updateMapService.update(mapId, map);\n return map;\n }\n}\n\n/**\n * Creates a dependency injection configuration for custom map loading on the client side.\n * \n * This function allows you to customize how maps are loaded and displayed by providing\n * a callback that defines custom map data and rendering components. It's designed to work\n * with the RPG-JS dependency injection system and enables integration of custom map formats\n * like Tiled TMX files or any other map data structure.\n * \n * The function sets up the necessary service providers for map loading, including:\n * - UpdateMapToken: Handles map updates in the client context\n * - LoadMapToken: Provides the LoadMapService with your custom loading logic\n * \n * **Design Concept:**\n * The function follows the provider pattern, creating a modular way to inject custom\n * map loading behavior into the RPG-JS client engine. It separates the concern of\n * map data fetching from map rendering, allowing developers to focus on their specific\n * map format while leveraging the engine's rendering capabilities.\n * \n * @param {LoadMapOptions} options - Callback function that handles map loading logic\n * @returns {Array<Object>} Array of dependency injection provider configurations\n * \n * @example\n * ```typescript\n * import { provideLoadMap } from '@rpgjs/client'\n * import { createModule } from '@rpgjs/common'\n * import MyTiledMapComponent from './MyTiledMapComponent.ce'\n * \n * // Basic usage with JSON map data\n * export function provideCustomMap() {\n * return createModule(\"CustomMap\", [\n * provideLoadMap(async (mapId) => {\n * const response = await fetch(`/maps/${mapId}.json`)\n * const mapData = await response.json()\n * \n * return {\n * data: mapData,\n * component: MyTiledMapComponent,\n * width: mapData.width,\n * height: mapData.height,\n * events: mapData.events\n * }\n * })\n * ])\n * }\n * \n * // Advanced usage with Tiled TMX files\n * export function provideTiledMap() {\n * return createModule(\"TiledMap\", [\n * provideLoadMap(async (mapId) => {\n * // Load TMX file\n * const tmxResponse = await fetch(`/tiled/${mapId}.tmx`)\n * const tmxData = await tmxResponse.text()\n * \n * // Parse TMX data (using a TMX parser)\n * const parsedMap = parseTMX(tmxData)\n * \n * return {\n * data: parsedMap,\n * component: TiledMapRenderer,\n * width: parsedMap.width * parsedMap.tilewidth,\n * height: parsedMap.height * parsedMap.tileheight,\n * events: parsedMap.objectGroups?.find(g => g.name === 'events')?.objects\n * }\n * })\n * ])\n * }\n * \n * // Synchronous usage for static maps\n * export function provideStaticMap() {\n * return createModule(\"StaticMap\", [\n * provideLoadMap((mapId) => {\n * const staticMaps = {\n * 'town': { tiles: [...], npcs: [...] },\n * 'dungeon': { tiles: [...], monsters: [...] }\n * }\n * \n * return {\n * data: staticMaps[mapId],\n * component: StaticMapComponent,\n * width: 800,\n * height: 600\n * }\n * })\n * ])\n * }\n * ```\n * \n * @since 4.0.0\n * @see {@link LoadMapOptions} for callback function signature\n * @see {@link MapData} for return data structure\n */\nexport function provideLoadMap(options: LoadMapOptions) {\n return [\n {\n provide: UpdateMapToken,\n useFactory: (context: Context) => {\n if (context['side'] === 'client') {\n console.warn('UpdateMapToken is not overridden')\n }\n return\n },\n },\n {\n provide: LoadMapToken,\n useFactory: (context: Context) => new LoadMapService(context, options),\n },\n ];\n}\n"],"names":[],"mappings":";;;AAGO,MAAM,YAAe,GAAA;AAkCrB,MAAM,cAAe,CAAA;AAAA,EAG1B,WAAA,CAAoB,SAA0B,OAAyB,EAAA;AAAnD,IAAA,IAAA,CAAA,OAAA,GAAA,OAAA;AAA0B,IAAA,IAAA,CAAA,OAAA,GAAA,OAAA;AAC5C,IAAI,IAAA,OAAA,CAAQ,MAAM,CAAA,KAAM,QAAU,EAAA;AAChC,MAAA;AAAA;AAEF,IAAK,IAAA,CAAA,gBAAA,GAAmB,MAAO,CAAA,OAAA,EAAS,cAAc,CAAA;AAAA;AACxD,EAEA,MAAM,KAAK,KAAe,EAAA;AACxB,IAAM,MAAA,GAAA,GAAM,MAAM,IAAK,CAAA,OAAA,CAAQ,MAAM,OAAQ,CAAA,MAAA,EAAQ,EAAE,CAAC,CAAA;AACxD,IAAA,MAAM,IAAK,CAAA,gBAAA,CAAiB,MAAO,CAAA,KAAA,EAAO,GAAG,CAAA;AAC7C,IAAO,OAAA,GAAA;AAAA;AAEX;AA6FO,SAAS,eAAe,OAAyB,EAAA;AACtD,EAAO,OAAA;AAAA,IACL;AAAA,MACE,OAAS,EAAA,cAAA;AAAA,MACT,UAAA,EAAY,CAAC,OAAqB,KAAA;AAChC,QAAI,IAAA,OAAA,CAAQ,MAAM,CAAA,KAAM,QAAU,EAAA;AAChC,UAAA,OAAA,CAAQ,KAAK,kCAAkC,CAAA;AAAA;AAEjD,QAAA;AAAA;AACF,KACF;AAAA,IACA;AAAA,MACE,OAAS,EAAA,YAAA;AAAA,MACT,YAAY,CAAC,OAAA,KAAqB,IAAI,cAAA,CAAe,SAAS,OAAO;AAAA;AACvE,GACF;AACF;;;;"}
1
+ {"version":3,"file":"index7.js","sources":["../src/services/loadMap.ts"],"sourcesContent":["import { Context, inject } from \"@signe/di\";\nimport { UpdateMapToken, UpdateMapService } from \"@rpgjs/common\";\n\nexport const LoadMapToken = 'LoadMapToken'\n\nexport type LoadMapOptions = (mapId: string) => Promise<void>\n\nexport class LoadMapService {\n private updateMapService: UpdateMapService;\n\n constructor(private context: Context, private options: LoadMapOptions) {\n this.updateMapService = inject(context, UpdateMapToken);\n }\n\n async load(mapId: string) {\n const map = await this.options(mapId.replace('map-', ''))\n await this.updateMapService.update(mapId, map);\n return map;\n }\n}\n\nexport function provideLoadMap(options: LoadMapOptions) {\n return [\n {\n provide: UpdateMapToken,\n useFactory: (context: Context) => console.warn('UpdateMapToken is not overridden'),\n },\n {\n provide: LoadMapToken,\n useFactory: (context: Context) => new LoadMapService(context, options),\n },\n ];\n}\n"],"names":[],"mappings":";;;AAGO,MAAM,YAAe,GAAA;AAIrB,MAAM,cAAe,CAAA;AAAA,EAG1B,WAAA,CAAoB,SAA0B,OAAyB,EAAA;AAAnD,IAAA,IAAA,CAAA,OAAA,GAAA,OAAA;AAA0B,IAAA,IAAA,CAAA,OAAA,GAAA,OAAA;AAC5C,IAAK,IAAA,CAAA,gBAAA,GAAmB,MAAO,CAAA,OAAA,EAAS,cAAc,CAAA;AAAA;AACxD,EAEA,MAAM,KAAK,KAAe,EAAA;AACxB,IAAM,MAAA,GAAA,GAAM,MAAM,IAAK,CAAA,OAAA,CAAQ,MAAM,OAAQ,CAAA,MAAA,EAAQ,EAAE,CAAC,CAAA;AACxD,IAAA,MAAM,IAAK,CAAA,gBAAA,CAAiB,MAAO,CAAA,KAAA,EAAO,GAAG,CAAA;AAC7C,IAAO,OAAA,GAAA;AAAA;AAEX;AAEO,SAAS,eAAe,OAAyB,EAAA;AACtD,EAAO,OAAA;AAAA,IACL;AAAA,MACE,OAAS,EAAA,cAAA;AAAA,MACT,UAAY,EAAA,CAAC,OAAqB,KAAA,OAAA,CAAQ,KAAK,kCAAkC;AAAA,KACnF;AAAA,IACA;AAAA,MACE,OAAS,EAAA,YAAA;AAAA,MACT,YAAY,CAAC,OAAA,KAAqB,IAAI,cAAA,CAAe,SAAS,OAAO;AAAA;AACvE,GACF;AACF;;;;"}
package/dist/index8.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { provideModules, findModules } from '@rpgjs/common';
2
- import { inject } from './index16.js';
2
+ import { inject } from './index15.js';
3
3
  import { RpgGui } from './index9.js';
4
4
 
5
5
  function provideClientModules(modules) {
@@ -41,12 +41,12 @@ function provideClientModules(modules) {
41
41
  }
42
42
  };
43
43
  }
44
- if (module.componentAnimations) {
45
- const componentAnimations = [...module.componentAnimations];
46
- module.componentAnimations = {
44
+ if (module.effects) {
45
+ const effects = [...module.effects];
46
+ module.effects = {
47
47
  load: (engine) => {
48
- componentAnimations.forEach((componentAnimation) => {
49
- engine.addComponentAnimation(componentAnimation);
48
+ effects.forEach((effect) => {
49
+ engine.addEffect(effect);
50
50
  });
51
51
  }
52
52
  };
@@ -61,24 +61,6 @@ function provideClientModules(modules) {
61
61
  }
62
62
  };
63
63
  }
64
- if (module.sprite) {
65
- const sprite = { ...module.sprite };
66
- module.sprite = {
67
- ...sprite,
68
- load: (engine) => {
69
- if (sprite.componentsBehind) {
70
- sprite.componentsBehind.forEach((component) => {
71
- engine.addSpriteComponentBehind(component);
72
- });
73
- }
74
- if (sprite.componentsInFront) {
75
- sprite.componentsInFront.forEach((component) => {
76
- engine.addSpriteComponentInFront(component);
77
- });
78
- }
79
- }
80
- };
81
- }
82
64
  return module;
83
65
  });
84
66
  return modules2;
@@ -1 +1 @@
1
- {"version":3,"file":"index8.js","sources":["../src/module.ts"],"sourcesContent":["import { findModules, provideModules } from \"@rpgjs/common\";\nimport { RpgClientEngine } from \"./RpgClientEngine\";\nimport { RpgClient } from \"./RpgClient\";\nimport { inject } from \"@signe/di\";\nimport { RpgGui } from \"./Gui/Gui\";\n\nexport function provideClientModules(modules: RpgClient[]) {\n return provideModules(modules, \"client\", (modules, context) => {\n const mainModuleClient = findModules(context, 'Client')\n modules = [...mainModuleClient, ...modules]\n modules = modules.map((module) => {\n if ('client' in module) {\n module = module.client as any;\n }\n if (module.spritesheets) {\n const spritesheets = [...module.spritesheets];\n module.spritesheets = {\n load: (engine: RpgClientEngine) => {\n spritesheets.forEach((spritesheet) => {\n engine.addSpriteSheet(spritesheet);\n });\n },\n };\n }\n if (module.sounds) {\n const sounds = [...module.sounds];\n module.sounds = {\n load: (engine: RpgClientEngine) => {\n sounds.forEach((sound) => {\n engine.addSound(sound);\n });\n },\n };\n }\n if (module.gui) {\n const gui = [...module.gui];\n module.gui = {\n load: (engine: RpgClientEngine) => {\n const guiService = inject(engine.context, RpgGui);\n gui.forEach((gui) => {\n guiService.add(gui);\n });\n },\n };\n }\n if (module.componentAnimations) {\n const componentAnimations = [...module.componentAnimations];\n module.componentAnimations = {\n load: (engine: RpgClientEngine) => {\n componentAnimations.forEach((componentAnimation) => {\n engine.addComponentAnimation(componentAnimation);\n });\n },\n };\n }\n if (module.particles) {\n const particles = [...module.particles];\n module.particles = {\n load: (engine: RpgClientEngine) => {\n particles.forEach((particle) => {\n engine.addParticle(particle);\n });\n },\n };\n }\n if (module.sprite) {\n const sprite = {...module.sprite};\n module.sprite = {\n ...sprite,\n load: (engine: RpgClientEngine) => {\n if (sprite.componentsBehind) {\n sprite.componentsBehind.forEach((component) => {\n engine.addSpriteComponentBehind(component);\n });\n }\n if (sprite.componentsInFront) {\n sprite.componentsInFront.forEach((component) => {\n engine.addSpriteComponentInFront(component);\n });\n }\n },\n };\n }\n return module;\n });\n return modules\n });\n}\n\nexport const GlobalConfigToken = \"GlobalConfigToken\";\n\nexport function provideGlobalConfig(config: any) {\n return {\n provide: GlobalConfigToken,\n useValue: config ?? {},\n };\n}\n\nexport function provideClientGlobalConfig(config: any = {}) {\n if (!config.keyboardControls) {\n config.keyboardControls = {\n up: 'up',\n down: 'down',\n left: 'left',\n right: 'right',\n action: 'space'\n }\n }\n return provideGlobalConfig(config)\n}\n\n"],"names":["modules","gui"],"mappings":";;;;AAMO,SAAS,qBAAqB,OAAsB,EAAA;AACzD,EAAA,OAAO,cAAe,CAAA,OAAA,EAAS,QAAU,EAAA,CAACA,UAAS,OAAY,KAAA;AAC7D,IAAM,MAAA,gBAAA,GAAmB,WAAY,CAAA,OAAA,EAAS,QAAQ,CAAA;AACtD,IAAAA,QAAU,GAAA,CAAC,GAAG,gBAAA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F,SACF;AAAA;AAEF,MAAO,OAAA,MAAA;AAAA,KACR,CAAA;AACD,IAAOD,OAAAA,QAAAA;AAAA,GACR,CAAA;AACH;AAEO,MAAM,iBAAoB,GAAA;AAE1B,SAAS,oBAAoB,MAAa,EAAA;AAC/C,EAAO,OAAA;AAAA,IACL,OAAS,EAAA,iBAAA;AAAA,IACT,QAAA,EAAU,UAAU;AAAC,GACvB;AACF;AAEgB,SAAA,yBAAA,CAA0B,MAAc,GAAA,EAAI,EAAA;AAC1D,EAAI,IAAA,CAAC,OAAO,gBAAkB,EAAA;AAC5B,IAAA,MAAA,CAAO,gBAAmB,GAAA;AAAA,MACxB,EAAI,EAAA,IAAA;AAAA,MACJ,IAAM,EAAA,MAAA;AAAA,MACN,IAAM,EAAA,MAAA;AAAA,MACN,KAAO,EAAA,OAAA;AAAA,MACP,MAAQ,EAAA;AAAA,KACV;AAAA;AAEF,EAAA,OAAO,oBAAoB,MAAM,CAAA;AACnC;;;;"}
1
+ {"version":3,"file":"index8.js","sources":["../src/module.ts"],"sourcesContent":["import { findModules, provideModules } from \"@rpgjs/common\";\nimport { RpgClientEngine } from \"./RpgClientEngine\";\nimport { RpgClient } from \"./RpgClient\";\nimport { inject } from \"@signe/di\";\nimport { RpgGui } from \"./Gui/Gui\";\n\nexport function provideClientModules(modules: RpgClient[]) {\n return provideModules(modules, \"client\", (modules, context) => {\n const mainModuleClient = findModules(context, 'Client')\n modules = [...mainModuleClient, ...modules]\n modules = modules.map((module) => {\n if ('client' in module) {\n module = module.client as any;\n }\n if (module.spritesheets) {\n const spritesheets = [...module.spritesheets];\n module.spritesheets = {\n load: (engine: RpgClientEngine) => {\n spritesheets.forEach((spritesheet) => {\n engine.addSpriteSheet(spritesheet);\n });\n },\n };\n }\n if (module.sounds) {\n const sounds = [...module.sounds];\n module.sounds = {\n load: (engine: RpgClientEngine) => {\n sounds.forEach((sound) => {\n engine.addSound(sound);\n });\n },\n };\n }\n if (module.gui) {\n const gui = [...module.gui];\n module.gui = {\n load: (engine: RpgClientEngine) => {\n const guiService = inject(engine.context, RpgGui);\n gui.forEach((gui) => {\n guiService.add(gui);\n });\n },\n };\n }\n if (module.effects) {\n const effects = [...module.effects];\n module.effects = {\n load: (engine: RpgClientEngine) => {\n effects.forEach((effect) => {\n engine.addEffect(effect);\n });\n },\n };\n }\n if (module.particles) {\n const particles = [...module.particles];\n module.particles = {\n load: (engine: RpgClientEngine) => {\n particles.forEach((particle) => {\n engine.addParticle(particle);\n });\n },\n };\n }\n return module;\n });\n return modules\n });\n}\n\nexport const GlobalConfigToken = \"GlobalConfigToken\";\n\nexport function provideGlobalConfig(config: any) {\n return {\n provide: GlobalConfigToken,\n useValue: config ?? {},\n };\n}\n\nexport function provideClientGlobalConfig(config: any = {}) {\n if (!config.keyboardControls) {\n config.keyboardControls = {\n up: 'up',\n down: 'down',\n left: 'left',\n right: 'right',\n action: 'space'\n }\n }\n return provideGlobalConfig(config)\n}\n\n"],"names":["modules","gui"],"mappings":";;;;AAMO,SAAS,qBAAqB,OAAsB,EAAA;AACzD,EAAA,OAAO,cAAe,CAAA,OAAA,EAAS,QAAU,EAAA,CAACA,UAAS,OAAY,KAAA;AAC7D,IAAM,MAAA,gBAAA,GAAmB,WAAY,CAAA,OAAA,EAAS,QAAQ,CAAA;AACtD,IAAAA,QAAU,GAAA,CAAC,GAAG,gBAAA,EAAkB,GAAGA,QAAO,CAAA;AAC1C,IAAAA,QAAUA,GAAAA,QAAAA,CAAQ,GAAI,CAAA,CAAC,MAAW,KAAA;AAChC,MAAA,IAAI,YAAY,MAAQ,EAAA;AACtB,QAAA,MAAA,GAAS,MAAO,CAAA,MAAA;AAAA;AAElB,MAAA,IAAI,OAAO,YAAc,EAAA;AACvB,QAAA,MAAM,YAAe,GAAA,CAAC,GAAG,MAAA,CAAO,YAAY,CAAA;AAC5C,QAAA,MAAA,CAAO,YAAe,GAAA;AAAA,UACpB,IAAA,EAAM,CAAC,MAA4B,KAAA;AACjC,YAAa,YAAA,CAA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MAAA,CAAO,SAAS,CAAA;AACtC,QAAA,MAAA,CAAO,SAAY,GAAA;AAAA,UACjB,IAAA,EAAM,CAAC,MAA4B,KAAA;AACjC,YAAU,SAAA,CAAA,OAAA,CAAQ,CAAC,QAAa,KAAA;AAC9B,cAAA,MAAA,CAAO,YAAY,QAAQ,CAAA;AAAA,aAC5B,CAAA;AAAA;AACH,SACF;AAAA;AAEF,MAAO,OAAA,MAAA;AAAA,KACR,CAAA;AACD,IAAOD,OAAAA,QAAAA;AAAA,GACR,CAAA;AACH;AAEO,MAAM,iBAAoB,GAAA;AAE1B,SAAS,oBAAoB,MAAa,EAAA;AAC/C,EAAO,OAAA;AAAA,IACL,OAAS,EAAA,iBAAA;AAAA,IACT,QAAA,EAAU,UAAU;AAAC,GACvB;AACF;AAEgB,SAAA,yBAAA,CAA0B,MAAc,GAAA,EAAI,EAAA;AAC1D,EAAI,IAAA,CAAC,OAAO,gBAAkB,EAAA;AAC5B,IAAA,MAAA,CAAO,gBAAmB,GAAA;AAAA,MACxB,EAAI,EAAA,IAAA;AAAA,MACJ,IAAM,EAAA,MAAA;AAAA,MACN,IAAM,EAAA,MAAA;AAAA,MACN,KAAO,EAAA,OAAA;AAAA,MACP,MAAQ,EAAA;AAAA,KACV;AAAA;AAEF,EAAA,OAAO,oBAAoB,MAAM,CAAA;AACnC;;;;"}
package/dist/index9.js CHANGED
@@ -1,6 +1,6 @@
1
- import { inject } from './index16.js';
1
+ import { inject } from './index15.js';
2
2
  import { signal } from 'canvasengine';
3
- import { WebSocketToken } from './index17.js';
3
+ import { WebSocketToken } from './index16.js';
4
4
  import { PrebuiltGui } from './index10.js';
5
5
 
6
6
  const throwError = (id) => {
@@ -19,106 +19,4 @@ export declare const Presets: {
19
19
  framesHeight: number;
20
20
  framesWidth: number;
21
21
  };
22
- LPCSpritesheetPreset: (options: {
23
- id: string;
24
- imageSource: string;
25
- width: number;
26
- height: number;
27
- ratio?: number;
28
- }) => {
29
- id: string;
30
- image: string;
31
- width: number;
32
- height: number;
33
- opacity: number;
34
- rectWidth: number;
35
- rectHeight: number;
36
- framesWidth: number;
37
- framesHeight: number;
38
- spriteRealSize: {
39
- width: number;
40
- height: number;
41
- };
42
- textures: {
43
- attack3?: {
44
- offset: {
45
- x: number;
46
- y: number;
47
- };
48
- rectWidth: number;
49
- rectHeight: number;
50
- framesWidth: number;
51
- framesHeight: number;
52
- animations: ({ direction }: {
53
- direction: any;
54
- }) => any[];
55
- } | undefined;
56
- stand: {
57
- offset: {
58
- x: number;
59
- y: number;
60
- };
61
- animations: ({ direction }: {
62
- direction: any;
63
- }) => {
64
- time: number;
65
- frameX: number;
66
- frameY: number;
67
- }[][];
68
- };
69
- walk: {
70
- offset: {
71
- x: number;
72
- y: number;
73
- };
74
- framesWidth: number;
75
- framesHeight: number;
76
- animations: ({ direction }: {
77
- direction: any;
78
- }) => any[];
79
- };
80
- attack: {
81
- offset: {
82
- x: number;
83
- y: number;
84
- };
85
- framesWidth: number;
86
- framesHeight: number;
87
- animations: ({ direction }: {
88
- direction: any;
89
- }) => any[];
90
- };
91
- skill: {
92
- framesWidth: number;
93
- framesHeight: number;
94
- animations: ({ direction }: {
95
- direction: any;
96
- }) => any[];
97
- };
98
- attack2: {
99
- offset: {
100
- x: number;
101
- y: number;
102
- };
103
- framesWidth: number;
104
- framesHeight: number;
105
- animations: ({ direction }: {
106
- direction: any;
107
- }) => any[];
108
- };
109
- };
110
- };
111
- AnimationSpritesheetPreset: (framesWidth: number, framesHeight: number) => {
112
- framesWidth: number;
113
- framesHeight: number;
114
- textures: {
115
- default: {
116
- animations: () => {
117
- time: number;
118
- frameX: number;
119
- frameY: number;
120
- }[][];
121
- };
122
- };
123
- };
124
22
  };
@@ -1,135 +1,14 @@
1
1
  import { Context } from '@signe/di';
2
2
  export declare const LoadMapToken = "LoadMapToken";
3
- /**
4
- * Represents the structure of map data that should be returned by the load map callback.
5
- * This interface defines all the properties that can be provided when loading a custom map.
6
- *
7
- * @interface MapData
8
- */
9
- type MapData = {
10
- /** Raw map data that will be passed to the map component */
11
- data: any;
12
- /** CanvasEngine component that will render the map */
13
- component: any;
14
- /** Optional map width in pixels, used for viewport calculations */
15
- width?: number;
16
- /** Optional map height in pixels, used for viewport calculations */
17
- height?: number;
18
- /** Optional map events data (NPCs, interactive objects, etc.) */
19
- events?: any;
20
- /** Optional map identifier, defaults to the mapId parameter if not provided */
21
- id?: string;
22
- };
23
- /**
24
- * Callback function type for loading map data.
25
- * This function receives a map ID and should return either a MapData object directly
26
- * or a Promise that resolves to a MapData object.
27
- *
28
- * @callback LoadMapOptions
29
- * @param {string} mapId - The identifier of the map to load
30
- * @returns {Promise<MapData> | MapData} The map data object or a promise resolving to it
31
- */
32
- export type LoadMapOptions = (mapId: string) => Promise<MapData> | MapData;
3
+ export type LoadMapOptions = (mapId: string) => Promise<void>;
33
4
  export declare class LoadMapService {
34
5
  private context;
35
6
  private options;
36
7
  private updateMapService;
37
8
  constructor(context: Context, options: LoadMapOptions);
38
- load(mapId: string): Promise<MapData>;
9
+ load(mapId: string): Promise<void>;
39
10
  }
40
- /**
41
- * Creates a dependency injection configuration for custom map loading on the client side.
42
- *
43
- * This function allows you to customize how maps are loaded and displayed by providing
44
- * a callback that defines custom map data and rendering components. It's designed to work
45
- * with the RPG-JS dependency injection system and enables integration of custom map formats
46
- * like Tiled TMX files or any other map data structure.
47
- *
48
- * The function sets up the necessary service providers for map loading, including:
49
- * - UpdateMapToken: Handles map updates in the client context
50
- * - LoadMapToken: Provides the LoadMapService with your custom loading logic
51
- *
52
- * **Design Concept:**
53
- * The function follows the provider pattern, creating a modular way to inject custom
54
- * map loading behavior into the RPG-JS client engine. It separates the concern of
55
- * map data fetching from map rendering, allowing developers to focus on their specific
56
- * map format while leveraging the engine's rendering capabilities.
57
- *
58
- * @param {LoadMapOptions} options - Callback function that handles map loading logic
59
- * @returns {Array<Object>} Array of dependency injection provider configurations
60
- *
61
- * @example
62
- * ```typescript
63
- * import { provideLoadMap } from '@rpgjs/client'
64
- * import { createModule } from '@rpgjs/common'
65
- * import MyTiledMapComponent from './MyTiledMapComponent.ce'
66
- *
67
- * // Basic usage with JSON map data
68
- * export function provideCustomMap() {
69
- * return createModule("CustomMap", [
70
- * provideLoadMap(async (mapId) => {
71
- * const response = await fetch(`/maps/${mapId}.json`)
72
- * const mapData = await response.json()
73
- *
74
- * return {
75
- * data: mapData,
76
- * component: MyTiledMapComponent,
77
- * width: mapData.width,
78
- * height: mapData.height,
79
- * events: mapData.events
80
- * }
81
- * })
82
- * ])
83
- * }
84
- *
85
- * // Advanced usage with Tiled TMX files
86
- * export function provideTiledMap() {
87
- * return createModule("TiledMap", [
88
- * provideLoadMap(async (mapId) => {
89
- * // Load TMX file
90
- * const tmxResponse = await fetch(`/tiled/${mapId}.tmx`)
91
- * const tmxData = await tmxResponse.text()
92
- *
93
- * // Parse TMX data (using a TMX parser)
94
- * const parsedMap = parseTMX(tmxData)
95
- *
96
- * return {
97
- * data: parsedMap,
98
- * component: TiledMapRenderer,
99
- * width: parsedMap.width * parsedMap.tilewidth,
100
- * height: parsedMap.height * parsedMap.tileheight,
101
- * events: parsedMap.objectGroups?.find(g => g.name === 'events')?.objects
102
- * }
103
- * })
104
- * ])
105
- * }
106
- *
107
- * // Synchronous usage for static maps
108
- * export function provideStaticMap() {
109
- * return createModule("StaticMap", [
110
- * provideLoadMap((mapId) => {
111
- * const staticMaps = {
112
- * 'town': { tiles: [...], npcs: [...] },
113
- * 'dungeon': { tiles: [...], monsters: [...] }
114
- * }
115
- *
116
- * return {
117
- * data: staticMaps[mapId],
118
- * component: StaticMapComponent,
119
- * width: 800,
120
- * height: 600
121
- * }
122
- * })
123
- * ])
124
- * }
125
- * ```
126
- *
127
- * @since 4.0.0
128
- * @see {@link LoadMapOptions} for callback function signature
129
- * @see {@link MapData} for return data structure
130
- */
131
11
  export declare function provideLoadMap(options: LoadMapOptions): {
132
12
  provide: string;
133
13
  useFactory: (context: Context) => void;
134
14
  }[];
135
- export {};
@@ -4,21 +4,17 @@ import { RpgClientEngine } from '../RpgClientEngine';
4
4
  import { AbstractWebsocket } from './AbstractSocket';
5
5
  import { UpdateMapService } from '@rpgjs/common';
6
6
  interface MmorpgOptions {
7
- host?: string;
7
+ host: string;
8
8
  }
9
9
  declare class BridgeWebsocket extends AbstractWebsocket {
10
10
  protected context: Context;
11
11
  private options;
12
12
  private socket;
13
- constructor(context: Context, options?: MmorpgOptions);
14
- connection(listeners?: (data: any) => void): Promise<void>;
13
+ constructor(context: Context, options: MmorpgOptions);
14
+ connection(): Promise<void>;
15
15
  on(key: string, callback: (data: any) => void): void;
16
16
  off(event: string, callback: (data: any) => void): void;
17
17
  emit(event: string, data: any): void;
18
- updateProperties({ room }: {
19
- room: any;
20
- }): void;
21
- reconnect(listeners?: (data: any) => void): Promise<void>;
22
18
  }
23
19
  declare class UpdateMapStandaloneService extends UpdateMapService {
24
20
  protected context: Context;
package/package.json CHANGED
@@ -1,12 +1,16 @@
1
1
  {
2
2
  "name": "@rpgjs/client",
3
- "version": "5.0.0-alpha.10",
3
+ "version": "5.0.0-alpha.3",
4
4
  "description": "RPGJS is a framework for creating RPG/MMORPG games",
5
5
  "main": "dist/index.js",
6
6
  "types": "./dist/index.d.ts",
7
7
  "publishConfig": {
8
8
  "access": "public"
9
9
  },
10
+ "scripts": {
11
+ "dev": "vite build --watch",
12
+ "build": "vite build"
13
+ },
10
14
  "keywords": [
11
15
  "rpg",
12
16
  "game",
@@ -16,27 +20,21 @@
16
20
  ],
17
21
  "author": "Samuel Ronce",
18
22
  "license": "MIT",
19
- "peerDependencies": {
20
- "@canvasengine/presets": "*",
21
- "canvasengine": "*",
22
- "pixi.js": "^8.9.2"
23
- },
24
23
  "dependencies": {
25
- "@rpgjs/common": "5.0.0-alpha.10",
24
+ "@canvasengine/presets": "2.0.0-beta.22",
25
+ "@rpgjs/common": "workspace:*",
26
26
  "@signe/di": "^2.3.3",
27
27
  "@signe/room": "^2.3.3",
28
28
  "@signe/sync": "^2.3.3",
29
+ "canvasengine": "2.0.0-beta.22",
30
+ "pixi.js": "^8.10.1",
29
31
  "rxjs": "^7.8.2"
30
32
  },
31
33
  "devDependencies": {
32
- "@canvasengine/compiler": "2.0.0-beta.22",
34
+ "@canvasengine/compiler": "2.0.0-beta.21",
33
35
  "vite": "^6.2.5",
34
36
  "vite-plugin-dts": "^4.5.3",
35
37
  "vitest": "^3.1.1"
36
38
  },
37
- "type": "module",
38
- "scripts": {
39
- "dev": "vite build --watch",
40
- "build": "vite build"
41
- }
42
- }
39
+ "type": "module"
40
+ }
@@ -1,10 +1,10 @@
1
1
  import { generateUID, RpgCommonPlayer } from "@rpgjs/common";
2
2
  import { signal } from "canvasengine";
3
3
 
4
- export class AnimationManager {
4
+ export class EffectManager {
5
5
  current = signal<any[]>([]);
6
6
 
7
- displayEffect(params: any, player: RpgCommonPlayer | { x: number, y: number }) {
7
+ displayEffect(params: any, player: RpgCommonPlayer) {
8
8
  const id = generateUID();
9
9
  this.current().push({
10
10
  ...params,
@@ -1,14 +1,10 @@
1
1
  import { RpgCommonPlayer } from "@rpgjs/common";
2
2
  import { trigger, signal } from "canvasengine";
3
- import { Subscription } from "rxjs";
4
3
 
5
4
  export abstract class RpgClientObject extends RpgCommonPlayer {
6
5
  abstract type: string;
7
6
  emitParticleTrigger = trigger()
8
7
  particleName = signal('')
9
- animationCurrentIndex = signal(0)
10
- animationIsPlaying = signal(false)
11
- private animationSubscription?: Subscription
12
8
 
13
9
  flash(color: string, duration: number = 100) {
14
10
  const lastTint = this.tint()
@@ -17,69 +13,4 @@ export abstract class RpgClientObject extends RpgCommonPlayer {
17
13
  this.tint.set(lastTint)
18
14
  }, duration)
19
15
  }
20
-
21
- /**
22
- * Reset animation state when animation changes externally
23
- *
24
- * This method should be called when the animation changes due to movement
25
- * or other external factors to ensure the animation system doesn't get stuck
26
- *
27
- * @example
28
- * ```ts
29
- * // Reset when player starts moving
30
- * player.resetAnimationState();
31
- * ```
32
- */
33
- resetAnimationState() {
34
- this.animationIsPlaying.set(false);
35
- this.animationCurrentIndex.set(0);
36
- if (this.animationSubscription) {
37
- this.animationSubscription.unsubscribe();
38
- this.animationSubscription = undefined;
39
- }
40
- }
41
-
42
- /**
43
- * Set a custom animation for a specific number of times
44
- *
45
- * Plays a custom animation for the specified number of repetitions.
46
- * The animation system prevents overlapping animations and automatically
47
- * returns to the previous animation when complete.
48
- *
49
- * @param animationName - Name of the animation to play
50
- * @param nbTimes - Number of times to repeat the animation (default: Infinity for continuous)
51
- *
52
- * @example
53
- * ```ts
54
- * // Play attack animation 3 times
55
- * player.setAnimation('attack', 3);
56
- *
57
- * // Play continuous spell animation
58
- * player.setAnimation('spell');
59
- * ```
60
- */
61
- setAnimation(animationName: string, nbTimes: number = Infinity) {
62
- if (this.animationIsPlaying()) return;
63
- this.animationIsPlaying.set(true);
64
- const previousAnimationName = this.animationName();
65
- this.animationCurrentIndex.set(0);
66
-
67
- // Clean up any existing subscription
68
- if (this.animationSubscription) {
69
- this.animationSubscription.unsubscribe();
70
- }
71
-
72
- this.animationSubscription = this.animationCurrentIndex.observable.subscribe(index => {
73
- if (index >= nbTimes) {
74
- this.animationCurrentIndex.set(0);
75
- this.animationName.set(previousAnimationName);
76
- this.animationIsPlaying.set(false);
77
- if (this.animationSubscription) {
78
- this.animationSubscription.unsubscribe();
79
- this.animationSubscription = undefined;
80
- }
81
- }
82
- })
83
- this.animationName.set(animationName);
84
- }
85
16
  }