@rpgjs/client 5.0.0-alpha.2 → 5.0.0-alpha.21

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 (172) hide show
  1. package/dist/Game/AnimationManager.d.ts +8 -0
  2. package/dist/Game/Map.d.ts +7 -1
  3. package/dist/Gui/Gui.d.ts +170 -5
  4. package/dist/Resource.d.ts +97 -0
  5. package/dist/RpgClient.d.ts +259 -59
  6. package/dist/RpgClientEngine.d.ts +379 -6
  7. package/dist/Sound.d.ts +199 -0
  8. package/dist/components/animations/index.d.ts +4 -0
  9. package/dist/components/dynamics/parse-value.d.ts +1 -0
  10. package/dist/components/gui/index.d.ts +3 -3
  11. package/dist/components/index.d.ts +3 -1
  12. package/dist/components/prebuilt/index.d.ts +18 -0
  13. package/dist/index.d.ts +6 -1
  14. package/dist/index.js +11 -4
  15. package/dist/index.js.map +1 -1
  16. package/dist/index10.js +149 -4
  17. package/dist/index10.js.map +1 -1
  18. package/dist/index11.js +22 -7
  19. package/dist/index11.js.map +1 -1
  20. package/dist/index12.js +6 -4
  21. package/dist/index12.js.map +1 -1
  22. package/dist/index13.js +11 -14
  23. package/dist/index13.js.map +1 -1
  24. package/dist/index14.js +8 -40
  25. package/dist/index14.js.map +1 -1
  26. package/dist/index15.js +217 -180
  27. package/dist/index15.js.map +1 -1
  28. package/dist/index16.js +104 -7
  29. package/dist/index16.js.map +1 -1
  30. package/dist/index17.js +82 -372
  31. package/dist/index17.js.map +1 -1
  32. package/dist/index18.js +110 -27
  33. package/dist/index18.js.map +1 -1
  34. package/dist/index19.js +360 -18
  35. package/dist/index19.js.map +1 -1
  36. package/dist/index2.js +726 -32
  37. package/dist/index2.js.map +1 -1
  38. package/dist/index20.js +5 -2416
  39. package/dist/index20.js.map +1 -1
  40. package/dist/index21.js +47 -109
  41. package/dist/index21.js.map +1 -1
  42. package/dist/index22.js +7 -107
  43. package/dist/index22.js.map +1 -1
  44. package/dist/index23.js +394 -65
  45. package/dist/index23.js.map +1 -1
  46. package/dist/index24.js +40 -15
  47. package/dist/index24.js.map +1 -1
  48. package/dist/index25.js +20 -36
  49. package/dist/index25.js.map +1 -1
  50. package/dist/index26.js +2629 -1
  51. package/dist/index26.js.map +1 -1
  52. package/dist/index27.js +102 -310
  53. package/dist/index27.js.map +1 -1
  54. package/dist/index28.js +63 -17
  55. package/dist/index28.js.map +1 -1
  56. package/dist/index29.js +18 -8
  57. package/dist/index29.js.map +1 -1
  58. package/dist/index3.js +70 -8
  59. package/dist/index3.js.map +1 -1
  60. package/dist/index30.js +24 -8
  61. package/dist/index30.js.map +1 -1
  62. package/dist/index31.js +88 -167
  63. package/dist/index31.js.map +1 -1
  64. package/dist/index32.js +34 -494
  65. package/dist/index32.js.map +1 -1
  66. package/dist/index33.js +22 -10
  67. package/dist/index33.js.map +1 -1
  68. package/dist/index34.js +3 -4401
  69. package/dist/index34.js.map +1 -1
  70. package/dist/index35.js +20 -1
  71. package/dist/index35.js.map +1 -1
  72. package/dist/index36.js +18 -82
  73. package/dist/index36.js.map +1 -1
  74. package/dist/index37.js +8 -58
  75. package/dist/index37.js.map +1 -1
  76. package/dist/index38.js +4 -13
  77. package/dist/index38.js.map +1 -1
  78. package/dist/index39.js +10 -18
  79. package/dist/index39.js.map +1 -1
  80. package/dist/index4.js +25 -5
  81. package/dist/index4.js.map +1 -1
  82. package/dist/index40.js +7 -0
  83. package/dist/index40.js.map +1 -0
  84. package/dist/index41.js +3690 -0
  85. package/dist/index41.js.map +1 -0
  86. package/dist/index42.js +187 -0
  87. package/dist/index42.js.map +1 -0
  88. package/dist/index43.js +504 -0
  89. package/dist/index43.js.map +1 -0
  90. package/dist/index44.js +77 -0
  91. package/dist/index44.js.map +1 -0
  92. package/dist/index45.js +6 -0
  93. package/dist/index45.js.map +1 -0
  94. package/dist/index46.js +20 -0
  95. package/dist/index46.js.map +1 -0
  96. package/dist/index47.js +146 -0
  97. package/dist/index47.js.map +1 -0
  98. package/dist/index48.js +12 -0
  99. package/dist/index48.js.map +1 -0
  100. package/dist/index49.js +113 -0
  101. package/dist/index49.js.map +1 -0
  102. package/dist/index5.js +2 -1
  103. package/dist/index5.js.map +1 -1
  104. package/dist/index50.js +136 -0
  105. package/dist/index50.js.map +1 -0
  106. package/dist/index51.js +137 -0
  107. package/dist/index51.js.map +1 -0
  108. package/dist/index52.js +112 -0
  109. package/dist/index52.js.map +1 -0
  110. package/dist/index53.js +141 -0
  111. package/dist/index53.js.map +1 -0
  112. package/dist/index54.js +9 -0
  113. package/dist/index54.js.map +1 -0
  114. package/dist/index55.js +54 -0
  115. package/dist/index55.js.map +1 -0
  116. package/dist/index6.js +1 -1
  117. package/dist/index6.js.map +1 -1
  118. package/dist/index7.js +11 -3
  119. package/dist/index7.js.map +1 -1
  120. package/dist/index8.js +68 -7
  121. package/dist/index8.js.map +1 -1
  122. package/dist/index9.js +278 -15
  123. package/dist/index9.js.map +1 -1
  124. package/dist/presets/animation.d.ts +31 -0
  125. package/dist/presets/faceset.d.ts +30 -0
  126. package/dist/presets/index.d.ts +103 -0
  127. package/dist/presets/lpc.d.ts +89 -0
  128. package/dist/services/keyboardControls.d.ts +5 -0
  129. package/dist/services/loadMap.d.ts +123 -2
  130. package/dist/services/mmorpg.d.ts +12 -4
  131. package/dist/services/standalone.d.ts +54 -2
  132. package/package.json +22 -18
  133. package/src/Game/{EffectManager.ts → AnimationManager.ts} +3 -2
  134. package/src/Game/Map.ts +20 -2
  135. package/src/Game/Object.ts +163 -9
  136. package/src/Gui/Gui.ts +362 -17
  137. package/src/Resource.ts +150 -0
  138. package/src/RpgClient.ts +264 -58
  139. package/src/RpgClientEngine.ts +848 -36
  140. package/src/Sound.ts +253 -0
  141. package/src/components/{effects → animations}/animation.ce +3 -6
  142. package/src/components/{effects → animations}/index.ts +1 -1
  143. package/src/components/character.ce +193 -36
  144. package/src/components/dynamics/parse-value.ts +80 -0
  145. package/src/components/dynamics/text.ce +183 -0
  146. package/src/components/gui/box.ce +17 -0
  147. package/src/components/gui/dialogbox/index.ce +73 -35
  148. package/src/components/gui/dialogbox/selection.ce +16 -1
  149. package/src/components/gui/index.ts +3 -4
  150. package/src/components/index.ts +5 -1
  151. package/src/components/prebuilt/hp-bar.ce +255 -0
  152. package/src/components/prebuilt/index.ts +22 -0
  153. package/src/components/scenes/canvas.ce +12 -10
  154. package/src/components/scenes/draw-map.ce +6 -23
  155. package/src/components/scenes/event-layer.ce +9 -3
  156. package/src/core/setup.ts +2 -0
  157. package/src/index.ts +7 -2
  158. package/src/module.ts +72 -6
  159. package/src/presets/animation.ts +46 -0
  160. package/src/presets/faceset.ts +60 -0
  161. package/src/presets/index.ts +7 -1
  162. package/src/presets/lpc.ts +108 -0
  163. package/src/services/keyboardControls.ts +8 -0
  164. package/src/services/loadMap.ts +132 -3
  165. package/src/services/mmorpg.ts +29 -5
  166. package/src/services/standalone.ts +70 -6
  167. package/tsconfig.json +1 -1
  168. package/vite.config.ts +1 -1
  169. package/dist/Game/EffectManager.d.ts +0 -5
  170. package/dist/components/effects/index.d.ts +0 -4
  171. package/src/components/scenes/element-map.ce +0 -23
  172. /package/src/components/{effects → animations}/hit.ce +0 -0
