@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
@@ -1,73 +1,320 @@
1
- <Container x y zIndex={y} viewportFollow={isMe} controls>
2
- @for (component of componentsBehind) {
1
+ <Container x={smoothX} y={smoothY} zIndex={z} viewportFollow={shouldFollowCamera} controls onBeforeDestroy visible>
2
+ @for (compConfig of normalizedComponentsBehind) {
3
3
  <Container>
4
- <component object />
4
+ <compConfig.component object ...compConfig.props />
5
5
  </Container>
6
6
  }
7
- <Particle emit={@emitParticleTrigger} settings={@particleSettings} zIndex={1000} name={particleName} />
7
+ <PlayerComponents object position="bottom" graphicBounds />
8
+ <PlayerComponents object position="left" graphicBounds />
9
+ <Particle emit={emitParticleTrigger} settings={particleSettings} zIndex={1000} name={particleName} />
8
10
  <Container>
9
- @for (graphicId of graphics) {
10
- <Sprite sheet={@sheet(@graphicId)} direction tint />
11
+ @for (graphicObj of graphicsSignals) {
12
+ <Container scale={graphicScale(graphicObj)}>
13
+ <Sprite
14
+ sheet={sheet(graphicObj)}
15
+ direction
16
+ tint
17
+ hitbox
18
+ shadowCaster={shadowCaster(graphicObj)}
19
+ flash={flashConfig}
20
+ />
21
+ </Container>
11
22
  }
12
23
  </Container>
13
- @for (component of componentsInFront) {
14
- <Container>
15
- <component object />
24
+ <PlayerComponents object position="center" graphicBounds />
25
+ <PlayerComponents object position="right" graphicBounds />
26
+ <PlayerComponents object position="top" graphicBounds />
27
+ @for (compConfig of normalizedComponentsInFront) {
28
+ <Container dependencies={compConfig.dependencies}>
29
+ <compConfig.component object ...compConfig.props />
16
30
  </Container>
17
- }
18
- <!-- <Ellipse
19
- x={shadow.@x}
20
- y={shadow.@y}
21
- width={shadow.@width}
22
- height={shadow.@height}
23
- color="black"
24
- blur={10}
25
- alpha={0.5}
26
- /> -->
31
+ }
32
+ @for (attachedGui of attachedGuis) {
33
+ @if (shouldDisplayAttachedGui) {
34
+ <Container>
35
+ <attachedGui.component ...attachedGui.data() dependencies={attachedGui.dependencies} object={object} onFinish={(data) => {
36
+ onAttachedGuiFinish(attachedGui, data)
37
+ }} onInteraction={(name, data) => {
38
+ onAttachedGuiInteraction(attachedGui, name, data)
39
+ }} />
40
+ </Container>
41
+ }
42
+ }
27
43
  </Container>
28
44
 
29
45
  <script>
30
- import { signal, effect, mount, computed, tick } from "canvasengine";
46
+ import { signal, effect, mount, computed, tick, animatedSignal, on } from "canvasengine";
47
+ import { Assets } from "pixi.js";
48
+
49
+ import { lastValueFrom, combineLatest, pairwise, filter, map, startWith } from "rxjs";
31
50
  import { Particle } from "@canvasengine/presets";
32
51
  import { GameEngineToken, ModulesToken } from "@rpgjs/common";
33
52
  import { RpgClientEngine } from "../RpgClientEngine";
34
53
  import { inject } from "../core/inject";
35
- import { Direction } from "@rpgjs/common";
54
+ import { Direction, Animation } from "@rpgjs/common";
36
55
  import Hit from "./effects/hit.ce";
56
+ import PlayerComponents from "./player-components.ce";
57
+ import { RpgGui } from "../Gui/Gui";
58
+ import { getCanMoveValue } from "../utils/readPropValue";
37
59
 
38
60
  const { object, id } = defineProps();
39
-
61
+
40
62
  const client = inject(RpgClientEngine);
41
63
  const hooks = inject(ModulesToken);
64
+ const guiService = inject(RpgGui);
42
65
 
43
66
  const spritesheets = client.spritesheets;
44
- const playerId = client.playerId;
45
67
  const componentsBehind = client.spriteComponentsBehind;
46
68
  const componentsInFront = client.spriteComponentsInFront;
47
- const isMe = computed(() => id() === playerId);
48
-
49
- const x = object.x;
50
- const y = object.y;
51
- const tint = object.tint;
52
- const direction = object.direction;
53
- const animationName = object.animationName;
54
- const emitParticleTrigger = object.emitParticleTrigger;
69
+ const readProp = (value) => typeof value === 'function' ? value() : value;
70
+ const isCurrentPlayer = () => {
71
+ const playerId = client.playerIdSignal();
72
+ const currentPlayer = playerId ? client.sceneMap?.players?.()?.[playerId] : undefined;
73
+ return readProp(id) === playerId
74
+ || readProp(object?.id) === playerId
75
+ || object === currentPlayer
76
+ || object === client.sceneMap?.getCurrentPlayer?.();
77
+ };
78
+ const isMe = computed(isCurrentPlayer);
79
+ const shadowsEnabled = computed(() => {
80
+ const lighting = client.sceneMap?.lighting?.();
81
+ return Boolean(lighting?.shadows?.enabled || (lighting?.spots?.length ?? 0) > 0);
82
+ });
83
+
84
+ /**
85
+ * Normalize a single sprite component configuration
86
+ *
87
+ * Handles both direct component references and configuration objects with optional props and dependencies.
88
+ * Extracts the component reference and creates a computed function that returns the props.
89
+ *
90
+ * ## Design
91
+ *
92
+ * Supports two formats:
93
+ * 1. Direct component: `ShadowComponent`
94
+ * 2. Configuration object: `{ component: LightHalo, props: {...}, dependencies: (object) => [...] }`
95
+ *
96
+ * The normalization process:
97
+ * - Extracts the actual component from either format
98
+ * - Extracts dependencies function if provided
99
+ * - Creates a computed function that returns props (static object or dynamic function result)
100
+ * - Returns a normalized object with `component`, `props`, and `dependencies`
101
+ *
102
+ * @param comp - Component reference or configuration object
103
+ * @returns Normalized component configuration with component, props, and dependencies
104
+ *
105
+ * @example
106
+ * ```ts
107
+ * // Direct component
108
+ * normalizeComponent(ShadowComponent)
109
+ * // => { component: ShadowComponent, props: {}, dependencies: undefined }
110
+ *
111
+ * // With static props
112
+ * normalizeComponent({ component: LightHalo, props: { radius: 30 } })
113
+ * // => { component: LightHalo, props: { radius: 30 }, dependencies: undefined }
114
+ *
115
+ * // With dynamic props and dependencies
116
+ * normalizeComponent({
117
+ * component: HealthBar,
118
+ * props: (object) => ({ hp: object.hp(), maxHp: object.param.maxHp() }),
119
+ * dependencies: (object) => [object.hp, object.param.maxHp]
120
+ * })
121
+ * // => { component: HealthBar, props: {...}, dependencies: (object) => [...] }
122
+ * ```
123
+ */
124
+ const normalizeComponent = (comp) => {
125
+ let componentRef;
126
+ let propsValue;
127
+ let dependenciesFn;
128
+
129
+ // If it's a direct component reference
130
+ if (typeof comp === 'function' || (comp && typeof comp === 'object' && !comp.component)) {
131
+ componentRef = comp;
132
+ propsValue = undefined;
133
+ dependenciesFn = undefined;
134
+ }
135
+ // If it's a configuration object with component and props
136
+ else if (comp && typeof comp === 'object' && comp.component) {
137
+ componentRef = comp.component;
138
+ // Support both "data" (legacy) and "props" (new) for backward compatibility
139
+ propsValue = comp.props !== undefined ? comp.props : comp.data;
140
+ dependenciesFn = comp.dependencies;
141
+ }
142
+ // Fallback: treat as direct component
143
+ else {
144
+ componentRef = comp;
145
+ propsValue = undefined;
146
+ dependenciesFn = undefined;
147
+ }
148
+
149
+ // Return props directly (object or function), not as computed
150
+ // The computed will be created in the template when needed
151
+ return {
152
+ component: componentRef,
153
+ props: typeof propsValue === 'function' ? propsValue(object) : propsValue || {},
154
+ dependencies: dependenciesFn ? dependenciesFn(object) : []
155
+ };
156
+ };
157
+
158
+ /**
159
+ * Normalize an array of sprite components
160
+ *
161
+ * Applies normalization to each component in the array using `normalizeComponent`.
162
+ *
163
+ * @param components - Array of component references or configuration objects
164
+ * @returns Array of normalized component configurations
165
+ */
166
+ const normalizeComponents = (components) => {
167
+ return components.map((comp) => normalizeComponent(comp));
168
+ };
169
+
170
+
171
+ /**
172
+ * Normalized components to render behind sprites
173
+ * Handles both direct component references and configuration objects with optional props and dependencies
174
+ *
175
+ * Supports multiple formats:
176
+ * 1. Direct component: `ShadowComponent`
177
+ * 2. Configuration object: `{ component: LightHalo, props: {...} }`
178
+ * 3. With dynamic props: `{ component: LightHalo, props: (object) => {...} }`
179
+ * 4. With dependencies: `{ component: HealthBar, dependencies: (object) => [object.hp, object.param.maxHp] }`
180
+ *
181
+ * Components with dependencies will only be displayed when all dependencies are resolved (!= undefined).
182
+ * The object is passed to the dependencies function to allow sprite-specific dependency resolution.
183
+ *
184
+ * @example
185
+ * ```ts
186
+ * // Direct component
187
+ * componentsBehind: [ShadowComponent]
188
+ *
189
+ * // With static props
190
+ * componentsBehind: [{ component: LightHalo, props: { radius: 30 } }]
191
+ *
192
+ * // With dynamic props and dependencies
193
+ * componentsBehind: [{
194
+ * component: HealthBar,
195
+ * props: (object) => ({ hp: object.hp(), maxHp: object.param.maxHp() }),
196
+ * dependencies: (object) => [object.hp, object.param.maxHp]
197
+ * }]
198
+ * ```
199
+ */
200
+ const normalizedComponentsBehind = computed(() => {
201
+ return normalizeComponents(componentsBehind());
202
+ });
203
+
204
+ /**
205
+ * Normalized components to render in front of sprites
206
+ * Handles both direct component references and configuration objects with optional props and dependencies
207
+ *
208
+ * See `normalizedComponentsBehind` for format details.
209
+ * Components with dependencies will only be displayed when all dependencies are resolved.
210
+ */
211
+ const normalizedComponentsInFront = computed(() => {
212
+ return normalizeComponents(componentsInFront());
213
+ });
214
+
215
+ /**
216
+ * Determine if the camera should follow this sprite
217
+ *
218
+ * The camera follows this sprite if:
219
+ * - It's explicitly set as the camera follow target, OR
220
+ * - It's the current player and no explicit target is set (default behavior)
221
+ */
222
+ const shouldFollowCamera = computed(() => {
223
+ const cameraTargetId = client.cameraFollowTargetId();
224
+ // If a target is explicitly set, only follow if this sprite is the target
225
+ if (cameraTargetId !== null) {
226
+ return id() === cameraTargetId;
227
+ }
228
+ // Otherwise, follow the current player (default behavior)
229
+ return isMe();
230
+ });
231
+
232
+ /**
233
+ * Get all attached GUI components that should be rendered on sprites
234
+ * These are GUIs with attachToSprite: true
235
+ */
236
+ const attachedGuis = computed(() => {
237
+ return guiService.getAttachedGuis();
238
+ });
239
+
240
+ /**
241
+ * Check if attached GUIs should be displayed for this sprite
242
+ * This is controlled by showAttachedGui/hideAttachedGui on the server
243
+ */
244
+ const shouldDisplayAttachedGui = computed(() => {
245
+ return guiService.shouldDisplayAttachedGui(id());
246
+ });
247
+
248
+ const {
249
+ x,
250
+ y,
251
+ tint,
252
+ direction,
253
+ animationName,
254
+ animationCurrentIndex,
255
+ emitParticleTrigger,
256
+ particleName,
257
+ graphics,
258
+ hitbox,
259
+ isConnected,
260
+ graphicsSignals,
261
+ flashTrigger
262
+ } = object;
263
+
264
+ /**
265
+ * Flash configuration signals for dynamic options
266
+ * These signals are updated when the flash trigger is activated with options
267
+ */
268
+ const flashType = signal<'alpha' | 'tint' | 'both'>('alpha');
269
+ const flashDuration = signal(300);
270
+ const flashCycles = signal(1);
271
+ const flashAlpha = signal(0.3);
272
+ const flashTint = signal(0xffffff);
273
+
274
+ /**
275
+ * Listen to flash trigger to update configuration dynamically
276
+ * When flash is triggered with options, update the signals
277
+ */
278
+ on(flashTrigger, (data) => {
279
+ if (data && typeof data === 'object') {
280
+ if (data.type !== undefined) flashType.set(data.type);
281
+ if (data.duration !== undefined) flashDuration.set(data.duration);
282
+ if (data.cycles !== undefined) flashCycles.set(data.cycles);
283
+ if (data.alpha !== undefined) flashAlpha.set(data.alpha);
284
+ if (data.tint !== undefined) flashTint.set(data.tint);
285
+ }
286
+ });
287
+
288
+ /**
289
+ * Flash configuration for the sprite
290
+ *
291
+ * This configuration is used by the flash directive to create visual feedback effects.
292
+ * The flash trigger is exposed through the object, allowing both server events and
293
+ * client-side code to trigger flash animations. Options can be passed dynamically
294
+ * through the trigger, which updates the reactive signals.
295
+ */
296
+ const flashConfig = computed(() => ({
297
+ trigger: flashTrigger,
298
+ type: flashType(),
299
+ duration: flashDuration(),
300
+ cycles: flashCycles(),
301
+ alpha: flashAlpha(),
302
+ tint: flashTint(),
303
+ }));
304
+
55
305
  const particleSettings = client.particleSettings;
56
- const particleName = object.particleName;
57
- const graphics = object.graphics;
58
-
59
- const hitbox = object.hitbox;
60
- const widthShadow = 10;
61
- const shadow = computed(() => ({
62
- x: hitbox().w / 2,
63
- y: hitbox().h - (hitbox().h / 2),
64
- width: hitbox().w + widthShadow,
65
- height: hitbox().h,
66
- }))
67
- const canControls = () => isMe() && object.canMove()
306
+
307
+ const canControls = () => isMe() && getCanMoveValue(object)
68
308
  const keyboardControls = client.globalConfig.keyboardControls;
69
309
 
70
- const controls = signal({
310
+ const visible = computed(() => {
311
+ if (object.isEvent()) {
312
+ return true
313
+ }
314
+ return isConnected()
315
+ });
316
+
317
+ const controls = {
71
318
  down: {
72
319
  repeat: true,
73
320
  bind: keyboardControls.down,
@@ -101,35 +348,530 @@
101
348
  keyDown() {
102
349
  if (canControls()) {
103
350
  client.processAction({ action: 'action' })
104
- // particleName.set('hit')
105
- // emitParticleTrigger.start()
106
- // object.flash('red')
107
351
  }
108
352
  },
109
353
  },
354
+ escape: {
355
+ bind: keyboardControls.escape,
356
+ keyDown() {
357
+ if (canControls()) {
358
+ client.processAction({ action: 'escape' })
359
+ }
360
+ },
361
+ },
362
+ gamepad: {
363
+ enabled: true
364
+ }
365
+ };
366
+
367
+ const smoothX = animatedSignal(x(), {
368
+ duration: isMe() ? 0 : 0
110
369
  });
111
370
 
112
- const sheet = (graphicId) => {
371
+ const smoothY = animatedSignal(y(), {
372
+ duration: isMe() ? 0 : 0,
373
+ });
374
+
375
+ const z = computed(() => {
376
+ return object.y() + object.z()
377
+ });
378
+
379
+ const realAnimationName = signal(animationName());
380
+
381
+ const xSubscription = x.observable.subscribe((value) => {
382
+ smoothX.set(value);
383
+ });
384
+
385
+ const ySubscription = y.observable.subscribe((value) => {
386
+ smoothY.set(value);
387
+ });
388
+
389
+ const sheet = (graphicObject) => {
113
390
  return {
114
- definition: spritesheets.get(graphicId),
115
- playing: animationName,
391
+ definition: graphicObject,
392
+ playing: realAnimationName(),
116
393
  params: {
117
- direction
394
+ direction: direction()
118
395
  },
396
+ onFinish() {
397
+ animationCurrentIndex.update(index => index + 1)
398
+ }
119
399
  };
120
400
  }
121
401
 
122
- mount((element) => {
123
- hooks.callHooks("client-sprite-onInit", element.componentInstance)
124
- hooks.callHooks("client-sceneMap-onAddSprite", client.sceneMap, element.componentInstance)
402
+ const graphicScale = (graphicObject) => {
403
+ const scale = graphicObject?.scale;
404
+ if (Array.isArray(scale)) return scale;
405
+ if (typeof scale === 'number') return [scale, scale];
406
+ if (scale && typeof scale === 'object') {
407
+ const x = typeof scale.x === 'number' ? scale.x : 1;
408
+ const y = typeof scale.y === 'number' ? scale.y : x;
409
+ return [x, y];
410
+ }
411
+ return undefined;
412
+ }
413
+
414
+ const shadowCaster = (graphicObject) => {
415
+ const box = hitbox();
416
+ const bounds = graphicBounds();
417
+ const scale = graphicScale(graphicObject);
418
+ const scaleY = Array.isArray(scale) && typeof scale[1] === 'number' ? Math.abs(scale[1]) : 1;
419
+ const height = Math.max(bounds?.height ?? box?.h ?? 32, box?.h ?? 32) * scaleY;
420
+
421
+ return {
422
+ enabled: shadowsEnabled,
423
+ height,
424
+ footAnchor: { x: 0.5, y: 1 },
425
+ footOffset: { x: 0, y: 2 },
426
+ alpha: 0.5,
427
+ blur: 3.5,
428
+ gradientPower: 2,
429
+ hardness: 0.42,
430
+ minLength: Math.max(6, (box?.h ?? 32) * 0.25),
431
+ maxLength: Math.max(90, height * 1.8),
432
+ contactAlpha: 0.3,
433
+ contactScale: 0.3,
434
+ };
435
+ }
436
+
437
+ const imageDimensions = signal({});
438
+ const loadingImageDimensions = new Set();
439
+
440
+ const toPositiveNumber = (value) => {
441
+ const number = typeof value === 'number' ? value : parseFloat(value);
442
+ return Number.isFinite(number) && number > 0 ? number : undefined;
443
+ };
444
+
445
+ const toFiniteNumber = (value, fallback = 0) => {
446
+ const number = typeof value === 'number' ? value : parseFloat(value);
447
+ return Number.isFinite(number) ? number : fallback;
448
+ };
449
+
450
+ const clampRatio = (value) => Math.min(1, Math.max(0, value));
451
+
452
+ const normalizePair = (value, fallback = [1, 1]) => {
453
+ if (Array.isArray(value)) {
454
+ const x = toFiniteNumber(value[0], fallback[0]);
455
+ const y = toFiniteNumber(value[1] ?? value[0], x);
456
+ return [x, y];
457
+ }
458
+ if (typeof value === 'number') {
459
+ return [value, value];
460
+ }
461
+ if (value && typeof value === 'object') {
462
+ const x = toFiniteNumber(value.x, fallback[0]);
463
+ const y = toFiniteNumber(value.y ?? value.x, x);
464
+ return [x, y];
465
+ }
466
+ return fallback;
467
+ };
468
+
469
+ const normalizeAnchor = (value) => {
470
+ if (!Array.isArray(value)) return undefined;
471
+ const [x, y] = normalizePair(value, [0, 0]);
472
+ return [clampRatio(x), clampRatio(y)];
473
+ };
474
+
475
+ const resolveImageSource = (image) => {
476
+ if (typeof image === 'string') return image;
477
+ if (typeof image?.default === 'string') return image.default;
478
+ return undefined;
479
+ };
125
480
 
126
- return () => {
127
- hooks.callHooks("client-sprite-onDestroy", element.componentInstance)
128
- hooks.callHooks("client-sceneMap-onRemoveSprite", client.sceneMap, element.componentInstance)
481
+ const parentTextureOptions = (graphicObject) => {
482
+ const props = [
483
+ 'width',
484
+ 'height',
485
+ 'framesHeight',
486
+ 'framesWidth',
487
+ 'rectWidth',
488
+ 'rectHeight',
489
+ 'offset',
490
+ 'image',
491
+ 'sound',
492
+ 'spriteRealSize',
493
+ 'scale',
494
+ 'anchor',
495
+ 'pivot',
496
+ 'x',
497
+ 'y',
498
+ 'opacity'
499
+ ];
500
+
501
+ return props.reduce((options, prop) => {
502
+ if (graphicObject?.[prop] !== undefined) {
503
+ options[prop] = graphicObject[prop];
504
+ }
505
+ return options;
506
+ }, {});
507
+ };
508
+
509
+ const resolveTextureOptions = (graphicObject) => {
510
+ const textures = graphicObject?.textures ?? {};
511
+ const texture =
512
+ textures[realAnimationName()] ??
513
+ textures[Animation.Stand] ??
514
+ Object.values(textures)[0] ??
515
+ {};
516
+
517
+ return {
518
+ ...parentTextureOptions(graphicObject),
519
+ ...texture
520
+ };
521
+ };
522
+
523
+ const resolveFirstAnimationFrame = (textureOptions) => {
524
+ const animations = textureOptions?.animations;
525
+ if (!animations) return {};
526
+
527
+ try {
528
+ const frames = typeof animations === 'function'
529
+ ? animations({ direction: direction() })
530
+ : animations;
531
+ if (!Array.isArray(frames)) return {};
532
+ const firstGroup = frames[0];
533
+ return Array.isArray(firstGroup) ? firstGroup[0] ?? {} : firstGroup ?? {};
534
+ }
535
+ catch {
536
+ return {};
129
537
  }
538
+ };
539
+
540
+ const optionValue = (prop, frame, textureOptions, graphicObject) => {
541
+ return frame?.[prop] ?? textureOptions?.[prop] ?? graphicObject?.[prop];
542
+ };
543
+
544
+ const resolveFrameSize = (textureOptions, dimensions) => {
545
+ const framesWidth = toPositiveNumber(textureOptions?.framesWidth) ?? 1;
546
+ const framesHeight = toPositiveNumber(textureOptions?.framesHeight) ?? 1;
547
+ const imageSource = resolveImageSource(textureOptions?.image);
548
+ const loadedSize = imageSource ? dimensions[imageSource] : undefined;
549
+ const fullWidth = toPositiveNumber(textureOptions?.width) ?? loadedSize?.width;
550
+ const fullHeight = toPositiveNumber(textureOptions?.height) ?? loadedSize?.height;
551
+ const width = toPositiveNumber(textureOptions?.rectWidth) ??
552
+ toPositiveNumber(textureOptions?.spriteWidth) ??
553
+ (fullWidth ? fullWidth / framesWidth : undefined);
554
+ const height = toPositiveNumber(textureOptions?.rectHeight) ??
555
+ toPositiveNumber(textureOptions?.spriteHeight) ??
556
+ (fullHeight ? fullHeight / framesHeight : undefined);
557
+
558
+ return {
559
+ width,
560
+ height
561
+ };
562
+ };
563
+
564
+ const resolveHitboxAnchor = (spriteWidth, spriteHeight, realSize, box) => {
565
+ if (!spriteWidth || !spriteHeight || !box) {
566
+ return [0, 0];
567
+ }
568
+
569
+ const heightOfSprite = typeof realSize === 'number' ? realSize : realSize?.height;
570
+ const resolvedHeight = toPositiveNumber(heightOfSprite) ?? spriteHeight;
571
+ const gap = Math.max(0, (spriteHeight - resolvedHeight) / 2);
572
+ const hitboxTopLeftX = clampRatio((spriteWidth - box.w) / 2 / spriteWidth);
573
+ const hitboxTopLeftY = clampRatio((spriteHeight - box.h - gap) / spriteHeight);
574
+ const hitboxCenterX = clampRatio(hitboxTopLeftX + box.w / 2 / spriteWidth);
575
+ const hitboxCenterY = clampRatio(hitboxTopLeftY + box.h / 2 / spriteHeight);
576
+ const footY = clampRatio((spriteHeight - gap) / spriteHeight);
577
+
578
+ switch (box.anchorMode ?? 'top-left') {
579
+ case 'center':
580
+ return [hitboxCenterX, hitboxCenterY];
581
+ case 'foot':
582
+ return [hitboxCenterX, footY];
583
+ case 'top-left':
584
+ default:
585
+ return [hitboxTopLeftX, hitboxTopLeftY];
586
+ }
587
+ };
588
+
589
+ const loadImageDimensions = (image) => {
590
+ const source = resolveImageSource(image);
591
+ if (!source || imageDimensions()[source] || loadingImageDimensions.has(source)) {
592
+ return;
593
+ }
594
+
595
+ loadingImageDimensions.add(source);
596
+ Assets.load(source)
597
+ .then((texture) => {
598
+ const width = toPositiveNumber(texture?.width);
599
+ const height = toPositiveNumber(texture?.height);
600
+ if (!width || !height) return;
601
+
602
+ imageDimensions.update((dimensions) => ({
603
+ ...dimensions,
604
+ [source]: { width, height }
605
+ }));
606
+ })
607
+ .catch(() => {})
608
+ .finally(() => {
609
+ loadingImageDimensions.delete(source);
610
+ });
611
+ };
612
+
613
+ effect(() => {
614
+ const sources = new Set();
615
+
616
+ graphicsSignals().forEach((graphicObject) => {
617
+ const baseImage = resolveImageSource(graphicObject?.image);
618
+ if (baseImage) sources.add(baseImage);
619
+
620
+ Object.values(graphicObject?.textures ?? {}).forEach((textureOptions) => {
621
+ const image = resolveImageSource(textureOptions?.image ?? graphicObject?.image);
622
+ if (image) sources.add(image);
623
+ });
624
+ });
625
+
626
+ sources.forEach((source) => loadImageDimensions(source));
627
+ });
628
+
629
+ const hitboxBounds = computed(() => {
630
+ const box = hitbox();
631
+ const width = box?.w ?? 0;
632
+ const height = box?.h ?? 0;
633
+
634
+ return {
635
+ left: 0,
636
+ top: 0,
637
+ right: width,
638
+ bottom: height,
639
+ width,
640
+ height,
641
+ centerX: width / 2,
642
+ centerY: height / 2
643
+ };
644
+ });
645
+
646
+ const graphicBounds = computed(() => {
647
+ const box = hitbox();
648
+ const fallback = hitboxBounds();
649
+ const dimensions = imageDimensions();
650
+ const graphics = graphicsSignals();
651
+ let bounds = null;
652
+
653
+ graphics.forEach((graphicObject) => {
654
+ const textureOptions = resolveTextureOptions(graphicObject);
655
+ const frame = resolveFirstAnimationFrame(textureOptions);
656
+ const size = resolveFrameSize(textureOptions, dimensions);
657
+ const spriteWidth = size.width ?? box?.w;
658
+ const spriteHeight = size.height ?? box?.h;
659
+
660
+ if (!spriteWidth || !spriteHeight) {
661
+ return;
662
+ }
663
+
664
+ const explicitAnchor = normalizeAnchor(optionValue('anchor', frame, textureOptions, graphicObject));
665
+ const anchor = explicitAnchor ?? resolveHitboxAnchor(
666
+ spriteWidth,
667
+ spriteHeight,
668
+ optionValue('spriteRealSize', frame, textureOptions, graphicObject),
669
+ box
670
+ );
671
+ const scale = normalizePair(optionValue('scale', frame, textureOptions, graphicObject) ?? graphicScale(graphicObject));
672
+ const x = toFiniteNumber(optionValue('x', frame, textureOptions, graphicObject), 0);
673
+ const y = toFiniteNumber(optionValue('y', frame, textureOptions, graphicObject), 0);
674
+ const leftEdge = -anchor[0] * spriteWidth * scale[0];
675
+ const rightEdge = (1 - anchor[0]) * spriteWidth * scale[0];
676
+ const topEdge = -anchor[1] * spriteHeight * scale[1];
677
+ const bottomEdge = (1 - anchor[1]) * spriteHeight * scale[1];
678
+ const graphic = {
679
+ left: x + Math.min(leftEdge, rightEdge),
680
+ top: y + Math.min(topEdge, bottomEdge),
681
+ right: x + Math.max(leftEdge, rightEdge),
682
+ bottom: y + Math.max(topEdge, bottomEdge)
683
+ };
684
+
685
+ bounds = bounds
686
+ ? {
687
+ left: Math.min(bounds.left, graphic.left),
688
+ top: Math.min(bounds.top, graphic.top),
689
+ right: Math.max(bounds.right, graphic.right),
690
+ bottom: Math.max(bounds.bottom, graphic.bottom)
691
+ }
692
+ : graphic;
693
+ });
694
+
695
+ if (!bounds) {
696
+ return fallback;
697
+ }
698
+
699
+ const width = bounds.right - bounds.left;
700
+ const height = bounds.bottom - bounds.top;
701
+
702
+ return {
703
+ ...bounds,
704
+ width,
705
+ height,
706
+ centerX: bounds.left + width / 2,
707
+ centerY: bounds.top + height / 2
708
+ };
709
+ });
710
+
711
+ // Combine animation change detection with movement state from smoothX/smoothY
712
+ const movementAnimations = ['walk', 'stand'];
713
+ const epsilon = 0; // movement threshold to consider the easing still running
714
+
715
+ const stateX$ = smoothX.animatedState.observable;
716
+ const stateY$ = smoothY.animatedState.observable;
717
+ const animationName$ = animationName.observable;
718
+
719
+ const moving$ = combineLatest([stateX$, stateY$]).pipe(
720
+ map(([sx, sy]) => {
721
+ const xFinished = Math.abs(sx.value.current - sx.value.end) <= epsilon;
722
+ const yFinished = Math.abs(sy.value.current - sy.value.end) <= epsilon;
723
+ return !xFinished || !yFinished; // moving if X or Y is not finished
724
+ }),
725
+ startWith(false)
726
+ );
727
+
728
+ const animationChange$ = animationName$.pipe(
729
+ startWith(animationName()),
730
+ pairwise(),
731
+ filter(([prev, curr]) => prev !== curr)
732
+ );
733
+
734
+ let beforeRemovePromise = null;
735
+ let beforeRemoveTransitionValue = null;
736
+ const resolveRemoveContext = () => {
737
+ if (!object._removeTransition) return null;
738
+ const value = object._removeTransition();
739
+ if (!value || typeof value !== 'string') return null;
740
+ try {
741
+ const context = JSON.parse(value);
742
+ if (!context || typeof context !== 'object' || !context.active) return null;
743
+ context.__transitionValue = value;
744
+ return context;
745
+ }
746
+ catch {
747
+ return null;
748
+ }
749
+ };
750
+
751
+ const withTimeout = (promise, timeoutMs = 0) => {
752
+ if (!timeoutMs || timeoutMs <= 0) return promise;
753
+ return Promise.race([
754
+ promise,
755
+ new Promise((resolve) => setTimeout(resolve, timeoutMs)),
756
+ ]);
757
+ };
758
+
759
+ const runBeforeRemove = () => {
760
+ const context = resolveRemoveContext();
761
+ if (!context) return Promise.resolve();
762
+ if (beforeRemovePromise && beforeRemoveTransitionValue === context.__transitionValue) {
763
+ return beforeRemovePromise;
764
+ }
765
+ beforeRemoveTransitionValue = context.__transitionValue;
766
+ beforeRemovePromise = withTimeout(
767
+ lastValueFrom(hooks.callHooks("client-sprite-onBeforeRemove", object, context)),
768
+ context.timeoutMs
769
+ );
770
+ return beforeRemovePromise;
771
+ };
772
+
773
+ const removeTransitionSubscription = object._removeTransition?.observable?.subscribe(() => {
774
+ if (resolveRemoveContext()) {
775
+ runBeforeRemove();
776
+ }
777
+ });
778
+
779
+ const animationMovementSubscription = combineLatest([animationChange$, moving$]).subscribe(([[prev, curr], isMoving]) => {
780
+ if (curr == 'stand' && !isMoving) {
781
+ realAnimationName.set(curr);
782
+ }
783
+ else if (curr == 'walk' && isMoving) {
784
+ realAnimationName.set(curr);
785
+ }
786
+ else if (!movementAnimations.includes(curr)) {
787
+ realAnimationName.set(curr);
788
+ }
789
+ if (!isMoving && object.animationIsPlaying && object.animationIsPlaying()) {
790
+ if (movementAnimations.includes(curr)) {
791
+ if (typeof object.resetAnimationState === 'function') {
792
+ object.resetAnimationState();
793
+ }
794
+ }
795
+ }
796
+ });
797
+
798
+ /**
799
+ * Cleanup subscriptions and call hooks before sprite destruction.
800
+ *
801
+ * # Design
802
+ * - Prevent memory leaks by unsubscribing from all local subscriptions created in this component.
803
+ * - Execute destruction hooks to notify modules and scene map of sprite removal.
804
+ *
805
+ * @example
806
+ * await onBeforeDestroy();
807
+ */
808
+ const waitForTemporaryAnimationEnd = (maxDuration = 1200) => {
809
+ if (!object.animationIsPlaying || !object.animationIsPlaying()) {
810
+ return Promise.resolve();
811
+ }
812
+
813
+ return new Promise((resolve) => {
814
+ let finished = false;
815
+ let timeout;
816
+ let subscription;
817
+ const finish = () => {
818
+ if (finished) return;
819
+ finished = true;
820
+ clearTimeout(timeout);
821
+ subscription?.unsubscribe();
822
+ resolve();
823
+ };
824
+ timeout = setTimeout(finish, maxDuration);
825
+ subscription = object.animationIsPlaying.observable.subscribe((isPlaying) => {
826
+ if (!isPlaying) finish();
827
+ });
828
+ if (finished) subscription.unsubscribe();
829
+ });
830
+ };
831
+
832
+ const onBeforeDestroy = async () => {
833
+ await runBeforeRemove();
834
+ await waitForTemporaryAnimationEnd();
835
+ removeTransitionSubscription?.unsubscribe();
836
+ animationMovementSubscription.unsubscribe();
837
+ xSubscription.unsubscribe();
838
+ ySubscription.unsubscribe();
839
+ await lastValueFrom(hooks.callHooks("client-sprite-onDestroy", object))
840
+ await lastValueFrom(hooks.callHooks("client-sceneMap-onRemoveSprite", client.sceneMap, object))
841
+ }
842
+
843
+ mount((element) => {
844
+ hooks.callHooks("client-sprite-onAdd", object).subscribe()
845
+ hooks.callHooks("client-sceneMap-onAddSprite", client.sceneMap, object).subscribe()
846
+ effect(() => {
847
+ if (isCurrentPlayer()) {
848
+ client.setKeyboardControls(element.directives.controls)
849
+ }
850
+ })
130
851
  })
131
852
 
853
+ /**
854
+ * Handle attached GUI finish event
855
+ *
856
+ * @param gui - The GUI instance
857
+ * @param data - Data passed from the GUI component
858
+ */
859
+ const onAttachedGuiFinish = (gui, data) => {
860
+ guiService.guiClose(gui.name, data);
861
+ };
862
+
863
+ /**
864
+ * Handle attached GUI interaction event
865
+ *
866
+ * @param gui - The GUI instance
867
+ * @param name - Interaction name
868
+ * @param data - Interaction data
869
+ */
870
+ const onAttachedGuiInteraction = (gui, name, data) => {
871
+ guiService.guiInteraction(gui.name, name, data);
872
+ };
873
+
132
874
  tick(() => {
133
- hooks.callHooks("client-sprite-onUpdate")
875
+ hooks.callHooks("client-sprite-onUpdate").subscribe()
134
876
  })
135
- </script>
877
+ </script>