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

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 (275) hide show
  1. package/dist/Game/AnimationManager.d.ts +8 -0
  2. package/dist/{index19.js → Game/AnimationManager.js} +4 -3
  3. package/dist/Game/AnimationManager.js.map +1 -0
  4. package/dist/{index30.js → Game/Event.js} +2 -2
  5. package/dist/Game/Event.js.map +1 -0
  6. package/dist/Game/Map.d.ts +8 -1
  7. package/dist/Game/Map.js +54 -0
  8. package/dist/Game/Map.js.map +1 -0
  9. package/dist/Game/Object.d.ts +129 -0
  10. package/dist/Game/Object.js +218 -0
  11. package/dist/Game/Object.js.map +1 -0
  12. package/dist/{index29.js → Game/Player.js} +2 -2
  13. package/dist/Game/Player.js.map +1 -0
  14. package/dist/Gui/Gui.d.ts +177 -5
  15. package/dist/Gui/Gui.js +478 -0
  16. package/dist/Gui/Gui.js.map +1 -0
  17. package/dist/Gui/NotificationManager.d.ts +23 -0
  18. package/dist/Gui/NotificationManager.js +51 -0
  19. package/dist/Gui/NotificationManager.js.map +1 -0
  20. package/dist/Resource.d.ts +97 -0
  21. package/dist/Resource.js +114 -0
  22. package/dist/Resource.js.map +1 -0
  23. package/dist/RpgClient.d.ts +259 -59
  24. package/dist/RpgClientEngine.d.ts +632 -9
  25. package/dist/RpgClientEngine.js +1262 -0
  26. package/dist/RpgClientEngine.js.map +1 -0
  27. package/dist/Sound.d.ts +199 -0
  28. package/dist/Sound.js +97 -0
  29. package/dist/Sound.js.map +1 -0
  30. package/dist/components/animations/animation.ce.js +21 -0
  31. package/dist/components/animations/animation.ce.js.map +1 -0
  32. package/dist/{index23.js → components/animations/hit.ce.js} +3 -3
  33. package/dist/components/animations/hit.ce.js.map +1 -0
  34. package/dist/components/animations/index.d.ts +4 -0
  35. package/dist/components/animations/index.js +10 -0
  36. package/dist/components/animations/index.js.map +1 -0
  37. package/dist/components/character.ce.js +316 -0
  38. package/dist/components/character.ce.js.map +1 -0
  39. package/dist/components/dynamics/parse-value.d.ts +1 -0
  40. package/dist/components/dynamics/parse-value.js +54 -0
  41. package/dist/components/dynamics/parse-value.js.map +1 -0
  42. package/dist/components/dynamics/text.ce.js +141 -0
  43. package/dist/components/dynamics/text.ce.js.map +1 -0
  44. package/dist/components/gui/box.ce.js +27 -0
  45. package/dist/components/gui/box.ce.js.map +1 -0
  46. package/dist/components/gui/dialogbox/index.ce.js +152 -0
  47. package/dist/components/gui/dialogbox/index.ce.js.map +1 -0
  48. package/dist/components/gui/gameover.ce.js +141 -0
  49. package/dist/components/gui/gameover.ce.js.map +1 -0
  50. package/dist/components/gui/hud/hud.ce.js +35 -0
  51. package/dist/components/gui/hud/hud.ce.js.map +1 -0
  52. package/dist/components/gui/index.d.ts +15 -3
  53. package/dist/components/gui/menu/equip-menu.ce.js +349 -0
  54. package/dist/components/gui/menu/equip-menu.ce.js.map +1 -0
  55. package/dist/components/gui/menu/exit-menu.ce.js +35 -0
  56. package/dist/components/gui/menu/exit-menu.ce.js.map +1 -0
  57. package/dist/components/gui/menu/items-menu.ce.js +229 -0
  58. package/dist/components/gui/menu/items-menu.ce.js.map +1 -0
  59. package/dist/components/gui/menu/main-menu.ce.js +205 -0
  60. package/dist/components/gui/menu/main-menu.ce.js.map +1 -0
  61. package/dist/components/gui/menu/options-menu.ce.js +28 -0
  62. package/dist/components/gui/menu/options-menu.ce.js.map +1 -0
  63. package/dist/components/gui/menu/skills-menu.ce.js +53 -0
  64. package/dist/components/gui/menu/skills-menu.ce.js.map +1 -0
  65. package/dist/components/gui/mobile/index.d.ts +8 -0
  66. package/dist/components/gui/mobile/index.js +24 -0
  67. package/dist/components/gui/mobile/index.js.map +1 -0
  68. package/dist/components/gui/mobile/mobile.ce.js +17 -0
  69. package/dist/components/gui/mobile/mobile.ce.js.map +1 -0
  70. package/dist/components/gui/notification/notification.ce.js +38 -0
  71. package/dist/components/gui/notification/notification.ce.js.map +1 -0
  72. package/dist/components/gui/save-load.ce.js +242 -0
  73. package/dist/components/gui/save-load.ce.js.map +1 -0
  74. package/dist/components/gui/shop/shop.ce.js +322 -0
  75. package/dist/components/gui/shop/shop.ce.js.map +1 -0
  76. package/dist/components/gui/title-screen.ce.js +148 -0
  77. package/dist/components/gui/title-screen.ce.js.map +1 -0
  78. package/dist/components/index.d.ts +3 -1
  79. package/dist/components/prebuilt/hp-bar.ce.js +106 -0
  80. package/dist/components/prebuilt/hp-bar.ce.js.map +1 -0
  81. package/dist/components/prebuilt/index.d.ts +19 -0
  82. package/dist/components/prebuilt/light-halo.ce.js +76 -0
  83. package/dist/components/prebuilt/light-halo.ce.js.map +1 -0
  84. package/dist/components/scenes/canvas.ce.js +44 -0
  85. package/dist/components/scenes/canvas.ce.js.map +1 -0
  86. package/dist/components/scenes/draw-map.ce.js +34 -0
  87. package/dist/components/scenes/draw-map.ce.js.map +1 -0
  88. package/dist/{index13.js → components/scenes/event-layer.ce.js} +7 -6
  89. package/dist/components/scenes/event-layer.ce.js.map +1 -0
  90. package/dist/{index6.js → core/inject.js} +2 -2
  91. package/dist/core/inject.js.map +1 -0
  92. package/dist/core/setup.js +16 -0
  93. package/dist/core/setup.js.map +1 -0
  94. package/dist/index.d.ts +15 -1
  95. package/dist/index.js +40 -12
  96. package/dist/index.js.map +1 -1
  97. package/dist/module.d.ts +43 -4
  98. package/dist/module.js +175 -0
  99. package/dist/module.js.map +1 -0
  100. package/dist/node_modules/.pnpm/@signe_di@2.8.2/node_modules/@signe/di/dist/index.js +366 -0
  101. package/dist/node_modules/.pnpm/@signe_di@2.8.2/node_modules/@signe/di/dist/index.js.map +1 -0
  102. package/dist/{index27.js → node_modules/.pnpm/@signe_reactive@2.8.2/node_modules/@signe/reactive/dist/index.js} +229 -11
  103. package/dist/node_modules/.pnpm/@signe_reactive@2.8.2/node_modules/@signe/reactive/dist/index.js.map +1 -0
  104. package/dist/{index20.js → node_modules/.pnpm/@signe_room@2.8.2/node_modules/@signe/room/dist/index.js} +308 -40
  105. package/dist/node_modules/.pnpm/@signe_room@2.8.2/node_modules/@signe/room/dist/index.js.map +1 -0
  106. package/dist/{index26.js → node_modules/.pnpm/@signe_sync@2.8.2/node_modules/@signe/sync/dist/chunk-7QVYU63E.js} +1 -1
  107. package/dist/node_modules/.pnpm/@signe_sync@2.8.2/node_modules/@signe/sync/dist/chunk-7QVYU63E.js.map +1 -0
  108. package/dist/{index21.js → node_modules/.pnpm/@signe_sync@2.8.2/node_modules/@signe/sync/dist/client/index.js} +5 -5
  109. package/dist/node_modules/.pnpm/@signe_sync@2.8.2/node_modules/@signe/sync/dist/client/index.js.map +1 -0
  110. package/dist/{index17.js → node_modules/.pnpm/@signe_sync@2.8.2/node_modules/@signe/sync/dist/index.js} +89 -12
  111. package/dist/node_modules/.pnpm/@signe_sync@2.8.2/node_modules/@signe/sync/dist/index.js.map +1 -0
  112. package/dist/{index33.js → node_modules/.pnpm/dset@3.1.4/node_modules/dset/dist/index.js} +1 -1
  113. package/dist/node_modules/.pnpm/dset@3.1.4/node_modules/dset/dist/index.js.map +1 -0
  114. package/dist/{index31.js → node_modules/.pnpm/partysocket@1.1.3/node_modules/partysocket/dist/chunk-HAC622V3.js} +2 -2
  115. package/dist/node_modules/.pnpm/partysocket@1.1.3/node_modules/partysocket/dist/chunk-HAC622V3.js.map +1 -0
  116. package/dist/{index32.js → node_modules/.pnpm/partysocket@1.1.3/node_modules/partysocket/dist/chunk-S74YV6PU.js} +1 -1
  117. package/dist/node_modules/.pnpm/partysocket@1.1.3/node_modules/partysocket/dist/chunk-S74YV6PU.js.map +1 -0
  118. package/dist/{index34.js → node_modules/.pnpm/zod@3.24.2/node_modules/zod/lib/index.js} +1 -1
  119. package/dist/node_modules/.pnpm/zod@3.24.2/node_modules/zod/lib/index.js.map +1 -0
  120. package/dist/presets/animation.d.ts +31 -0
  121. package/dist/presets/animation.js +27 -0
  122. package/dist/presets/animation.js.map +1 -0
  123. package/dist/presets/faceset.d.ts +30 -0
  124. package/dist/presets/faceset.js +24 -0
  125. package/dist/presets/faceset.js.map +1 -0
  126. package/dist/presets/icon.d.ts +20 -0
  127. package/dist/presets/icon.js +15 -0
  128. package/dist/presets/icon.js.map +1 -0
  129. package/dist/presets/index.d.ts +123 -0
  130. package/dist/presets/index.js +16 -0
  131. package/dist/presets/index.js.map +1 -0
  132. package/dist/presets/lpc.d.ts +89 -0
  133. package/dist/presets/lpc.js +95 -0
  134. package/dist/presets/lpc.js.map +1 -0
  135. package/dist/{index25.js → presets/rmspritesheet.js} +1 -1
  136. package/dist/presets/rmspritesheet.js.map +1 -0
  137. package/dist/{index16.js → services/AbstractSocket.js} +1 -1
  138. package/dist/services/AbstractSocket.js.map +1 -0
  139. package/dist/services/keyboardControls.d.ts +15 -0
  140. package/dist/services/keyboardControls.js +21 -0
  141. package/dist/services/keyboardControls.js.map +1 -0
  142. package/dist/services/loadMap.d.ts +123 -2
  143. package/dist/{index7.js → services/loadMap.js} +12 -4
  144. package/dist/services/loadMap.js.map +1 -0
  145. package/dist/services/mmorpg.d.ts +16 -4
  146. package/dist/services/mmorpg.js +84 -0
  147. package/dist/services/mmorpg.js.map +1 -0
  148. package/dist/services/save.d.ts +19 -0
  149. package/dist/services/save.js +69 -0
  150. package/dist/services/save.js.map +1 -0
  151. package/dist/services/standalone.d.ts +65 -3
  152. package/dist/services/standalone.js +170 -0
  153. package/dist/services/standalone.js.map +1 -0
  154. package/dist/utils/getEntityProp.d.ts +39 -0
  155. package/dist/utils/getEntityProp.js +54 -0
  156. package/dist/utils/getEntityProp.js.map +1 -0
  157. package/package.json +24 -18
  158. package/src/Game/{EffectManager.ts → AnimationManager.ts} +3 -2
  159. package/src/Game/Map.ts +37 -2
  160. package/src/Game/Object.ts +296 -11
  161. package/src/Gui/Gui.ts +506 -18
  162. package/src/Gui/NotificationManager.ts +69 -0
  163. package/src/Resource.ts +150 -0
  164. package/src/RpgClient.ts +264 -58
  165. package/src/RpgClientEngine.ts +1421 -44
  166. package/src/Sound.ts +253 -0
  167. package/src/components/{effects → animations}/animation.ce +3 -6
  168. package/src/components/{effects → animations}/index.ts +1 -1
  169. package/src/components/character.ce +406 -40
  170. package/src/components/dynamics/parse-value.ts +80 -0
  171. package/src/components/dynamics/text.ce +183 -0
  172. package/src/components/gui/box.ce +17 -0
  173. package/src/components/gui/dialogbox/index.ce +204 -187
  174. package/src/components/gui/gameover.ce +158 -0
  175. package/src/components/gui/hud/hud.ce +56 -0
  176. package/src/components/gui/index.ts +30 -4
  177. package/src/components/gui/menu/equip-menu.ce +410 -0
  178. package/src/components/gui/menu/exit-menu.ce +41 -0
  179. package/src/components/gui/menu/items-menu.ce +317 -0
  180. package/src/components/gui/menu/main-menu.ce +291 -0
  181. package/src/components/gui/menu/options-menu.ce +35 -0
  182. package/src/components/gui/menu/skills-menu.ce +83 -0
  183. package/src/components/gui/mobile/index.ts +24 -0
  184. package/src/components/gui/mobile/mobile.ce +80 -0
  185. package/src/components/gui/notification/notification.ce +51 -0
  186. package/src/components/gui/save-load.ce +208 -0
  187. package/src/components/gui/shop/shop.ce +493 -0
  188. package/src/components/gui/title-screen.ce +163 -0
  189. package/src/components/index.ts +5 -1
  190. package/src/components/prebuilt/hp-bar.ce +255 -0
  191. package/src/components/prebuilt/index.ts +24 -0
  192. package/src/components/prebuilt/light-halo.ce +148 -0
  193. package/src/components/scenes/canvas.ce +19 -14
  194. package/src/components/scenes/draw-map.ce +21 -29
  195. package/src/components/scenes/event-layer.ce +10 -3
  196. package/src/components/scenes/transition.ce +60 -0
  197. package/src/core/setup.ts +2 -0
  198. package/src/index.ts +16 -2
  199. package/src/module.ts +145 -9
  200. package/src/presets/animation.ts +46 -0
  201. package/src/presets/faceset.ts +60 -0
  202. package/src/presets/icon.ts +17 -0
  203. package/src/presets/index.ts +9 -1
  204. package/src/presets/lpc.ts +108 -0
  205. package/src/services/keyboardControls.ts +20 -0
  206. package/src/services/loadMap.ts +132 -3
  207. package/src/services/mmorpg.ts +39 -5
  208. package/src/services/save.ts +103 -0
  209. package/src/services/standalone.ts +107 -15
  210. package/src/utils/getEntityProp.ts +87 -0
  211. package/tsconfig.json +1 -1
  212. package/vite.config.ts +5 -3
  213. package/CHANGELOG.md +0 -9
  214. package/dist/Game/EffectManager.d.ts +0 -5
  215. package/dist/components/effects/index.d.ts +0 -4
  216. package/dist/index10.js +0 -8
  217. package/dist/index10.js.map +0 -1
  218. package/dist/index11.js +0 -10
  219. package/dist/index11.js.map +0 -1
  220. package/dist/index12.js +0 -8
  221. package/dist/index12.js.map +0 -1
  222. package/dist/index13.js.map +0 -1
  223. package/dist/index14.js +0 -50
  224. package/dist/index14.js.map +0 -1
  225. package/dist/index15.js +0 -191
  226. package/dist/index15.js.map +0 -1
  227. package/dist/index16.js.map +0 -1
  228. package/dist/index17.js.map +0 -1
  229. package/dist/index18.js +0 -31
  230. package/dist/index18.js.map +0 -1
  231. package/dist/index19.js.map +0 -1
  232. package/dist/index2.js +0 -112
  233. package/dist/index2.js.map +0 -1
  234. package/dist/index20.js.map +0 -1
  235. package/dist/index21.js.map +0 -1
  236. package/dist/index22.js +0 -109
  237. package/dist/index22.js.map +0 -1
  238. package/dist/index23.js.map +0 -1
  239. package/dist/index24.js +0 -21
  240. package/dist/index24.js.map +0 -1
  241. package/dist/index25.js.map +0 -1
  242. package/dist/index26.js.map +0 -1
  243. package/dist/index27.js.map +0 -1
  244. package/dist/index28.js +0 -25
  245. package/dist/index28.js.map +0 -1
  246. package/dist/index29.js.map +0 -1
  247. package/dist/index3.js +0 -87
  248. package/dist/index3.js.map +0 -1
  249. package/dist/index30.js.map +0 -1
  250. package/dist/index31.js.map +0 -1
  251. package/dist/index32.js.map +0 -1
  252. package/dist/index33.js.map +0 -1
  253. package/dist/index34.js.map +0 -1
  254. package/dist/index35.js +0 -91
  255. package/dist/index35.js.map +0 -1
  256. package/dist/index36.js +0 -61
  257. package/dist/index36.js.map +0 -1
  258. package/dist/index37.js +0 -20
  259. package/dist/index37.js.map +0 -1
  260. package/dist/index38.js +0 -20
  261. package/dist/index38.js.map +0 -1
  262. package/dist/index4.js +0 -54
  263. package/dist/index4.js.map +0 -1
  264. package/dist/index5.js +0 -15
  265. package/dist/index5.js.map +0 -1
  266. package/dist/index6.js.map +0 -1
  267. package/dist/index7.js.map +0 -1
  268. package/dist/index8.js +0 -90
  269. package/dist/index8.js.map +0 -1
  270. package/dist/index9.js +0 -76
  271. package/dist/index9.js.map +0 -1
  272. package/src/components/gui/dialogbox/itemMenu.ce +0 -23
  273. package/src/components/gui/dialogbox/selection.ce +0 -67
  274. package/src/components/scenes/element-map.ce +0 -23
  275. /package/src/components/{effects → animations}/hit.ce +0 -0