@@ -0,0 +1,8 @@
1
+ import { RpgCommonPlayer } from '@rpgjs/common';
2
+ export declare class AnimationManager {
3
+ current: import('canvasengine').WritableArraySignal<any[]>;
4
+ displayEffect(params: any, player: RpgCommonPlayer | {
5
+ x: number;
6
+ y: number;
7
+ }): void;
8
+ }
@@ -1,7 +1,13 @@
1
1
  import { RpgCommonMap } from '@rpgjs/common';
2
2
  import { RpgClientPlayer } from './Player';
3
3
  import { RpgClientEvent } from './Event';
4
- export declare class RpgClientMap extends RpgCommonMap<RpgClientPlayer> {
4
+ import { RpgClientEngine } from '../RpgClientEngine';
5
+ export declare class RpgClientMap extends RpgCommonMap<any> {
6
+ engine: RpgClientEngine;
5
7
  players: import('canvasengine').WritableObjectSignal<Record<string, RpgClientPlayer>>;
6
8
  events: import('canvasengine').WritableObjectSignal<Record<string, RpgClientEvent>>;
9
+ currentPlayer: import('canvasengine').ComputedSignal<RpgClientPlayer>;
10
+ getCurrentPlayer(): RpgClientPlayer;
11
+ reset(): void;
12
+ stepPredictionTick(): void;
7
13
  }
package/dist/Gui/Gui.d.ts CHANGED
@@ -1,23 +1,188 @@
1
1
  import { Context } from '@signe/di';
2
+ import { Signal, WritableSignal } from 'canvasengine';
3
+ import { Subscription } from 'rxjs';
2
4
  interface GuiOptions {
3
- name: string;
5
+ name?: string;
6
+ id?: string;
4
7
  component: any;
5
8
  display?: boolean;
6
9
  data?: any;
10
+ /**
11
+ * Auto display the GUI when added to the system
12
+ * @default false
13
+ */
14
+ autoDisplay?: boolean;
15
+ /**
16
+ * Function that returns an array of Signal dependencies
17
+ * The GUI will only display when all dependencies are resolved (!= undefined)
18
+ * @returns Array of Signal dependencies
19
+ */
20
+ dependencies?: () => Signal[];
21
+ /**
22
+ * Attach the GUI to sprites instead of displaying globally
23
+ * When true, the GUI will be rendered in character.ce for each sprite
24
+ * @default false
25
+ */
26
+ attachToSprite?: boolean;
27
+ }
28
+ interface GuiInstance {
29
+ name: string;
30
+ component: any;
31
+ display: WritableSignal<boolean>;
32
+ data: WritableSignal<any>;
33
+ autoDisplay: boolean;
34
+ dependencies?: () => Signal[];
35
+ subscription?: Subscription;
36
+ attachToSprite?: boolean;
7
37
  }
8
38
  export declare class RpgGui {
9
39
  private context;
10
40
  private webSocket;
11
- gui: import('canvasengine').WritableArraySignal<any>;
41
+ gui: import('canvasengine').WritableObjectSignal<Record<string, GuiInstance>>;
42
+ extraGuis: GuiInstance[];
43
+ private vueGuiInstance;
44
+ /**
45
+ * Signal tracking which player IDs should display attached GUIs
46
+ * Key: player ID, Value: boolean (true = show, false = hide)
47
+ */
48
+ attachedGuiDisplayState: import('canvasengine').WritableObjectSignal<Record<string, boolean>>;
12
49
  constructor(context: Context);
13
50
  _initialize(): Promise<void>;
51
+ /**
52
+ * Set the VueGui instance reference for Vue component management
53
+ * This is called by VueGui when it's initialized
54
+ *
55
+ * @param vueGuiInstance - The VueGui instance
56
+ */
57
+ _setVueGuiInstance(vueGuiInstance: any): void;
58
+ /**
59
+ * Notify VueGui about GUI state changes
60
+ * This synchronizes the Vue component display state
61
+ *
62
+ * @param guiId - The GUI component ID
63
+ * @param display - Display state
64
+ * @param data - Component data
65
+ */
66
+ private _notifyVueGui;
67
+ /**
68
+ * Initialize Vue components in the VueGui instance
69
+ * This should be called after VueGui is mounted
70
+ */
71
+ _initializeVueComponents(): void;
14
72
  guiInteraction(guiId: string, name: string, data: any): void;
15
73
  guiClose(guiId: string, data?: any): void;
74
+ /**
75
+ * Add a GUI component to the system
76
+ *
77
+ * By default, only CanvasEngine components (.ce files) are accepted.
78
+ * Vue components should be handled by the @rpgjs/vue package.
79
+ *
80
+ * @param gui - GUI configuration options
81
+ * @param gui.name - Name or ID of the GUI component
82
+ * @param gui.id - Alternative ID if name is not provided
83
+ * @param gui.component - The component to render (must be a CanvasEngine component)
84
+ * @param gui.display - Initial display state (default: false)
85
+ * @param gui.data - Initial data for the component
86
+ * @param gui.autoDisplay - Auto display when added (default: false)
87
+ * @param gui.dependencies - Function returning Signal dependencies
88
+ * @param gui.attachToSprite - Attach GUI to sprites instead of global display (default: false)
89
+ *
90
+ * @example
91
+ * ```ts
92
+ * gui.add({
93
+ * name: 'inventory',
94
+ * component: InventoryComponent, // Must be a .ce component
95
+ * autoDisplay: true,
96
+ * dependencies: () => [playerSignal, inventorySignal]
97
+ * });
98
+ *
99
+ * // Attach to sprites
100
+ * gui.add({
101
+ * name: 'tooltip',
102
+ * component: TooltipComponent,
103
+ * attachToSprite: true
104
+ * });
105
+ * ```
106
+ */
16
107
  add(gui: GuiOptions): void;
17
- get(id: string | GuiOptions): any;
108
+ /**
109
+ * Get all attached GUI components (attachToSprite: true)
110
+ *
111
+ * Returns all GUI instances that are configured to be attached to sprites.
112
+ * These GUIs should be rendered in character.ce instead of canvas.ce.
113
+ *
114
+ * @returns Array of GUI instances with attachToSprite: true
115
+ *
116
+ * @example
117
+ * ```ts
118
+ * const attachedGuis = gui.getAttachedGuis();
119
+ * // Use in character.ce to render tooltips
120
+ * ```
121
+ */
122
+ getAttachedGuis(): GuiInstance[];
123
+ /**
124
+ * Check if a player should display attached GUIs
125
+ *
126
+ * @param playerId - The player ID to check
127
+ * @returns true if attached GUIs should be displayed for this player
128
+ */
129
+ shouldDisplayAttachedGui(playerId: string): boolean;
130
+ get(id: string): GuiInstance | undefined;
18
131
  exists(id: string): boolean;
19
- getAll(): any;
20
- display(id: string, data?: {}): void;
132
+ getAll(): Record<string, GuiInstance>;
133
+ /**
134
+ * Display a GUI component
135
+ *
136
+ * Displays the GUI immediately if no dependencies are configured,
137
+ * or waits for all dependencies to be resolved if dependencies are present.
138
+ * Automatically manages subscriptions to prevent memory leaks.
139
+ * Works with both CanvasEngine components and Vue components.
140
+ *
141
+ * @param id - The GUI component ID
142
+ * @param data - Data to pass to the component
143
+ * @param dependencies - Optional runtime dependencies (overrides config dependencies)
144
+ *
145
+ * @example
146
+ * ```ts
147
+ * // Display immediately
148
+ * gui.display('inventory', { items: [] });
149
+ *
150
+ * // Display with runtime dependencies
151
+ * gui.display('shop', { shopId: 1 }, [playerSignal, shopSignal]);
152
+ * ```
153
+ */
154
+ display(id: string, data?: {}, dependencies?: Signal[]): void;
155
+ /**
156
+ * Handle Vue component display logic
157
+ *
158
+ * @param id - GUI component ID
159
+ * @param data - Component data
160
+ * @param dependencies - Runtime dependencies
161
+ * @param guiInstance - GUI instance
162
+ */
163
+ private _handleVueComponentDisplay;
164
+ /**
165
+ * Handle CanvasEngine component display logic
166
+ *
167
+ * @param id - GUI component ID
168
+ * @param data - Component data
169
+ * @param dependencies - Runtime dependencies
170
+ * @param guiInstance - GUI instance
171
+ */
172
+ private _handleCanvasComponentDisplay;
173
+ /**
174
+ * Hide a GUI component
175
+ *
176
+ * Hides the GUI and cleans up any active subscriptions.
177
+ * Works with both CanvasEngine components and Vue components.
178
+ *
179
+ * @param id - The GUI component ID
180
+ *
181
+ * @example
182
+ * ```ts
183
+ * gui.hide('inventory');
184
+ * ```
185
+ */
21
186
  hide(id: string): void;
22
187
  }
23
188
  export {};
@@ -0,0 +1,97 @@
1
+ import { RpgClientEngine } from './RpgClientEngine';
2
+ /**
3
+ * RpgResource class
4
+ *
5
+ * Provides a unified API to access resource file links (images and sounds) in the game.
6
+ * Resources are stored as Maps of resource IDs to file paths/URLs.
7
+ *
8
+ * ## Design
9
+ *
10
+ * RpgResource acts as a facade over the engine's resource storage, providing
11
+ * easy access to resource file links. It maintains Maps that are synchronized
12
+ * with the engine's internal storage, but only stores the file paths/URLs,
13
+ * not the full resource objects.
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * import { RpgResource } from '@rpgjs/client'
18
+ *
19
+ * // Get spritesheet image link
20
+ * const imageLink = RpgResource.spritesheets.get('hero')
21
+ *
22
+ * // Get sound file link
23
+ * const soundLink = RpgResource.sounds.get('town-music')
24
+ *
25
+ * // Set a new resource link
26
+ * RpgResource.spritesheets.set('new-sprite', './assets/new-sprite.png')
27
+ * ```
28
+ */
29
+ export declare class RpgResource {
30
+ private static engine;
31
+ private static _spritesheets;
32
+ private static _sounds;
33
+ /**
34
+ * Initialize RpgResource with the engine instance
35
+ *
36
+ * This is called automatically by the engine during initialization.
37
+ * It synchronizes the resource Maps with the engine's internal storage.
38
+ *
39
+ * @param engine - The RpgClientEngine instance
40
+ */
41
+ static init(engine: RpgClientEngine): void;
42
+ /**
43
+ * Synchronize resource Maps with the engine's internal storage
44
+ *
45
+ * Extracts file links from spritesheets and sounds stored in the engine
46
+ * and updates the Maps accordingly.
47
+ *
48
+ * @private
49
+ */
50
+ private static syncResources;
51
+ /**
52
+ * Get/Set image links for spritesheets
53
+ *
54
+ * Map of spritesheet IDs to their image file paths/URLs.
55
+ * This Map is synchronized with the engine's spritesheet storage.
56
+ *
57
+ * @type {Map<string, string>}
58
+ *
59
+ * @example
60
+ * ```ts
61
+ * // Get an image link
62
+ * const imageLink = RpgResource.spritesheets.get('hero')
63
+ *
64
+ * // Set a new image link
65
+ * RpgResource.spritesheets.set('new-sprite', './assets/new-sprite.png')
66
+ *
67
+ * // Check if a spritesheet exists
68
+ * if (RpgResource.spritesheets.has('monster')) {
69
+ * const link = RpgResource.spritesheets.get('monster')
70
+ * }
71
+ * ```
72
+ */
73
+ static get spritesheets(): Map<string, string>;
74
+ /**
75
+ * Get/Set sound file links
76
+ *
77
+ * Map of sound IDs to their audio file paths/URLs.
78
+ * This Map is synchronized with the engine's sound storage.
79
+ *
80
+ * @type {Map<string, string>}
81
+ *
82
+ * @example
83
+ * ```ts
84
+ * // Get a sound link
85
+ * const soundLink = RpgResource.sounds.get('town-music')
86
+ *
87
+ * // Set a new sound link
88
+ * RpgResource.sounds.set('new-sound', './assets/new-sound.ogg')
89
+ *
90
+ * // Iterate over all sounds
91
+ * RpgResource.sounds.forEach((link, id) => {
92
+ * console.log(`Sound ${id}: ${link}`)
93
+ * })
94
+ * ```
95
+ */
96
+ static get sounds(): Map<string, string>;
97
+ }