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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (305) hide show
  1. package/dist/Game/AnimationManager.d.ts +8 -0
  2. package/dist/Game/AnimationManager.js +26 -0
  3. package/dist/Game/AnimationManager.js.map +1 -0
  4. package/dist/Game/Event.d.ts +1 -1
  5. package/dist/Game/Event.js +12 -0
  6. package/dist/Game/Event.js.map +1 -0
  7. package/dist/Game/Map.d.ts +23 -2
  8. package/dist/Game/Map.js +80 -0
  9. package/dist/Game/Map.js.map +1 -0
  10. package/dist/Game/Object.d.ts +157 -0
  11. package/dist/Game/Object.js +211 -0
  12. package/dist/Game/Object.js.map +1 -0
  13. package/dist/Game/Player.d.ts +1 -1
  14. package/dist/Game/Player.js +12 -0
  15. package/dist/Game/Player.js.map +1 -0
  16. package/dist/Gui/Gui.d.ts +177 -5
  17. package/dist/Gui/Gui.js +445 -0
  18. package/dist/Gui/Gui.js.map +1 -0
  19. package/dist/Gui/NotificationManager.d.ts +23 -0
  20. package/dist/Gui/NotificationManager.js +49 -0
  21. package/dist/Gui/NotificationManager.js.map +1 -0
  22. package/dist/Resource.d.ts +97 -0
  23. package/dist/Resource.js +133 -0
  24. package/dist/Resource.js.map +1 -0
  25. package/dist/RpgClient.d.ts +290 -58
  26. package/dist/RpgClientEngine.d.ts +649 -9
  27. package/dist/RpgClientEngine.js +1334 -0
  28. package/dist/RpgClientEngine.js.map +1 -0
  29. package/dist/Sound.d.ts +199 -0
  30. package/dist/Sound.js +167 -0
  31. package/dist/Sound.js.map +1 -0
  32. package/dist/_virtual/_@oxc-project_runtime@0.122.0/helpers/decorate.js +9 -0
  33. package/dist/_virtual/_@oxc-project_runtime@0.122.0/helpers/decorateMetadata.js +6 -0
  34. package/dist/components/animations/animation.ce.js +24 -0
  35. package/dist/components/animations/animation.ce.js.map +1 -0
  36. package/dist/components/animations/hit.ce.js +70 -0
  37. package/dist/components/animations/hit.ce.js.map +1 -0
  38. package/dist/components/animations/index.d.ts +4 -0
  39. package/dist/components/animations/index.js +11 -0
  40. package/dist/components/animations/index.js.map +1 -0
  41. package/dist/components/character.ce.js +392 -0
  42. package/dist/components/character.ce.js.map +1 -0
  43. package/dist/components/dynamics/parse-value.d.ts +1 -0
  44. package/dist/components/dynamics/parse-value.js +44 -0
  45. package/dist/components/dynamics/parse-value.js.map +1 -0
  46. package/dist/components/dynamics/text.ce.js +73 -0
  47. package/dist/components/dynamics/text.ce.js.map +1 -0
  48. package/dist/components/gui/box.ce.js +28 -0
  49. package/dist/components/gui/box.ce.js.map +1 -0
  50. package/dist/components/gui/dialogbox/index.ce.js +205 -0
  51. package/dist/components/gui/dialogbox/index.ce.js.map +1 -0
  52. package/dist/components/gui/gameover.ce.js +193 -0
  53. package/dist/components/gui/gameover.ce.js.map +1 -0
  54. package/dist/components/gui/hud/hud.ce.js +92 -0
  55. package/dist/components/gui/hud/hud.ce.js.map +1 -0
  56. package/dist/components/gui/index.d.ts +15 -3
  57. package/dist/components/gui/index.js +14 -0
  58. package/dist/components/gui/menu/equip-menu.ce.js +481 -0
  59. package/dist/components/gui/menu/equip-menu.ce.js.map +1 -0
  60. package/dist/components/gui/menu/exit-menu.ce.js +54 -0
  61. package/dist/components/gui/menu/exit-menu.ce.js.map +1 -0
  62. package/dist/components/gui/menu/items-menu.ce.js +344 -0
  63. package/dist/components/gui/menu/items-menu.ce.js.map +1 -0
  64. package/dist/components/gui/menu/main-menu.ce.js +417 -0
  65. package/dist/components/gui/menu/main-menu.ce.js.map +1 -0
  66. package/dist/components/gui/menu/options-menu.ce.js +48 -0
  67. package/dist/components/gui/menu/options-menu.ce.js.map +1 -0
  68. package/dist/components/gui/menu/skills-menu.ce.js +107 -0
  69. package/dist/components/gui/menu/skills-menu.ce.js.map +1 -0
  70. package/dist/components/gui/mobile/index.d.ts +8 -0
  71. package/dist/components/gui/mobile/index.js +21 -0
  72. package/dist/components/gui/mobile/index.js.map +1 -0
  73. package/dist/components/gui/mobile/mobile.ce.js +78 -0
  74. package/dist/components/gui/mobile/mobile.ce.js.map +1 -0
  75. package/dist/components/gui/notification/notification.ce.js +64 -0
  76. package/dist/components/gui/notification/notification.ce.js.map +1 -0
  77. package/dist/components/gui/save-load.ce.js +389 -0
  78. package/dist/components/gui/save-load.ce.js.map +1 -0
  79. package/dist/components/gui/shop/shop.ce.js +652 -0
  80. package/dist/components/gui/shop/shop.ce.js.map +1 -0
  81. package/dist/components/gui/title-screen.ce.js +190 -0
  82. package/dist/components/gui/title-screen.ce.js.map +1 -0
  83. package/dist/components/index.d.ts +1 -0
  84. package/dist/components/index.js +4 -0
  85. package/dist/components/prebuilt/hp-bar.ce.js +116 -0
  86. package/dist/components/prebuilt/hp-bar.ce.js.map +1 -0
  87. package/dist/components/prebuilt/index.d.ts +19 -0
  88. package/dist/components/prebuilt/index.js +2 -0
  89. package/dist/components/prebuilt/light-halo.ce.js +94 -0
  90. package/dist/components/prebuilt/light-halo.ce.js.map +1 -0
  91. package/dist/components/scenes/canvas.ce.js +60 -0
  92. package/dist/components/scenes/canvas.ce.js.map +1 -0
  93. package/dist/components/scenes/draw-map.ce.js +89 -0
  94. package/dist/components/scenes/draw-map.ce.js.map +1 -0
  95. package/dist/components/scenes/event-layer.ce.js +28 -0
  96. package/dist/components/scenes/event-layer.ce.js.map +1 -0
  97. package/dist/core/inject.js +18 -0
  98. package/dist/core/inject.js.map +1 -0
  99. package/dist/core/setup.js +16 -0
  100. package/dist/core/setup.js.map +1 -0
  101. package/dist/index.d.ts +15 -1
  102. package/dist/index.js +44 -14
  103. package/dist/module.d.ts +43 -4
  104. package/dist/module.js +176 -0
  105. package/dist/module.js.map +1 -0
  106. package/dist/node_modules/.pnpm/@signe_di@2.9.0/node_modules/@signe/di/dist/index.js +277 -0
  107. package/dist/node_modules/.pnpm/@signe_di@2.9.0/node_modules/@signe/di/dist/index.js.map +1 -0
  108. package/dist/node_modules/.pnpm/@signe_reactive@2.8.3/node_modules/@signe/reactive/dist/index.js +457 -0
  109. package/dist/node_modules/.pnpm/@signe_reactive@2.8.3/node_modules/@signe/reactive/dist/index.js.map +1 -0
  110. package/dist/node_modules/.pnpm/@signe_reactive@2.9.0/node_modules/@signe/reactive/dist/index.js +463 -0
  111. package/dist/node_modules/.pnpm/@signe_reactive@2.9.0/node_modules/@signe/reactive/dist/index.js.map +1 -0
  112. package/dist/node_modules/.pnpm/@signe_room@2.9.0/node_modules/@signe/room/dist/index.js +2191 -0
  113. package/dist/node_modules/.pnpm/@signe_room@2.9.0/node_modules/@signe/room/dist/index.js.map +1 -0
  114. package/dist/node_modules/.pnpm/@signe_sync@2.9.0/node_modules/@signe/sync/dist/chunk-7QVYU63E.js +10 -0
  115. package/dist/node_modules/.pnpm/@signe_sync@2.9.0/node_modules/@signe/sync/dist/chunk-7QVYU63E.js.map +1 -0
  116. package/dist/node_modules/.pnpm/@signe_sync@2.9.0/node_modules/@signe/sync/dist/client/index.js +91 -0
  117. package/dist/node_modules/.pnpm/@signe_sync@2.9.0/node_modules/@signe/sync/dist/client/index.js.map +1 -0
  118. package/dist/node_modules/.pnpm/@signe_sync@2.9.0/node_modules/@signe/sync/dist/index.js +325 -0
  119. package/dist/node_modules/.pnpm/@signe_sync@2.9.0/node_modules/@signe/sync/dist/index.js.map +1 -0
  120. package/dist/node_modules/.pnpm/dset@3.1.4/node_modules/dset/dist/index.js +14 -0
  121. package/dist/node_modules/.pnpm/dset@3.1.4/node_modules/dset/dist/index.js.map +1 -0
  122. package/dist/node_modules/.pnpm/partysocket@1.1.3/node_modules/partysocket/dist/chunk-HAC622V3.js +115 -0
  123. package/dist/node_modules/.pnpm/partysocket@1.1.3/node_modules/partysocket/dist/chunk-HAC622V3.js.map +1 -0
  124. package/dist/node_modules/.pnpm/partysocket@1.1.3/node_modules/partysocket/dist/chunk-S74YV6PU.js +401 -0
  125. package/dist/node_modules/.pnpm/partysocket@1.1.3/node_modules/partysocket/dist/chunk-S74YV6PU.js.map +1 -0
  126. package/dist/node_modules/.pnpm/partysocket@1.1.3/node_modules/partysocket/dist/index.js +2 -0
  127. package/dist/node_modules/.pnpm/zod@3.24.2/node_modules/zod/lib/index.js +3756 -0
  128. package/dist/node_modules/.pnpm/zod@3.24.2/node_modules/zod/lib/index.js.map +1 -0
  129. package/dist/presets/animation.d.ts +31 -0
  130. package/dist/presets/animation.js +39 -0
  131. package/dist/presets/animation.js.map +1 -0
  132. package/dist/presets/faceset.d.ts +30 -0
  133. package/dist/presets/faceset.js +51 -0
  134. package/dist/presets/faceset.js.map +1 -0
  135. package/dist/presets/icon.d.ts +20 -0
  136. package/dist/presets/icon.js +15 -0
  137. package/dist/presets/icon.js.map +1 -0
  138. package/dist/presets/index.d.ts +123 -0
  139. package/dist/presets/index.js +17 -0
  140. package/dist/presets/index.js.map +1 -0
  141. package/dist/presets/lpc.d.ts +89 -0
  142. package/dist/presets/lpc.js +98 -0
  143. package/dist/presets/lpc.js.map +1 -0
  144. package/dist/presets/rmspritesheet.js +42 -0
  145. package/dist/presets/rmspritesheet.js.map +1 -0
  146. package/dist/services/AbstractSocket.d.ts +9 -5
  147. package/dist/services/AbstractSocket.js +11 -0
  148. package/dist/services/AbstractSocket.js.map +1 -0
  149. package/dist/services/keyboardControls.d.ts +15 -0
  150. package/dist/services/keyboardControls.js +23 -0
  151. package/dist/services/keyboardControls.js.map +1 -0
  152. package/dist/services/loadMap.js +123 -0
  153. package/dist/services/loadMap.js.map +1 -0
  154. package/dist/services/mmorpg.d.ts +21 -9
  155. package/dist/services/mmorpg.js +131 -0
  156. package/dist/services/mmorpg.js.map +1 -0
  157. package/dist/services/save.d.ts +19 -0
  158. package/dist/services/save.js +77 -0
  159. package/dist/services/save.js.map +1 -0
  160. package/dist/services/standalone.d.ts +67 -7
  161. package/dist/services/standalone.js +168 -0
  162. package/dist/services/standalone.js.map +1 -0
  163. package/dist/utils/getEntityProp.d.ts +39 -0
  164. package/dist/utils/getEntityProp.js +52 -0
  165. package/dist/utils/getEntityProp.js.map +1 -0
  166. package/package.json +13 -9
  167. package/src/Game/{EffectManager.ts → AnimationManager.ts} +3 -2
  168. package/src/Game/Event.ts +1 -1
  169. package/src/Game/Map.ts +95 -3
  170. package/src/Game/Object.ts +330 -14
  171. package/src/Game/Player.ts +1 -1
  172. package/src/Gui/Gui.ts +506 -18
  173. package/src/Gui/NotificationManager.ts +69 -0
  174. package/src/Resource.ts +150 -0
  175. package/src/RpgClient.ts +300 -58
  176. package/src/RpgClientEngine.ts +1707 -48
  177. package/src/Sound.ts +253 -0
  178. package/src/components/{effects → animations}/animation.ce +3 -6
  179. package/src/components/{effects → animations}/index.ts +1 -1
  180. package/src/components/character.ce +406 -40
  181. package/src/components/dynamics/parse-value.ts +80 -0
  182. package/src/components/dynamics/text.ce +183 -0
  183. package/src/components/gui/box.ce +17 -0
  184. package/src/components/gui/dialogbox/index.ce +204 -187
  185. package/src/components/gui/gameover.ce +158 -0
  186. package/src/components/gui/hud/hud.ce +61 -0
  187. package/src/components/gui/index.ts +30 -4
  188. package/src/components/gui/menu/equip-menu.ce +410 -0
  189. package/src/components/gui/menu/exit-menu.ce +41 -0
  190. package/src/components/gui/menu/items-menu.ce +317 -0
  191. package/src/components/gui/menu/main-menu.ce +294 -0
  192. package/src/components/gui/menu/options-menu.ce +35 -0
  193. package/src/components/gui/menu/skills-menu.ce +83 -0
  194. package/src/components/gui/mobile/index.ts +24 -0
  195. package/src/components/gui/mobile/mobile.ce +80 -0
  196. package/src/components/gui/notification/notification.ce +51 -0
  197. package/src/components/gui/save-load.ce +208 -0
  198. package/src/components/gui/shop/shop.ce +493 -0
  199. package/src/components/gui/title-screen.ce +163 -0
  200. package/src/components/index.ts +3 -0
  201. package/src/components/prebuilt/hp-bar.ce +255 -0
  202. package/src/components/prebuilt/index.ts +24 -0
  203. package/src/components/prebuilt/light-halo.ce +148 -0
  204. package/src/components/scenes/canvas.ce +20 -15
  205. package/src/components/scenes/draw-map.ce +60 -13
  206. package/src/components/scenes/event-layer.ce +9 -2
  207. package/src/components/scenes/transition.ce +60 -0
  208. package/src/index.ts +16 -2
  209. package/src/module.ts +145 -9
  210. package/src/presets/animation.ts +46 -0
  211. package/src/presets/faceset.ts +60 -0
  212. package/src/presets/icon.ts +17 -0
  213. package/src/presets/index.ts +9 -1
  214. package/src/presets/lpc.ts +108 -0
  215. package/src/services/AbstractSocket.ts +10 -2
  216. package/src/services/keyboardControls.ts +20 -0
  217. package/src/services/loadMap.ts +1 -1
  218. package/src/services/mmorpg.ts +100 -12
  219. package/src/services/save.ts +103 -0
  220. package/src/services/standalone.ts +110 -18
  221. package/src/utils/getEntityProp.ts +87 -0
  222. package/tsconfig.json +1 -1
  223. package/vite.config.ts +4 -2
  224. package/dist/Game/EffectManager.d.ts +0 -5
  225. package/dist/components/effects/index.d.ts +0 -4
  226. package/dist/index.js.map +0 -1
  227. package/dist/index10.js +0 -8
  228. package/dist/index10.js.map +0 -1
  229. package/dist/index11.js +0 -10
  230. package/dist/index11.js.map +0 -1
  231. package/dist/index12.js +0 -8
  232. package/dist/index12.js.map +0 -1
  233. package/dist/index13.js +0 -17
  234. package/dist/index13.js.map +0 -1
  235. package/dist/index14.js +0 -91
  236. package/dist/index14.js.map +0 -1
  237. package/dist/index15.js +0 -50
  238. package/dist/index15.js.map +0 -1
  239. package/dist/index16.js +0 -191
  240. package/dist/index16.js.map +0 -1
  241. package/dist/index17.js +0 -9
  242. package/dist/index17.js.map +0 -1
  243. package/dist/index18.js +0 -387
  244. package/dist/index18.js.map +0 -1
  245. package/dist/index19.js +0 -31
  246. package/dist/index19.js.map +0 -1
  247. package/dist/index2.js +0 -112
  248. package/dist/index2.js.map +0 -1
  249. package/dist/index20.js +0 -24
  250. package/dist/index20.js.map +0 -1
  251. package/dist/index21.js +0 -2421
  252. package/dist/index21.js.map +0 -1
  253. package/dist/index22.js +0 -114
  254. package/dist/index22.js.map +0 -1
  255. package/dist/index23.js +0 -109
  256. package/dist/index23.js.map +0 -1
  257. package/dist/index24.js +0 -71
  258. package/dist/index24.js.map +0 -1
  259. package/dist/index25.js +0 -21
  260. package/dist/index25.js.map +0 -1
  261. package/dist/index26.js +0 -41
  262. package/dist/index26.js.map +0 -1
  263. package/dist/index27.js +0 -5
  264. package/dist/index27.js.map +0 -1
  265. package/dist/index28.js +0 -322
  266. package/dist/index28.js.map +0 -1
  267. package/dist/index29.js +0 -27
  268. package/dist/index29.js.map +0 -1
  269. package/dist/index3.js +0 -87
  270. package/dist/index3.js.map +0 -1
  271. package/dist/index30.js +0 -11
  272. package/dist/index30.js.map +0 -1
  273. package/dist/index31.js +0 -11
  274. package/dist/index31.js.map +0 -1
  275. package/dist/index32.js +0 -12
  276. package/dist/index32.js.map +0 -1
  277. package/dist/index33.js +0 -4403
  278. package/dist/index33.js.map +0 -1
  279. package/dist/index34.js +0 -316
  280. package/dist/index34.js.map +0 -1
  281. package/dist/index35.js +0 -174
  282. package/dist/index35.js.map +0 -1
  283. package/dist/index36.js +0 -501
  284. package/dist/index36.js.map +0 -1
  285. package/dist/index37.js +0 -61
  286. package/dist/index37.js.map +0 -1
  287. package/dist/index38.js +0 -20
  288. package/dist/index38.js.map +0 -1
  289. package/dist/index39.js +0 -20
  290. package/dist/index39.js.map +0 -1
  291. package/dist/index4.js +0 -67
  292. package/dist/index4.js.map +0 -1
  293. package/dist/index5.js +0 -16
  294. package/dist/index5.js.map +0 -1
  295. package/dist/index6.js +0 -17
  296. package/dist/index6.js.map +0 -1
  297. package/dist/index7.js +0 -39
  298. package/dist/index7.js.map +0 -1
  299. package/dist/index8.js +0 -90
  300. package/dist/index8.js.map +0 -1
  301. package/dist/index9.js +0 -76
  302. package/dist/index9.js.map +0 -1
  303. package/src/components/gui/dialogbox/itemMenu.ce +0 -23
  304. package/src/components/gui/dialogbox/selection.ce +0 -67
  305. /package/src/components/{effects → animations}/hit.ce +0 -0