package/dist/Gui/Gui.d.ts CHANGED
@@ -1,23 +1,195 @@
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;
37
+ }
38
+ interface GuiAction {
39
+ guiId: string;
40
+ name: string;
41
+ data: any;
42
+ clientActionId: string;
7
43
  }
44
+ type OptimisticReducer = (data: any, action: GuiAction) => any;
8
45
  export declare class RpgGui {
9
46
  private context;
10
47
  private webSocket;
11
- gui: import('canvasengine').WritableArraySignal<any>;
48
+ gui: import('canvasengine').WritableObjectSignal<Record<string, GuiInstance>>;
49
+ extraGuis: GuiInstance[];
50
+ private vueGuiInstance;
51
+ private optimisticReducers;
52
+ private pendingActions;
53
+ /**
54
+ * Signal tracking which player IDs should display attached GUIs
55
+ * Key: player ID, Value: boolean (true = show, false = hide)
56
+ */
57
+ attachedGuiDisplayState: import('canvasengine').WritableObjectSignal<Record<string, boolean>>;
12
58
  constructor(context: Context);
13
59
  _initialize(): Promise<void>;
60
+ /**
61
+ * Set the VueGui instance reference for Vue component management
62
+ * This is called by VueGui when it's initialized
63
+ *
64
+ * @param vueGuiInstance - The VueGui instance
65
+ */
66
+ _setVueGuiInstance(vueGuiInstance: any): void;
67
+ /**
68
+ * Notify VueGui about GUI state changes
69
+ * This synchronizes the Vue component display state
70
+ *
71
+ * @param guiId - The GUI component ID
72
+ * @param display - Display state
73
+ * @param data - Component data
74
+ */
75
+ private _notifyVueGui;
76
+ /**
77
+ * Initialize Vue components in the VueGui instance
78
+ * This should be called after VueGui is mounted
79
+ */
80
+ _initializeVueComponents(): void;
14
81
  guiInteraction(guiId: string, name: string, data: any): void;
15
82
  guiClose(guiId: string, data?: any): void;
83
+ /**
84
+ * Add a GUI component to the system
85
+ *
86
+ * By default, only CanvasEngine components (.ce files) are accepted.
87
+ * Vue components should be handled by the @rpgjs/vue package.
88
+ *
89
+ * @param gui - GUI configuration options
90
+ * @param gui.name - Name or ID of the GUI component
91
+ * @param gui.id - Alternative ID if name is not provided
92
+ * @param gui.component - The component to render (must be a CanvasEngine component)
93
+ * @param gui.display - Initial display state (default: false)
94
+ * @param gui.data - Initial data for the component
95
+ * @param gui.autoDisplay - Auto display when added (default: false)
96
+ * @param gui.dependencies - Function returning Signal dependencies
97
+ * @param gui.attachToSprite - Attach GUI to sprites instead of global display (default: false)
98
+ *
99
+ * @example
100
+ * ```ts
101
+ * gui.add({
102
+ * name: 'inventory',
103
+ * component: InventoryComponent, // Must be a .ce component
104
+ * autoDisplay: true,
105
+ * dependencies: () => [playerSignal, inventorySignal]
106
+ * });
107
+ *
108
+ * // Attach to sprites
109
+ * gui.add({
110
+ * name: 'tooltip',
111
+ * component: TooltipComponent,
112
+ * attachToSprite: true
113
+ * });
114
+ * ```
115
+ */
16
116
  add(gui: GuiOptions): void;
17
- get(id: string | GuiOptions): any;
117
+ registerOptimisticReducer(guiId: string, reducer: OptimisticReducer): void;
118
+ /**
119
+ * Get all attached GUI components (attachToSprite: true)
120
+ *
121
+ * Returns all GUI instances that are configured to be attached to sprites.
122
+ * These GUIs should be rendered in character.ce instead of canvas.ce.
123
+ *
124
+ * @returns Array of GUI instances with attachToSprite: true
125
+ *
126
+ * @example
127
+ * ```ts
128
+ * const attachedGuis = gui.getAttachedGuis();
129
+ * // Use in character.ce to render tooltips
130
+ * ```
131
+ */
132
+ getAttachedGuis(): GuiInstance[];
133
+ /**
134
+ * Check if a player should display attached GUIs
135
+ *
136
+ * @param playerId - The player ID to check
137
+ * @returns true if attached GUIs should be displayed for this player
138
+ */
139
+ shouldDisplayAttachedGui(playerId: string): boolean;
140
+ get(id: string): GuiInstance | undefined;
18
141
  exists(id: string): boolean;
19
- getAll(): any;
20
- display(id: string, data?: {}): void;
142
+ getAll(): Record<string, GuiInstance>;
143
+ /**
144
+ * Display a GUI component
145
+ *
146
+ * Displays the GUI immediately if no dependencies are configured,
147
+ * or waits for all dependencies to be resolved if dependencies are present.
148
+ * Automatically manages subscriptions to prevent memory leaks.
149
+ * Works with both CanvasEngine components and Vue components.
150
+ *
151
+ * @param id - The GUI component ID
152
+ * @param data - Data to pass to the component
153
+ * @param dependencies - Optional runtime dependencies (overrides config dependencies)
154
+ *
155
+ * @example
156
+ * ```ts
157
+ * // Display immediately
158
+ * gui.display('inventory', { items: [] });
159
+ *
160
+ * // Display with runtime dependencies
161
+ * gui.display('shop', { shopId: 1 }, [playerSignal, shopSignal]);
162
+ * ```
163
+ */
164
+ display(id: string, data?: {}, dependencies?: Signal[]): void;
165
+ isDisplaying(id: string): boolean;
166
+ /**
167
+ * Handle Vue component display logic
168
+ *
169
+ * @param id - GUI component ID
170
+ * @param data - Component data
171
+ * @param dependencies - Runtime dependencies
172
+ * @param guiInstance - GUI instance
173
+ */
174
+ private _handleVueComponentDisplay;
175
+ /**
176
+ * Hide a GUI component
177
+ *
178
+ * Hides the GUI and cleans up any active subscriptions.
179
+ * Works with both CanvasEngine components and Vue components.
180
+ *
181
+ * @param id - The GUI component ID
182
+ *
183
+ * @example
184
+ * ```ts
185
+ * gui.hide('inventory');
186
+ * ```
187
+ */
21
188
  hide(id: string): void;
189
+ private isVueComponent;
190
+ private clearPendingActions;
191
+ private applyReducers;
192
+ private applyOptimisticAction;
193
+ private applyServerUpdate;
22
194
  }
