@rpgjs/client 5.0.0-beta.7 → 5.0.0-beta.8

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 (73) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/Game/Map.js +2 -1
  3. package/dist/Game/Map.js.map +1 -1
  4. package/dist/Game/Object.d.ts +17 -9
  5. package/dist/Game/Object.js +1 -12
  6. package/dist/Game/Object.js.map +1 -1
  7. package/dist/Gui/Gui.d.ts +17 -4
  8. package/dist/Gui/Gui.js +63 -33
  9. package/dist/Gui/Gui.js.map +1 -1
  10. package/dist/Gui/Gui.spec.d.ts +1 -0
  11. package/dist/Resource.js +1 -1
  12. package/dist/Resource.js.map +1 -1
  13. package/dist/RpgClient.d.ts +35 -2
  14. package/dist/RpgClientEngine.d.ts +41 -5
  15. package/dist/RpgClientEngine.js +43 -3
  16. package/dist/RpgClientEngine.js.map +1 -1
  17. package/dist/components/character.ce.js +225 -2
  18. package/dist/components/character.ce.js.map +1 -1
  19. package/dist/components/dynamics/bar.ce.js +96 -0
  20. package/dist/components/dynamics/bar.ce.js.map +1 -0
  21. package/dist/components/dynamics/image.ce.js +23 -0
  22. package/dist/components/dynamics/image.ce.js.map +1 -0
  23. package/dist/components/dynamics/parse-value.d.ts +3 -0
  24. package/dist/components/dynamics/parse-value.js +51 -35
  25. package/dist/components/dynamics/parse-value.js.map +1 -1
  26. package/dist/components/dynamics/parse-value.spec.d.ts +1 -0
  27. package/dist/components/dynamics/shape-utils.d.ts +16 -0
  28. package/dist/components/dynamics/shape-utils.js +73 -0
  29. package/dist/components/dynamics/shape-utils.js.map +1 -0
  30. package/dist/components/dynamics/shape-utils.spec.d.ts +1 -0
  31. package/dist/components/dynamics/shape.ce.js +83 -0
  32. package/dist/components/dynamics/shape.ce.js.map +1 -0
  33. package/dist/components/dynamics/text.ce.js +28 -41
  34. package/dist/components/dynamics/text.ce.js.map +1 -1
  35. package/dist/components/player-components-utils.d.ts +67 -0
  36. package/dist/components/player-components-utils.js +162 -0
  37. package/dist/components/player-components-utils.js.map +1 -0
  38. package/dist/components/player-components-utils.spec.d.ts +1 -0
  39. package/dist/components/player-components.ce.js +188 -0
  40. package/dist/components/player-components.ce.js.map +1 -0
  41. package/dist/core/setup.js.map +1 -1
  42. package/dist/module.js +3 -0
  43. package/dist/module.js.map +1 -1
  44. package/dist/node_modules/.pnpm/@signe_reactive@2.10.0/node_modules/@signe/reactive/dist/index.js +197 -3
  45. package/dist/node_modules/.pnpm/@signe_reactive@2.10.0/node_modules/@signe/reactive/dist/index.js.map +1 -1
  46. package/dist/node_modules/.pnpm/@signe_room@2.10.0/node_modules/@signe/room/dist/index.js +1 -1
  47. package/dist/services/loadMap.d.ts +6 -0
  48. package/dist/services/loadMap.js.map +1 -1
  49. package/package.json +4 -4
  50. package/src/Game/Map.ts +12 -2
  51. package/src/Game/Object.ts +22 -35
  52. package/src/Gui/Gui.spec.ts +273 -0
  53. package/src/Gui/Gui.ts +105 -50
  54. package/src/Resource.ts +1 -2
  55. package/src/RpgClient.ts +36 -2
  56. package/src/RpgClientEngine.ts +64 -10
  57. package/src/components/character.ce +281 -1
  58. package/src/components/dynamics/bar.ce +87 -0
  59. package/src/components/dynamics/image.ce +20 -0
  60. package/src/components/dynamics/parse-value.spec.ts +41 -0
  61. package/src/components/dynamics/parse-value.ts +102 -37
  62. package/src/components/dynamics/shape-utils.spec.ts +46 -0
  63. package/src/components/dynamics/shape-utils.ts +61 -0
  64. package/src/components/dynamics/shape.ce +89 -0
  65. package/src/components/dynamics/text.ce +34 -149
  66. package/src/components/player-components-utils.spec.ts +109 -0
  67. package/src/components/player-components-utils.ts +205 -0
  68. package/src/components/player-components.ce +221 -0
  69. package/src/core/setup.ts +2 -2
  70. package/src/module.ts +5 -1
  71. package/src/services/loadMap.ts +2 -0
  72. package/dist/node_modules/.pnpm/@signe_reactive@2.9.2/node_modules/@signe/reactive/dist/index.js +0 -227
  73. package/dist/node_modules/.pnpm/@signe_reactive@2.9.2/node_modules/@signe/reactive/dist/index.js.map +0 -1
