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

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 (347) hide show
  1. package/CHANGELOG.md +37 -0
  2. package/LICENSE +19 -0
  3. package/dist/Game/AnimationManager.d.ts +8 -0
  4. package/dist/Game/AnimationManager.js +35 -0
  5. package/dist/Game/AnimationManager.js.map +1 -0
  6. package/dist/Game/AnimationManager.spec.d.ts +1 -0
  7. package/dist/Game/Event.d.ts +1 -1
  8. package/dist/Game/Event.js +12 -0
  9. package/dist/Game/Event.js.map +1 -0
  10. package/dist/Game/Map.d.ts +31 -2
  11. package/dist/Game/Map.js +138 -0
  12. package/dist/Game/Map.js.map +1 -0
  13. package/dist/Game/Object.d.ts +189 -0
  14. package/dist/Game/Object.js +255 -0
  15. package/dist/Game/Object.js.map +1 -0
  16. package/dist/Game/Player.d.ts +1 -1
  17. package/dist/Game/Player.js +12 -0
  18. package/dist/Game/Player.js.map +1 -0
  19. package/dist/Gui/Gui.d.ts +192 -7
  20. package/dist/Gui/Gui.js +475 -0
  21. package/dist/Gui/Gui.js.map +1 -0
  22. package/dist/Gui/Gui.spec.d.ts +1 -0
  23. package/dist/Gui/NotificationManager.d.ts +23 -0
  24. package/dist/Gui/NotificationManager.js +49 -0
  25. package/dist/Gui/NotificationManager.js.map +1 -0
  26. package/dist/Resource.d.ts +97 -0
  27. package/dist/Resource.js +133 -0
  28. package/dist/Resource.js.map +1 -0
  29. package/dist/RpgClient.d.ts +295 -13
  30. package/dist/RpgClientEngine.d.ts +671 -15
  31. package/dist/RpgClientEngine.js +1442 -0
  32. package/dist/RpgClientEngine.js.map +1 -0
  33. package/dist/Sound.d.ts +199 -0
  34. package/dist/Sound.js +167 -0
  35. package/dist/Sound.js.map +1 -0
  36. package/dist/_virtual/_@oxc-project_runtime@0.130.0/helpers/decorate.js +9 -0
  37. package/dist/_virtual/_@oxc-project_runtime@0.130.0/helpers/decorateMetadata.js +6 -0
  38. package/dist/components/animations/animation.ce.js +23 -0
  39. package/dist/components/animations/animation.ce.js.map +1 -0
  40. package/dist/components/animations/hit.ce.js +64 -0
  41. package/dist/components/animations/hit.ce.js.map +1 -0
  42. package/dist/components/animations/index.d.ts +4 -0
  43. package/dist/components/animations/index.js +11 -0
  44. package/dist/components/animations/index.js.map +1 -0
  45. package/dist/components/character.ce.js +572 -0
  46. package/dist/components/character.ce.js.map +1 -0
  47. package/dist/components/dynamics/bar.ce.js +96 -0
  48. package/dist/components/dynamics/bar.ce.js.map +1 -0
  49. package/dist/components/dynamics/image.ce.js +23 -0
  50. package/dist/components/dynamics/image.ce.js.map +1 -0
  51. package/dist/components/dynamics/parse-value.d.ts +4 -0
  52. package/dist/components/dynamics/parse-value.js +63 -0
  53. package/dist/components/dynamics/parse-value.js.map +1 -0
  54. package/dist/components/dynamics/parse-value.spec.d.ts +1 -0
  55. package/dist/components/dynamics/shape-utils.d.ts +16 -0
  56. package/dist/components/dynamics/shape-utils.js +73 -0
  57. package/dist/components/dynamics/shape-utils.js.map +1 -0
  58. package/dist/components/dynamics/shape-utils.spec.d.ts +1 -0
  59. package/dist/components/dynamics/shape.ce.js +83 -0
  60. package/dist/components/dynamics/shape.ce.js.map +1 -0
  61. package/dist/components/dynamics/text.ce.js +50 -0
  62. package/dist/components/dynamics/text.ce.js.map +1 -0
  63. package/dist/components/gui/box.ce.js +26 -0
  64. package/dist/components/gui/box.ce.js.map +1 -0
  65. package/dist/components/gui/dialogbox/index.ce.js +198 -0
  66. package/dist/components/gui/dialogbox/index.ce.js.map +1 -0
  67. package/dist/components/gui/gameover.ce.js +169 -0
  68. package/dist/components/gui/gameover.ce.js.map +1 -0
  69. package/dist/components/gui/hud/hud.ce.js +83 -0
  70. package/dist/components/gui/hud/hud.ce.js.map +1 -0
  71. package/dist/components/gui/index.d.ts +15 -3
  72. package/dist/components/gui/index.js +14 -0
  73. package/dist/components/gui/menu/equip-menu.ce.js +427 -0
  74. package/dist/components/gui/menu/equip-menu.ce.js.map +1 -0
  75. package/dist/components/gui/menu/exit-menu.ce.js +55 -0
  76. package/dist/components/gui/menu/exit-menu.ce.js.map +1 -0
  77. package/dist/components/gui/menu/items-menu.ce.js +326 -0
  78. package/dist/components/gui/menu/items-menu.ce.js.map +1 -0
  79. package/dist/components/gui/menu/main-menu.ce.js +399 -0
  80. package/dist/components/gui/menu/main-menu.ce.js.map +1 -0
  81. package/dist/components/gui/menu/options-menu.ce.js +49 -0
  82. package/dist/components/gui/menu/options-menu.ce.js.map +1 -0
  83. package/dist/components/gui/menu/skills-menu.ce.js +102 -0
  84. package/dist/components/gui/menu/skills-menu.ce.js.map +1 -0
  85. package/dist/components/gui/mobile/index.d.ts +8 -0
  86. package/dist/components/gui/mobile/index.js +21 -0
  87. package/dist/components/gui/mobile/index.js.map +1 -0
  88. package/dist/components/gui/mobile/mobile.ce.js +79 -0
  89. package/dist/components/gui/mobile/mobile.ce.js.map +1 -0
  90. package/dist/components/gui/notification/notification.ce.js +62 -0
  91. package/dist/components/gui/notification/notification.ce.js.map +1 -0
  92. package/dist/components/gui/save-load.ce.js +211 -0
  93. package/dist/components/gui/save-load.ce.js.map +1 -0
  94. package/dist/components/gui/shop/shop.ce.js +614 -0
  95. package/dist/components/gui/shop/shop.ce.js.map +1 -0
  96. package/dist/components/gui/title-screen.ce.js +164 -0
  97. package/dist/components/gui/title-screen.ce.js.map +1 -0
  98. package/dist/components/index.d.ts +1 -0
  99. package/dist/components/index.js +4 -0
  100. package/dist/components/player-components-utils.d.ts +67 -0
  101. package/dist/components/player-components-utils.js +162 -0
  102. package/dist/components/player-components-utils.js.map +1 -0
  103. package/dist/components/player-components-utils.spec.d.ts +1 -0
  104. package/dist/components/player-components.ce.js +188 -0
  105. package/dist/components/player-components.ce.js.map +1 -0
  106. package/dist/components/prebuilt/hp-bar.ce.js +113 -0
  107. package/dist/components/prebuilt/hp-bar.ce.js.map +1 -0
  108. package/dist/components/prebuilt/index.d.ts +19 -0
  109. package/dist/components/prebuilt/index.js +2 -0
  110. package/dist/components/prebuilt/light-halo.ce.js +70 -0
  111. package/dist/components/prebuilt/light-halo.ce.js.map +1 -0
  112. package/dist/components/scenes/canvas.ce.js +196 -0
  113. package/dist/components/scenes/canvas.ce.js.map +1 -0
  114. package/dist/components/scenes/draw-map.ce.js +79 -0
  115. package/dist/components/scenes/draw-map.ce.js.map +1 -0
  116. package/dist/components/scenes/event-layer.ce.js +29 -0
  117. package/dist/components/scenes/event-layer.ce.js.map +1 -0
  118. package/dist/core/inject.js +18 -0
  119. package/dist/core/inject.js.map +1 -0
  120. package/dist/core/setup.js +16 -0
  121. package/dist/core/setup.js.map +1 -0
  122. package/dist/decorators/spritesheet.d.ts +1 -0
  123. package/dist/decorators/spritesheet.js +11 -0
  124. package/dist/decorators/spritesheet.js.map +1 -0
  125. package/dist/index.d.ts +16 -1
  126. package/dist/index.js +45 -14
  127. package/dist/module.d.ts +43 -4
  128. package/dist/module.js +179 -0
  129. package/dist/module.js.map +1 -0
  130. package/dist/node_modules/.pnpm/@signe_di@3.0.1/node_modules/@signe/di/dist/index.js +167 -0
  131. package/dist/node_modules/.pnpm/@signe_di@3.0.1/node_modules/@signe/di/dist/index.js.map +1 -0
  132. package/dist/node_modules/.pnpm/@signe_reactive@3.0.1/node_modules/@signe/reactive/dist/index.js +239 -0
  133. package/dist/node_modules/.pnpm/@signe_reactive@3.0.1/node_modules/@signe/reactive/dist/index.js.map +1 -0
  134. package/dist/node_modules/.pnpm/@signe_room@3.0.1/node_modules/@signe/room/dist/chunk-EUXUH3YW.js +13 -0
  135. package/dist/node_modules/.pnpm/@signe_room@3.0.1/node_modules/@signe/room/dist/chunk-EUXUH3YW.js.map +1 -0
  136. package/dist/node_modules/.pnpm/@signe_room@3.0.1/node_modules/@signe/room/dist/index.js +696 -0
  137. package/dist/node_modules/.pnpm/@signe_room@3.0.1/node_modules/@signe/room/dist/index.js.map +1 -0
  138. package/dist/node_modules/.pnpm/@signe_sync@3.0.1/node_modules/@signe/sync/dist/client/index.js +44 -0
  139. package/dist/node_modules/.pnpm/@signe_sync@3.0.1/node_modules/@signe/sync/dist/client/index.js.map +1 -0
  140. package/dist/node_modules/.pnpm/@signe_sync@3.0.1/node_modules/@signe/sync/dist/index.js +241 -0
  141. package/dist/node_modules/.pnpm/@signe_sync@3.0.1/node_modules/@signe/sync/dist/index.js.map +1 -0
  142. package/dist/node_modules/.pnpm/partysocket@1.1.3/node_modules/partysocket/dist/chunk-HAC622V3.js +115 -0
  143. package/dist/node_modules/.pnpm/partysocket@1.1.3/node_modules/partysocket/dist/chunk-HAC622V3.js.map +1 -0
  144. package/dist/node_modules/.pnpm/partysocket@1.1.3/node_modules/partysocket/dist/chunk-S74YV6PU.js +401 -0
  145. package/dist/node_modules/.pnpm/partysocket@1.1.3/node_modules/partysocket/dist/chunk-S74YV6PU.js.map +1 -0
  146. package/dist/node_modules/.pnpm/partysocket@1.1.3/node_modules/partysocket/dist/index.js +2 -0
  147. package/dist/node_modules/.pnpm/zod@3.24.2/node_modules/zod/lib/index.js +3756 -0
  148. package/dist/node_modules/.pnpm/zod@3.24.2/node_modules/zod/lib/index.js.map +1 -0
  149. package/dist/presets/animation.d.ts +31 -0
  150. package/dist/presets/animation.js +39 -0
  151. package/dist/presets/animation.js.map +1 -0
  152. package/dist/presets/faceset.d.ts +30 -0
  153. package/dist/presets/faceset.js +51 -0
  154. package/dist/presets/faceset.js.map +1 -0
  155. package/dist/presets/icon.d.ts +20 -0
  156. package/dist/presets/icon.js +15 -0
  157. package/dist/presets/icon.js.map +1 -0
  158. package/dist/presets/index.d.ts +123 -0
  159. package/dist/presets/index.js +17 -0
  160. package/dist/presets/index.js.map +1 -0
  161. package/dist/presets/lpc.d.ts +89 -0
  162. package/dist/presets/lpc.js +98 -0
  163. package/dist/presets/lpc.js.map +1 -0
  164. package/dist/presets/rmspritesheet.js +42 -0
  165. package/dist/presets/rmspritesheet.js.map +1 -0
  166. package/dist/services/AbstractSocket.d.ts +9 -5
  167. package/dist/services/AbstractSocket.js +11 -0
  168. package/dist/services/AbstractSocket.js.map +1 -0
  169. package/dist/services/keyboardControls.d.ts +15 -0
  170. package/dist/services/keyboardControls.js +23 -0
  171. package/dist/services/keyboardControls.js.map +1 -0
  172. package/dist/services/loadMap.d.ts +6 -0
  173. package/dist/services/loadMap.js +123 -0
  174. package/dist/services/loadMap.js.map +1 -0
  175. package/dist/services/mmorpg.d.ts +21 -9
  176. package/dist/services/mmorpg.js +136 -0
  177. package/dist/services/mmorpg.js.map +1 -0
  178. package/dist/services/save.d.ts +19 -0
  179. package/dist/services/save.js +77 -0
  180. package/dist/services/save.js.map +1 -0
  181. package/dist/services/save.spec.d.ts +1 -0
  182. package/dist/services/standalone.d.ts +67 -7
  183. package/dist/services/standalone.js +168 -0
  184. package/dist/services/standalone.js.map +1 -0
  185. package/dist/utils/getEntityProp.d.ts +39 -0
  186. package/dist/utils/getEntityProp.js +53 -0
  187. package/dist/utils/getEntityProp.js.map +1 -0
  188. package/dist/utils/getEntityProp.spec.d.ts +1 -0
  189. package/dist/utils/readPropValue.d.ts +2 -0
  190. package/dist/utils/readPropValue.js +13 -0
  191. package/dist/utils/readPropValue.js.map +1 -0
  192. package/package.json +14 -11
  193. package/src/Game/AnimationManager.spec.ts +30 -0
  194. package/src/Game/AnimationManager.ts +33 -0
  195. package/src/Game/Event.ts +1 -1
  196. package/src/Game/Map.ts +184 -3
  197. package/src/Game/Object.ts +409 -14
  198. package/src/Game/Player.ts +1 -1
  199. package/src/Gui/Gui.spec.ts +273 -0
  200. package/src/Gui/Gui.ts +566 -23
  201. package/src/Gui/NotificationManager.ts +69 -0
  202. package/src/Resource.ts +149 -0
  203. package/src/RpgClient.ts +309 -14
  204. package/src/RpgClientEngine.ts +1790 -63
  205. package/src/Sound.ts +253 -0
  206. package/src/components/{effects → animations}/animation.ce +3 -6
  207. package/src/components/{effects → animations}/index.ts +1 -1
  208. package/src/components/character.ce +801 -59
  209. package/src/components/dynamics/bar.ce +87 -0
  210. package/src/components/dynamics/image.ce +20 -0
  211. package/src/components/dynamics/parse-value.spec.ts +83 -0
  212. package/src/components/dynamics/parse-value.ts +154 -0
  213. package/src/components/dynamics/shape-utils.spec.ts +46 -0
  214. package/src/components/dynamics/shape-utils.ts +61 -0
  215. package/src/components/dynamics/shape.ce +89 -0
  216. package/src/components/dynamics/text.ce +68 -0
  217. package/src/components/gui/box.ce +17 -0
  218. package/src/components/gui/dialogbox/index.ce +213 -187
  219. package/src/components/gui/gameover.ce +158 -0
  220. package/src/components/gui/hud/hud.ce +61 -0
  221. package/src/components/gui/index.ts +30 -4
  222. package/src/components/gui/menu/equip-menu.ce +410 -0
  223. package/src/components/gui/menu/exit-menu.ce +41 -0
  224. package/src/components/gui/menu/items-menu.ce +317 -0
  225. package/src/components/gui/menu/main-menu.ce +294 -0
  226. package/src/components/gui/menu/options-menu.ce +35 -0
  227. package/src/components/gui/menu/skills-menu.ce +83 -0
  228. package/src/components/gui/mobile/index.ts +24 -0
  229. package/src/components/gui/mobile/mobile.ce +80 -0
  230. package/src/components/gui/notification/notification.ce +51 -0
  231. package/src/components/gui/save-load.ce +208 -0
  232. package/src/components/gui/shop/shop.ce +493 -0
  233. package/src/components/gui/title-screen.ce +163 -0
  234. package/src/components/index.ts +3 -0
  235. package/src/components/player-components-utils.spec.ts +109 -0
  236. package/src/components/player-components-utils.ts +205 -0
  237. package/src/components/player-components.ce +221 -0
  238. package/src/components/prebuilt/hp-bar.ce +255 -0
  239. package/src/components/prebuilt/index.ts +24 -0
  240. package/src/components/prebuilt/light-halo.ce +148 -0
  241. package/src/components/scenes/canvas.ce +185 -21
  242. package/src/components/scenes/draw-map.ce +55 -21
  243. package/src/components/scenes/event-layer.ce +8 -2
  244. package/src/components/scenes/transition.ce +60 -0
  245. package/src/core/setup.ts +2 -2
  246. package/src/decorators/spritesheet.ts +8 -0
  247. package/src/index.ts +17 -2
  248. package/src/module.ts +132 -10
  249. package/src/presets/animation.ts +46 -0
  250. package/src/presets/faceset.ts +60 -0
  251. package/src/presets/icon.ts +17 -0
  252. package/src/presets/index.ts +9 -1
  253. package/src/presets/lpc.ts +108 -0
  254. package/src/services/AbstractSocket.ts +10 -2
  255. package/src/services/keyboardControls.ts +20 -0
  256. package/src/services/loadMap.ts +3 -1
  257. package/src/services/mmorpg.ts +106 -12
  258. package/src/services/save.spec.ts +127 -0
  259. package/src/services/save.ts +103 -0
  260. package/src/services/standalone.ts +110 -18
  261. package/src/utils/getEntityProp.spec.ts +96 -0
  262. package/src/utils/getEntityProp.ts +88 -0
  263. package/src/utils/readPropValue.ts +16 -0
  264. package/vite.config.ts +4 -2
  265. package/dist/Game/EffectManager.d.ts +0 -5
  266. package/dist/components/effects/index.d.ts +0 -4
  267. package/dist/index.js.map +0 -1
  268. package/dist/index10.js +0 -8
  269. package/dist/index10.js.map +0 -1
  270. package/dist/index11.js +0 -10
  271. package/dist/index11.js.map +0 -1
  272. package/dist/index12.js +0 -8
  273. package/dist/index12.js.map +0 -1
  274. package/dist/index13.js +0 -17
  275. package/dist/index13.js.map +0 -1
  276. package/dist/index14.js +0 -107
  277. package/dist/index14.js.map +0 -1
  278. package/dist/index15.js +0 -50
  279. package/dist/index15.js.map +0 -1
  280. package/dist/index16.js +0 -191
  281. package/dist/index16.js.map +0 -1
  282. package/dist/index17.js +0 -9
  283. package/dist/index17.js.map +0 -1
  284. package/dist/index18.js +0 -387
  285. package/dist/index18.js.map +0 -1
  286. package/dist/index19.js +0 -31
  287. package/dist/index19.js.map +0 -1
  288. package/dist/index2.js +0 -181
  289. package/dist/index2.js.map +0 -1
  290. package/dist/index20.js +0 -24
  291. package/dist/index20.js.map +0 -1
  292. package/dist/index21.js +0 -2421
  293. package/dist/index21.js.map +0 -1
  294. package/dist/index22.js +0 -114
  295. package/dist/index22.js.map +0 -1
  296. package/dist/index23.js +0 -109
  297. package/dist/index23.js.map +0 -1
  298. package/dist/index24.js +0 -71
  299. package/dist/index24.js.map +0 -1
  300. package/dist/index25.js +0 -21
  301. package/dist/index25.js.map +0 -1
  302. package/dist/index26.js +0 -41
  303. package/dist/index26.js.map +0 -1
  304. package/dist/index27.js +0 -5
  305. package/dist/index27.js.map +0 -1
  306. package/dist/index28.js +0 -322
  307. package/dist/index28.js.map +0 -1
  308. package/dist/index29.js +0 -27
  309. package/dist/index29.js.map +0 -1
  310. package/dist/index3.js +0 -87
  311. package/dist/index3.js.map +0 -1
  312. package/dist/index30.js +0 -11
  313. package/dist/index30.js.map +0 -1
  314. package/dist/index31.js +0 -11
  315. package/dist/index31.js.map +0 -1
  316. package/dist/index32.js +0 -174
  317. package/dist/index32.js.map +0 -1
  318. package/dist/index33.js +0 -501
  319. package/dist/index33.js.map +0 -1
  320. package/dist/index34.js +0 -12
  321. package/dist/index34.js.map +0 -1
  322. package/dist/index35.js +0 -4403
  323. package/dist/index35.js.map +0 -1
  324. package/dist/index36.js +0 -316
  325. package/dist/index36.js.map +0 -1
  326. package/dist/index37.js +0 -61
  327. package/dist/index37.js.map +0 -1
  328. package/dist/index38.js +0 -20
  329. package/dist/index38.js.map +0 -1
  330. package/dist/index39.js +0 -20
  331. package/dist/index39.js.map +0 -1
  332. package/dist/index4.js +0 -67
  333. package/dist/index4.js.map +0 -1
  334. package/dist/index5.js +0 -16
  335. package/dist/index5.js.map +0 -1
  336. package/dist/index6.js +0 -17
  337. package/dist/index6.js.map +0 -1
  338. package/dist/index7.js +0 -39
  339. package/dist/index7.js.map +0 -1
  340. package/dist/index8.js +0 -108
  341. package/dist/index8.js.map +0 -1
  342. package/dist/index9.js +0 -76
  343. package/dist/index9.js.map +0 -1
  344. package/src/Game/EffectManager.ts +0 -20
  345. package/src/components/gui/dialogbox/itemMenu.ce +0 -23
  346. package/src/components/gui/dialogbox/selection.ce +0 -67
  347. /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,35 +1,66 @@
