@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,39 +1,73 @@
1
- <Container sound={backgroundMusic} >
1
+ <Container sound={backgroundMusic} shake={shakeConfig} freeze={engine.gamePause}>
2
2
  <Container sound={backgroundAmbientSound} />
3
3
 
4
- <sceneComponent() data={map.@data} params={map.@params} />
5
-
6
- @for (effect of effects) {
4
+ @if (map() && sceneComponent()) {
5
+ <sceneComponent() data={map().data} params={map().params} />
6
+ }
7
+
8
+ @for (componentAnimation of componentAnimations) {
7
9
  <Container>
8
- @for (animation of effect.current) {
9
- <effect.component ...animation />
10
+ @for (animation of componentAnimation.current) {
11
+ <componentAnimation.component ...animation />
10
12
  }
11
13
  </Container>
12
14
  }
15
+
16
+ @if (weatherProps()) {
17
+ <Weather ...weatherProps() />
18
+ }
13
19
  </Container>
14
20
 
15
21
  <script>
16
- import { effect, signal, computed, mount } from 'canvasengine'
22
+ import { computed } from 'canvasengine'
17
23
  import { inject } from "../../core/inject";
18
24
  import { RpgClientEngine } from "../../RpgClientEngine";
25
+ import { Weather } from '@canvasengine/presets'
19
26
 
20
27
  const engine = inject(RpgClientEngine);
21
- const effects = engine.effects
22
- const map = engine.sceneMap.data
28
+ const componentAnimations = engine.componentAnimations
29
+ const map = engine.sceneMap?.data
23
30
  const sceneComponent = computed(() => map()?.component)
24
- const sceneParams = map()?.params
25
- const mapParams = map().params
26
- const animations = engine.sceneMap.animations
31
+ const mapParams = map()?.params
32
+ const weather = engine.sceneMap.weather
27
33
  const backgroundMusic = { src: mapParams?.backgroundMusic, autoplay: true, loop: true }
28
34
  const backgroundAmbientSound = { src: mapParams?.backgroundAmbientSound, autoplay: true, loop: true }
29
-
30
- const data = signal(map().data)
31
35
 
32
- const scale = mapParams?.scale || 1
33
- const worldWidth = (mapParams?.width || 2048) * scale
34
- const worldHeight = (mapParams?.height || 2048) * scale
35
-
36
- const clamp = {
37
- direction: "all"
36
+ const shakeConfig = {
37
+ trigger: engine.mapShakeTrigger,
38
+ intensity: 10,
39
+ duration: 500,
40
+ frequency: 10,
41
+ direction: 'both'
38
42
  }
39
- </script>
43
+
44
+ const weatherProps = computed(() => {
45
+ const state = weather?.()
46
+ if (!state) {
47
+ return null
48
+ }
49
+ const validEffects = ['rain', 'snow', 'fog', 'cloud']
50
+ if (!validEffects.includes(state.effect)) {
51
+ return null
52
+ }
53
+ const params = state.params ?? {}
54
+ return {
55
+ effect: state.effect,
56
+ speed: params.speed,
57
+ windDirection: params.windDirection,
58
+ windStrength: params.windStrength,
59
+ density: params.density,
60
+ maxDrops: params.maxDrops,
61
+ height: params.height,
62
+ scale: params.scale,
63
+ sunIntensity: params.sunIntensity,
64
+ sunAngle: params.sunAngle,
65
+ raySpread: params.raySpread,
66
+ rayTwinkle: params.rayTwinkle,
67
+ rayTwinkleSpeed: params.rayTwinkleSpeed,
68
+ zIndex: params.zIndex ?? 1000,
69
+ alpha: params.alpha,
70
+ blendMode: params.blendMode,
71
+ }
72
+ })
73
+ </script>
@@ -6,15 +6,21 @@
6
6
  @for ((player,id) of players) {
7
7
  <Character id={id} object={player} />
8
8
  }
9
+
10
+ @for (child of children) {
11
+ <child />
12
+ }
9
13
  </Container>
10
14
 
11
15
  <script>
12
- import { effect, signal } from 'canvasengine'
13
16
  import { inject } from "../../core/inject";
14
17
  import { RpgClientEngine } from "../../RpgClientEngine";
15
18
  import Character from "../character.ce";
19
+ import LightHalo from "../prebuilt/light-halo.ce";
16
20
 
17
21
  const engine = inject(RpgClientEngine);
22
+ const { children } = defineProps()
23
+
18
24
  const players = engine.sceneMap.players
19
25
  const events = engine.sceneMap.events
20
- </script>
26
+ </script>
@@ -0,0 +1,60 @@
1
+ <Rect
2
+ x={0}
3
+ y={0}
4
+ width={engine.width}
5
+ height={engine.height}
6
+ fill={color}
7
+ alpha={opacity}
8
+ zIndex={100000}
9
+ />
10
+
11
+ <script>
12
+ import { animatedSignal, mount, computed, signal } from "canvasengine";
13
+ import { inject } from "../../core/inject";
14
+ import { RpgClientEngine } from "../../RpgClientEngine";
15
+
16
+ const {
17
+ onFinish,
18
+ duration,
19
+ color,
20
+ fadeIn
21
+ } = defineProps({
22
+ duration: {
23
+ default: 1000
24
+ },
25
+ color: {
26
+ default: 'black'
27
+ },
28
+ fadeIn: {
29
+ default: true
30
+ }
31
+ });
32
+
33
+ const engine = inject(RpgClientEngine);
34
+
35
+ // Calculate width and height from engine
36
+ const width = computed(() => {
37
+ const w = engine.width();
38
+ return typeof w === 'string' ? parseInt(w) || 1920 : w;
39
+ });
40
+
41
+ const height = computed(() => {
42
+ const h = engine.height();
43
+ return typeof h === 'string' ? parseInt(h) || 1080 : h;
44
+ });
45
+
46
+ // Animation: fade in from transparent to opaque, or fade out from opaque to transparent
47
+ const opacity = animatedSignal(fadeIn() ? 0 : 1, {
48
+ duration: duration(),
49
+ onComplete: () => {
50
+ if (onFinish) {
51
+ onFinish();
52
+ }
53
+ }
54
+ });
55
+
56
+ mount(() => {
57
+ // Start the fade animation
58
+ opacity.set(fadeIn() ? 1 : 0);
59
+ });
60
+ </script>
package/src/core/setup.ts CHANGED
@@ -14,7 +14,7 @@ export async function startGame(options: SetupOptions) {
14
14
 
15
15
  await injector(context, options.providers);
16
16
 
17
- const engine = inject(context, RpgClientEngine);
17
+ const engine = inject<RpgClientEngine>(context, RpgClientEngine);
18
18
  await engine.start();
19
19
  return context;
20
- }
20
+ }
@@ -0,0 +1,8 @@
1
+ export function Spritesheet(options: Record<string, any> = {}) {
2
+ return (target: any) => {
3
+ Object.assign(target, options);
4
+ if (target.prototype) {
5
+ Object.assign(target.prototype, options);
6
+ }
7
+ };
8
+ }
package/src/index.ts CHANGED
@@ -2,12 +2,27 @@ export * from "./RpgClientEngine";
2
2
  export type * from "./RpgClient";
3
3
  export * from "./services/standalone";
4
4
  export * from "./services/mmorpg";
5
+ export * from "./services/save";
5
6
  export * from "./core/setup";
6
7
  export * from "./core/inject";
7
8
  export * from "./services/loadMap";
8
9
  export * from "./module";
9
10
  export * from "./Gui/Gui";
10
11
  export * from "./components/gui";
11
- export * from "./components/effects";
12
+ export * from "./components/animations";
13
+ export * from "./components/prebuilt";
12
14
  export * from "./presets";
13
- export * from "./components";
15
+ export * from "./components";
16
+ export * from "./components/gui";
17
+ export * from "./Sound";
18
+ export * from "./Resource";
19
+ export * from "./decorators/spritesheet";
20
+ export * from "./utils/getEntityProp";
21
+ export { Context } from "@signe/di";
22
+ export { KeyboardControls, Input } from "canvasengine";
23
+ export { Control } from "./services/keyboardControls";
24
+ export { RpgClientObject } from "./Game/Object";
25
+ export { RpgClientPlayer } from "./Game/Player";
26
+ export { RpgClientEvent } from "./Game/Event";
27
+ export { withMobile } from "./components/gui/mobile";
28
+ export * from "./services/AbstractSocket";
package/src/module.ts CHANGED
@@ -1,14 +1,69 @@
1
1
  import { findModules, provideModules } from "@rpgjs/common";
2
+ import { FactoryProvider } from "@signe/di";
2
3
  import { RpgClientEngine } from "./RpgClientEngine";
3
4
  import { RpgClient } from "./RpgClient";
4
5
  import { inject } from "@signe/di";
5
6
  import { RpgGui } from "./Gui/Gui";
7
+ import { getSoundMetadata } from "./Sound";
6
8
 
7
- export function provideClientModules(modules: RpgClient[]) {
9
+ /**
10
+ * Type for client modules that can be either:
11
+ * - An object implementing RpgClient interface
12
+ * - A class decorated with @RpgModule decorator
13
+ */
14
+ export type RpgClientModule = RpgClient | (new () => any);
15
+
16
+ /**
17
+ * Provides client modules configuration to Dependency Injection
18
+ *
19
+ * This function accepts an array of client modules that can be either:
20
+ * - Objects implementing the RpgClient interface
21
+ * - Classes decorated with the @RpgModule decorator (which will be instantiated)
22
+ *
23
+ * @param modules - Array of client modules (objects or classes)
24
+ * @returns FactoryProvider configuration for DI
25
+ * @example
26
+ * ```ts
27
+ * // Using an object
28
+ * provideClientModules([
29
+ * {
30
+ * engine: {
31
+ * onConnected(engine) {
32
+ * console.log('Client connected')
33
+ * }
34
+ * }
35
+ * }
36
+ * ])
37
+ *
38
+ * // Using a decorated class
39
+ * @RpgModule<RpgClient>({
40
+ * engine: {
41
+ * onStart(engine) {
42
+ * console.log('Client started')
43
+ * }
44
+ * }
45
+ * })
46
+ * class MyClientModule {}
47
+ *
48
+ * provideClientModules([MyClientModule])
49
+ * ```
50
+ */
51
+ export function provideClientModules(modules: RpgClientModule[]): FactoryProvider {
8
52
  return provideModules(modules, "client", (modules, context) => {
9
53
  const mainModuleClient = findModules(context, 'Client')
10
54
  modules = [...mainModuleClient, ...modules]
11
55
  modules = modules.map((module) => {
56
+ // If module is a class (constructor function), instantiate it
57
+ // The RpgModule decorator adds properties to the prototype, which will be accessible via the instance
58
+ if (typeof module === 'function') {
59
+ const instance = new module() as any;
60
+ // Copy all enumerable properties (including from prototype) to a plain object
61
+ const moduleObj: any = {};
62
+ for (const key in instance) {
63
+ moduleObj[key] = instance[key];
64
+ }
65
+ module = moduleObj;
66
+ }
12
67
  if ('client' in module) {
13
68
  module = module.client as any;
14
69
  }
@@ -22,33 +77,95 @@ export function provideClientModules(modules: RpgClient[]) {
22
77
  },
23
78
  };
24
79
  }
80
+ if (module.spritesheetResolver) {
81
+ const resolver = module.spritesheetResolver;
82
+ module.spritesheetResolver = {
83
+ load: (engine: RpgClientEngine) => {
84
+ engine.setSpritesheetResolver(resolver);
85
+ },
86
+ };
87
+ }
25
88
  if (module.sounds) {
26
89
  const sounds = [...module.sounds];
27
90
  module.sounds = {
28
91
  load: (engine: RpgClientEngine) => {
29
92
  sounds.forEach((sound) => {
30
- engine.addSound(sound);
93
+ // Check if it's a class decorated with @Sound
94
+ if (typeof sound === 'function' || (sound && sound.constructor && sound.constructor !== Object)) {
95
+ const metadata = getSoundMetadata(sound);
96
+ if (metadata) {
97
+ // Handle single sound
98
+ if (metadata.id && metadata.sound) {
99
+ engine.addSound({
100
+ id: metadata.id,
101
+ src: metadata.sound,
102
+ loop: metadata.loop,
103
+ volume: metadata.volume,
104
+ });
105
+ }
106
+ // Handle multiple sounds
107
+ if (metadata.sounds) {
108
+ Object.entries(metadata.sounds).forEach(([soundId, soundSrc]) => {
109
+ engine.addSound({
110
+ id: soundId,
111
+ src: soundSrc,
112
+ loop: metadata.loop,
113
+ volume: metadata.volume,
114
+ });
115
+ });
116
+ }
117
+ } else {
118
+ // Not a decorated class, treat as regular sound object
119
+ engine.addSound(sound);
120
+ }
121
+ } else {
122
+ // Regular sound object
123
+ engine.addSound(sound);
124
+ }
31
125
  });
32
126
  },
33
127
  };
34
128
  }
129
+ if (module.soundResolver) {
130
+ const resolver = module.soundResolver;
131
+ module.soundResolver = {
132
+ load: (engine: RpgClientEngine) => {
133
+ engine.setSoundResolver(resolver);
134
+ },
135
+ };
136
+ }
35
137
  if (module.gui) {
36
138
  const gui = [...module.gui];
37
139
  module.gui = {
38
140
  load: (engine: RpgClientEngine) => {
39
- const guiService = inject(engine.context, RpgGui);
141
+ const guiService = inject(engine.context, RpgGui) as RpgGui;
40
142
  gui.forEach((gui) => {
41
143
  guiService.add(gui);
42
144
  });
43
145
  },
44
146
  };
45
147
  }
46
- if (module.effects) {
47
- const effects = [...module.effects];
48
- module.effects = {
148
+ if (module.componentAnimations) {
149
+ const componentAnimations = [...module.componentAnimations];
150
+ module.componentAnimations = {
49
151
  load: (engine: RpgClientEngine) => {
50
- effects.forEach((effect) => {
51
- engine.addEffect(effect);
152
+ componentAnimations.forEach((componentAnimation) => {
153
+ engine.addComponentAnimation(componentAnimation);
154
+ });
155
+ },
156
+ };
157
+ }
158
+ if (module.transitions) {
159
+ const transitions = [...module.transitions];
160
+ module.transitions = {
161
+ load: (engine: RpgClientEngine) => {
162
+ const guiService = inject(engine.context, RpgGui) as RpgGui;
163
+ transitions.forEach((transition) => {
164
+ guiService.add({
165
+ name: transition.id,
166
+ component: transition.component,
167
+ data: transition.props || {}
168
+ });
52
169
  });
53
170
  },
54
171
  };
@@ -78,6 +195,11 @@ export function provideClientModules(modules: RpgClient[]) {
78
195
  engine.addSpriteComponentInFront(component);
79
196
  });
80
197
  }
198
+ if (sprite.components) {
199
+ Object.entries(sprite.components).forEach(([id, component]) => {
200
+ engine.registerSpriteComponent(id, component);
201
+ });
202
+ }
81
203
  },
82
204
  };
83
205
  }
@@ -103,9 +225,9 @@ export function provideClientGlobalConfig(config: any = {}) {
103
225
  down: 'down',
104
226
  left: 'left',
105
227
  right: 'right',
106
- action: 'space'
228
+ action: 'space',
229
+ escape: 'escape'
107
230
  }
108
231
  }
109
232
  return provideGlobalConfig(config)
110
233
  }
111
-
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Creates an animation spritesheet preset with automatic frame generation
3
+ *
4
+ * This function generates animation frames based on the provided width and height dimensions.
5
+ * It creates a sequence of frames that progresses through the spritesheet from left to right,
6
+ * top to bottom, with each frame having a 10ms time increment.
7
+ *
8
+ * @param {number} framesWidth - The number of frames horizontally in the spritesheet
9
+ * @param {number} framesHeight - The number of frames vertically in the spritesheet
10
+ * @returns {Object} Animation preset configuration object
11
+ *
12
+ * @example
13
+ * ```javascript
14
+ * // For a 4x4 spritesheet
15
+ * const preset = AnimationSpritesheetPreset(4, 4);
16
+ * // This will generate 16 frames with coordinates from (0,0) to (3,3)
17
+ * ```
18
+ */
19
+ export const AnimationSpritesheetPreset = (framesWidth: number, framesHeight: number) => {
20
+
21
+ const animations: Array<{ time: number; frameX: number; frameY: number }> = [];
22
+
23
+ for (let y = 0; y < framesHeight; y++) {
24
+ for (let x = 0; x < framesWidth; x++) {
25
+ const frameIndex = y * framesWidth + x;
26
+ animations.push({
27
+ time: frameIndex * 10,
28
+ frameX: x,
29
+ frameY: y
30
+ });
31
+ }
32
+ }
33
+
34
+ return {
35
+ framesWidth,
36
+ framesHeight,
37
+ textures: {
38
+ default: {
39
+ animations: () => [
40
+ animations
41
+ ],
42
+ }
43
+ }
44
+ };
45
+ };
46
+
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Creates a faceset preset for character expressions
3
+ *
4
+ * This preset allows you to define multiple facial expressions for a character,
5
+ * where each expression corresponds to a specific frame position (frameX, frameY)
6
+ * within a single faceset texture. Each expression is defined by its position
7
+ * in the faceset grid.
8
+ *
9
+ * @param options - Object containing the faceset configuration
10
+ * @param framesWidth - Number of frames horizontally in the faceset texture
11
+ * @param framesHeight - Number of frames vertically in the faceset texture
12
+ * @param expressions - Object mapping expression names to their frame positions as tuples [frameX, frameY]
13
+ * @returns Faceset configuration with animations for each expression
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * const faceset = FacesetPreset({
18
+ * id: "facesetId",
19
+ * image: "faceset.png",
20
+ * width: 1024,
21
+ * height: 1024,
22
+ * }, 4, 2, {
23
+ * happy: [0, 0],
24
+ * sad: [1, 0],
25
+ * angry: [2, 0],
26
+ * surprised: [3, 0]
27
+ * });
28
+ * ```
29
+ */
30
+ export const FacesetPreset = (
31
+ options: any,
32
+ framesWidth: number,
33
+ framesHeight: number,
34
+ expressions: Record<string, [number, number]>,
35
+ ) => {
36
+
37
+ const textures: Record<string, any> = {};
38
+
39
+ // Create texture configuration for each expression
40
+ Object.keys(expressions).forEach((expressionName) => {
41
+ const [frameX, frameY] = expressions[expressionName];
42
+ textures[expressionName] = {
43
+ animations: () => [
44
+ [{
45
+ time: 0,
46
+ frameX: frameX,
47
+ frameY: frameY
48
+ }]
49
+ ],
50
+ };
51
+ });
52
+
53
+ return {
54
+ ...options,
55
+ framesWidth,
56
+ framesHeight,
57
+ textures
58
+ };
59
+ };
60
+
@@ -0,0 +1,17 @@
1
+ export const IconPreset = (options: {
2
+ image: string;
3
+ framesWidth: number;
4
+ framesHeight: number;
5
+ id: string;
6
+ }) => {
7
+ return {
8
+ textures: {
9
+ default: {
10
+ animations: () => [
11
+ [{ time: 0, frameX: 0, frameY: 0 }]
12
+ ]
13
+ }
14
+ },
15
+ ...options
16
+ }
17
+ }
@@ -1,5 +1,13 @@
1
+ import { AnimationSpritesheetPreset } from "./animation";
2
+ import { LPCSpritesheetPreset } from "./lpc";
1
3
  import { RMSpritesheet } from "./rmspritesheet";
4
+ import { FacesetPreset } from "./faceset";
5
+ import { IconPreset } from "./icon";
2
6
 
3
7
  export const Presets = {
4
- RMSpritesheet
8
+ RMSpritesheet,
9
+ LPCSpritesheetPreset,
10
+ AnimationSpritesheetPreset,
11
+ FacesetPreset,
12
+ IconPreset
5
13
  }
@@ -0,0 +1,108 @@
1
+ import { Animation, Direction } from "@rpgjs/common";
2
+
3
+ export const LPCSpritesheetPreset = (options: {
4
+ id: string;
5
+ imageSource: string;
6
+ width: number;
7
+ height: number;
8
+ ratio?: number;
9
+ }) => {
10
+ const ratio = options.ratio ?? 1;
11
+
12
+ const frameY = (direction: Direction) => {
13
+ return {
14
+ [Direction.Down]: 2,
15
+ [Direction.Left]: 1,
16
+ [Direction.Right]: 3,
17
+ [Direction.Up]: 0,
18
+ }[direction];
19
+ };
20
+
21
+ const stand = (direction: Direction) => [
22
+ { time: 0, frameX: 0, frameY: frameY(direction) },
23
+ ];
24
+ const anim = (
25
+ direction: Direction,
26
+ framesWidth: number,
27
+ speed: number = 5
28
+ ) => {
29
+ const array: any = [];
30
+ for (let i = 0; i < framesWidth; i++) {
31
+ array.push({ time: i * speed, frameX: i, frameY: frameY(direction) });
32
+ }
33
+ return array;
34
+ };
35
+
36
+ return {
37
+ id: options.id,
38
+ image: options.imageSource,
39
+ width: options.width,
40
+ height: options.height,
41
+ opacity: 1,
42
+ rectWidth: 64 * ratio,
43
+ rectHeight: 64 * ratio,
44
+ framesWidth: 6,
45
+ framesHeight: 4,
46
+ spriteRealSize: {
47
+ width: 48 * ratio,
48
+ height: 52 * ratio,
49
+ },
50
+ textures: {
51
+ [Animation.Stand]: {
52
+ offset: {
53
+ x: 0,
54
+ y: 512 * ratio,
55
+ },
56
+ animations: ({ direction }) => [stand(direction)],
57
+ },
58
+ [Animation.Walk]: {
59
+ offset: {
60
+ x: 0,
61
+ y: 512 * ratio,
62
+ },
63
+ framesWidth: 9,
64
+ framesHeight: 4,
65
+ animations: ({ direction }) => [anim(direction, 9)],
66
+ },
67
+ [Animation.Attack]: {
68
+ offset: {
69
+ x: 0,
70
+ y: 768 * ratio,
71
+ },
72
+ framesWidth: 6,
73
+ framesHeight: 4,
74
+ animations: ({ direction }) => [anim(direction, 6, 3)],
75
+ },
76
+ [Animation.Skill]: {
77
+ framesWidth: 7,
78
+ framesHeight: 4,
79
+ animations: ({ direction }) => [anim(direction, 7, 3)],
80
+ },
81
+ attack2: {
82
+ offset: {
83
+ x: 0,
84
+ y: 256 * ratio,
85
+ },
86
+ framesWidth: 7,
87
+ framesHeight: 8,
88
+ animations: ({ direction }) => [anim(direction, 7, 3)],
89
+ },
90
+ ...(options.height > 3000
91
+ ? {
92
+ attack3: {
93
+ offset: {
94
+ x: 0,
95
+ y: 5568 - 288 * 4,
96
+ },
97
+ rectWidth: 288,
98
+ rectHeight: 288,
99
+ framesWidth: 6,
100
+ framesHeight: 4,
101
+ animations: ({ direction }) => [anim(direction, 6, 3)],
102
+ },
103
+ }
104
+ : {}),
105
+ },
106
+ };
107
+ };
108
+