@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
@@ -0,0 +1,8 @@
1
+ import { RpgCommonPlayer } from '@rpgjs/common';
2
+ export declare class AnimationManager {
3
+ current: import('canvasengine').WritableArraySignal<any[]>;
4
+ displayEffect(params: any, player: RpgCommonPlayer | {
5
+ x: number;
6
+ y: number;
7
+ }): void;
8
+ }
@@ -0,0 +1,26 @@
1
+ import { signal } from "canvasengine";
2
+ import { generateUID } from "@rpgjs/common";
3
+ //#region src/Game/AnimationManager.ts
4
+ var AnimationManager = class {
5
+ constructor() {
6
+ this.current = signal([]);
7
+ }
8
+ displayEffect(params, player) {
9
+ const id = generateUID();
10
+ this.current().push({
11
+ ...params,
12
+ id,
13
+ x: player.x,
14
+ y: player.y,
15
+ object: player,
16
+ onFinish: () => {
17
+ const index = this.current().findIndex((value) => value.id === id);
18
+ this.current().splice(index, 1);
19
+ }
20
+ });
21
+ }
22
+ };
23
+ //#endregion
24
+ export { AnimationManager };
25
+
26
+ //# sourceMappingURL=AnimationManager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AnimationManager.js","names":[],"sources":["../../src/Game/AnimationManager.ts"],"sourcesContent":["import { generateUID, RpgCommonPlayer } from \"@rpgjs/common\";\nimport { signal } from \"canvasengine\";\n\nexport class AnimationManager {\n current = signal<any[]>([]);\n\n displayEffect(params: any, player: RpgCommonPlayer | { x: number, y: number }) {\n const id = generateUID();\n this.current().push({\n ...params,\n id,\n x: player.x,\n y: player.y,\n object: player,\n onFinish: () => {\n const index = this.current().findIndex((value) => value.id === id);\n this.current().splice(index, 1);\n },\n });\n }\n}\n"],"mappings":";;;AAGA,IAAa,mBAAb,MAA8B;;iBAClB,OAAc,EAAE,CAAC;;CAE3B,cAAc,QAAa,QAAoD;EAC7E,MAAM,KAAK,aAAa;AACxB,OAAK,SAAS,CAAC,KAAK;GAClB,GAAG;GACH;GACA,GAAG,OAAO;GACV,GAAG,OAAO;GACV,QAAQ;GACR,gBAAgB;IACd,MAAM,QAAQ,KAAK,SAAS,CAAC,WAAW,UAAU,MAAM,OAAO,GAAG;AAClE,SAAK,SAAS,CAAC,OAAO,OAAO,EAAE;;GAElC,CAAC"}
@@ -1,4 +1,4 @@
1
1
  import { RpgClientObject } from './Object';
2
2
  export declare class RpgClientEvent extends RpgClientObject {
3
- type: string;
3
+ _type: string;
4
4
  }
@@ -0,0 +1,12 @@
1
+ import { RpgClientObject } from "./Object.js";
2
+ //#region src/Game/Event.ts
3
+ var RpgClientEvent = class extends RpgClientObject {
4
+ constructor(..._args) {
5
+ super(..._args);
6
+ this._type = "event";
7
+ }
8
+ };
9
+ //#endregion
10
+ export { RpgClientEvent };
11
+
12
+ //# sourceMappingURL=Event.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Event.js","names":[],"sources":["../../src/Game/Event.ts"],"sourcesContent":["import { RpgClientObject } from \"./Object\"; \n\nexport class RpgClientEvent extends RpgClientObject {\n _type = 'event'\n} "],"mappings":";;AAEA,IAAa,iBAAb,cAAoC,gBAAgB;;;eACxC"}
@@ -1,7 +1,28 @@
1
- import { RpgCommonMap } from '@rpgjs/common';
1
+ import { RpgCommonMap, WeatherState, MapPhysicsInitContext, MapPhysicsEntityContext } from '@rpgjs/common';
2
2
  import { RpgClientPlayer } from './Player';
3
3
  import { RpgClientEvent } from './Event';