1
- <Canvas width={@engine.width} height={@engine.height}>
2
- <Viewport worldWidth worldHeight clamp>
3
- @if (sceneData) {
4
- <SceneMap />
1
+ <Canvas width={engine.width} height={engine.height}>
2
+ <Viewport worldWidth worldHeight clamp sortableChildren={true}>
3
+ @if (lightingAmbientEnabled()) {
4
+ <NightAmbiant
5
+ spots={nightLights}
6
+ darkness={lightingDarknessProps}
7
+ haze={lightingHaze}
8
+ />
5
9
  }
10
+ @if (shadowEnabled()) {
11
+ <SpriteShadows
12
+ lights={shadowLights}
13
+ ambientLight={shadowAmbientLight}
14
+ minInfluence={shadowMinInfluence}
15
+ falloffPower={shadowFalloffPower}
16
+ mode={shadowMode}
17
+ updateHz={shadowUpdateHz}
18
+ scanHz={shadowScanHz}
19
+ cullToViewport={shadowCullToViewport}
20
+ shadowColor={shadowColor}
21
+ />
22
+ }
23
+ <SceneMap />
6
24
  </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
- }
25
+ @for (gui of guiList) {
26
+ <Container display="flex">
27
+ @if (gui.display) {
28
+ <gui.component data={gui.data} dependencies={gui.dependencies} onFinish={(data) => {
29
+ onGuiFinish(gui, data)
30
+ }} onInteraction={(name, data) => {
31
+ onGuiInteraction(gui, name, data)
32
+ }} />
33
+ }
34
+ </Container>
35
+ }
18
36
  </Canvas>