23
195
  export {};
@@ -0,0 +1,478 @@
1
+ import { inject } from '../node_modules/.pnpm/@signe_di@2.8.2/node_modules/@signe/di/dist/index.js';
2
+ import { signal } from 'canvasengine';
3
+ import { WebSocketToken } from '../services/AbstractSocket.js';
4
+ import component from '../components/gui/dialogbox/index.ce.js';
5
+ import { combineLatest } from 'rxjs';
6
+ import { PrebuiltGui } from '@rpgjs/common';
7
+ import '../Sound.js';
8
+ import '../Resource.js';
9
+ import '../node_modules/.pnpm/@signe_sync@2.8.2/node_modules/@signe/sync/dist/index.js';
10
+ import '../Game/Map.js';
11
+ import 'pixi.js';
12
+ import '../node_modules/.pnpm/@signe_room@2.8.2/node_modules/@signe/room/dist/index.js';
13
+ import '../node_modules/.pnpm/@signe_sync@2.8.2/node_modules/@signe/sync/dist/client/index.js';
14
+ import '@canvasengine/presets';
15
+ import component$2 from '../components/gui/shop/shop.ce.js';
16
+ import component$4 from '../components/gui/save-load.ce.js';
17
+ import component$1 from '../components/gui/menu/main-menu.ce.js';
18
+ import component$3 from '../components/gui/notification/notification.ce.js';
19
+ import component$5 from '../components/gui/title-screen.ce.js';
20
+ import component$6 from '../components/gui/gameover.ce.js';
21
+
22
+ const throwError = (id) => {
23
+ throw `The GUI named ${id} is non-existent. Please add the component in the gui property of the decorator @RpgClient`;
24
+ };
25
+ const updateItemQuantity = (items, id) => {
26
+ const index = items.findIndex((item2) => item2?.id === id);
27
+ if (index === -1) return items;
28
+ const item = items[index];
29
+ if (item?.usable === false) return items;
30
+ if (item?.consumable === false) return items;
31
+ const quantity = typeof item?.quantity === "number" ? item.quantity : 1;
32
+ const nextQuantity = Math.max(0, quantity - 1);
33
+ if (nextQuantity === quantity) return items;
34
+ if (nextQuantity <= 0) {
35
+ return items.filter((_, idx) => idx !== index);
36
+ }
37
+ const nextItems = items.slice();
38
+ nextItems[index] = { ...item, quantity: nextQuantity };
39
+ return nextItems;
40
+ };
41
+ const updateEquippedFlag = (items, id, equip) => {
42
+ const index = items.findIndex((item2) => item2?.id === id);
43
+ if (index === -1) return items;
44
+ const item = items[index];
45
+ if (item?.equipped === equip) return items;
46
+ const nextItems = items.slice();
47
+ nextItems[index] = { ...item, equipped: equip };
48
+ return nextItems;
49
+ };
50
+ const mainMenuOptimisticReducer = (data, action) => {
51
+ if (!data || typeof data !== "object") return data;
52
+ if (action.name === "useItem") {
53
+ if (!Array.isArray(data.items)) return data;
54
+ const id = action.data?.id;
55
+ if (!id) return data;
56
+ const nextItems = updateItemQuantity(data.items, id);
57
+ if (nextItems === data.items) return data;
58
+ return { ...data, items: nextItems };
59
+ }
60
+ if (action.name === "equipItem") {
61
+ const id = action.data?.id;
62
+ if (!id || typeof action.data?.equip !== "boolean") return data;
63
+ const equip = action.data.equip;
64
+ let nextItems = data.items;
65
+ let nextEquips = data.equips;
66
+ if (Array.isArray(data.items)) {
67
+ nextItems = updateEquippedFlag(data.items, id, equip);
68
+ }
69
+ if (Array.isArray(data.equips)) {
70
+ nextEquips = updateEquippedFlag(data.equips, id, equip);
71
+ }
72
+ if (nextItems === data.items && nextEquips === data.equips) return data;
73
+ return {
74
+ ...data,
75
+ ...nextItems !== data.items ? { items: nextItems } : {},
76
+ ...nextEquips !== data.equips ? { equips: nextEquips } : {}
77
+ };
78
+ }
79
+ return data;
80
+ };
81
+ class RpgGui {
82
+ constructor(context) {
83
+ this.context = context;
84
+ this.gui = signal({});
85
+ this.extraGuis = [];
86
+ this.vueGuiInstance = null;
87
+ // Reference to VueGui instance
88
+ this.optimisticReducers = /* @__PURE__ */ new Map();
89
+ this.pendingActions = /* @__PURE__ */ new Map();
90
+ /**
91
+ * Signal tracking which player IDs should display attached GUIs
92
+ * Key: player ID, Value: boolean (true = show, false = hide)
93
+ */
94
+ this.attachedGuiDisplayState = signal({});
95
+ this.webSocket = inject(context, WebSocketToken);
96
+ this.add({
97
+ name: "rpg-dialog",
98
+ component: component
99
+ });
100
+ this.add({
101
+ name: PrebuiltGui.MainMenu,
102
+ component: component$1
103
+ });
104
+ this.add({
105
+ name: PrebuiltGui.Shop,
106
+ component: component$2
107
+ });
108
+ this.add({
109
+ name: PrebuiltGui.Notification,
110
+ component: component$3,
111
+ autoDisplay: true
112
+ });
113
+ this.add({
114
+ name: PrebuiltGui.Save,
115
+ component: component$4
116
+ });
117
+ this.add({
118
+ name: PrebuiltGui.TitleScreen,
119
+ component: component$5
120
+ });
121
+ this.add({
122
+ name: PrebuiltGui.Gameover,
123
+ component: component$6
124
+ });
125
+ this.registerOptimisticReducer(PrebuiltGui.MainMenu, mainMenuOptimisticReducer);
126
+ }
127
+ async _initialize() {
128
+ this.webSocket.on("gui.open", (data) => {
129
+ this.clearPendingActions(data.guiId);
130
+ this.display(data.guiId, data.data);
131
+ });
132
+ this.webSocket.on("gui.exit", (guiId) => {
133
+ this.hide(guiId);
134
+ });
135
+ this.webSocket.on("gui.update", (payload) => {
136
+ this.applyServerUpdate(payload.guiId, payload.data, payload.clientActionId);
137
+ });
138
+ this.webSocket.on("gui.tooltip", (data) => {
139
+ const currentState = { ...this.attachedGuiDisplayState() };
140
+ data.players.forEach((playerId) => {
141
+ currentState[playerId] = data.display;
142
+ });
143
+ this.attachedGuiDisplayState.set(currentState);
144
+ });
145
+ }
146
+ /**
147
+ * Set the VueGui instance reference for Vue component management
148
+ * This is called by VueGui when it's initialized
149
+ *
150
+ * @param vueGuiInstance - The VueGui instance
151
+ */
152
+ _setVueGuiInstance(vueGuiInstance) {
153
+ this.vueGuiInstance = vueGuiInstance;
154
+ }
155
+ /**
156
+ * Notify VueGui about GUI state changes
157
+ * This synchronizes the Vue component display state
158
+ *
159
+ * @param guiId - The GUI component ID
160
+ * @param display - Display state
161
+ * @param data - Component data
162
+ */
163
+ _notifyVueGui(guiId, display, data = {}) {
164
+ if (this.vueGuiInstance && this.vueGuiInstance.vm) {
165
+ const extraGui = this.extraGuis.find((gui) => gui.name === guiId);
166
+ if (extraGui) {
167
+ this.vueGuiInstance.vm.gui[guiId] = {
168
+ name: guiId,
169
+ display,
170
+ data,
171
+ attachToSprite: extraGui.attachToSprite || false
172
+ };
173
+ this.vueGuiInstance.vm.gui = Object.assign({}, this.vueGuiInstance.vm.gui);
174
+ }
175
+ }
176
+ }
177
+ /**
178
+ * Initialize Vue components in the VueGui instance
179
+ * This should be called after VueGui is mounted
180
+ */
181
+ _initializeVueComponents() {
182
+ if (this.vueGuiInstance && this.vueGuiInstance.vm) {
183
+ this.extraGuis.forEach((gui) => {
184
+ this.vueGuiInstance.vm.gui[gui.name] = {
185
+ name: gui.name,
186
+ display: gui.display(),
187
+ data: gui.data(),
188
+ attachToSprite: gui.attachToSprite || false
189
+ };
190
+ });
191
+ this.vueGuiInstance.vm.gui = Object.assign({}, this.vueGuiInstance.vm.gui);
192
+ }
193
+ }
194
+ guiInteraction(guiId, name, data) {
195
+ const clientActionId = globalThis.crypto?.randomUUID?.() || `${Date.now()}-${Math.random()}`;
196
+ const actionData = { ...data || {}, clientActionId };
197
+ this.applyOptimisticAction({
198
+ guiId,
199
+ name,
200
+ data: actionData,
201
+ clientActionId
202
+ });
203
+ this.webSocket.emit("gui.interaction", {
204
+ guiId,
205
+ name,
206
+ data: actionData
207
+ });
208
+ }
209
+ guiClose(guiId, data) {
210
+ this.webSocket.emit("gui.exit", {
211
+ guiId,
212
+ data
213
+ });
214
+ }
215
+ /**
216
+ * Add a GUI component to the system
217
+ *
218
+ * By default, only CanvasEngine components (.ce files) are accepted.
219
+ * Vue components should be handled by the @rpgjs/vue package.
220
+ *
221
+ * @param gui - GUI configuration options
222
+ * @param gui.name - Name or ID of the GUI component
223
+ * @param gui.id - Alternative ID if name is not provided
224
+ * @param gui.component - The component to render (must be a CanvasEngine component)
225
+ * @param gui.display - Initial display state (default: false)
226
+ * @param gui.data - Initial data for the component
227
+ * @param gui.autoDisplay - Auto display when added (default: false)
228
+ * @param gui.dependencies - Function returning Signal dependencies
229
+ * @param gui.attachToSprite - Attach GUI to sprites instead of global display (default: false)
230
+ *
231
+ * @example
232
+ * ```ts
233
+ * gui.add({
234
+ * name: 'inventory',
235
+ * component: InventoryComponent, // Must be a .ce component
236
+ * autoDisplay: true,
237
+ * dependencies: () => [playerSignal, inventorySignal]
238
+ * });
239
+ *
240
+ * // Attach to sprites
241
+ * gui.add({
242
+ * name: 'tooltip',
243
+ * component: TooltipComponent,
244
+ * attachToSprite: true
245
+ * });
246
+ * ```
247
+ */
248
+ add(gui) {
249
+ const guiId = gui.name || gui.id;
250
+ if (!guiId) {
251
+ throw new Error("GUI must have a name or id");
252
+ }
253
+ const guiInstance = {
254
+ name: guiId,
255
+ component: gui.component,
256
+ display: signal(gui.display || false),
257
+ data: signal(gui.data || {}),
258
+ autoDisplay: gui.autoDisplay || false,
259
+ dependencies: gui.dependencies ? gui.dependencies() : [],
260
+ attachToSprite: gui.attachToSprite || false
261
+ };
262
+ if (typeof gui.component !== "function") {
263
+ guiInstance.component = gui;
264
+ this.extraGuis.push(guiInstance);
265
+ if (guiInstance.autoDisplay) {
266
+ this._notifyVueGui(guiId, true, gui.data || {});
267
+ }
268
+ return;
269
+ }
270
+ this.gui()[guiId] = guiInstance;
271
+ if (guiInstance.autoDisplay && typeof gui.component === "function") {
272
+ this.display(guiId, gui.data);
273
+ }
274
+ }
275
+ registerOptimisticReducer(guiId, reducer) {
276
+ const existing = this.optimisticReducers.get(guiId) || [];
277
+ this.optimisticReducers.set(guiId, existing.concat(reducer));
278
+ }
279
+ /**
280
+ * Get all attached GUI components (attachToSprite: true)
281
+ *
282
+ * Returns all GUI instances that are configured to be attached to sprites.
283
+ * These GUIs should be rendered in character.ce instead of canvas.ce.
284
+ *
285
+ * @returns Array of GUI instances with attachToSprite: true
286
+ *
287
+ * @example
288
+ * ```ts
289
+ * const attachedGuis = gui.getAttachedGuis();
290
+ * // Use in character.ce to render tooltips
291
+ * ```
292
+ */
293
+ getAttachedGuis() {
294
+ const allGuis = this.getAll();
295
+ return Object.values(allGuis).filter((gui) => gui.attachToSprite === true);
296
+ }
297
+ /**
298
+ * Check if a player should display attached GUIs
299
+ *
300
+ * @param playerId - The player ID to check
301
+ * @returns true if attached GUIs should be displayed for this player
302
+ */
303
+ shouldDisplayAttachedGui(playerId) {
304
+ return this.attachedGuiDisplayState()[playerId] === true;
305
+ }
306
+ get(id) {
307
+ const canvasGui = this.gui()[id];
308
+ if (canvasGui) {
309
+ return canvasGui;
310
+ }
311
+ return this.extraGuis.find((gui) => gui.name === id);
312
+ }
313
+ exists(id) {
314
+ return !!this.get(id);
315
+ }
316
+ getAll() {
317
+ const allGuis = { ...this.gui() };
318
+ this.extraGuis.forEach((gui) => {
319
+ allGuis[gui.name] = gui;
320
+ });
321
+ return allGuis;
322
+ }
323
+ /**
324
+ * Display a GUI component
325
+ *
326
+ * Displays the GUI immediately if no dependencies are configured,
327
+ * or waits for all dependencies to be resolved if dependencies are present.
328
+ * Automatically manages subscriptions to prevent memory leaks.
329
+ * Works with both CanvasEngine components and Vue components.
330
+ *
331
+ * @param id - The GUI component ID
332
+ * @param data - Data to pass to the component
333
+ * @param dependencies - Optional runtime dependencies (overrides config dependencies)
334
+ *
335
+ * @example
336
+ * ```ts
337
+ * // Display immediately
338
+ * gui.display('inventory', { items: [] });
339
+ *
340
+ * // Display with runtime dependencies
341
+ * gui.display('shop', { shopId: 1 }, [playerSignal, shopSignal]);
342
+ * ```
343
+ */
344
+ display(id, data = {}, dependencies = []) {
345
+ if (!this.exists(id)) {
346
+ throw throwError(id);
347
+ }
348
+ const guiInstance = this.get(id);
349
+ const isVueComponent = this.extraGuis.some((gui) => gui.name === id);
350
+ if (isVueComponent) {
351
+ this._handleVueComponentDisplay(id, data, dependencies, guiInstance);
352
+ } else {
353
+ guiInstance.data.set(data);
354
+ guiInstance.display.set(true);
355
+ }
356
+ }
357
+ isDisplaying(id) {
358
+ const guiInstance = this.get(id);
359
+ if (!guiInstance) return false;
360
+ return guiInstance.display();
361
+ }
362
+ /**
363
+ * Handle Vue component display logic
364
+ *
365
+ * @param id - GUI component ID
366
+ * @param data - Component data
367
+ * @param dependencies - Runtime dependencies
368
+ * @param guiInstance - GUI instance
369
+ */
370
+ _handleVueComponentDisplay(id, data, dependencies, guiInstance) {
371
+ if (guiInstance.subscription) {
372
+ guiInstance.subscription.unsubscribe();
373
+ guiInstance.subscription = void 0;
374
+ }
375
+ const deps = dependencies.length > 0 ? dependencies : guiInstance.dependencies ? guiInstance.dependencies() : [];
376
+ if (deps.length > 0) {
377
+ guiInstance.subscription = combineLatest(
378
+ deps.map((dependency) => dependency.observable)
379
+ ).subscribe((values) => {
380
+ if (values.every((value) => value !== void 0)) {
381
+ guiInstance.data.set(data);
382
+ guiInstance.display.set(true);
383
+ this._notifyVueGui(id, true, data);
384
+ }
385
+ });
386
+ return;
387
+ }
388
+ guiInstance.data.set(data);
389
+ guiInstance.display.set(true);
390
+ this._notifyVueGui(id, true, data);
391
+ }
392
+ /**
393
+ * Hide a GUI component
394
+ *
395
+ * Hides the GUI and cleans up any active subscriptions.
396
+ * Works with both CanvasEngine components and Vue components.
397
+ *
398
+ * @param id - The GUI component ID
399
+ *
400
+ * @example
401
+ * ```ts
402
+ * gui.hide('inventory');
403
+ * ```
404
+ */
405
+ hide(id) {
406
+ if (!this.exists(id)) {
407
+ throw throwError(id);
408
+ }
409
+ const guiInstance = this.get(id);
410
+ if (guiInstance.subscription) {
411
+ guiInstance.subscription.unsubscribe();
412
+ guiInstance.subscription = void 0;
413
+ }
414
+ guiInstance.display.set(false);
415
+ const isVueComponent = this.extraGuis.some((gui) => gui.name === id);
416
+ if (isVueComponent) {
417
+ this._notifyVueGui(id, false);
418
+ }
419
+ }
420
+ isVueComponent(id) {
421
+ return this.extraGuis.some((gui) => gui.name === id);
422
+ }
423
+ clearPendingActions(guiId) {
424
+ this.pendingActions.delete(guiId);
425
+ }
426
+ applyReducers(guiId, data, actions) {
427
+ const reducers = this.optimisticReducers.get(guiId);
428
+ if (!reducers || reducers.length === 0) return data;
429
+ let next = data;
430
+ for (const action of actions) {
431
+ for (const reducer of reducers) {
432
+ const updated = reducer(next, action);
433
+ if (updated !== void 0 && updated !== null && updated !== next) {
434
+ next = updated;
435
+ }
436
+ }
437
+ }
438
+ return next;
439
+ }
440
+ applyOptimisticAction(action) {
441
+ const guiInstance = this.get(action.guiId);
442
+ if (!guiInstance) return;
443
+ const reducers = this.optimisticReducers.get(action.guiId);
444
+ if (!reducers || reducers.length === 0) return;
445
+ const currentData = guiInstance.data();
446
+ const nextData = this.applyReducers(action.guiId, currentData, [action]);
447
+ if (nextData === currentData) return;
448
+ guiInstance.data.set(nextData);
449
+ const pending = this.pendingActions.get(action.guiId) || [];
450
+ pending.push(action);
451
+ this.pendingActions.set(action.guiId, pending);
452
+ if (this.isVueComponent(action.guiId)) {
453
+ this._notifyVueGui(action.guiId, guiInstance.display(), nextData);
454
+ }
455
+ }
456
+ applyServerUpdate(guiId, data, clientActionId) {
457
+ const guiInstance = this.get(guiId);
458
+ if (!guiInstance) return;
459
+ let pending = this.pendingActions.get(guiId) || [];
460
+ if (clientActionId) {
461
+ pending = pending.filter((action) => action.clientActionId !== clientActionId);
462
+ } else {
463
+ pending = [];
464
+ }
465
+ let nextData = data;
466
+ if (pending.length) {
467
+ nextData = this.applyReducers(guiId, nextData, pending);
468
+ }
469
+ guiInstance.data.set(nextData);
470
+ this.pendingActions.set(guiId, pending);
471
+ if (this.isVueComponent(guiId)) {
472
+ this._notifyVueGui(guiId, guiInstance.display(), nextData);
473
+ }
474
+ }
475
+ }
476
+
477
+ export { RpgGui };
478
+ //# sourceMappingURL=Gui.js.map