@@ -1,55 +1,297 @@
1
- <Container x y zIndex={y} viewportFollow={isMe} controls>
2
- <Particle emit={@emitParticleTrigger} settings={@particleSettings} zIndex={1000} name={particleName} />
3
- @for (graphicId of graphics) {
4
- <Sprite sheet={@sheet(@graphicId)} direction tint />
1
+ <Container x={smoothX} y={smoothY} zIndex={z} viewportFollow={shouldFollowCamera} controls onBeforeDestroy visible>
2
+ @for (compConfig of normalizedComponentsBehind) {
3
+ <Container>
4
+ <compConfig.component object ...compConfig.props />
5
+ </Container>
6
+ }
7
+ <Particle emit={emitParticleTrigger} settings={particleSettings} zIndex={1000} name={particleName} />
8
+ <Container>
9
+ @for (graphicObj of graphicsSignals) {
10
+ <Sprite
11
+ sheet={sheet(graphicObj)}
12
+ direction
13
+ tint
14
+ hitbox
15
+ flash={flashConfig}
16
+ />
17
+ }
18
+ </Container>
19
+ @for (compConfig of normalizedComponentsInFront) {
20
+ <Container dependencies={compConfig.dependencies}>
21
+ <compConfig.component object ...compConfig.props />
22
+ </Container>
23
+ }
24
+ @for (attachedGui of attachedGuis) {
25
+ @if (shouldDisplayAttachedGui) {
26
+ <Container>
27
+ <attachedGui.component ...attachedGui.data() dependencies={attachedGui.dependencies} object={object} onFinish={(data) => {
28
+ onAttachedGuiFinish(attachedGui, data)
29
+ }} onInteraction={(name, data) => {
30
+ onAttachedGuiInteraction(attachedGui, name, data)
31
+ }} />
32
+ </Container>
33
+ }
5
34
  }
6
- <!-- <Ellipse
7
- x={shadow.@x}
8
- y={shadow.@y}
9
- width={shadow.@width}
10
- height={shadow.@height}
11
- color="black"
12
- blur={10}
13
- alpha={0.5}
14
- /> -->
15
35
  </Container>
16
36
 
17
37
  <script>
18
- import { signal, effect, mount, computed } from "canvasengine";
38
+ import { signal, effect, mount, computed, tick, animatedSignal, on } from "canvasengine";
39
+
40
+ import { lastValueFrom, combineLatest, pairwise, filter, map, startWith } from "rxjs";
19
41
  import { Particle } from "@canvasengine/presets";
20
- import { GameEngineToken } from "@rpgjs/common";
42
+ import { GameEngineToken, ModulesToken } from "@rpgjs/common";
21
43
  import { RpgClientEngine } from "../RpgClientEngine";
22
44
  import { inject } from "../core/inject";
23
45
  import { Direction } from "@rpgjs/common";
24
46
  import Hit from "./effects/hit.ce";
47
+ import PlayerComponents from "./player-components.ce";
48
+ import { RpgGui } from "../Gui/Gui";
25
49
 
26
- const { object, id, isMe } = defineProps();
50
+ const { object, id } = defineProps();
27
51
 
28
52
  const client = inject(RpgClientEngine);
53
+ const hooks = inject(ModulesToken);
54
+ const guiService = inject(RpgGui);
29
55
 
30
56
  const spritesheets = client.spritesheets;
57
+ const playerId = client.playerId;
58
+ const componentsBehind = client.spriteComponentsBehind;
59
+ const componentsInFront = client.spriteComponentsInFront;
60
+ const isMe = computed(() => id() === playerId);
61
+
62
+ /**
63
+ * Normalize a single sprite component configuration
64
+ *
65
+ * Handles both direct component references and configuration objects with optional props and dependencies.
66
+ * Extracts the component reference and creates a computed function that returns the props.
67
+ *
68
+ * ## Design
69
+ *
70
+ * Supports two formats:
71
+ * 1. Direct component: `ShadowComponent`
72
+ * 2. Configuration object: `{ component: LightHalo, props: {...}, dependencies: (object) => [...] }`
73
+ *
74
+ * The normalization process:
75
+ * - Extracts the actual component from either format
76
+ * - Extracts dependencies function if provided
77
+ * - Creates a computed function that returns props (static object or dynamic function result)
78
+ * - Returns a normalized object with `component`, `props`, and `dependencies`
79
+ *
80
+ * @param comp - Component reference or configuration object
81
+ * @returns Normalized component configuration with component, props, and dependencies
82
+ *
83
+ * @example
84
+ * ```ts
85
+ * // Direct component
86
+ * normalizeComponent(ShadowComponent)
87
+ * // => { component: ShadowComponent, props: {}, dependencies: undefined }
88
+ *
89
+ * // With static props
90
+ * normalizeComponent({ component: LightHalo, props: { radius: 30 } })
91
+ * // => { component: LightHalo, props: { radius: 30 }, dependencies: undefined }
92
+ *
93
+ * // With dynamic props and dependencies
94
+ * normalizeComponent({
95
+ * component: HealthBar,
96
+ * props: (object) => ({ hp: object.hp(), maxHp: object.param.maxHp() }),
97
+ * dependencies: (object) => [object.hp, object.param.maxHp]
98
+ * })
99
+ * // => { component: HealthBar, props: {...}, dependencies: (object) => [...] }
100
+ * ```
101
+ */
102
+ const normalizeComponent = (comp) => {
103
+ let componentRef;
104
+ let propsValue;
105
+ let dependenciesFn;
106
+
107
+ // If it's a direct component reference
108
+ if (typeof comp === 'function' || (comp && typeof comp === 'object' && !comp.component)) {
109
+ componentRef = comp;
110
+ propsValue = undefined;
111
+ dependenciesFn = undefined;
112
+ }
113
+ // If it's a configuration object with component and props
114
+ else if (comp && typeof comp === 'object' && comp.component) {
115
+ componentRef = comp.component;
116
+ // Support both "data" (legacy) and "props" (new) for backward compatibility
117
+ propsValue = comp.props !== undefined ? comp.props : comp.data;
118
+ dependenciesFn = comp.dependencies;
119
+ }
120
+ // Fallback: treat as direct component
121
+ else {
122
+ componentRef = comp;
123
+ propsValue = undefined;
124
+ dependenciesFn = undefined;
125
+ }
126
+
127
+ // Return props directly (object or function), not as computed
128
+ // The computed will be created in the template when needed
129
+ return {
130
+ component: componentRef,
131
+ props: typeof propsValue === 'function' ? propsValue(object) : propsValue || {},
132
+ dependencies: dependenciesFn ? dependenciesFn(object) : []
133
+ };
134
+ };
135
+
136
+ /**
137
+ * Normalize an array of sprite components
138
+ *
139
+ * Applies normalization to each component in the array using `normalizeComponent`.
140
+ *
141
+ * @param components - Array of component references or configuration objects
142
+ * @returns Array of normalized component configurations
143
+ */
144
+ const normalizeComponents = (components) => {
145
+ return components.map((comp) => normalizeComponent(comp));
146
+ };
147
+
148
+
149
+ /**
150
+ * Normalized components to render behind sprites
151
+ * Handles both direct component references and configuration objects with optional props and dependencies
152
+ *
153
+ * Supports multiple formats:
154
+ * 1. Direct component: `ShadowComponent`
155
+ * 2. Configuration object: `{ component: LightHalo, props: {...} }`
156
+ * 3. With dynamic props: `{ component: LightHalo, props: (object) => {...} }`
157
+ * 4. With dependencies: `{ component: HealthBar, dependencies: (object) => [object.hp, object.param.maxHp] }`
158
+ *
159
+ * Components with dependencies will only be displayed when all dependencies are resolved (!= undefined).
160
+ * The object is passed to the dependencies function to allow sprite-specific dependency resolution.
161
+ *
162
+ * @example
163
+ * ```ts
164
+ * // Direct component
165
+ * componentsBehind: [ShadowComponent]
166
+ *
167
+ * // With static props
168
+ * componentsBehind: [{ component: LightHalo, props: { radius: 30 } }]
169
+ *
170
+ * // With dynamic props and dependencies
171
+ * componentsBehind: [{
172
+ * component: HealthBar,
173
+ * props: (object) => ({ hp: object.hp(), maxHp: object.param.maxHp() }),
174
+ * dependencies: (object) => [object.hp, object.param.maxHp]
175
+ * }]
176
+ * ```
177
+ */
178
+ const normalizedComponentsBehind = computed(() => {
179
+ return normalizeComponents(componentsBehind());
180
+ });
181
+
182
+ /**
183
+ * Normalized components to render in front of sprites
184
+ * Handles both direct component references and configuration objects with optional props and dependencies
185
+ *
186
+ * See `normalizedComponentsBehind` for format details.
187
+ * Components with dependencies will only be displayed when all dependencies are resolved.
188
+ */
189
+ const normalizedComponentsInFront = computed(() => {
190
+ return normalizeComponents(componentsInFront());
191
+ });
192
+
193
+ /**
194
+ * Determine if the camera should follow this sprite
195
+ *
196
+ * The camera follows this sprite if:
197
+ * - It's explicitly set as the camera follow target, OR
198
+ * - It's the current player and no explicit target is set (default behavior)
199
+ */
200
+ const shouldFollowCamera = computed(() => {
201
+ const cameraTargetId = client.cameraFollowTargetId();
202
+ // If a target is explicitly set, only follow if this sprite is the target
203
+ if (cameraTargetId !== null) {
204
+ return id() === cameraTargetId;
205
+ }
206
+ // Otherwise, follow the current player (default behavior)
207
+ return isMe();
208
+ });
209
+
210
+ /**
211
+ * Get all attached GUI components that should be rendered on sprites
212
+ * These are GUIs with attachToSprite: true
213
+ */
214
+ const attachedGuis = computed(() => {
215
+ return guiService.getAttachedGuis();
216
+ });
217
+
218
+ /**
219
+ * Check if attached GUIs should be displayed for this sprite
220
+ * This is controlled by showAttachedGui/hideAttachedGui on the server
221
+ */
222
+ const shouldDisplayAttachedGui = computed(() => {
223
+ return guiService.shouldDisplayAttachedGui(id());
224
+ });
225
+
226
+ const {
227
+ x,
228
+ y,
229
+ tint,
230
+ direction,
231
+ animationName,
232
+ animationCurrentIndex,
233
+ emitParticleTrigger,
234
+ particleName,
235
+ graphics,
236
+ hitbox,
237
+ isConnected,
238
+ graphicsSignals,
239
+ flashTrigger
240
+ } = object;
241
+
242
+ /**
243
+ * Flash configuration signals for dynamic options
244
+ * These signals are updated when the flash trigger is activated with options
245
+ */
246
+ const flashType = signal<'alpha' | 'tint' | 'both'>('alpha');
247
+ const flashDuration = signal(300);
248
+ const flashCycles = signal(1);
249
+ const flashAlpha = signal(0.3);
250
+ const flashTint = signal(0xffffff);
251
+
252
+ /**
253
+ * Listen to flash trigger to update configuration dynamically
254
+ * When flash is triggered with options, update the signals
255
+ */
256
+ on(flashTrigger, (data) => {
257
+ if (data && typeof data === 'object') {
258
+ if (data.type !== undefined) flashType.set(data.type);
259
+ if (data.duration !== undefined) flashDuration.set(data.duration);
260
+ if (data.cycles !== undefined) flashCycles.set(data.cycles);
261
+ if (data.alpha !== undefined) flashAlpha.set(data.alpha);
262
+ if (data.tint !== undefined) flashTint.set(data.tint);
263
+ }
264
+ });
265
+
266
+ /**
267
+ * Flash configuration for the sprite
268
+ *
269
+ * This configuration is used by the flash directive to create visual feedback effects.
270
+ * The flash trigger is exposed through the object, allowing both server events and
271
+ * client-side code to trigger flash animations. Options can be passed dynamically
272
+ * through the trigger, which updates the reactive signals.
273
+ */
274
+ const flashConfig = computed(() => ({
275
+ trigger: flashTrigger,
276
+ type: flashType(),
277
+ duration: flashDuration(),
278
+ cycles: flashCycles(),
279
+ alpha: flashAlpha(),
280
+ tint: flashTint(),
281
+ }));
31
282
 
32
- const x = object.x;
33
- const y = object.y;
34
- const tint = object.tint;
35
- const direction = object.direction;
36
- const animationName = object.animationName;
37
- const emitParticleTrigger = object.emitParticleTrigger;
38
283
  const particleSettings = client.particleSettings;
39
- const particleName = object.particleName;
40
- const graphics = object.graphics;
41
-
42
- const hitbox = object.hitbox;
43
- const widthShadow = 10;
44
- const shadow = computed(() => ({
45
- x: hitbox().w / 2,
46
- y: hitbox().h - (hitbox().h / 2),
47
- width: hitbox().w + widthShadow,
48
- height: hitbox().h,
49
- }))
284
+
50
285
  const canControls = () => isMe() && object.canMove()
51
286
  const keyboardControls = client.globalConfig.keyboardControls;
52
287
 
288
+ const visible = computed(() => {
289
+ if (object.isEvent()) {
290
+ return true
291
+ }
292
+ return isConnected()
293
+ });
294
+
53
295
  const controls = signal({
54
296
  down: {
55
297
  repeat: true,
@@ -84,21 +326,145 @@
84
326
  keyDown() {
85
327
  if (canControls()) {
86
328
  client.processAction({ action: 'action' })
87
- // particleName.set('hit')
88
- // emitParticleTrigger.start()
89
- // object.flash('red')
90
329
  }
91
330
  },
92
331
  },
332
+ escape: {
333
+ bind: keyboardControls.escape,
334
+ keyDown() {
335
+ if (canControls()) {
336
+ client.processAction({ action: 'escape' })
337
+ }
338
+ },
339
+ },
340
+ gamepad: {
341
+ enabled: true
342
+ }
343
+ });
344
+
345
+ const smoothX = animatedSignal(x(), {
346
+ duration: isMe() ? 0 : 0
347
+ });
348
+
349
+ const smoothY = animatedSignal(y(), {
350
+ duration: isMe() ? 0 : 0,
93
351
  });
94
352
 
95
- const sheet = (graphicId) => {
353
+ const z = computed(() => {
354
+ return object.y() + object.z()
355
+ });
356
+
357
+ const realAnimationName = signal(animationName());
358
+
359
+ const xSubscription = x.observable.subscribe((value) => {
360
+ smoothX.set(value);
361
+ });
362
+
363
+ const ySubscription = y.observable.subscribe((value) => {
364
+ smoothY.set(value);
365
+ });
366
+
367
+ const sheet = (graphicObject) => {
96
368
  return {
97
- definition: spritesheets.get(graphicId),
98
- playing: animationName,
369
+ definition: graphicObject,
370
+ playing: realAnimationName(),
99
371
  params: {
100
- direction
372
+ direction: direction()
101
373
  },
374
+ onFinish() {
375
+ animationCurrentIndex.update(index => index + 1)
376
+ }
102
377
  };
103
378
  }
379
+
380
+ // Combine animation change detection with movement state from smoothX/smoothY
381
+ const movementAnimations = ['walk', 'stand'];
382
+ const epsilon = 0; // movement threshold to consider the easing still running
383
+
384
+ const stateX$ = smoothX.animatedState.observable;
385
+ const stateY$ = smoothY.animatedState.observable;
386
+ const animationName$ = animationName.observable;
387
+
388
+ const moving$ = combineLatest([stateX$, stateY$]).pipe(
389
+ map(([sx, sy]) => {
390
+ const xFinished = Math.abs(sx.value.current - sx.value.end) <= epsilon;
391
+ const yFinished = Math.abs(sy.value.current - sy.value.end) <= epsilon;
392
+ return !xFinished || !yFinished; // moving if X or Y is not finished
393
+ }),
394
+ startWith(false)
395
+ );
396
+
397
+ const animationChange$ = animationName$.pipe(
398
+ startWith(animationName()),
399
+ pairwise(),
400
+ filter(([prev, curr]) => prev !== curr)
401
+ );
402
+
403
+ const animationMovementSubscription = combineLatest([animationChange$, moving$]).subscribe(([[prev, curr], isMoving]) => {
404
+ if (curr == 'stand' && !isMoving) {
405
+ realAnimationName.set(curr);
406
+ }
407
+ else if (curr == 'walk' && isMoving) {
408
+ realAnimationName.set(curr);
409
+ }
410
+ else if (!movementAnimations.includes(curr)) {
411
+ realAnimationName.set(curr);
412
+ }
413
+ if (!isMoving && object.animationIsPlaying && object.animationIsPlaying()) {
414
+ if (movementAnimations.includes(curr)) {
415
+ if (typeof object.resetAnimationState === 'function') {
416
+ object.resetAnimationState();
417
+ }
418
+ }
419
+ }
420
+ });
421
+
422
+ /**
423
+ * Cleanup subscriptions and call hooks before sprite destruction.
424
+ *
425
+ * # Design
426
+ * - Prevent memory leaks by unsubscribing from all local subscriptions created in this component.
427
+ * - Execute destruction hooks to notify modules and scene map of sprite removal.
428
+ *
429
+ * @example
430
+ * await onBeforeDestroy();
431
+ */
432
+ const onBeforeDestroy = async () => {
433
+ animationMovementSubscription.unsubscribe();
434
+ xSubscription.unsubscribe();
435
+ ySubscription.unsubscribe();
436
+ await lastValueFrom(hooks.callHooks("client-sprite-onDestroy", object))
437
+ await lastValueFrom(hooks.callHooks("client-sceneMap-onRemoveSprite", client.sceneMap, object))
438
+ }
439
+
440
+ mount((element) => {
441
+ hooks.callHooks("client-sprite-onAdd", object).subscribe()
442
+ hooks.callHooks("client-sceneMap-onAddSprite", client.sceneMap, object).subscribe()
443
+ if (isMe()) client.setKeyboardControls(element.directives.controls)
444
+ })
445
+
446
+ /**
447
+ * Handle attached GUI finish event
448
+ *
449
+ * @param gui - The GUI instance
450
+ * @param data - Data passed from the GUI component
451
+ */
452
+ const onAttachedGuiFinish = (gui, data) => {
453
+ guiService.guiClose(gui.name, data);
454
+ };
455
+
456
+ /**
457
+ * Handle attached GUI interaction event
458
+ *
459
+ * @param gui - The GUI instance
460
+ * @param name - Interaction name
461
+ * @param data - Interaction data
462
+ */
463
+ const onAttachedGuiInteraction = (gui, name, data) => {
464
+ guiService.guiInteraction(gui.name, name, data);
465
+ };
466
+
467
+ tick(() => {
468
+ hooks.callHooks("client-sprite-onUpdate").subscribe()
469
+ })
104
470
  </script>
@@ -0,0 +1,80 @@
1
+ import { computed } from "canvasengine";
2
+
3
+ interface MatchResult {
4
+ property: string;
5
+ fullMatch: string;
6
+ index: number;
7
+ }
8
+
9
+ export const parseDynamicValue = (value: any, object?: any) => {
10
+ if (typeof value !== 'string') {
11
+ return computed(() => String(value ?? ''));
12
+ }
13
+
14
+ // Find all dynamic references like {propertyName}
15
+ const pattern = /\{([^}]+)\}/g;
16
+ const matches: MatchResult[] = [];
17
+ let match;
18
+
19
+ while ((match = pattern.exec(value)) !== null) {
20
+ matches.push({
21
+ property: match[1],
22
+ fullMatch: match[0],
23
+ index: match.index!
24
+ });
25
+ }
26
+
27
+ // If no dynamic references found, return simple computed
28
+ if (matches.length === 0) {
29
+ return computed(() => value);
30
+ }
31
+
32
+ // Create computed that tracks all referenced signals
33
+ return computed(() => {
34
+ let result = value;
35
+
36
+ // Replace from end to start to preserve indices
37
+ for (let i = matches.length - 1; i >= 0; i--) {
38
+ const { property, fullMatch } = matches[i];
39
+
40
+ // Try to access the property from the object
41
+ // Support nested properties like {param.maxHp}
42
+ let propertyValue = '';
43
+ try {
44
+ const propertyPath = property.split('.');
45
+ let currentValue = object;
46
+
47
+ for (let j = 0; j < propertyPath.length; j++) {
48
+ const prop = propertyPath[j];
49
+
50
+ // Check if currentValue is a signal (function) and call it
51
+ if (typeof currentValue === 'function') {
52
+ currentValue = currentValue();
53
+ }
54
+
55
+ // Access the property
56
+ if (currentValue && typeof currentValue === 'object' && prop in currentValue) {
57
+ currentValue = currentValue[prop];
58
+ } else {
59
+ currentValue = undefined;
60
+ break;
61
+ }
62
+ }
63
+
64
+ // If the final value is a signal, call it
65
+ if (typeof currentValue === 'function') {
66
+ currentValue = currentValue();
67
+ }
68
+
69
+ propertyValue = currentValue != null ? String(currentValue) : '';
70
+ } catch (error) {
71
+ // If property doesn't exist or can't be accessed, use empty string
72
+ propertyValue = '';
73
+ }
74
+
75
+ result = result.replace(fullMatch, propertyValue);
76
+ }
77
+
78
+ return result;
79
+ });
80
+ };