@rpgjs/client 5.0.0-alpha.9 → 5.0.0-beta.1

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