@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,64 @@
1
+ import { Text, animatedSignal, h, mount, signal, tick, useDefineProps, useProps } from "canvasengine";
2
+ import { Direction } from "@rpgjs/common";
3
+ //#region src/components/animations/hit.ce
4
+ function component($$props) {
5
+ useProps($$props);
6
+ const { text, direction, onFinish, duration, color, x: positionX, y: positionY } = useDefineProps($$props)({
7
+ duration: { default: 1e3 },
8
+ color: { default: "black" }
9
+ });
10
+ const scale = animatedSignal(1, { duration: duration() });
11
+ const randomPosition = () => Math.floor(Math.random() * 60);
12
+ const initialY = randomPosition();
13
+ const x = signal(positionX());
14
+ const y = signal(positionY() - initialY);
15
+ let velocityX = 0;
16
+ let velocityY = 0;
17
+ const speed = 200;
18
+ switch (direction()) {
19
+ case Direction.Left:
20
+ velocityX = speed;
21
+ break;
22
+ case Direction.Right:
23
+ velocityX = -speed;
24
+ break;
25
+ case Direction.Up:
26
+ velocityY = speed;
27
+ break;
28
+ case Direction.Down:
29
+ velocityY = -speed;
30
+ break;
31
+ }
32
+ velocityX += (Math.random() - .5) * 100;
33
+ velocityY += (Math.random() - .5) * 100;
34
+ const gravity = 500;
35
+ const deceleration = .98;
36
+ mount(() => {
37
+ scale.set(.1);
38
+ });
39
+ let elapsedTime = 0;
40
+ tick(({ deltaTime }) => {
41
+ elapsedTime += deltaTime;
42
+ if (elapsedTime < duration()) {
43
+ x.update((x) => x + velocityX * deltaTime / 1e3);
44
+ y.update((y) => y + velocityY * deltaTime / 1e3);
45
+ velocityY += gravity * deltaTime / 1e3;
46
+ velocityX *= deceleration;
47
+ velocityY *= deceleration;
48
+ } else if (onFinish) onFinish();
49
+ });
50
+ return h(Text, {
51
+ x,
52
+ y,
53
+ zIndex: 1e4,
54
+ color,
55
+ scale,
56
+ size: 30,
57
+ text
58
+ });
59
+ }
60
+ var __ce_component = component;
61
+ //#endregion
62
+ export { __ce_component as default };
63
+
64
+ //# sourceMappingURL=hit.ce.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hit.ce.js","names":[],"sources":["../../../src/components/animations/hit.ce"],"sourcesContent":["<Text x y zIndex={10000} color scale size={30} text />\n\n<script>\n import { animatedSignal, mount, signal, tick } from \"canvasengine\";\n import { Direction } from \"@rpgjs/common\";\n const {\n text,\n direction,\n onFinish,\n duration,\n color,\n x: positionX,\n y: positionY\n } = defineProps({\n duration: {\n default: 1000\n },\n color: {\n default: 'black'\n }\n });\n\n const scale = animatedSignal(1, {\n duration: duration(),\n });\n\n // Generate random initial position\n const randomPosition = () => Math.floor(Math.random() * 60);\n const initialY = randomPosition();\n const x = signal(positionX());\n const y = signal(positionY() - initialY);\n\n // Initial velocity\n let velocityX = 0;\n let velocityY = 0;\n\n // Set initial velocity based on direction\n const speed = 200;\n switch (direction()) {\n case Direction.Left:\n velocityX = speed;\n break;\n case Direction.Right:\n velocityX = -speed;\n break;\n case Direction.Up:\n velocityY = speed;\n break;\n case Direction.Down:\n velocityY = -speed;\n break;\n }\n\n // Add some randomness to the velocity\n velocityX += (Math.random() - 0.5) * 100;\n velocityY += (Math.random() - 0.5) * 100;\n\n const gravity = 500; // Gravity effect\n const deceleration = 0.98; // Deceleration factor\n\n mount(() => {\n scale.set(0.1);\n });\n\n let elapsedTime = 0;\n\n tick(({ deltaTime }) => {\n elapsedTime += deltaTime;\n \n if (elapsedTime < duration()) {\n // Update position\n x.update((x) => x + (velocityX * deltaTime) / 1000);\n y.update((y) => y + (velocityY * deltaTime) / 1000);\n\n // Apply gravity\n velocityY += (gravity * deltaTime) / 1000;\n\n // Apply deceleration\n velocityX *= deceleration;\n velocityY *= deceleration;\n } else {\n if (onFinish) {\n onFinish();\n }\n }\n });\n</script>\n"],"mappings":";;;AAOI,SAAS,UAAA,SAAA;CACD,SAAA,OAAA;CAER,MAAK,EAAA,MAAA,WAAA,UAAA,UAAA,OAAA,GAAA,WAAA,GAAA,cADG,eAAA,OACH,EAAA;EACL,UAAG,EACA,SAAA,IACH;EACA,OAAA,EACE,SAAS,QACX;CACJ,CAAC;CACD,MAAM,QAAQ,eAAO,GAAA,EACjB,UAAA,SAAA,EACJ,CAAC;;CAED,MAAE,WAAc,eAAgB;CAChC,MAAI,IAAA,OAAU,UAAU,CAAA;CACxB,MAAI,IAAA,OAAA,UAAA,IAAA,QAAA;;CAEJ,IAAI,YAAU;CACd,MAAE,QAAM;CACR,QAAQ,UAAU,GAAlB;EACE,KAAO,UAAU;GACX,YAAW;;EAEf,KAAC,UAAQ;GACP,YAAa,CAAA;GACb;;GAEE,YAAS;GACT;EACN,KAAO,UAAU;GACX,YAAW,CAAA;GACb;CACN;CACA,cAAS,KAAU,OAAK,IAAA,MAAA;CACxB,cAAM,KAAa,OAAK,IAAA,MAAA;CACxB,MAAM,UAAK;CACX,MAAI,eAAiB;CACrB,YAAM;EACF,MAAE,IAAK,EAAA;CACX,CAAC;CACD,IAAI,cAAc;CAClB,MAAM,EAAA,gBAAK;EACT,eAAA;;GAGA,EAAA,QAAc,MAAK,IAAQ,YAAU,YAAG,GAAA;GACxC,EAAA,QAAc,MAAK,IAAQ,YAAU,YAAG,GAAA;GAElC,aAAc,UAAI,YAAQ;;GAG1B,aAAM;EACV,OAAA,IAAA,UAGE,SAAe;CAGrB,CAAC;CAEO,OADL,EAAA,MAAA;EAAA;EAAA;EAAA,QAAA;EAAA;EAAA;EAAA,MAAA;EAAA;CAAA,CACgB;AACb;AAEA,IAAE,iBAEC"}
@@ -0,0 +1,4 @@
1
+ export declare const PrebuiltComponentAnimations: {
2
+ Hit: any;
3
+ Animation: any;
4
+ };
@@ -0,0 +1,11 @@
1
+ import __ce_component from "./hit.ce.js";
2
+ import __ce_component$1 from "./animation.ce.js";
3
+ //#region src/components/animations/index.ts
4
+ var PrebuiltComponentAnimations = {
5
+ Hit: __ce_component,
6
+ Animation: __ce_component$1
7
+ };
8
+ //#endregion
9
+ export { PrebuiltComponentAnimations };
10
+
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../src/components/animations/index.ts"],"sourcesContent":["import Hit from \"./hit.ce\";\nimport Animation from \"./animation.ce\";\n\nexport const PrebuiltComponentAnimations = {\n Hit,\n Animation\n}"],"mappings":";;;AAGA,IAAa,8BAA8B;CACvC,KAAA;CACA,WAAA;AACJ"}
@@ -0,0 +1,572 @@
1
+ import { inject } from "../core/inject.js";
2
+ import { getCanMoveValue } from "../utils/readPropValue.js";
3
+ import { RpgGui } from "../Gui/Gui.js";
4
+ import { RpgClientEngine } from "../RpgClientEngine.js";
5
+ import __ce_component$1 from "./player-components.ce.js";
6
+ import { Container, Sprite, animatedSignal, computed, cond, effect, h, loop, mount, on, signal, tick, useDefineProps, useProps } from "canvasengine";
7
+ import { Particle } from "@canvasengine/presets";
8
+ import { Animation, Direction, ModulesToken } from "@rpgjs/common";
9
+ import { combineLatest, filter, lastValueFrom, map, pairwise, startWith } from "rxjs";
10
+ import { Assets } from "pixi.js";
11
+ //#region src/components/character.ce
12
+ function component($$props) {
13
+ useProps($$props);
14
+ const { object, id } = useDefineProps($$props)();
15
+ const client = inject(RpgClientEngine);
16
+ const hooks = inject(ModulesToken);
17
+ const guiService = inject(RpgGui);
18
+ client.spritesheets;
19
+ const componentsBehind = client.spriteComponentsBehind;
20
+ const componentsInFront = client.spriteComponentsInFront;
21
+ const readProp = (value) => typeof value === "function" ? value() : value;
22
+ const isCurrentPlayer = () => {
23
+ const playerId = client.playerIdSignal();
24
+ const currentPlayer = playerId ? client.sceneMap?.players?.()?.[playerId] : void 0;
25
+ return readProp(id) === playerId || readProp(object?.id) === playerId || object === currentPlayer || object === client.sceneMap?.getCurrentPlayer?.();
26
+ };
27
+ const isMe = computed(isCurrentPlayer);
28
+ const shadowsEnabled = computed(() => {
29
+ const lighting = client.sceneMap?.lighting?.();
30
+ return Boolean(lighting?.shadows?.enabled || (lighting?.spots?.length ?? 0) > 0);
31
+ });
32
+ const normalizeComponent = (comp) => {
33
+ let componentRef;
34
+ let propsValue;
35
+ let dependenciesFn;
36
+ if (typeof comp === "function" || comp && typeof comp === "object" && !comp.component) {
37
+ componentRef = comp;
38
+ propsValue = void 0;
39
+ dependenciesFn = void 0;
40
+ } else if (comp && typeof comp === "object" && comp.component) {
41
+ componentRef = comp.component;
42
+ propsValue = comp.props !== void 0 ? comp.props : comp.data;
43
+ dependenciesFn = comp.dependencies;
44
+ } else {
45
+ componentRef = comp;
46
+ propsValue = void 0;
47
+ dependenciesFn = void 0;
48
+ }
49
+ return {
50
+ component: componentRef,
51
+ props: typeof propsValue === "function" ? propsValue(object) : propsValue || {},
52
+ dependencies: dependenciesFn ? dependenciesFn(object) : []
53
+ };
54
+ };
55
+ const normalizeComponents = (components) => {
56
+ return components.map((comp) => normalizeComponent(comp));
57
+ };
58
+ const normalizedComponentsBehind = computed(() => {
59
+ return normalizeComponents(componentsBehind());
60
+ });
61
+ const normalizedComponentsInFront = computed(() => {
62
+ return normalizeComponents(componentsInFront());
63
+ });
64
+ const shouldFollowCamera = computed(() => {
65
+ const cameraTargetId = client.cameraFollowTargetId();
66
+ if (cameraTargetId !== null) return id() === cameraTargetId;
67
+ return isMe();
68
+ });
69
+ const attachedGuis = computed(() => {
70
+ return guiService.getAttachedGuis();
71
+ });
72
+ const shouldDisplayAttachedGui = computed(() => {
73
+ return guiService.shouldDisplayAttachedGui(id());
74
+ });
75
+ const { x, y, tint, direction, animationName, animationCurrentIndex, emitParticleTrigger, particleName, graphics, hitbox, isConnected, graphicsSignals, flashTrigger } = object;
76
+ const flashType = signal("alpha");
77
+ const flashDuration = signal(300);
78
+ const flashCycles = signal(1);
79
+ const flashAlpha = signal(.3);
80
+ const flashTint = signal(16777215);
81
+ on(flashTrigger, (data) => {
82
+ if (data && typeof data === "object") {
83
+ if (data.type !== void 0) flashType.set(data.type);
84
+ if (data.duration !== void 0) flashDuration.set(data.duration);
85
+ if (data.cycles !== void 0) flashCycles.set(data.cycles);
86
+ if (data.alpha !== void 0) flashAlpha.set(data.alpha);
87
+ if (data.tint !== void 0) flashTint.set(data.tint);
88
+ }
89
+ });
90
+ const flashConfig = computed(() => ({
91
+ trigger: flashTrigger,
92
+ type: flashType(),
93
+ duration: flashDuration(),
94
+ cycles: flashCycles(),
95
+ alpha: flashAlpha(),
96
+ tint: flashTint()
97
+ }));
98
+ const particleSettings = client.particleSettings;
99
+ const canControls = () => isMe() && getCanMoveValue(object);
100
+ const keyboardControls = client.globalConfig.keyboardControls;
101
+ const visible = computed(() => {
102
+ if (object.isEvent()) return true;
103
+ return isConnected();
104
+ });
105
+ const controls = {
106
+ down: {
107
+ repeat: true,
108
+ bind: keyboardControls.down,
109
+ keyDown() {
110
+ if (canControls()) client.processInput({ input: Direction.Down });
111
+ }
112
+ },
113
+ up: {
114
+ repeat: true,
115
+ bind: keyboardControls.up,
116
+ keyDown() {
117
+ if (canControls()) client.processInput({ input: Direction.Up });
118
+ }
119
+ },
120
+ left: {
121
+ repeat: true,
122
+ bind: keyboardControls.left,
123
+ keyDown() {
124
+ if (canControls()) client.processInput({ input: Direction.Left });
125
+ }
126
+ },
127
+ right: {
128
+ repeat: true,
129
+ bind: keyboardControls.right,
130
+ keyDown() {
131
+ if (canControls()) client.processInput({ input: Direction.Right });
132
+ }
133
+ },
134
+ action: {
135
+ bind: keyboardControls.action,
136
+ keyDown() {
137
+ if (canControls()) client.processAction({ action: "action" });
138
+ }
139
+ },
140
+ escape: {
141
+ bind: keyboardControls.escape,
142
+ keyDown() {
143
+ if (canControls()) client.processAction({ action: "escape" });
144
+ }
145
+ },
146
+ gamepad: { enabled: true }
147
+ };
148
+ const smoothX = animatedSignal(x(), { duration: isMe() ? 0 : 0 });
149
+ const smoothY = animatedSignal(y(), { duration: isMe() ? 0 : 0 });
150
+ const z = computed(() => {
151
+ return object.y() + object.z();
152
+ });
153
+ const realAnimationName = signal(animationName());
154
+ const xSubscription = x.observable.subscribe((value) => {
155
+ smoothX.set(value);
156
+ });
157
+ const ySubscription = y.observable.subscribe((value) => {
158
+ smoothY.set(value);
159
+ });
160
+ const sheet = (graphicObject) => {
161
+ return {
162
+ definition: graphicObject,
163
+ playing: realAnimationName(),
164
+ params: { direction: direction() },
165
+ onFinish() {
166
+ animationCurrentIndex.update((index) => index + 1);
167
+ }
168
+ };
169
+ };
170
+ const graphicScale = (graphicObject) => {
171
+ const scale = graphicObject?.scale;
172
+ if (Array.isArray(scale)) return scale;
173
+ if (typeof scale === "number") return [scale, scale];
174
+ if (scale && typeof scale === "object") {
175
+ const x = typeof scale.x === "number" ? scale.x : 1;
176
+ return [x, typeof scale.y === "number" ? scale.y : x];
177
+ }
178
+ };
179
+ const shadowCaster = (graphicObject) => {
180
+ const box = hitbox();
181
+ const bounds = graphicBounds();
182
+ const scale = graphicScale(graphicObject);
183
+ const scaleY = Array.isArray(scale) && typeof scale[1] === "number" ? Math.abs(scale[1]) : 1;
184
+ const height = Math.max(bounds?.height ?? box?.h ?? 32, box?.h ?? 32) * scaleY;
185
+ return {
186
+ enabled: shadowsEnabled,
187
+ height,
188
+ footAnchor: {
189
+ x: .5,
190
+ y: 1
191
+ },
192
+ footOffset: {
193
+ x: 0,
194
+ y: 2
195
+ },
196
+ alpha: .5,
197
+ blur: 3.5,
198
+ gradientPower: 2,
199
+ hardness: .42,
200
+ minLength: Math.max(6, (box?.h ?? 32) * .25),
201
+ maxLength: Math.max(90, height * 1.8),
202
+ contactAlpha: .3,
203
+ contactScale: .3
204
+ };
205
+ };
206
+ const imageDimensions = signal({});
207
+ const loadingImageDimensions = /* @__PURE__ */ new Set();
208
+ const toPositiveNumber = (value) => {
209
+ const number = typeof value === "number" ? value : parseFloat(value);
210
+ return Number.isFinite(number) && number > 0 ? number : void 0;
211
+ };
212
+ const toFiniteNumber = (value, fallback = 0) => {
213
+ const number = typeof value === "number" ? value : parseFloat(value);
214
+ return Number.isFinite(number) ? number : fallback;
215
+ };
216
+ const clampRatio = (value) => Math.min(1, Math.max(0, value));
217
+ const normalizePair = (value, fallback = [1, 1]) => {
218
+ if (Array.isArray(value)) {
219
+ const x = toFiniteNumber(value[0], fallback[0]);
220
+ return [x, toFiniteNumber(value[1] ?? value[0], x)];
221
+ }
222
+ if (typeof value === "number") return [value, value];
223
+ if (value && typeof value === "object") {
224
+ const x = toFiniteNumber(value.x, fallback[0]);
225
+ return [x, toFiniteNumber(value.y ?? value.x, x)];
226
+ }
227
+ return fallback;
228
+ };
229
+ const normalizeAnchor = (value) => {
230
+ if (!Array.isArray(value)) return void 0;
231
+ const [x, y] = normalizePair(value, [0, 0]);
232
+ return [clampRatio(x), clampRatio(y)];
233
+ };
234
+ const resolveImageSource = (image) => {
235
+ if (typeof image === "string") return image;
236
+ if (typeof image?.default === "string") return image.default;
237
+ };
238
+ const parentTextureOptions = (graphicObject) => {
239
+ return [
240
+ "width",
241
+ "height",
242
+ "framesHeight",
243
+ "framesWidth",
244
+ "rectWidth",
245
+ "rectHeight",
246
+ "offset",
247
+ "image",
248
+ "sound",
249
+ "spriteRealSize",
250
+ "scale",
251
+ "anchor",
252
+ "pivot",
253
+ "x",
254
+ "y",
255
+ "opacity"
256
+ ].reduce((options, prop) => {
257
+ if (graphicObject?.[prop] !== void 0) options[prop] = graphicObject[prop];
258
+ return options;
259
+ }, {});
260
+ };
261
+ const resolveTextureOptions = (graphicObject) => {
262
+ const textures = graphicObject?.textures ?? {};
263
+ const texture = textures[realAnimationName()] ?? textures[Animation.Stand] ?? Object.values(textures)[0] ?? {};
264
+ return {
265
+ ...parentTextureOptions(graphicObject),
266
+ ...texture
267
+ };
268
+ };
269
+ const resolveFirstAnimationFrame = (textureOptions) => {
270
+ const animations = textureOptions?.animations;
271
+ if (!animations) return {};
272
+ try {
273
+ const frames = typeof animations === "function" ? animations({ direction: direction() }) : animations;
274
+ if (!Array.isArray(frames)) return {};
275
+ const firstGroup = frames[0];
276
+ return Array.isArray(firstGroup) ? firstGroup[0] ?? {} : firstGroup ?? {};
277
+ } catch {
278
+ return {};
279
+ }
280
+ };
281
+ const optionValue = (prop, frame, textureOptions, graphicObject) => {
282
+ return frame?.[prop] ?? textureOptions?.[prop] ?? graphicObject?.[prop];
283
+ };
284
+ const resolveFrameSize = (textureOptions, dimensions) => {
285
+ const framesWidth = toPositiveNumber(textureOptions?.framesWidth) ?? 1;
286
+ const framesHeight = toPositiveNumber(textureOptions?.framesHeight) ?? 1;
287
+ const imageSource = resolveImageSource(textureOptions?.image);
288
+ const loadedSize = imageSource ? dimensions[imageSource] : void 0;
289
+ const fullWidth = toPositiveNumber(textureOptions?.width) ?? loadedSize?.width;
290
+ const fullHeight = toPositiveNumber(textureOptions?.height) ?? loadedSize?.height;
291
+ return {
292
+ width: toPositiveNumber(textureOptions?.rectWidth) ?? toPositiveNumber(textureOptions?.spriteWidth) ?? (fullWidth ? fullWidth / framesWidth : void 0),
293
+ height: toPositiveNumber(textureOptions?.rectHeight) ?? toPositiveNumber(textureOptions?.spriteHeight) ?? (fullHeight ? fullHeight / framesHeight : void 0)
294
+ };
295
+ };
296
+ const resolveHitboxAnchor = (spriteWidth, spriteHeight, realSize, box) => {
297
+ if (!spriteWidth || !spriteHeight || !box) return [0, 0];
298
+ const resolvedHeight = toPositiveNumber(typeof realSize === "number" ? realSize : realSize?.height) ?? spriteHeight;
299
+ const gap = Math.max(0, (spriteHeight - resolvedHeight) / 2);
300
+ const hitboxTopLeftX = clampRatio((spriteWidth - box.w) / 2 / spriteWidth);
301
+ const hitboxTopLeftY = clampRatio((spriteHeight - box.h - gap) / spriteHeight);
302
+ const hitboxCenterX = clampRatio(hitboxTopLeftX + box.w / 2 / spriteWidth);
303
+ const hitboxCenterY = clampRatio(hitboxTopLeftY + box.h / 2 / spriteHeight);
304
+ const footY = clampRatio((spriteHeight - gap) / spriteHeight);
305
+ switch (box.anchorMode ?? "top-left") {
306
+ case "center": return [hitboxCenterX, hitboxCenterY];
307
+ case "foot": return [hitboxCenterX, footY];
308
+ default: return [hitboxTopLeftX, hitboxTopLeftY];
309
+ }
310
+ };
311
+ const loadImageDimensions = (image) => {
312
+ const source = resolveImageSource(image);
313
+ if (!source || imageDimensions()[source] || loadingImageDimensions.has(source)) return;
314
+ loadingImageDimensions.add(source);
315
+ Assets.load(source).then((texture) => {
316
+ const width = toPositiveNumber(texture?.width);
317
+ const height = toPositiveNumber(texture?.height);
318
+ if (!width || !height) return;
319
+ imageDimensions.update((dimensions) => ({
320
+ ...dimensions,
321
+ [source]: {
322
+ width,
323
+ height
324
+ }
325
+ }));
326
+ }).catch(() => {}).finally(() => {
327
+ loadingImageDimensions.delete(source);
328
+ });
329
+ };
330
+ effect(() => {
331
+ const sources = /* @__PURE__ */ new Set();
332
+ graphicsSignals().forEach((graphicObject) => {
333
+ const baseImage = resolveImageSource(graphicObject?.image);
334
+ if (baseImage) sources.add(baseImage);
335
+ Object.values(graphicObject?.textures ?? {}).forEach((textureOptions) => {
336
+ const image = resolveImageSource(textureOptions?.image ?? graphicObject?.image);
337
+ if (image) sources.add(image);
338
+ });
339
+ });
340
+ sources.forEach((source) => loadImageDimensions(source));
341
+ });
342
+ const hitboxBounds = computed(() => {
343
+ const box = hitbox();
344
+ const width = box?.w ?? 0;
345
+ const height = box?.h ?? 0;
346
+ return {
347
+ left: 0,
348
+ top: 0,
349
+ right: width,
350
+ bottom: height,
351
+ width,
352
+ height,
353
+ centerX: width / 2,
354
+ centerY: height / 2
355
+ };
356
+ });
357
+ const graphicBounds = computed(() => {
358
+ const box = hitbox();
359
+ const fallback = hitboxBounds();
360
+ const dimensions = imageDimensions();
361
+ const graphics = graphicsSignals();
362
+ let bounds = null;
363
+ graphics.forEach((graphicObject) => {
364
+ const textureOptions = resolveTextureOptions(graphicObject);
365
+ const frame = resolveFirstAnimationFrame(textureOptions);
366
+ const size = resolveFrameSize(textureOptions, dimensions);
367
+ const spriteWidth = size.width ?? box?.w;
368
+ const spriteHeight = size.height ?? box?.h;
369
+ if (!spriteWidth || !spriteHeight) return;
370
+ const anchor = normalizeAnchor(optionValue("anchor", frame, textureOptions, graphicObject)) ?? resolveHitboxAnchor(spriteWidth, spriteHeight, optionValue("spriteRealSize", frame, textureOptions, graphicObject), box);
371
+ const scale = normalizePair(optionValue("scale", frame, textureOptions, graphicObject) ?? graphicScale(graphicObject));
372
+ const x = toFiniteNumber(optionValue("x", frame, textureOptions, graphicObject), 0);
373
+ const y = toFiniteNumber(optionValue("y", frame, textureOptions, graphicObject), 0);
374
+ const leftEdge = -anchor[0] * spriteWidth * scale[0];
375
+ const rightEdge = (1 - anchor[0]) * spriteWidth * scale[0];
376
+ const topEdge = -anchor[1] * spriteHeight * scale[1];
377
+ const bottomEdge = (1 - anchor[1]) * spriteHeight * scale[1];
378
+ const graphic = {
379
+ left: x + Math.min(leftEdge, rightEdge),
380
+ top: y + Math.min(topEdge, bottomEdge),
381
+ right: x + Math.max(leftEdge, rightEdge),
382
+ bottom: y + Math.max(topEdge, bottomEdge)
383
+ };
384
+ bounds = bounds ? {
385
+ left: Math.min(bounds.left, graphic.left),
386
+ top: Math.min(bounds.top, graphic.top),
387
+ right: Math.max(bounds.right, graphic.right),
388
+ bottom: Math.max(bounds.bottom, graphic.bottom)
389
+ } : graphic;
390
+ });
391
+ if (!bounds) return fallback;
392
+ const width = bounds.right - bounds.left;
393
+ const height = bounds.bottom - bounds.top;
394
+ return {
395
+ ...bounds,
396
+ width,
397
+ height,
398
+ centerX: bounds.left + width / 2,
399
+ centerY: bounds.top + height / 2
400
+ };
401
+ });
402
+ const movementAnimations = ["walk", "stand"];
403
+ const epsilon = 0;
404
+ const stateX$ = smoothX.animatedState.observable;
405
+ const stateY$ = smoothY.animatedState.observable;
406
+ const animationName$ = animationName.observable;
407
+ const moving$ = combineLatest([stateX$, stateY$]).pipe(map(([sx, sy]) => {
408
+ const xFinished = Math.abs(sx.value.current - sx.value.end) <= epsilon;
409
+ const yFinished = Math.abs(sy.value.current - sy.value.end) <= epsilon;
410
+ return !xFinished || !yFinished;
411
+ }), startWith(false));
412
+ const animationChange$ = animationName$.pipe(startWith(animationName()), pairwise(), filter(([prev, curr]) => prev !== curr));
413
+ let beforeRemovePromise = null;
414
+ let beforeRemoveTransitionValue = null;
415
+ const resolveRemoveContext = () => {
416
+ if (!object._removeTransition) return null;
417
+ const value = object._removeTransition();
418
+ if (!value || typeof value !== "string") return null;
419
+ try {
420
+ const context = JSON.parse(value);
421
+ if (!context || typeof context !== "object" || !context.active) return null;
422
+ context.__transitionValue = value;
423
+ return context;
424
+ } catch {
425
+ return null;
426
+ }
427
+ };
428
+ const withTimeout = (promise, timeoutMs = 0) => {
429
+ if (!timeoutMs || timeoutMs <= 0) return promise;
430
+ return Promise.race([promise, new Promise((resolve) => setTimeout(resolve, timeoutMs))]);
431
+ };
432
+ const runBeforeRemove = () => {
433
+ const context = resolveRemoveContext();
434
+ if (!context) return Promise.resolve();
435
+ if (beforeRemovePromise && beforeRemoveTransitionValue === context.__transitionValue) return beforeRemovePromise;
436
+ beforeRemoveTransitionValue = context.__transitionValue;
437
+ beforeRemovePromise = withTimeout(lastValueFrom(hooks.callHooks("client-sprite-onBeforeRemove", object, context)), context.timeoutMs);
438
+ return beforeRemovePromise;
439
+ };
440
+ const removeTransitionSubscription = object._removeTransition?.observable?.subscribe(() => {
441
+ if (resolveRemoveContext()) runBeforeRemove();
442
+ });
443
+ const animationMovementSubscription = combineLatest([animationChange$, moving$]).subscribe(([[prev, curr], isMoving]) => {
444
+ if (curr == "stand" && !isMoving) realAnimationName.set(curr);
445
+ else if (curr == "walk" && isMoving) realAnimationName.set(curr);
446
+ else if (!movementAnimations.includes(curr)) realAnimationName.set(curr);
447
+ if (!isMoving && object.animationIsPlaying && object.animationIsPlaying()) {
448
+ if (movementAnimations.includes(curr)) {
449
+ if (typeof object.resetAnimationState === "function") object.resetAnimationState();
450
+ }
451
+ }
452
+ });
453
+ const waitForTemporaryAnimationEnd = (maxDuration = 1200) => {
454
+ if (!object.animationIsPlaying || !object.animationIsPlaying()) return Promise.resolve();
455
+ return new Promise((resolve) => {
456
+ let finished = false;
457
+ let timeout;
458
+ let subscription;
459
+ const finish = () => {
460
+ if (finished) return;
461
+ finished = true;
462
+ clearTimeout(timeout);
463
+ subscription?.unsubscribe();
464
+ resolve();
465
+ };
466
+ timeout = setTimeout(finish, maxDuration);
467
+ subscription = object.animationIsPlaying.observable.subscribe((isPlaying) => {
468
+ if (!isPlaying) finish();
469
+ });
470
+ if (finished) subscription.unsubscribe();
471
+ });
472
+ };
473
+ const onBeforeDestroy = async () => {
474
+ await runBeforeRemove();
475
+ await waitForTemporaryAnimationEnd();
476
+ removeTransitionSubscription?.unsubscribe();
477
+ animationMovementSubscription.unsubscribe();
478
+ xSubscription.unsubscribe();
479
+ ySubscription.unsubscribe();
480
+ await lastValueFrom(hooks.callHooks("client-sprite-onDestroy", object));
481
+ await lastValueFrom(hooks.callHooks("client-sceneMap-onRemoveSprite", client.sceneMap, object));
482
+ };
483
+ mount((element) => {
484
+ hooks.callHooks("client-sprite-onAdd", object).subscribe();
485
+ hooks.callHooks("client-sceneMap-onAddSprite", client.sceneMap, object).subscribe();
486
+ effect(() => {
487
+ if (isCurrentPlayer()) client.setKeyboardControls(element.directives.controls);
488
+ });
489
+ });
490
+ const onAttachedGuiFinish = (gui, data) => {
491
+ guiService.guiClose(gui.name, data);
492
+ };
493
+ const onAttachedGuiInteraction = (gui, name, data) => {
494
+ guiService.guiInteraction(gui.name, name, data);
495
+ };
496
+ tick(() => {
497
+ hooks.callHooks("client-sprite-onUpdate").subscribe();
498
+ });
499
+ return h(Container, {
500
+ x: smoothX,
501
+ y: smoothY,
502
+ zIndex: z,
503
+ viewportFollow: shouldFollowCamera,
504
+ controls,
505
+ onBeforeDestroy,
506
+ visible
507
+ }, [
508
+ loop(normalizedComponentsBehind, (compConfig) => h(Container, null, h(compConfig.component, {
509
+ object,
510
+ ...compConfig.props
511
+ }))),
512
+ h(__ce_component$1, {
513
+ object,
514
+ position: "bottom",
515
+ graphicBounds
516
+ }),
517
+ h(__ce_component$1, {
518
+ object,
519
+ position: "left",
520
+ graphicBounds
521
+ }),
522
+ h(Particle, {
523
+ emit: emitParticleTrigger,
524
+ settings: particleSettings,
525
+ zIndex: 1e3,
526
+ name: particleName
527
+ }),
528
+ h(Container, null, loop(graphicsSignals, (graphicObj) => h(Container, { scale: computed(() => graphicScale(graphicObj)) }, h(Sprite, {
529
+ sheet: computed(() => sheet(graphicObj)),
530
+ direction,
531
+ tint,
532
+ hitbox,
533
+ shadowCaster: computed(() => shadowCaster(graphicObj)),
534
+ flash: flashConfig
535
+ })))),
536
+ h(__ce_component$1, {
537
+ object,
538
+ position: "center",
539
+ graphicBounds
540
+ }),
541
+ h(__ce_component$1, {
542
+ object,
543
+ position: "right",
544
+ graphicBounds
545
+ }),
546
+ h(__ce_component$1, {
547
+ object,
548
+ position: "top",
549
+ graphicBounds
550
+ }),
551
+ loop(normalizedComponentsInFront, (compConfig) => h(Container, { dependencies: compConfig.dependencies }, h(compConfig.component, {
552
+ object,
553
+ ...compConfig.props
554
+ }))),
555
+ loop(attachedGuis, (attachedGui) => cond(shouldDisplayAttachedGui, () => h(Container, null, h(attachedGui.component, {
556
+ ...attachedGui.data(),
557
+ dependencies: attachedGui.dependencies,
558
+ object,
559
+ onFinish: (data) => {
560
+ onAttachedGuiFinish(attachedGui, data);
561
+ },
562
+ onInteraction: (name, data) => {
563
+ onAttachedGuiInteraction(attachedGui, name, data);
564
+ }
565
+ }))))
566
+ ]);
567
+ }
568
+ var __ce_component = component;
569
+ //#endregion
570
+ export { __ce_component as default };
571
+
572
+ //# sourceMappingURL=character.ce.js.map