@@ -5,6 +5,12 @@ import { RpgClientObject } from './Game/Object';
5
5
  import { MapPhysicsEntityContext, MapPhysicsInitContext } from '@rpgjs/common';
6
6
  type RpgComponent = RpgClientObject;
7
7
  type SceneMap = Container;
8
+ export type SpriteComponentConfig = ComponentFunction | {
9
+ component: ComponentFunction;
10
+ props?: Record<string, any> | ((object: RpgClientObject) => Record<string, any>);
11
+ data?: Record<string, any> | ((object: RpgClientObject) => Record<string, any>);
12
+ dependencies?: (object: RpgClientObject) => any[];
13
+ };
8
14
  export interface RpgSpriteBeforeRemoveContext {
9
15
  reason?: string;
10
16
  data?: any;
@@ -85,7 +91,7 @@ export interface RpgSpriteHooks {
85
91
  * }
86
92
  * ```
87
93
  */
88
- componentsBehind?: ComponentFunction[];
94
+ componentsBehind?: SpriteComponentConfig[];
89
95
  /**
90
96
  * Array of components to render in front of the sprite
91
97
  * These components will be displayed with a higher z-index than the sprite itself
@@ -99,7 +105,27 @@ export interface RpgSpriteHooks {
99
105
  * }
100
106
  * ```
101
107
  */
102
- componentsInFront?: ComponentFunction[];
108
+ componentsInFront?: SpriteComponentConfig[];
109
+ /**
110
+ * Reusable sprite components addressable by server-side component definitions.
111
+ *
112
+ * The server sends only the component id and serializable props. The client
113
+ * registry maps that id to the CanvasEngine component that renders it.
114
+ *
115
+ * @prop {Record<string, ComponentFunction>} [components]
116
+ * @memberof RpgSpriteHooks
117
+ * @example
118
+ * ```ts
119
+ * import GuildBadge from './components/guild-badge.ce'
120
+ *
121
+ * const sprite: RpgSpriteHooks = {
122
+ * components: {
123
+ * guildBadge: GuildBadge
124
+ * }
125
+ * }
126
+ * ```
127
+ */
128
+ components?: Record<string, ComponentFunction>;
103
129
  /**
104
130
  * As soon as the sprite is initialized
105
131
  *
@@ -479,6 +505,13 @@ export interface RpgClient {
479
505
  * ```
480
506
  */
481
507
  attachToSprite?: boolean;
508
+ /**
509
+ * Vue v4 compatibility alias for `attachToSprite`.
510
+ *
511
+ * Prefer `attachToSprite` in v5 projects. This is read by `@rpgjs/vue`
512
+ * for Vue GUI components migrated from the v4 GUI API.
513
+ */
514
+ rpgAttachToSprite?: boolean;
482
515
  } | any)[];
483
516
  /**
484
517
  * Array containing the list of sounds
@@ -1,9 +1,19 @@
1
+ import { Trigger } from 'canvasengine';
1
2
  import { AbstractWebsocket } from './services/AbstractSocket';
2
3
  import { Direction } from '@rpgjs/common';
3
4
  import { RpgClientMap } from './Game/Map';
4
5
  import { AnimationManager } from './Game/AnimationManager';
5
6
  import { Observable } from 'rxjs';
6
7
  import * as PIXI from "pixi.js";
8
+ type ConfigurableTrigger<T> = Omit<Trigger<T>, "start"> & {
9
+ start(config?: T): Promise<void>;
10
+ };
11
+ type MapShakeOptions = {
12
+ intensity?: number;
13
+ duration?: number;
14
+ frequency?: number;
15
+ direction?: string;
16
+ };
7
17
  export declare class RpgClientEngine<T = any> {
8
18
  context: any;
9
19
  private guiService;
@@ -17,7 +27,7 @@ export declare class RpgClientEngine<T = any> {
17
27
  stopProcessingInput: boolean;
18
28
  width: any;
19
29
  height: any;
20
- spritesheets: Map<string, any>;
30
+ spritesheets: Map<string | number, any>;
21
31
  sounds: Map<string, any>;
22
32
  componentAnimations: any[];
23
33
  private spritesheetResolver?;
@@ -32,10 +42,11 @@ export declare class RpgClientEngine<T = any> {
32
42
  playerIdSignal: any;
33
43
  spriteComponentsBehind: any;
34
44
  spriteComponentsInFront: any;
45
+ spriteComponents: Map<string, any>;
35
46
  /** ID of the sprite that the camera should follow. null means follow the current player */