4
- export declare class RpgClientMap extends RpgCommonMap<RpgClientPlayer> {
4
+ import { RpgClientEngine } from '../RpgClientEngine';
5
+ export declare class RpgClientMap extends RpgCommonMap<any> {
6
+ engine: RpgClientEngine;
5
7
  players: import('canvasengine').WritableObjectSignal<Record<string, RpgClientPlayer>>;
6
8
  events: import('canvasengine').WritableObjectSignal<Record<string, RpgClientEvent>>;
9
+ currentPlayer: import('canvasengine').ComputedSignal<RpgClientPlayer>;
10
+ weatherState: import('canvasengine').WritableSignal<WeatherState | null>;
11
+ localWeatherOverride: import('canvasengine').WritableSignal<WeatherState | null>;
12
+ weather: import('canvasengine').ComputedSignal<WeatherState | null>;
13
+ private manualClientPhysicsTick;
14
+ private readonly isTestEnvironment;
15
+ constructor();
16
+ configureClientPrediction(enabled: boolean): void;
17
+ getCurrentPlayer(): RpgClientPlayer;
18
+ reset(force?: boolean): void;
19
+ getWeather(): WeatherState | null;
20
+ setLocalWeather(next: WeatherState | null): void;
21
+ clearLocalWeather(): void;
22
+ stepClientPhysics(deltaMs: number): number;
23
+ stepPredictionTick(): void;
24
+ protected emitPhysicsInit(context: MapPhysicsInitContext): void;
25
+ protected emitPhysicsEntityAdd(context: MapPhysicsEntityContext): void;
26
+ protected emitPhysicsEntityRemove(context: MapPhysicsEntityContext): void;
27
+ protected emitPhysicsReset(): void;
7
28
  }
@@ -0,0 +1,80 @@
1
+ import { inject } from "../core/inject.js";
2
+ import { sync, users } from "../node_modules/.pnpm/@signe_sync@2.9.0/node_modules/@signe/sync/dist/index.js";
3
+ import { RpgClientPlayer } from "./Player.js";
4
+ import { RpgClientEvent } from "./Event.js";
5
+ import { __decorateMetadata } from "../_virtual/_@oxc-project_runtime@0.122.0/helpers/decorateMetadata.js";
6
+ import { __decorate } from "../_virtual/_@oxc-project_runtime@0.122.0/helpers/decorate.js";
7
+ import { RpgClientEngine } from "../RpgClientEngine.js";
8
+ import { computed, signal } from "canvasengine";
9
+ import { RpgCommonMap } from "@rpgjs/common";
10
+ //#region src/Game/Map.ts
11
+ var RpgClientMap = class extends RpgCommonMap {
12
+ constructor() {
13
+ super();
14
+ this.engine = inject(RpgClientEngine);
15
+ this.players = signal({});
16
+ this.events = signal({});
17
+ this.currentPlayer = computed(() => this.players()[this.engine.playerIdSignal()]);
18
+ this.weatherState = signal(null);
19
+ this.localWeatherOverride = signal(null);
20
+ this.weather = computed(() => {
21
+ const local = this.localWeatherOverride();
22
+ const state = this.weatherState();
23
+ return local ?? state;
24
+ });
25
+ this.manualClientPhysicsTick = false;
26
+ const isTest = typeof process !== "undefined" && process.env?.TEST === "true" || typeof window !== "undefined" && window.__RPGJS_TEST__ === true;
27
+ this.isTestEnvironment = isTest;
28
+ if (isTest) this.autoTickEnabled = false;
29
+ }
30
+ configureClientPrediction(enabled) {
31
+ this.manualClientPhysicsTick = enabled;
32
+ this.autoTickEnabled = enabled ? false : !this.isTestEnvironment;
33
+ }
34
+ getCurrentPlayer() {
35
+ return this.currentPlayer();
36
+ }
37
+ reset(force = false) {
38
+ const currentPlayerId = this.engine.playerIdSignal();
39
+ const currentPlayer = !force && currentPlayerId ? this.players()[currentPlayerId] : void 0;
40
+ this.players.set(currentPlayerId && currentPlayer ? { [currentPlayerId]: currentPlayer } : {});
41
+ this.events.set({});
42
+ this.weatherState.set(null);
43
+ this.localWeatherOverride.set(null);
44
+ this.clearPhysic();
45
+ }
46
+ getWeather() {
47
+ return this.weather();
48
+ }
49
+ setLocalWeather(next) {
50
+ this.localWeatherOverride.set(next);
51
+ }
52
+ clearLocalWeather() {
53
+ this.localWeatherOverride.set(null);
54
+ }
55
+ stepClientPhysics(deltaMs) {
56
+ if (!this.manualClientPhysicsTick) return 0;
57
+ return this.nextTick(deltaMs);
58
+ }
59
+ stepPredictionTick() {
60
+ this.forceSingleTick();
61
+ }
62
+ emitPhysicsInit(context) {
63
+ this.engine?.emitSceneMapHook?.("onPhysicsInit", this, context);
64
+ }
65
+ emitPhysicsEntityAdd(context) {
66
+ this.engine?.emitSceneMapHook?.("onPhysicsEntityAdd", this, context);
67
+ }
68
+ emitPhysicsEntityRemove(context) {
69
+ this.engine?.emitSceneMapHook?.("onPhysicsEntityRemove", this, context);
70
+ }
71
+ emitPhysicsReset() {
72
+ this.engine?.emitSceneMapHook?.("onPhysicsReset", this);
73
+ }
74
+ };
75
+ __decorate([users(RpgClientPlayer), __decorateMetadata("design:type", Object)], RpgClientMap.prototype, "players", void 0);
76
+ __decorate([sync(RpgClientEvent), __decorateMetadata("design:type", Object)], RpgClientMap.prototype, "events", void 0);
77
+ //#endregion
78
+ export { RpgClientMap };
79
+
80
+ //# sourceMappingURL=Map.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Map.js","names":[],"sources":["../../src/Game/Map.ts"],"sourcesContent":["import {\n RpgCommonMap,\n type WeatherState,\n type MapPhysicsInitContext,\n type MapPhysicsEntityContext,\n} from \"@rpgjs/common\";\nimport { sync, users } from \"@signe/sync\";\nimport { RpgClientPlayer } from \"./Player\";\nimport { Signal, signal, computed, effect } from \"canvasengine\";\nimport { RpgClientEvent } from \"./Event\";\nimport { RpgClientEngine } from \"../RpgClientEngine\";\nimport { inject } from \"../core/inject\";\n\nexport class RpgClientMap extends RpgCommonMap<any> {\n engine: RpgClientEngine = inject(RpgClientEngine)\n @users(RpgClientPlayer) players = signal<Record<string, RpgClientPlayer>>({});\n @sync(RpgClientEvent) events = signal<Record<string, RpgClientEvent>>({});\n currentPlayer = computed(() => this.players()[this.engine.playerIdSignal()!])\n weatherState = signal<WeatherState | null>(null);\n localWeatherOverride = signal<WeatherState | null>(null);\n weather = computed<WeatherState | null>(() => {\n const local = this.localWeatherOverride() \n const state = this.weatherState()\n return local ?? state\n });\n private manualClientPhysicsTick = false;\n private readonly isTestEnvironment: boolean;\n\n constructor() {\n super();\n // Détecter l'environnement de test\n const isTest = (typeof process !== 'undefined' && process.env?.TEST === 'true')\n || (typeof window !== 'undefined' && (window as any).__RPGJS_TEST__ === true);\n this.isTestEnvironment = isTest;\n if (isTest) {\n this.autoTickEnabled = false;\n }\n }\n\n configureClientPrediction(enabled: boolean): void {\n this.manualClientPhysicsTick = enabled;\n this.autoTickEnabled = enabled ? false : !this.isTestEnvironment;\n }\n\n getCurrentPlayer() {\n return this.currentPlayer()\n }\n\n reset(force = false) {\n const currentPlayerId = this.engine.playerIdSignal();\n const currentPlayer = !force && currentPlayerId\n ? this.players()[currentPlayerId]\n : undefined;\n\n this.players.set(\n currentPlayerId && currentPlayer ? { [currentPlayerId]: currentPlayer } : {}\n );\n this.events.set({})\n this.weatherState.set(null);\n this.localWeatherOverride.set(null);\n this.clearPhysic()\n }\n\n getWeather(): WeatherState | null {\n return this.weather();\n }\n\n setLocalWeather(next: WeatherState | null): void {\n this.localWeatherOverride.set(next);\n }\n\n clearLocalWeather(): void {\n this.localWeatherOverride.set(null);\n }\n\n stepClientPhysics(deltaMs: number): number {\n if (!this.manualClientPhysicsTick) {\n return 0;\n }\n return this.nextTick(deltaMs);\n }\n\n stepPredictionTick(): void {\n this.forceSingleTick();\n }\n\n protected emitPhysicsInit(context: MapPhysicsInitContext): void {\n this.engine?.emitSceneMapHook?.(\"onPhysicsInit\", this, context);\n }\n\n protected emitPhysicsEntityAdd(context: MapPhysicsEntityContext): void {\n this.engine?.emitSceneMapHook?.(\"onPhysicsEntityAdd\", this, context);\n }\n\n protected emitPhysicsEntityRemove(context: MapPhysicsEntityContext): void {\n this.engine?.emitSceneMapHook?.(\"onPhysicsEntityRemove\", this, context);\n }\n\n protected emitPhysicsReset(): void {\n this.engine?.emitSceneMapHook?.(\"onPhysicsReset\", this);\n }\n}\n"],"mappings":";;;;;;;;;;AAaA,IAAa,eAAb,cAAkC,aAAkB;CAelD,cAAc;AACZ,SAAO;gBAfiB,OAAO,gBAAgB;iBACf,OAAwC,EAAE,CAAC;gBAC9C,OAAuC,EAAE,CAAC;uBACzD,eAAe,KAAK,SAAS,CAAC,KAAK,OAAO,gBAAgB,EAAG;sBAC9D,OAA4B,KAAK;8BACzB,OAA4B,KAAK;iBAC9C,eAAoC;GAC5C,MAAM,QAAQ,KAAK,sBAAsB;GACzC,MAAM,QAAQ,KAAK,cAAc;AACjC,UAAO,SAAS;IAChB;iCACgC;EAMhC,MAAM,SAAU,OAAO,YAAY,eAAe,QAAQ,KAAK,SAAS,UAClE,OAAO,WAAW,eAAgB,OAAe,mBAAmB;AAC1E,OAAK,oBAAoB;AACzB,MAAI,OACF,MAAK,kBAAkB;;CAI3B,0BAA0B,SAAwB;AAChD,OAAK,0BAA0B;AAC/B,OAAK,kBAAkB,UAAU,QAAQ,CAAC,KAAK;;CAGjD,mBAAmB;AACjB,SAAO,KAAK,eAAe;;CAG7B,MAAM,QAAQ,OAAO;EACnB,MAAM,kBAAkB,KAAK,OAAO,gBAAgB;EACpD,MAAM,gBAAgB,CAAC,SAAS,kBAC5B,KAAK,SAAS,CAAC,mBACf,KAAA;AAEJ,OAAK,QAAQ,IACX,mBAAmB,gBAAgB,GAAG,kBAAkB,eAAe,GAAG,EAAE,CAC7E;AACD,OAAK,OAAO,IAAI,EAAE,CAAC;AACnB,OAAK,aAAa,IAAI,KAAK;AAC3B,OAAK,qBAAqB,IAAI,KAAK;AACnC,OAAK,aAAa;;CAGpB,aAAkC;AAChC,SAAO,KAAK,SAAS;;CAGvB,gBAAgB,MAAiC;AAC/C,OAAK,qBAAqB,IAAI,KAAK;;CAGrC,oBAA0B;AACxB,OAAK,qBAAqB,IAAI,KAAK;;CAGrC,kBAAkB,SAAyB;AACzC,MAAI,CAAC,KAAK,wBACR,QAAO;AAET,SAAO,KAAK,SAAS,QAAQ;;CAG/B,qBAA2B;AACzB,OAAK,iBAAiB;;CAGxB,gBAA0B,SAAsC;AAC9D,OAAK,QAAQ,mBAAmB,iBAAiB,MAAM,QAAQ;;CAGjE,qBAA+B,SAAwC;AACrE,OAAK,QAAQ,mBAAmB,sBAAsB,MAAM,QAAQ;;CAGtE,wBAAkC,SAAwC;AACxE,OAAK,QAAQ,mBAAmB,yBAAyB,MAAM,QAAQ;;CAGzE,mBAAmC;AACjC,OAAK,QAAQ,mBAAmB,kBAAkB,KAAK;;;YApFxD,MAAM,gBAAgB,EAAA,mBAAA,eAAA,OAAA,CAAA,EAAA,aAAA,WAAA,WAAA,KAAA,EAAA;YACtB,KAAK,eAAe,EAAA,mBAAA,eAAA,OAAA,CAAA,EAAA,aAAA,WAAA,UAAA,KAAA,EAAA"}
@@ -0,0 +1,157 @@
1
+ import { Hooks, RpgCommonPlayer } from '@rpgjs/common';
2
+ import { RpgClientEngine } from '../RpgClientEngine';
3
+ type Frame = {
4
+ x: number;
5
+ y: number;
6
+ ts: number;
7
+ };
8
+ export declare abstract class RpgClientObject extends RpgCommonPlayer {
9
+ abstract _type: string;
10
+ emitParticleTrigger: import('canvasengine').Trigger<any>;
11
+ particleName: import('canvasengine').WritableSignal<string>;
12
+ animationCurrentIndex: import('canvasengine').WritableSignal<number>;
13
+ animationIsPlaying: import('canvasengine').WritableSignal<boolean>;
14
+ _param: import('canvasengine').WritableObjectSignal<{}>;
15
+ frames: Frame[];
16
+ graphicsSignals: import('canvasengine').WritableArraySignal<any[]>;
17
+ _component: {};
18
+ flashTrigger: import('canvasengine').Trigger<any>;
19
+ constructor();
20
+ /**
21
+ * Access the shared client hook registry.
22
+ *
23
+ * @returns The hook service used to register and trigger client-side hooks.
24
+ */
25
+ get hooks(): Hooks;
26
+ /**
27
+ * Access the current client engine instance.
28
+ *
29
+ * @returns The active {@link RpgClientEngine} instance.
30
+ */
31
+ get engine(): RpgClientEngine<unknown>;
32
+ private animationSubscription?;
33
+ /**
34
+ * Trigger a flash animation on this sprite
35
+ *
36
+ * This method triggers a flash effect using CanvasEngine's flash directive.
37
+ * The flash can be configured with various options including type (alpha, tint, or both),
38
+ * duration, cycles, and color.
39
+ *
40
+ * ## Design
41
+ *
42
+ * The flash uses a trigger system that is connected to the flash directive in the
43
+ * character component. This allows for flexible configuration and can be triggered
44
+ * from both server events and client-side code.
45
+ *
46
+ * @param options - Flash configuration options
47
+ * @param options.type - Type of flash effect: 'alpha' (opacity), 'tint' (color), or 'both' (default: 'alpha')
48
+ * @param options.duration - Duration of the flash animation in milliseconds (default: 300)
49
+ * @param options.cycles - Number of flash cycles (flash on/off) (default: 1)
50
+ * @param options.alpha - Alpha value when flashing, from 0 to 1 (default: 0.3)
51
+ * @param options.tint - Tint color when flashing as hex value or color name (default: 0xffffff - white)
52
+ *
53
+ * @example
54
+ * ```ts
55
+ * // Simple flash with default settings (alpha flash)
56
+ * player.flash();
57
+ *
58
+ * // Flash with red tint
59
+ * player.flash({ type: 'tint', tint: 0xff0000 });
60
+ *
61
+ * // Flash with both alpha and tint
62
+ * player.flash({
63
+ * type: 'both',
64
+ * alpha: 0.5,
65
+ * tint: 0xff0000,
66
+ * duration: 200,
67
+ * cycles: 2
68
+ * });
69
+ *
70
+ * // Quick damage flash
71
+ * player.flash({
72
+ * type: 'tint',
73
+ * tint: 0xff0000,
74
+ * duration: 150,
75
+ * cycles: 1
76
+ * });
77
+ * ```
78
+ */
79
+ flash(options?: {
80
+ type?: 'alpha' | 'tint' | 'both';
81
+ duration?: number;
82
+ cycles?: number;
83
+ alpha?: number;
84
+ tint?: number | string;
85
+ }): void;
86
+ /**
87
+ * Reset animation state when animation changes externally
88
+ *
89
+ * This method should be called when the animation changes due to movement
90
+ * or other external factors to ensure the animation system doesn't get stuck
91
+ *
92
+ * @example
93
+ * ```ts
94
+ * // Reset when player starts moving
95
+ * player.resetAnimationState();
96
+ * ```
97
+ */
98
+ resetAnimationState(): void;
99
+ /**
100
+ * Set a custom animation for a specific number of times
101
+ *
102
+ * Plays a custom animation for the specified number of repetitions.
103
+ * The animation system prevents overlapping animations and automatically
104
+ * returns to the previous animation when complete.
105
+ *
106
+ * @param animationName - Name of the animation to play
107
+ * @param nbTimes - Number of times to repeat the animation (default: Infinity for continuous)
108
+ *
109
+ * @example
110
+ * ```ts
111
+ * // Play attack animation 3 times
112
+ * player.setAnimation('attack', 3);
113
+ *
114
+ * // Play continuous spell animation
115
+ * player.setAnimation('spell');
116
+ * ```
117
+ */
118
+ setAnimation(animationName: string, nbTimes?: number): void;
119
+ /**
120
+ * Set a custom animation with temporary graphic change
121
+ *
122
+ * Plays a custom animation for the specified number of repetitions and temporarily
123
+ * changes the player's graphic (sprite sheet) during the animation. The graphic
124
+ * is automatically reset when the animation finishes.
125
+ *
126
+ * @param animationName - Name of the animation to play
127
+ * @param graphic - The graphic(s) to temporarily use during the animation
128
+ * @param nbTimes - Number of times to repeat the animation (default: Infinity for continuous)
129
+ *
130
+ * @example
131
+ * ```ts
132
+ * // Play attack animation with temporary graphic change
133
+ * player.setAnimation('attack', 'hero_attack', 3);
134
+ * ```
135
+ */
136
+ setAnimation(animationName: string, graphic?: string | string[], nbTimes?: number): void;
137
+ /**
138
+ * Display a registered component animation effect on this object.
139
+ *
140
+ * @param id - Identifier of the component animation to play.
141
+ * @param params - Parameters forwarded to the animation effect.
142
+ */
143
+ showComponentAnimation(id: string, params: any): void;
144
+ /**
145
+ * Check whether this client object represents an event.
146
+ *
147
+ * @returns `true` if the object type is `event`, otherwise `false`.
148
+ */
149
+ isEvent(): boolean;
150
+ /**
151
+ * Check whether this client object represents a player.
152
+ *
153
+ * @returns `true` if the object type is `player`, otherwise `false`.
154
+ */
155
+ isPlayer(): boolean;
156
+ }
157
+ export {};
@@ -0,0 +1,211 @@
1
+ import { inject } from "../core/inject.js";
2
+ import component from "../components/dynamics/text.ce.js";
3
+ import { RpgClientEngine } from "../RpgClientEngine.js";
4
+ import { signal, trigger } from "canvasengine";
5
+ import { ModulesToken, RpgCommonPlayer } from "@rpgjs/common";
6
+ import { filter, from, map, switchMap } from "rxjs";
7
+ //#region src/Game/Object.ts
8
+ var DYNAMIC_COMPONENTS = { text: component };
9
+ var RpgClientObject = class extends RpgCommonPlayer {
10
+ constructor() {
11
+ super();
12
+ this.emitParticleTrigger = trigger();
13
+ this.particleName = signal("");
14
+ this.animationCurrentIndex = signal(0);
15
+ this.animationIsPlaying = signal(false);
16
+ this._param = signal({});
17
+ this.frames = [];
18
+ this.graphicsSignals = signal([]);
19
+ this._component = {};
20
+ this.flashTrigger = trigger();
21
+ this.hooks.callHooks("client-sprite-onInit", this).subscribe();
22
+ this._frames.observable.subscribe(({ items }) => {
23
+ if (!this.id) return;
24
+ const nextFrames = items.flatMap((item) => Array.isArray(item) ? item : [item]);
25
+ this.frames = [...this.frames, ...nextFrames];
26
+ });
27
+ this.graphics.observable.pipe(map(({ items }) => items), filter((graphics) => graphics.length > 0), switchMap((graphics) => from(Promise.all(graphics.map((graphic) => this.engine.getSpriteSheet(graphic)))))).subscribe((sheets) => {
28
+ this.graphicsSignals.set(sheets);
29
+ });
30
+ this.componentsTop.observable.pipe(filter((value) => value !== null && value !== void 0), map((value) => typeof value === "string" ? JSON.parse(value) : value)).subscribe(({ components }) => {
31
+ for (const component of components) for (const [key, value] of Object.entries(component)) {
32
+ this._component = value;
33
+ console.log(value);
34
+ const type = value.type;
35
+ if (DYNAMIC_COMPONENTS[type]) this.engine.addSpriteComponentInFront(DYNAMIC_COMPONENTS[type]);
36
+ }
37
+ });
38
+ this.engine.tick.pipe().subscribe(() => {
39
+ const frame = this.frames.shift();
40
+ if (frame) {
41
+ if (typeof frame.x !== "number" || typeof frame.y !== "number") return;
42
+ this.engine.scene.setBodyPosition(this.id, frame.x, frame.y, "top-left");
43
+ }
44
+ });
45
+ }
46
+ /**
47
+ * Access the shared client hook registry.
48
+ *
49
+ * @returns The hook service used to register and trigger client-side hooks.
50
+ */
51
+ get hooks() {
52
+ return inject(ModulesToken);
53
+ }
54
+ /**
55
+ * Access the current client engine instance.
56
+ *
57
+ * @returns The active {@link RpgClientEngine} instance.
58
+ */
59
+ get engine() {
60
+ return inject(RpgClientEngine);
61
+ }
62
+ /**
63
+ * Trigger a flash animation on this sprite
64
+ *
65
+ * This method triggers a flash effect using CanvasEngine's flash directive.
66
+ * The flash can be configured with various options including type (alpha, tint, or both),
67
+ * duration, cycles, and color.
68
+ *
69
+ * ## Design
70
+ *
71
+ * The flash uses a trigger system that is connected to the flash directive in the
72
+ * character component. This allows for flexible configuration and can be triggered
73
+ * from both server events and client-side code.
74
+ *
75
+ * @param options - Flash configuration options
76
+ * @param options.type - Type of flash effect: 'alpha' (opacity), 'tint' (color), or 'both' (default: 'alpha')
77
+ * @param options.duration - Duration of the flash animation in milliseconds (default: 300)
78
+ * @param options.cycles - Number of flash cycles (flash on/off) (default: 1)
79
+ * @param options.alpha - Alpha value when flashing, from 0 to 1 (default: 0.3)
80
+ * @param options.tint - Tint color when flashing as hex value or color name (default: 0xffffff - white)
81
+ *
82
+ * @example
83
+ * ```ts
84
+ * // Simple flash with default settings (alpha flash)
85
+ * player.flash();
86
+ *
87
+ * // Flash with red tint
88
+ * player.flash({ type: 'tint', tint: 0xff0000 });
89
+ *
90
+ * // Flash with both alpha and tint
91
+ * player.flash({
92
+ * type: 'both',
93
+ * alpha: 0.5,
94
+ * tint: 0xff0000,
95
+ * duration: 200,
96
+ * cycles: 2
97
+ * });
98
+ *
99
+ * // Quick damage flash
100
+ * player.flash({
101
+ * type: 'tint',
102
+ * tint: 0xff0000,
103
+ * duration: 150,
104
+ * cycles: 1
105
+ * });
106
+ * ```
107
+ */
108
+ flash(options) {
109
+ const flashOptions = {
110
+ type: options?.type || "alpha",
111
+ duration: options?.duration ?? 300,
112
+ cycles: options?.cycles ?? 1,
113
+ alpha: options?.alpha ?? .3,
114
+ tint: options?.tint ?? 16777215
115
+ };
116
+ let tintValue = flashOptions.tint;
117
+ if (typeof tintValue === "string") tintValue = {
118
+ "white": 16777215,
119
+ "red": 16711680,
120
+ "green": 65280,
121
+ "blue": 255,
122
+ "yellow": 16776960,
123
+ "cyan": 65535,
124
+ "magenta": 16711935,
125
+ "black": 0
126
+ }[tintValue.toLowerCase()] ?? 16777215;
127
+ this.flashTrigger.start({
128
+ ...flashOptions,
129
+ tint: tintValue
130
+ });
131
+ }
132
+ /**
133
+ * Reset animation state when animation changes externally
134
+ *
135
+ * This method should be called when the animation changes due to movement
136
+ * or other external factors to ensure the animation system doesn't get stuck
137
+ *
138
+ * @example
139
+ * ```ts
140
+ * // Reset when player starts moving
141
+ * player.resetAnimationState();
142
+ * ```
143
+ */
144
+ resetAnimationState() {
145
+ this.animationIsPlaying.set(false);
146
+ this.animationCurrentIndex.set(0);
147
+ if (this.animationSubscription) {
148
+ this.animationSubscription.unsubscribe();
149
+ this.animationSubscription = void 0;
150
+ }
151
+ }
152
+ setAnimation(animationName, graphicOrNbTimes, nbTimes) {
153
+ if (this.animationIsPlaying()) return;
154
+ this.animationIsPlaying.set(true);
155
+ const previousAnimationName = this.animationName();
156
+ const previousGraphics = this.graphics();
157
+ this.animationCurrentIndex.set(0);
158
+ let graphic;
159
+ let finalNbTimes = Infinity;
160
+ if (typeof graphicOrNbTimes === "number") finalNbTimes = graphicOrNbTimes;
161
+ else if (graphicOrNbTimes !== void 0) {
162
+ graphic = graphicOrNbTimes;
163
+ finalNbTimes = nbTimes ?? Infinity;
164
+ } else finalNbTimes = Infinity;
165
+ if (graphic !== void 0) if (Array.isArray(graphic)) this.graphics.set(graphic);
166
+ else this.graphics.set([graphic]);
167
+ if (this.animationSubscription) this.animationSubscription.unsubscribe();
168
+ this.animationSubscription = this.animationCurrentIndex.observable.subscribe((index) => {
169
+ if (index >= finalNbTimes) {
170
+ this.animationCurrentIndex.set(0);
171
+ this.animationName.set(previousAnimationName);
172
+ if (graphic !== void 0) this.graphics.set(previousGraphics);
173
+ this.animationIsPlaying.set(false);
174
+ if (this.animationSubscription) {
175
+ this.animationSubscription.unsubscribe();
176
+ this.animationSubscription = void 0;
177
+ }
178
+ }
179
+ });
180
+ this.animationName.set(animationName);
181
+ }
182
+ /**
183
+ * Display a registered component animation effect on this object.
184
+ *
185
+ * @param id - Identifier of the component animation to play.
186
+ * @param params - Parameters forwarded to the animation effect.
187
+ */
188
+ showComponentAnimation(id, params) {
189
+ inject(RpgClientEngine).getComponentAnimation(id).displayEffect(params, this);
190
+ }
191
+ /**
192
+ * Check whether this client object represents an event.
193
+ *
194
+ * @returns `true` if the object type is `event`, otherwise `false`.
195
+ */
196
+ isEvent() {
197
+ return this._type === "event";
198
+ }
199
+ /**
200
+ * Check whether this client object represents a player.
201
+ *
202
+ * @returns `true` if the object type is `player`, otherwise `false`.
203
+ */
204
+ isPlayer() {
205
+ return this._type === "player";
206
+ }
207
+ };
208
+ //#endregion
209
+ export { RpgClientObject };
210
+
211
+ //# sourceMappingURL=Object.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Object.js","names":[],"sources":["../../src/Game/Object.ts"],"sourcesContent":["import { Hooks, ModulesToken, RpgCommonPlayer } from \"@rpgjs/common\";\nimport { trigger, signal, effect } from \"canvasengine\";\nimport { filter, from, map, Subscription, switchMap } from \"rxjs\";\nimport { inject } from \"../core/inject\";\nimport { RpgClientEngine } from \"../RpgClientEngine\";\nimport TextComponent from \"../components/dynamics/text.ce\";\n\nconst DYNAMIC_COMPONENTS = {\n text: TextComponent,\n}\n\ntype Frame = { x: number; y: number; ts: number };\n\nexport abstract class RpgClientObject extends RpgCommonPlayer {\n abstract _type: string;\n emitParticleTrigger = trigger();\n particleName = signal(\"\");\n animationCurrentIndex = signal(0);\n animationIsPlaying = signal(false);\n _param = signal({});\n frames: Frame[] = [];\n graphicsSignals = signal<any[]>([]);\n _component = {} // temporary component memory\n flashTrigger = trigger();\n\n constructor() {\n super();\n this.hooks.callHooks(\"client-sprite-onInit\", this).subscribe();\n\n this._frames.observable.subscribe(({ items }) => {\n if (!this.id) return;\n //if (this.id == this.engine.playerIdSignal()!) return;\n const nextFrames = items.flatMap((item): Frame[] =>\n Array.isArray(item) ? item : [item]\n );\n this.frames = [...this.frames, ...nextFrames];\n });\n\n this.graphics.observable\n .pipe(\n map(({ items }) => items),\n filter(graphics => graphics.length > 0),\n switchMap(graphics => from(Promise.all(graphics.map(graphic => this.engine.getSpriteSheet(graphic)))))\n )\n .subscribe((sheets) => { \n this.graphicsSignals.set(sheets);\n });\n\n this.componentsTop.observable\n .pipe(\n filter(value => value !== null && value !== undefined),\n map((value) => typeof value === 'string' ? JSON.parse(value) : value),\n )\n .subscribe(({components}) => {\n for (const component of components) {\n for (const [key, value] of Object.entries(component)) {\n this._component = value as any; // temporary component memory\n console.log(value)\n const type = (value as any).type as keyof typeof DYNAMIC_COMPONENTS;\n if (DYNAMIC_COMPONENTS[type]) {\n this.engine.addSpriteComponentInFront(DYNAMIC_COMPONENTS[type]);\n }\n }\n }\n });\n\n this.engine.tick\n .pipe\n //throttleTime(10)\n ()\n .subscribe(() => {\n const frame = this.frames.shift();\n if (frame) {\n if (typeof frame.x !== \"number\" || typeof frame.y !== \"number\") return;\n this.engine.scene.setBodyPosition(\n this.id,\n frame.x,\n frame.y,\n \"top-left\"\n );\n }\n });\n }\n\n /**\n * Access the shared client hook registry.\n *\n * @returns The hook service used to register and trigger client-side hooks.\n */\n get hooks() {\n return inject<Hooks>(ModulesToken);\n }\n\n /**\n * Access the current client engine instance.\n *\n * @returns The active {@link RpgClientEngine} instance.\n */\n get engine() {\n return inject(RpgClientEngine);\n }\n\n private animationSubscription?: Subscription;\n\n /**\n * Trigger a flash animation on this sprite\n * \n * This method triggers a flash effect using CanvasEngine's flash directive.\n * The flash can be configured with various options including type (alpha, tint, or both),\n * duration, cycles, and color.\n * \n * ## Design\n * \n * The flash uses a trigger system that is connected to the flash directive in the\n * character component. This allows for flexible configuration and can be triggered\n * from both server events and client-side code.\n * \n * @param options - Flash configuration options\n * @param options.type - Type of flash effect: 'alpha' (opacity), 'tint' (color), or 'both' (default: 'alpha')\n * @param options.duration - Duration of the flash animation in milliseconds (default: 300)\n * @param options.cycles - Number of flash cycles (flash on/off) (default: 1)\n * @param options.alpha - Alpha value when flashing, from 0 to 1 (default: 0.3)\n * @param options.tint - Tint color when flashing as hex value or color name (default: 0xffffff - white)\n * \n * @example\n * ```ts\n * // Simple flash with default settings (alpha flash)\n * player.flash();\n * \n * // Flash with red tint\n * player.flash({ type: 'tint', tint: 0xff0000 });\n * \n * // Flash with both alpha and tint\n * player.flash({ \n * type: 'both', \n * alpha: 0.5, \n * tint: 0xff0000,\n * duration: 200,\n * cycles: 2\n * });\n * \n * // Quick damage flash\n * player.flash({ \n * type: 'tint', \n * tint: 0xff0000, \n * duration: 150,\n * cycles: 1\n * });\n * ```\n */\n flash(options?: {\n type?: 'alpha' | 'tint' | 'both';\n duration?: number;\n cycles?: number;\n alpha?: number;\n tint?: number | string;\n }): void {\n const flashOptions = {\n type: options?.type || 'alpha',\n duration: options?.duration ?? 300,\n cycles: options?.cycles ?? 1,\n alpha: options?.alpha ?? 0.3,\n tint: options?.tint ?? 0xffffff,\n };\n \n // Convert color name to hex if needed\n let tintValue = flashOptions.tint;\n if (typeof tintValue === 'string') {\n // Common color name to hex mapping\n const colorMap: Record<string, number> = {\n 'white': 0xffffff,\n 'red': 0xff0000,\n 'green': 0x00ff00,\n 'blue': 0x0000ff,\n 'yellow': 0xffff00,\n 'cyan': 0x00ffff,\n 'magenta': 0xff00ff,\n 'black': 0x000000,\n };\n tintValue = colorMap[tintValue.toLowerCase()] ?? 0xffffff;\n }\n \n this.flashTrigger.start({\n ...flashOptions,\n tint: tintValue,\n });\n }\n\n /**\n * Reset animation state when animation changes externally\n *\n * This method should be called when the animation changes due to movement\n * or other external factors to ensure the animation system doesn't get stuck\n *\n * @example\n * ```ts\n * // Reset when player starts moving\n * player.resetAnimationState();\n * ```\n */\n resetAnimationState() {\n this.animationIsPlaying.set(false);\n this.animationCurrentIndex.set(0);\n if (this.animationSubscription) {\n this.animationSubscription.unsubscribe();\n this.animationSubscription = undefined;\n }\n }\n\n /**\n * Set a custom animation for a specific number of times\n *\n * Plays a custom animation for the specified number of repetitions.\n * The animation system prevents overlapping animations and automatically\n * returns to the previous animation when complete.\n *\n * @param animationName - Name of the animation to play\n * @param nbTimes - Number of times to repeat the animation (default: Infinity for continuous)\n *\n * @example\n * ```ts\n * // Play attack animation 3 times\n * player.setAnimation('attack', 3);\n *\n * // Play continuous spell animation\n * player.setAnimation('spell');\n * ```\n */\n setAnimation(animationName: string, nbTimes?: number): void;\n /**\n * Set a custom animation with temporary graphic change\n *\n * Plays a custom animation for the specified number of repetitions and temporarily\n * changes the player's graphic (sprite sheet) during the animation. The graphic\n * is automatically reset when the animation finishes.\n *\n * @param animationName - Name of the animation to play\n * @param graphic - The graphic(s) to temporarily use during the animation\n * @param nbTimes - Number of times to repeat the animation (default: Infinity for continuous)\n *\n * @example\n * ```ts\n * // Play attack animation with temporary graphic change\n * player.setAnimation('attack', 'hero_attack', 3);\n * ```\n */\n setAnimation(animationName: string, graphic?: string | string[], nbTimes?: number): void;\n setAnimation(animationName: string, graphicOrNbTimes?: string | string[] | number, nbTimes?: number): void {\n if (this.animationIsPlaying()) return;\n this.animationIsPlaying.set(true);\n const previousAnimationName = this.animationName();\n const previousGraphics = this.graphics();\n this.animationCurrentIndex.set(0);\n\n let graphic: string | string[] | undefined;\n let finalNbTimes: number = Infinity;\n\n // Handle overloads\n if (typeof graphicOrNbTimes === 'number') {\n // setAnimation(animationName, nbTimes)\n finalNbTimes = graphicOrNbTimes;\n } else if (graphicOrNbTimes !== undefined) {\n // setAnimation(animationName, graphic, nbTimes)\n graphic = graphicOrNbTimes;\n finalNbTimes = nbTimes ?? Infinity;\n } else {\n // setAnimation(animationName) - nbTimes remains Infinity\n finalNbTimes = Infinity;\n }\n\n // Temporarily change graphic if provided\n if (graphic !== undefined) {\n if (Array.isArray(graphic)) {\n this.graphics.set(graphic);\n } else {\n this.graphics.set([graphic]);\n }\n }\n\n // Clean up any existing subscription\n if (this.animationSubscription) {\n this.animationSubscription.unsubscribe();\n }\n\n this.animationSubscription =\n this.animationCurrentIndex.observable.subscribe((index) => {\n if (index >= finalNbTimes) {\n this.animationCurrentIndex.set(0);\n this.animationName.set(previousAnimationName);\n // Reset graphic to previous value if it was changed\n if (graphic !== undefined) {\n this.graphics.set(previousGraphics);\n }\n this.animationIsPlaying.set(false);\n if (this.animationSubscription) {\n this.animationSubscription.unsubscribe();\n this.animationSubscription = undefined;\n }\n }\n });\n this.animationName.set(animationName);\n }\n\n /**\n * Display a registered component animation effect on this object.\n *\n * @param id - Identifier of the component animation to play.\n * @param params - Parameters forwarded to the animation effect.\n */\n showComponentAnimation(id: string, params: any) {\n const engine = inject(RpgClientEngine);\n engine.getComponentAnimation(id).displayEffect(params, this);\n }\n \n /**\n * Check whether this client object represents an event.\n *\n * @returns `true` if the object type is `event`, otherwise `false`.\n */\n isEvent(): boolean {\n return this._type === 'event';\n }\n\n /**\n * Check whether this client object represents a player.\n *\n * @returns `true` if the object type is `player`, otherwise `false`.\n */\n isPlayer(): boolean {\n return this._type === 'player';\n }\n}\n"],"mappings":"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"}
@@ -1,4 +1,4 @@
1
1
  import { RpgClientObject } from './Object';
2
2
  export declare class RpgClientPlayer extends RpgClientObject {
3
- type: string;
3
+ _type: string;
4
4
  }
@@ -0,0 +1,12 @@
1
+ import { RpgClientObject } from "./Object.js";
2
+ //#region src/Game/Player.ts
3
+ var RpgClientPlayer = class extends RpgClientObject {
4
+ constructor(..._args) {
5
+ super(..._args);
6
+ this._type = "player";
7
+ }
8
+ };
9
+ //#endregion
10
+ export { RpgClientPlayer };
11
+
12
+ //# sourceMappingURL=Player.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Player.js","names":[],"sources":["../../src/Game/Player.ts"],"sourcesContent":["import { RpgClientObject } from \"./Object\";\n\nexport class RpgClientPlayer extends RpgClientObject {\n _type = 'player'\n} "],"mappings":";;AAEA,IAAa,kBAAb,cAAqC,gBAAgB;;;eACzC"}