19
37
 
20
38
  <script>
21
- import { signal, computed, effect } from "canvasengine";
39
+ import { computed, effect } from "canvasengine";
22
40
  import { inject } from "../../core/inject";
23
41
  import { RpgClientEngine } from "../../RpgClientEngine";
24
42
  import SceneMap from './draw-map.ce'
25
43
  import { RpgGui } from "../../Gui/Gui";
44
+ import { delay } from "@rpgjs/common";
45
+ import { NightAmbiant, SpriteShadows } from '@canvasengine/presets'
26
46
 
27
47
  const engine = inject(RpgClientEngine);
28
48
  const guiService = inject(RpgGui);
29
49
  const sceneData = engine.sceneMap.data
30
- const gui = guiService.gui
31
- const worldWidth = computed(() => sceneData()?.width)
32
- const worldHeight = computed(() => sceneData()?.height)
50
+ const lighting = engine.sceneMap.lighting
51
+ const guiList = computed(() => {
52
+ return Object.values(guiService.gui()).filter((gui) => !gui.attachToSprite)
53
+ })
54
+ const worldWidth = computed(() => {
55
+ const data = sceneData?.()
56
+ const scale = Number(data?.params?.scale ?? 1) || 1
57
+ return Number(data?.width ?? data?.params?.width ?? 2048) * scale
58
+ })
59
+ const worldHeight = computed(() => {
60
+ const data = sceneData?.()
61
+ const scale = Number(data?.params?.scale ?? 1) || 1
62
+ return Number(data?.height ?? data?.params?.height ?? 2048) * scale
63
+ })
33
64
 