36
47
  cameraFollowTargetId: any;
37
48
  /** Trigger for map shake animation */
38
- mapShakeTrigger: any;
49
+ mapShakeTrigger: ConfigurableTrigger<MapShakeOptions>;
39
50
  controlsReady: any;
40
51
  gamePause: any;
41
52
  private predictionEnabled;
@@ -175,7 +186,7 @@ export declare class RpgClientEngine<T = any> {
175
186
  * });
176
187
  * ```
177
188
  */
178
- setSpritesheetResolver(resolver: (id: string) => any | Promise<any>): void;
189
+ setSpritesheetResolver(resolver: (id: string | number) => any | Promise<any>): void;
179
190
  /**
180
191
  * Get a spritesheet by ID, using resolver if not found in cache
181
192
  *
@@ -183,7 +194,7 @@ export declare class RpgClientEngine<T = any> {
183
194
  * If not found and a resolver is set, it calls the resolver to create the spritesheet.
184
195
  * The resolved spritesheet is automatically cached for future use.
185
196
  *
186
- * @param id - The spritesheet ID to retrieve
197
+ * @param id - The spritesheet ID or legacy tile ID to retrieve
187
198
  * @returns The spritesheet if found or created, or undefined if not found and no resolver
188
199
  * @returns Promise<any> if the resolver is asynchronous
189
200
  *
@@ -196,7 +207,7 @@ export declare class RpgClientEngine<T = any> {
196
207
  * const spritesheet = await engine.getSpriteSheet('dynamic-sprite');
197
208
  * ```
198
209
  */
199
- getSpriteSheet(id: string): any | Promise<any>;
210
+ getSpriteSheet(id: string | number): any | Promise<any>;
200
211
  /**
201
212
  * Add a sound to the engine
202
213
  *
@@ -451,6 +462,30 @@ export declare class RpgClientEngine<T = any> {
451
462
  props: (object: any) => any;
452
463
  dependencies?: (object: any) => any[];
453
464
  }): any;
465
+ /**
466
+ * Register a reusable sprite component that can be addressed by the server.
467
+ *
468
+ * Server-side component definitions only carry the component id and
469
+ * serializable props. The client registry maps that id to the CanvasEngine
470
+ * component that performs the actual rendering.
471
+ *
472
+ * @param id - Stable component id used by server component definitions
473
+ * @param component - CanvasEngine component to render for this id
474
+ * @returns The registered component
475
+ *
476
+ * @example
477
+ * ```ts
478
+ * engine.registerSpriteComponent('guildBadge', GuildBadgeComponent);
479
+ * ```
480
+ */
481
+ registerSpriteComponent(id: string, component: any): any;
482
+ /**
483
+ * Get a reusable sprite component by id.
484
+ *
485
+ * @param id - Component id registered on the client
486
+ * @returns The CanvasEngine component, or undefined when missing
487
+ */
488
+ getSpriteComponent(id: string): any;
454
489
  /**
455
490
  * Add a component animation to the engine
456
491
  *
@@ -700,3 +735,4 @@ export declare class RpgClientEngine<T = any> {
700
735
  */
701
736
  clear(): void;
702
737
  }
738
+ export {};
@@ -11,6 +11,10 @@ import { RpgClientMap } from "./Game/Map.js";
11
11
  import { AnimationManager } from "./Game/AnimationManager.js";
12
12
  import { GlobalConfigToken } from "./module.js";
13
13
  import { PrebuiltComponentAnimations } from "./components/animations/index.js";
