@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
@@ -0,0 +1,255 @@
1
+ <!--
2
+ HP Bar Component
3
+
4
+ A beautiful, animated health bar component for displaying player HP above sprites.
5
+ Features a gradient color based on HP level, smooth animations, and modern styling.
6
+
7
+ ## Design
8
+
9
+ The bar changes color dynamically based on HP percentage:
10
+ - Green (#4ade80) when HP > 60% - Healthy state
11
+ - Yellow (#facc15) when HP 30-60% - Caution state
12
+ - Orange (#fb923c) when HP 15-30% - Danger state
13
+ - Red (#ef4444) when HP < 15% - Critical state
14
+
15
+ @example
16
+ ```ts
17
+ import HpBar from './hp-bar.ce';
18
+
19
+ // In module configuration
20
+ export default defineModule<RpgClient>({
21
+ sprite: {
22
+ componentsInFront: [HpBar]
23
+ }
24
+ })
25
+ ```
26
+ -->
27
+
28
+ <Container x={position.x} y={position.y}>
29
+ <!-- Background shadow for depth effect -->
30
+ <Graphics draw={drawShadow} x={1} y={1} />
31
+
32
+ <!-- Main background -->
33
+ <Graphics draw={drawBackground} />
34
+
35
+ <!-- HP fill bar -->
36
+ <Graphics draw={drawFill} />
37
+
38
+ <!-- Highlight overlay for 3D effect -->
39
+ <Graphics draw={drawHighlight} />
40
+
41
+ <!-- Border frame -->
42
+ <Graphics draw={drawBorder} />
43
+ </Container>
44
+
45
+ <script>
46
+ import { computed, animatedSignal, effect } from "canvasengine";
47
+
48
+ const { object } = defineProps();
49
+
50
+ // ====================
51
+ // Configuration
52
+ // ====================
53
+
54
+ /** Total width of the HP bar in pixels */
55
+ const barWidth = 50;
56
+
57
+ /** Total height of the HP bar in pixels */
58
+ const barHeight = 8;
59
+
60
+ /** Border radius for rounded corners */
61
+ const borderRadius = 4;
62
+
63
+ /** Inner border radius for the fill bar */
64
+ const innerRadius = 3;
65
+
66
+ /** Padding between background and fill */
67
+ const padding = 1;
68
+
69
+ /** Background color (dark theme) */
70
+ const bgColor = 0x16213e;
71
+
72
+ /** Shadow color */
73
+ const shadowColor = 0x000000;
74
+
75
+ /** Border color */
76
+ const borderColor = 0x4a5568;
77
+
78
+ // ====================
79
+ // Calculated dimensions
80
+ // ====================
81
+
82
+ /** Maximum fill width */
83
+ const maxFillWidth = barWidth - (padding * 2);
84
+
85
+ /** Fill height */
86
+ const fillHeight = barHeight - (padding * 2);
87
+
88
+ /** Highlight height (half of fill) */
89
+ const highlightHeight = Math.floor(fillHeight / 2);
90
+
91
+ // ====================
92
+ // Reactive HP values
93
+ // ====================
94
+
95
+ /** Gets hitbox dimensions for positioning */
96
+ const hitbox = object.hitbox;
97
+
98
+ /**
99
+ * Gets the current HP value from the player object
100
+ * Uses hpSignal which is synchronized from the server
101
+ */
102
+ const currentHp = computed(() => {
103
+ return object.hpSignal?.() ?? 0;
104
+ });
105
+
106
+ /**
107
+ * Gets the maximum HP value from player parameters
108
+ * Reads from _param.maxHp which contains calculated stats
109
+ */
110
+ const maxHp = computed(() => {
111
+ const params = object._param?.() ?? {};
112
+ return params.maxHp ?? 100;
113
+ });
114
+
115
+ /**
116
+ * Calculates HP percentage (0 to 1)
117
+ */
118
+ const hpPercent = computed(() => {
119
+ const max = maxHp();
120
+ if (max <= 0) return 0;
121
+ const percent = currentHp() / max;
122
+ return Math.max(0, Math.min(1, percent));
123
+ });
124
+
125
+ // ====================
126
+ // Animated values
127
+ // ====================
128
+
129
+ /**
130
+ * Animated percentage for smooth bar transitions
131
+ */
132
+ const animatedPercent = animatedSignal(hpPercent(), {
133
+ duration: 300,
134
+ easing: 'easeOutCubic'
135
+ });
136
+
137
+ // Update animated value when HP changes
138
+ effect(() => {
139
+ const newPercent = hpPercent();
140
+ animatedPercent.set(newPercent);
141
+ });
142
+
143
+ // ====================
144
+ // Visual calculations
145
+ // ====================
146
+
147
+ /**
148
+ * Position of the bar relative to the sprite
149
+ */
150
+ const position = computed(() => ({
151
+ x: (hitbox().w / 2) - (barWidth / 2),
152
+ y: -barHeight - 8
153
+ }));
154
+
155
+ /**
156
+ * Current width of the HP fill based on animated percentage
157
+ */
158
+ const fillWidth = computed(() => {
159
+ const percent = animatedPercent();
160
+ const width = maxFillWidth * percent;
161
+ // Ensure minimum visible width when HP > 0
162
+ if (percent > 0 && width < innerRadius * 2) {
163
+ return innerRadius * 2;
164
+ }
165
+ return Math.max(0, width);
166
+ });
167
+
168
+ /**
169
+ * Determines HP bar color based on current HP percentage
170
+ * Returns hex color number for PixiJS
171
+ *
172
+ * ## Color Thresholds
173
+ * - Green (0x4ade80): HP > 60% - Healthy
174
+ * - Yellow (0xfacc15): HP 30-60% - Caution
175
+ * - Orange (0xfb923c): HP 15-30% - Danger
176
+ * - Red (0xef4444): HP < 15% - Critical
177
+ */
178
+ const hpColorHex = computed(() => {
179
+ const percent = hpPercent();
180
+
181
+ if (percent > 0.6) {
182
+ return 0x4ade80; // Green - healthy
183
+ } else if (percent > 0.3) {
184
+ return 0xfacc15; // Yellow - caution
185
+ } else if (percent > 0.15) {
186
+ return 0xfb923c; // Orange - danger
187
+ } else {
188
+ return 0xef4444; // Red - critical
189
+ }
190
+ });
191
+
192
+ // ====================
193
+ // Drawing functions
194
+ // ====================
195
+
196
+ /**
197
+ * Draws the shadow behind the HP bar for depth effect
198
+ */
199
+ const drawShadow = (g) => {
200
+ g.roundRect(0, 0, barWidth, barHeight, borderRadius);
201
+ g.fill({ color: shadowColor, alpha: 0.3 });
202
+ };
203
+
204
+ /**
205
+ * Draws the main background of the HP bar
206
+ */
207
+ const drawBackground = (g) => {
208
+ g.roundRect(0, 0, barWidth, barHeight, borderRadius);
209
+ g.fill({ color: bgColor, alpha: 0.9 });
210
+ };
211
+
212
+ /**
213
+ * Draws the HP fill bar with dynamic color
214
+ */
215
+ const drawFill = (g) => {
216
+ const width = fillWidth();
217
+ if (width > 0) {
218
+ g.roundRect(padding, padding, width, fillHeight, innerRadius);
219
+ g.fill({ color: hpColorHex() });
220
+ }
221
+ };
222
+
223
+ /**
224
+ * Draws the highlight overlay for 3D effect
225
+ */
226
+ const drawHighlight = (g) => {
227
+ const width = fillWidth();
228
+ if (width > 0) {
229
+ g.roundRect(padding, padding, width, highlightHeight, innerRadius);
230
+ g.fill({ color: 0xffffff, alpha: 0.25 });
231
+ }
232
+ };
233
+
234
+ /**
235
+ * Draws the border frame around the HP bar
236
+ *
237
+ * Uses PixiJS Graphics API to create a rounded rectangle stroke
238
+ * that serves as a visual border for the bar.
239
+ *
240
+ * @param g - PixiJS Graphics object
241
+ *
242
+ * @example
243
+ * ```html
244
+ * <Graphics draw={drawBorder} />
245
+ * ```
246
+ */
247
+ const drawBorder = (g) => {
248
+ g.roundRect(0, 0, barWidth, barHeight, borderRadius);
249
+ g.stroke({
250
+ color: borderColor,
251
+ width: 1,
252
+ alpha: 0.7
253
+ });
254
+ };
255
+ </script>
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Prebuilt sprite components for common UI elements
3
+ *
4
+ * This module exports ready-to-use components that can be attached
5
+ * to sprites using componentsInFront or componentsBehind configuration.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * import { HpBar } from '@rpgjs/client/components/prebuilt';
10
+ *
11
+ * export default defineModule<RpgClient>({
12
+ * sprite: {
13
+ * componentsInFront: [HpBar]
14
+ * }
15
+ * })
16
+ * ```
17
+ */
18
+
19
+ export { default as HpBar } from './hp-bar.ce';
20
+ export { default as LightHalo } from './light-halo.ce';
21
+
22
+
23
+
24
+
@@ -0,0 +1,148 @@
1
+ <Container x={position.x} y={position.y}>
2
+ <Graphics draw={drawHalo} />
3
+ </Container>
4
+
5
+ <script>
6
+ import { computed, signal, tick, mount } from "canvasengine";
7
+ import { BlurFilter } from "pixi.js";
8
+
9
+ /**
10
+ * Component props for LightHalo
11
+ *
12
+ * All props are signals (even static ones) and must be read with `()`.
13
+ * Props are optional and will use default values if not provided.
14
+ *
15
+ * @property {Object} object - The sprite object (required)
16
+ * @property {number|Signal<number>} [baseRadius] - Base radius of the light halo in pixels (default: 30)
17
+ * @property {number|Signal<number>} [radiusVariation] - Radius variation range (halo will pulse between baseRadius ± radiusVariation) (default: 10)
18
+ * @property {number|Signal<number>} [baseOpacity] - Base opacity of the light halo (0 to 1) (default: 0.6)
19
+ * @property {number|Signal<number>} [opacityVariation] - Opacity variation range (halo will fade between baseOpacity ± opacityVariation) (default: 0.3)
20
+ * @property {number|Signal<number>} [sizeSpeed] - Animation speed for size pulsing (higher = faster) (default: 0.002)
21
+ * @property {number|Signal<number>} [opacitySpeed] - Animation speed for opacity fading (higher = faster) (default: 0.003)
22
+ * @property {number|Signal<number>} [lightColor] - Color of the light halo (hex value, warm yellow-white by default: 0xffffaa)
23
+ */
24
+ const {
25
+ object,
26
+ baseRadius,
27
+ radiusVariation,
28
+ baseOpacity,
29
+ opacityVariation,
30
+ sizeSpeed,
31
+ opacitySpeed,
32
+ lightColor
33
+ } = defineProps();
34
+
35
+ // ====================
36
+ // Props with default values
37
+ // ====================
38
+
39
+ const getBaseRadius = computed(() => baseRadius?.() ?? 30);
40
+ const getRadiusVariation = computed(() => radiusVariation?.() ?? 10);
41
+ const getBaseOpacity = computed(() => baseOpacity?.() ?? 0.6);
42
+ const getOpacityVariation = computed(() => opacityVariation?.() ?? 0.3);
43
+ const getSizeSpeed = computed(() => sizeSpeed?.() ?? 0.002);
44
+ const getOpacitySpeed = computed(() => opacitySpeed?.() ?? 0.003);
45
+ const getLightColor = computed(() => lightColor?.() ?? 0xffffaa);
46
+
47
+ // ====================
48
+ // Animation state
49
+ // ====================
50
+
51
+ /** Time counter for animations */
52
+ const time = signal(0);
53
+
54
+ /**
55
+ * Current radius of the halo with pulsing animation
56
+ * Uses multiple sine waves for more organic movement
57
+ */
58
+ const currentRadius = computed(() => {
59
+ const t = time();
60
+ const base = getBaseRadius();
61
+ const variation = getRadiusVariation();
62
+ const speed = getSizeSpeed();
63
+
64
+ // Combine two sine waves for less predictable pulsing
65
+ const pulse1 = Math.sin(t * speed);
66
+ const pulse2 = Math.sin(t * speed * 1.5) * 0.5;
67
+ const combinedPulse = (pulse1 + pulse2) / 1.5;
68
+
69
+ return base + (combinedPulse * variation);
70
+ });
71
+
72
+ /**
73
+ * Current opacity of the halo with fading animation
74
+ * Includes a subtle flicker effect
75
+ */
76
+ const currentOpacity = computed(() => {
77
+ const t = time();
78
+ const base = getBaseOpacity();
79
+ const variation = getOpacityVariation();
80
+ const speed = getOpacitySpeed();
81
+
82
+ // Main breathing cycle
83
+ const fade = Math.sin(t * speed);
84
+
85
+ // Subtle high-frequency flicker (candle-like)
86
+ const flicker = (Math.random() - 0.5) * 0.1;
87
+
88
+ return Math.max(0, Math.min(1, base + (fade * variation) + flicker));
89
+ });
90
+
91
+ // ====================
92
+ // Position calculations
93
+ // ====================
94
+
95
+ const hitbox = object.hitbox;
96
+
97
+ const position = computed(() => ({
98
+ x: hitbox().w / 2,
99
+ y: hitbox().h / 2
100
+ }));
101
+
102
+ // ====================
103
+ // Drawing function
104
+ // ====================
105
+
106
+ // Create filters once to avoid recreation on every frame
107
+ const blurFilter = new BlurFilter({ strength: 20, quality: 3 });
108
+
109
+ /**
110
+ * Draws the light halo effect with realistic diffusion
111
+ */
112
+ const drawHalo = (g) => {
113
+ const radius = currentRadius();
114
+ const opacity = currentOpacity();
115
+ const color = getLightColor();
116
+
117
+ if (opacity <= 0 || radius <= 0) return;
118
+
119
+ // Set blend mode to ADD for glowing light effect
120
+ g.blendMode = 'add';
121
+
122
+ // Apply blur filter for soft light diffusion
123
+ g.filters = [blurFilter];
124
+
125
+ // Draw main light source
126
+ // The blur filter will spread this out into a nice gradient
127
+ g.circle(0, 0, radius);
128
+ g.fill({
129
+ color: color,
130
+ alpha: opacity
131
+ });
132
+
133
+ // Draw a smaller, brighter core
134
+ g.circle(0, 0, radius * 0.4);
135
+ g.fill({
136
+ color: 0xffffff,
137
+ alpha: opacity * 0.5
138
+ });
139
+ };
140
+
141
+ // ====================
142
+ // Animation loop
143
+ // ====================
144
+ tick(() => {
145
+ time.update(t => t + 1);
146
+ });
147
+ </script>
148
+
@@ -1,20 +1,20 @@
1
- <Canvas width={@engine.width} height={@engine.height}>
2
- <Viewport worldWidth worldHeight clamp>
1
+ <Canvas width={engine.width} height={engine.height}>
2
+ <Viewport worldWidth worldHeight clamp sortableChildren={true}>
3
3
  @if (sceneData) {
4
4
  <SceneMap />
5
5
  }
6
6
  </Viewport>
7
- @for (gui of gui) {
8
- <Container display="flex">
9
- @if (gui.display) {
10
- <gui.component ...gui.data() onFinish={(data) => {
11
- onGuiFinish(gui, data)
12
- }} onInteraction={(name, data) => {
13
- onGuiInteraction(gui, name, data)
14
- }} />
15
- }
16
- </Container>
17
- }
7
+ @for (gui of guiList) {
8
+ <Container display="flex">
9
+ @if (gui.display) {
10
+ <gui.component data={gui.data} dependencies={gui.dependencies} onFinish={(data) => {
11
+ onGuiFinish(gui, data)
12
+ }} onInteraction={(name, data) => {
13
+ onGuiInteraction(gui, name, data)
14
+ }} />
15
+ }
16
+ </Container>
17
+ }
18
18
  </Canvas>
19
19
 
20
20
  <script>
@@ -23,11 +23,14 @@
23
23
  import { RpgClientEngine } from "../../RpgClientEngine";
24
24
  import SceneMap from './draw-map.ce'
25
25
  import { RpgGui } from "../../Gui/Gui";
26
+ import { delay } from "@rpgjs/common";
26
27
 
27
28
  const engine = inject(RpgClientEngine);
28
29
  const guiService = inject(RpgGui);
29
30
  const sceneData = engine.sceneMap.data
30
- const gui = guiService.gui
31
+ const guiList = computed(() => {
32
+ return Object.values(guiService.gui()).filter((gui) => !gui.attachToSprite)
33
+ })
31
34
  const worldWidth = computed(() => sceneData()?.width)
32
35
  const worldHeight = computed(() => sceneData()?.height)
33
36
 
@@ -38,7 +41,9 @@
38
41
  })
39
42
 
40
43
  const onGuiFinish = (gui, data) => {
41
- guiService.guiClose(gui.name, data)
44
+ delay(() => {
45
+ guiService.guiClose(gui.name, data)
46
+ })
42
47
  }
43
48
 
44
49
  const onGuiInteraction = (gui, name, data) => {
@@ -1,33 +1,42 @@
1
- <Container sound={backgroundMusic} >
1
+ <Container sound={backgroundMusic} shake={shakeConfig} freeze={engine.gamePause}>
2
2
  <Container sound={backgroundAmbientSound} />
3
3
 
4
- <sceneComponent() data={map.@data} params={map.@params} />
5
-
6
- @for (effect of effects) {
4
+ @if (map() && sceneComponent()) {
5
+ <sceneComponent() data={map().data} params={map().params} />
6
+ }
7
+
8
+ @for (componentAnimation of componentAnimations) {
7
9
  <Container>
8
- @for (animation of effect.current) {
9
- <effect.component ...animation />
10
+ @for (animation of componentAnimation.current) {
11
+ <componentAnimation.component ...animation />
10
12
  }
11
13
  </Container>
12
14
  }
15
+
16
+ @if (weatherProps) {
17
+ <Weather ...weatherProps() />
18
+ }
13
19
  </Container>
14
20
 
15
21
  <script>
16
- import { effect, signal, computed, mount } from 'canvasengine'
22
+ import { NoiseFilter } from 'pixi-filters';
23
+ import { effect, signal, computed, mount, on, tick } from 'canvasengine'
17
24
  import { inject } from "../../core/inject";
18
25
  import { RpgClientEngine } from "../../RpgClientEngine";
26
+ import { Weather } from '@canvasengine/presets'
19
27
 
20
28
  const engine = inject(RpgClientEngine);
21
- const effects = engine.effects
22
- const map = engine.sceneMap.data
29
+ const componentAnimations = engine.componentAnimations
30
+ const map = engine.sceneMap?.data
23
31
  const sceneComponent = computed(() => map()?.component)
24
32
  const sceneParams = map()?.params
25
- const mapParams = map().params
33
+ const mapParams = map()?.params
26
34
  const animations = engine.sceneMap.animations
35
+ const weather = engine.sceneMap.weather
27
36
  const backgroundMusic = { src: mapParams?.backgroundMusic, autoplay: true, loop: true }
28
37
  const backgroundAmbientSound = { src: mapParams?.backgroundAmbientSound, autoplay: true, loop: true }
29
-
30
- const data = signal(map().data)
38
+
39
+ const data = signal(map()?.data)
31
40
 
32
41
  const scale = mapParams?.scale || 1
33
42
  const worldWidth = (mapParams?.width || 2048) * scale
@@ -36,4 +45,42 @@
36
45
  const clamp = {
37
46
  direction: "all"
38
47
  }
39
- </script>
48
+
49
+ const shakeConfig = {
50
+ trigger: engine.mapShakeTrigger,
51
+ intensity: 10,
52
+ duration: 500,
53
+ frequency: 10,
54
+ direction: 'both'
55
+ }
56
+
57
+ const weatherProps = computed(() => {
58
+ const state = weather?.()
59
+ if (!state) {
60
+ return null
61
+ }
62
+ const validEffects = ['rain', 'snow', 'fog', 'cloud']
63
+ if (!validEffects.includes(state.effect)) {
64
+ return null
65
+ }
66
+ const params = state.params ?? {}
67
+ return {
68
+ effect: state.effect,
69
+ speed: params.speed,
70
+ windDirection: params.windDirection,
71
+ windStrength: params.windStrength,
72
+ density: params.density,
73
+ maxDrops: params.maxDrops,
74
+ height: params.height,
75
+ scale: params.scale,
76
+ sunIntensity: params.sunIntensity,
77
+ sunAngle: params.sunAngle,
78
+ raySpread: params.raySpread,
79
+ rayTwinkle: params.rayTwinkle,
80
+ rayTwinkleSpeed: params.rayTwinkleSpeed,
81
+ zIndex: params.zIndex ?? 1000,
82
+ alpha: params.alpha,
83
+ blendMode: params.blendMode,
84
+ }
85
+ })
86
+ </script>
@@ -6,6 +6,10 @@
6
6
  @for ((player,id) of players) {
7
7
  <Character id={id} object={player} />
8
8
  }
9
+
10
+ @for (child of children) {
11
+ <child />
12
+ }
9
13
  </Container>
10
14
 
11
15
  <script>
@@ -13,8 +17,11 @@
13
17
  import { inject } from "../../core/inject";
14
18
  import { RpgClientEngine } from "../../RpgClientEngine";
15
19
  import Character from "../character.ce";
20
+ import LightHalo from "../prebuilt/light-halo.ce";
16
21
 
17
22
  const engine = inject(RpgClientEngine);
23
+ const { children } = defineProps()
24
+
18
25
  const players = engine.sceneMap.players
19
26
  const events = engine.sceneMap.events
20
27
  </script>
@@ -0,0 +1,60 @@
1
+ <Rect
2
+ x={0}
3
+ y={0}
4
+ width={engine.width}
5
+ height={engine.height}
6
+ fill={color}
7
+ alpha={opacity}
8
+ zIndex={100000}
9
+ />
10
+
11
+ <script>
12
+ import { animatedSignal, mount, computed, signal } from "canvasengine";
13
+ import { inject } from "../../core/inject";
14
+ import { RpgClientEngine } from "../../RpgClientEngine";
15
+
16
+ const {
17
+ onFinish,
18
+ duration,
19
+ color,
20
+ fadeIn
21
+ } = defineProps({
22
+ duration: {
23
+ default: 1000
24
+ },
25
+ color: {
26
+ default: 'black'
27
+ },
28
+ fadeIn: {
29
+ default: true
30
+ }
31
+ });
32
+
33
+ const engine = inject(RpgClientEngine);
34
+
35
+ // Calculate width and height from engine
36
+ const width = computed(() => {
37
+ const w = engine.width();
38
+ return typeof w === 'string' ? parseInt(w) || 1920 : w;
39
+ });
40
+
41
+ const height = computed(() => {
42
+ const h = engine.height();
43
+ return typeof h === 'string' ? parseInt(h) || 1080 : h;
44
+ });
45
+
46
+ // Animation: fade in from transparent to opaque, or fade out from opaque to transparent
47
+ const opacity = animatedSignal(fadeIn() ? 0 : 1, {
48
+ duration: duration(),
49
+ onComplete: () => {
50
+ if (onFinish) {
51
+ onFinish();
52
+ }
53
+ }
54
+ });
55
+
56
+ mount(() => {
57
+ // Start the fade animation
58
+ opacity.set(fadeIn() ? 1 : 0);
59
+ });
60
+ </script>
package/src/index.ts CHANGED
@@ -2,12 +2,26 @@ export * from "./RpgClientEngine";
2
2
  export type * from "./RpgClient";
3
3
  export * from "./services/standalone";
4
4
  export * from "./services/mmorpg";
5
+ export * from "./services/save";
5
6
  export * from "./core/setup";
6
7
  export * from "./core/inject";
7
8
  export * from "./services/loadMap";
8
9
  export * from "./module";
9
10
  export * from "./Gui/Gui";
10
11
  export * from "./components/gui";
11
- export * from "./components/effects";
12
+ export * from "./components/animations";
13
+ export * from "./components/prebuilt";
12
14
  export * from "./presets";
13
- export * from "./components";
15
+ export * from "./components";
16
+ export * from "./components/gui";
17
+ export * from "./Sound";
18
+ export * from "./Resource";
19
+ export * from "./utils/getEntityProp";
20
+ export { Context } from "@signe/di";
21
+ export { KeyboardControls, Input } from "canvasengine";
22
+ export { Control } from "./services/keyboardControls";
23
+ export { RpgClientObject } from "./Game/Object";
24
+ export { RpgClientPlayer } from "./Game/Player";
25
+ export { RpgClientEvent } from "./Game/Event";
26
+ export { withMobile } from "./components/gui/mobile";
27
+ export * from "./services/AbstractSocket";