34
65
  effect(() => {
35
66
  if (sceneData() && !sceneData().component) {
@@ -38,14 +69,147 @@
38
69
  })
39
70
 
40
71
  const onGuiFinish = (gui, data) => {
41
- guiService.guiClose(gui.name, data)
72
+ delay(() => {
73
+ guiService.guiClose(gui.name, data)
74
+ })
42
75
  }
43
76
 
44
77
  const onGuiInteraction = (gui, name, data) => {
45
78
  guiService.guiInteraction(gui.name, name, data)
46
79
  }
47
-
80
+
48
81
  const clamp = {
49
82
  direction: "all"
50
83
  }
84
+ const NIGHT_SPOT_RADIUS_SCALE = 4.25
85
+ const NIGHT_SPOT_MIN_RADIUS = 170
86
+ const NIGHT_SPOT_MIN_INTENSITY = 1
87
+ const SHADOW_SPOT_RADIUS_SCALE = 12
88
+ const SHADOW_SPOT_MIN_RADIUS = 480
89
+ const SHADOW_SPOT_MIN_INTENSITY = 1.35
90
+
91
+ const nightSpotRadius = (radius) => Math.max(radius * NIGHT_SPOT_RADIUS_SCALE, NIGHT_SPOT_MIN_RADIUS)
92
+ const shadowSpotRadius = (radius) => Math.max(radius * SHADOW_SPOT_RADIUS_SCALE, SHADOW_SPOT_MIN_RADIUS)
93
+ const nightSpotIntensity = (intensity, fallback) => Math.max(intensity ?? fallback, NIGHT_SPOT_MIN_INTENSITY)
94
+ const shadowSpotIntensity = (intensity) => Math.max(intensity ?? 1.3, SHADOW_SPOT_MIN_INTENSITY)
95
+
96
+ const lightingAmbient = computed(() => {
97
+ const state = lighting?.()
98
+ return state?.ambient ?? {}
99
+ })
100
+
101
+ const nightLights = computed(() => {
102
+ const state = lighting?.()
103
+ return (state?.spots ?? []).map((spot, index) => {
104
+ const radius = spot.radius ?? 180
105
+ return {
106
+ x: spot.x,
107
+ y: spot.y,
108
+ radius: nightSpotRadius(radius),
109
+ intensity: nightSpotIntensity(spot.intensity, index === 0 ? 1 : 0.92),
110
+ flicker: spot.flicker,
111
+ flickerSpeed: spot.flickerSpeed ?? 14,
112
+ pulse: spot.pulse,
113
+ pulseSpeed: spot.pulseSpeed,
114
+ phase: spot.phase,
115
+ }
116
+ })
117
+ })
118
+ const hasLightSpots = computed(() => {
119
+ const state = lighting?.()
120
+ return (state?.spots?.length ?? 0) > 0
121
+ })
122
+
123
+ const lightingDarkness = computed(() => {
124
+ const darkness = lightingAmbient().darkness
125
+ return typeof darkness === "number" ? darkness : 0
126
+ })
127
+
128
+ const lightingAmbientEnabled = computed(() => {
129
+ const state = lighting?.()
130
+ return Boolean(state && lightingDarkness() > 0)
131
+ })
132
+
133
+ const lightingDarknessProps = computed(() => ({
134
+ opacity: lightingDarkness(),
135
+ color: lightingAmbient().darkColor ?? "#080a12",
136
+ }))
137
+ const lightingHaze = computed(() => ({
138
+ color: lightingAmbient().fogColor ?? "#12182a",
139
+ radius: lightingAmbient().fogRadius ?? 0.44,
140
+ softness: lightingAmbient().fogSoftness ?? 0.3,
141
+ opacity: lightingAmbient().fogOpacity ?? 0.35,
142
+ }))
143
+
144
+ const defaultSunLight = () => {
145
+ const data = sceneData?.()
146
+ const width = Number(data?.width ?? data?.params?.width ?? 2048)
147
+ const height = Number(data?.height ?? data?.params?.height ?? 2048)
148
+ const scale = Number(data?.params?.scale ?? 1) || 1
149
+ const mapWidth = width * scale
150
+ const mapHeight = height * scale
151
+
152
+ return {
153
+ x: -mapWidth * 0.35,
154
+ y: -mapHeight * 0.45,
155
+ z: 520,
156
+ radius: Math.max(mapWidth, mapHeight) * 2.5,
157
+ intensity: 0.85,
158
+ shadowWeight: lightingDarkness() > 0 ? 2.2 : 1,
159
+ enabled: true,
160
+ }
161
+ }
162
+
163
+ const shadowState = computed(() => {
164
+ const state = lighting?.()
165
+ return state?.shadows ?? null
166
+ })
167
+
168
+ const shadowLights = computed(() => {
169
+ const state = lighting?.()
170
+ const defaultSun = defaultSunLight()
171
+ const sun = {
172
+ ...defaultSun,
173
+ ...(state?.sun ?? {}),
174
+ shadowWeight: state?.sun?.shadowWeight ?? defaultSun.shadowWeight,
175
+ }
176
+ const spotLights = (state?.spots ?? []).map((spot) => {
177
+ const radius = spot.radius ?? 180
178
+ return {
179
+ x: spot.x,
180
+ y: spot.y,
181
+ z: 170,
182
+ radius: shadowSpotRadius(radius),
183
+ intensity: shadowSpotIntensity(spot.intensity),
184
+ shadowWeight: 2.4,
185
+ enabled: true,
186
+ }
187
+ })
188
+
189
+ return [
190
+ ...((sun.enabled === false || sun.intensity <= 0) ? [] : [sun]),
191
+ ...spotLights,
192
+ ]
193
+ })
194
+
195
+ const shadowAmbientLight = computed(() => {
196
+ const shadows = shadowState()
197
+ if (shadows?.ambientLight === null || shadows?.ambientLight?.enabled === false) {
198
+ return null
199
+ }
200
+ return shadows?.ambientLight ?? { x: -0.18, y: -1, z: 420, intensity: 0.32, shadowWeight: 1 }
201
+ })
202
+
203
+ const shadowEnabled = computed(() => {
204
+ const shadows = shadowState()
205
+ return Boolean((shadows?.enabled || hasLightSpots()) && (shadowLights().length > 0 || shadowAmbientLight()))
206
+ })
207
+
208
+ const shadowMode = computed(() => shadowState()?.mode ?? "strongest")
209
+ const shadowUpdateHz = computed(() => shadowState()?.updateHz ?? 60)
210
+ const shadowScanHz = computed(() => shadowState()?.scanHz ?? 8)
211
+ const shadowCullToViewport = computed(() => shadowState()?.cullToViewport ?? true)
212
+ const shadowMinInfluence = computed(() => shadowState()?.minInfluence ?? 0.24)
213
+ const shadowFalloffPower = computed(() => shadowState()?.falloffPower ?? 0.85)
214
+ const shadowColor = computed(() => shadowState()?.shadowColor ?? "#05070d")
51
215
  </script>