14
+ import __ce_component$1 from "./components/dynamics/text.ce.js";
15
+ import __ce_component$2 from "./components/dynamics/bar.ce.js";
16
+ import __ce_component$3 from "./components/dynamics/shape.ce.js";
17
+ import __ce_component$4 from "./components/dynamics/image.ce.js";
14
18
  import { NotificationManager } from "./Gui/NotificationManager.js";
15
19
  import { Howl, bootstrapCanvas, signal, trigger } from "canvasengine";
16
20
  import { Direction, ModulesToken, PredictionController } from "@rpgjs/common";
@@ -30,6 +34,7 @@ var RpgClientEngine = class {
30
34
  this.playerIdSignal = signal(null);
31
35
  this.spriteComponentsBehind = signal([]);
32
36
  this.spriteComponentsInFront = signal([]);
37
+ this.spriteComponents = /* @__PURE__ */ new Map();
33
38
  this.cameraFollowTargetId = signal(null);
34
39
  this.mapShakeTrigger = trigger();
35
40
  this.controlsReady = signal(void 0);
@@ -72,6 +77,12 @@ var RpgClientEngine = class {
72
77
  id: "animation",
73
78
  component: PrebuiltComponentAnimations.Animation
74
79
  });
80
+ this.registerSpriteComponent("rpg:text", __ce_component$1);
81
+ this.registerSpriteComponent("rpg:hpBar", __ce_component$2);
82
+ this.registerSpriteComponent("rpg:spBar", __ce_component$2);
83
+ this.registerSpriteComponent("rpg:bar", __ce_component$2);
84
+ this.registerSpriteComponent("rpg:shape", __ce_component$3);
85
+ this.registerSpriteComponent("rpg:image", __ce_component$4);
75
86
  this.predictionEnabled = this.globalConfig?.prediction?.enabled !== false;
76
87
  this.initializePredictionController();
77
88
  }
@@ -163,7 +174,7 @@ var RpgClientEngine = class {
163
174
  });
164
175
  this.tickSubscriptions.push(tickSubscription);
165
176
  await this.webSocket.connection(() => {
166
- inject(SaveClientService).initialize(this.webSocket);
177
+ inject(SaveClientService).initialize();
167
178
  this.initListeners();
168
179
  this.guiService._initialize();
169
180
  this.startPingPong();
@@ -409,7 +420,7 @@ var RpgClientEngine = class {
409
420
  query: transferToken ? { transferToken } : void 0
410
421
  });
411
422
  await this.webSocket.reconnect(() => {
412
- inject(SaveClientService).initialize(this.webSocket);
423
+ inject(SaveClientService).initialize();
413
424
  this.initListeners();
414
425
  this.guiService._initialize();
415
426
  });
@@ -464,7 +475,7 @@ var RpgClientEngine = class {
464
475
  * If not found and a resolver is set, it calls the resolver to create the spritesheet.
465
476
  * The resolved spritesheet is automatically cached for future use.
466
477
  *
467
- * @param id - The spritesheet ID to retrieve
478
+ * @param id - The spritesheet ID or legacy tile ID to retrieve
468
479
  * @returns The spritesheet if found or created, or undefined if not found and no resolver
469
480
  * @returns Promise<any> if the resolver is asynchronous
470
481
  *
@@ -813,6 +824,35 @@ var RpgClientEngine = class {
813
824
  return component;
814
825
  }
815
826
  /**
827
+ * Register a reusable sprite component that can be addressed by the server.
828
+ *
829
+ * Server-side component definitions only carry the component id and
830
+ * serializable props. The client registry maps that id to the CanvasEngine
831
+ * component that performs the actual rendering.
832
+ *
833
+ * @param id - Stable component id used by server component definitions
834
+ * @param component - CanvasEngine component to render for this id
835
+ * @returns The registered component
836
+ *
837
+ * @example
838
+ * ```ts
839
+ * engine.registerSpriteComponent('guildBadge', GuildBadgeComponent);
840
+ * ```
841
+ */
842
+ registerSpriteComponent(id, component) {
843
+ this.spriteComponents.set(id, component);
844
+ return component;
845
+ }
846
+ /**
847
+ * Get a reusable sprite component by id.
848
+ *
849
+ * @param id - Component id registered on the client
850
+ * @returns The CanvasEngine component, or undefined when missing
851
+ */
852
+ getSpriteComponent(id) {
853
+ return this.spriteComponents.get(id);
854
+ }
855
+ /**
816
856
  * Add a component animation to the engine
817
857
  *
818
858
  * Component animations are temporary visual effects that can be displayed