@rpgjs/client 5.0.0-alpha.4 → 5.0.0-alpha.40

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 (278) hide show
  1. package/dist/Game/AnimationManager.d.ts +8 -0
  2. package/dist/{index19.js → Game/AnimationManager.js} +4 -3
  3. package/dist/Game/AnimationManager.js.map +1 -0
  4. package/dist/{index30.js → Game/Event.js} +2 -2
  5. package/dist/Game/Event.js.map +1 -0
  6. package/dist/Game/Map.d.ts +19 -2
  7. package/dist/Game/Map.js +84 -0
  8. package/dist/Game/Map.js.map +1 -0
  9. package/dist/Game/Object.d.ts +129 -0
  10. package/dist/Game/Object.js +218 -0
  11. package/dist/Game/Object.js.map +1 -0
  12. package/dist/{index29.js → Game/Player.js} +2 -2
  13. package/dist/Game/Player.js.map +1 -0
  14. package/dist/Gui/Gui.d.ts +177 -5
  15. package/dist/Gui/Gui.js +478 -0
  16. package/dist/Gui/Gui.js.map +1 -0
  17. package/dist/Gui/NotificationManager.d.ts +23 -0
  18. package/dist/Gui/NotificationManager.js +51 -0
  19. package/dist/Gui/NotificationManager.js.map +1 -0
  20. package/dist/Resource.d.ts +97 -0
  21. package/dist/Resource.js +114 -0
  22. package/dist/Resource.js.map +1 -0
  23. package/dist/RpgClient.d.ts +259 -59
  24. package/dist/RpgClientEngine.d.ts +648 -9
  25. package/dist/RpgClientEngine.js +1484 -0
  26. package/dist/RpgClientEngine.js.map +1 -0
  27. package/dist/Sound.d.ts +199 -0
  28. package/dist/Sound.js +97 -0
  29. package/dist/Sound.js.map +1 -0
  30. package/dist/components/animations/animation.ce.js +21 -0
  31. package/dist/components/animations/animation.ce.js.map +1 -0
  32. package/dist/{index23.js → components/animations/hit.ce.js} +3 -3
  33. package/dist/components/animations/hit.ce.js.map +1 -0
  34. package/dist/components/animations/index.d.ts +4 -0
  35. package/dist/components/animations/index.js +10 -0
  36. package/dist/components/animations/index.js.map +1 -0
  37. package/dist/components/character.ce.js +316 -0
  38. package/dist/components/character.ce.js.map +1 -0
  39. package/dist/components/dynamics/parse-value.d.ts +1 -0
  40. package/dist/components/dynamics/parse-value.js +54 -0
  41. package/dist/components/dynamics/parse-value.js.map +1 -0
  42. package/dist/components/dynamics/text.ce.js +141 -0
  43. package/dist/components/dynamics/text.ce.js.map +1 -0
  44. package/dist/components/gui/box.ce.js +27 -0
  45. package/dist/components/gui/box.ce.js.map +1 -0
  46. package/dist/components/gui/dialogbox/index.ce.js +152 -0
  47. package/dist/components/gui/dialogbox/index.ce.js.map +1 -0
  48. package/dist/components/gui/gameover.ce.js +141 -0
  49. package/dist/components/gui/gameover.ce.js.map +1 -0
  50. package/dist/components/gui/hud/hud.ce.js +35 -0
  51. package/dist/components/gui/hud/hud.ce.js.map +1 -0
  52. package/dist/components/gui/index.d.ts +15 -3
  53. package/dist/components/gui/menu/equip-menu.ce.js +349 -0
  54. package/dist/components/gui/menu/equip-menu.ce.js.map +1 -0
  55. package/dist/components/gui/menu/exit-menu.ce.js +35 -0
  56. package/dist/components/gui/menu/exit-menu.ce.js.map +1 -0
  57. package/dist/components/gui/menu/items-menu.ce.js +229 -0
  58. package/dist/components/gui/menu/items-menu.ce.js.map +1 -0
  59. package/dist/components/gui/menu/main-menu.ce.js +208 -0
  60. package/dist/components/gui/menu/main-menu.ce.js.map +1 -0
  61. package/dist/components/gui/menu/options-menu.ce.js +28 -0
  62. package/dist/components/gui/menu/options-menu.ce.js.map +1 -0
  63. package/dist/components/gui/menu/skills-menu.ce.js +53 -0
  64. package/dist/components/gui/menu/skills-menu.ce.js.map +1 -0
  65. package/dist/components/gui/mobile/index.d.ts +8 -0
  66. package/dist/components/gui/mobile/index.js +24 -0
  67. package/dist/components/gui/mobile/index.js.map +1 -0
  68. package/dist/components/gui/mobile/mobile.ce.js +17 -0
  69. package/dist/components/gui/mobile/mobile.ce.js.map +1 -0
  70. package/dist/components/gui/notification/notification.ce.js +38 -0
  71. package/dist/components/gui/notification/notification.ce.js.map +1 -0
  72. package/dist/components/gui/save-load.ce.js +242 -0
  73. package/dist/components/gui/save-load.ce.js.map +1 -0
  74. package/dist/components/gui/shop/shop.ce.js +322 -0
  75. package/dist/components/gui/shop/shop.ce.js.map +1 -0
  76. package/dist/components/gui/title-screen.ce.js +148 -0
  77. package/dist/components/gui/title-screen.ce.js.map +1 -0
  78. package/dist/components/index.d.ts +3 -1
  79. package/dist/components/prebuilt/hp-bar.ce.js +106 -0
  80. package/dist/components/prebuilt/hp-bar.ce.js.map +1 -0
  81. package/dist/components/prebuilt/index.d.ts +19 -0
  82. package/dist/components/prebuilt/light-halo.ce.js +76 -0
  83. package/dist/components/prebuilt/light-halo.ce.js.map +1 -0
  84. package/dist/components/scenes/canvas.ce.js +44 -0
  85. package/dist/components/scenes/canvas.ce.js.map +1 -0
  86. package/dist/components/scenes/draw-map.ce.js +66 -0
  87. package/dist/components/scenes/draw-map.ce.js.map +1 -0
  88. package/dist/{index13.js → components/scenes/event-layer.ce.js} +7 -6
  89. package/dist/components/scenes/event-layer.ce.js.map +1 -0
  90. package/dist/{index6.js → core/inject.js} +2 -2
  91. package/dist/core/inject.js.map +1 -0
  92. package/dist/core/setup.js +16 -0
  93. package/dist/core/setup.js.map +1 -0
  94. package/dist/index.d.ts +15 -1
  95. package/dist/index.js +40 -12
  96. package/dist/index.js.map +1 -1
  97. package/dist/module.d.ts +43 -4
  98. package/dist/module.js +175 -0
  99. package/dist/module.js.map +1 -0
  100. package/dist/node_modules/.pnpm/@signe_di@2.8.3/node_modules/@signe/di/dist/index.js +366 -0
  101. package/dist/node_modules/.pnpm/@signe_di@2.8.3/node_modules/@signe/di/dist/index.js.map +1 -0
  102. package/dist/{index27.js → node_modules/.pnpm/@signe_reactive@2.8.3/node_modules/@signe/reactive/dist/index.js} +229 -11
  103. package/dist/node_modules/.pnpm/@signe_reactive@2.8.3/node_modules/@signe/reactive/dist/index.js.map +1 -0
  104. package/dist/{index20.js → node_modules/.pnpm/@signe_room@2.8.3/node_modules/@signe/room/dist/index.js} +308 -40
  105. package/dist/node_modules/.pnpm/@signe_room@2.8.3/node_modules/@signe/room/dist/index.js.map +1 -0
  106. package/dist/{index26.js → node_modules/.pnpm/@signe_sync@2.8.3/node_modules/@signe/sync/dist/chunk-7QVYU63E.js} +1 -1
  107. package/dist/node_modules/.pnpm/@signe_sync@2.8.3/node_modules/@signe/sync/dist/chunk-7QVYU63E.js.map +1 -0
  108. package/dist/{index21.js → node_modules/.pnpm/@signe_sync@2.8.3/node_modules/@signe/sync/dist/client/index.js} +5 -5
  109. package/dist/node_modules/.pnpm/@signe_sync@2.8.3/node_modules/@signe/sync/dist/client/index.js.map +1 -0
  110. package/dist/{index17.js → node_modules/.pnpm/@signe_sync@2.8.3/node_modules/@signe/sync/dist/index.js} +89 -12
  111. package/dist/node_modules/.pnpm/@signe_sync@2.8.3/node_modules/@signe/sync/dist/index.js.map +1 -0
  112. package/dist/{index31.js → node_modules/.pnpm/dset@3.1.4/node_modules/dset/dist/index.js} +1 -1
  113. package/dist/node_modules/.pnpm/dset@3.1.4/node_modules/dset/dist/index.js.map +1 -0
  114. package/dist/{index34.js → node_modules/.pnpm/partysocket@1.1.3/node_modules/partysocket/dist/chunk-HAC622V3.js} +2 -2
  115. package/dist/node_modules/.pnpm/partysocket@1.1.3/node_modules/partysocket/dist/chunk-HAC622V3.js.map +1 -0
  116. package/dist/{index35.js → node_modules/.pnpm/partysocket@1.1.3/node_modules/partysocket/dist/chunk-S74YV6PU.js} +1 -1
  117. package/dist/node_modules/.pnpm/partysocket@1.1.3/node_modules/partysocket/dist/chunk-S74YV6PU.js.map +1 -0
  118. package/dist/{index32.js → node_modules/.pnpm/zod@3.24.2/node_modules/zod/lib/index.js} +1 -1
  119. package/dist/node_modules/.pnpm/zod@3.24.2/node_modules/zod/lib/index.js.map +1 -0
  120. package/dist/presets/animation.d.ts +31 -0
  121. package/dist/presets/animation.js +27 -0
  122. package/dist/presets/animation.js.map +1 -0
  123. package/dist/presets/faceset.d.ts +30 -0
  124. package/dist/presets/faceset.js +24 -0
  125. package/dist/presets/faceset.js.map +1 -0
  126. package/dist/presets/icon.d.ts +20 -0
  127. package/dist/presets/icon.js +15 -0
  128. package/dist/presets/icon.js.map +1 -0
  129. package/dist/presets/index.d.ts +123 -0
  130. package/dist/presets/index.js +16 -0
  131. package/dist/presets/index.js.map +1 -0
  132. package/dist/presets/lpc.d.ts +89 -0
  133. package/dist/presets/lpc.js +95 -0
  134. package/dist/presets/lpc.js.map +1 -0
  135. package/dist/{index25.js → presets/rmspritesheet.js} +1 -1
  136. package/dist/presets/rmspritesheet.js.map +1 -0
  137. package/dist/services/AbstractSocket.d.ts +9 -5
  138. package/dist/{index16.js → services/AbstractSocket.js} +1 -1
  139. package/dist/services/AbstractSocket.js.map +1 -0
  140. package/dist/services/keyboardControls.d.ts +15 -0
  141. package/dist/services/keyboardControls.js +21 -0
  142. package/dist/services/keyboardControls.js.map +1 -0
  143. package/dist/services/loadMap.d.ts +123 -2
  144. package/dist/{index7.js → services/loadMap.js} +12 -4
  145. package/dist/services/loadMap.js.map +1 -0
  146. package/dist/services/mmorpg.d.ts +24 -8
  147. package/dist/services/mmorpg.js +139 -0
  148. package/dist/services/mmorpg.js.map +1 -0
  149. package/dist/services/save.d.ts +19 -0
  150. package/dist/services/save.js +69 -0
  151. package/dist/services/save.js.map +1 -0
  152. package/dist/services/standalone.d.ts +67 -7
  153. package/dist/services/standalone.js +170 -0
  154. package/dist/services/standalone.js.map +1 -0
  155. package/dist/utils/getEntityProp.d.ts +39 -0
  156. package/dist/utils/getEntityProp.js +54 -0
  157. package/dist/utils/getEntityProp.js.map +1 -0
  158. package/package.json +18 -12
  159. package/src/Game/{EffectManager.ts → AnimationManager.ts} +3 -2
  160. package/src/Game/Map.ts +74 -3
  161. package/src/Game/Object.ts +296 -11
  162. package/src/Gui/Gui.ts +506 -18
  163. package/src/Gui/NotificationManager.ts +69 -0
  164. package/src/Resource.ts +150 -0
  165. package/src/RpgClient.ts +264 -58
  166. package/src/RpgClientEngine.ts +1705 -48
  167. package/src/Sound.ts +253 -0
  168. package/src/components/{effects → animations}/animation.ce +3 -6
  169. package/src/components/{effects → animations}/index.ts +1 -1
  170. package/src/components/character.ce +406 -40
  171. package/src/components/dynamics/parse-value.ts +80 -0
  172. package/src/components/dynamics/text.ce +183 -0
  173. package/src/components/gui/box.ce +17 -0
  174. package/src/components/gui/dialogbox/index.ce +204 -187
  175. package/src/components/gui/gameover.ce +158 -0
  176. package/src/components/gui/hud/hud.ce +61 -0
  177. package/src/components/gui/index.ts +30 -4
  178. package/src/components/gui/menu/equip-menu.ce +410 -0
  179. package/src/components/gui/menu/exit-menu.ce +41 -0
  180. package/src/components/gui/menu/items-menu.ce +317 -0
  181. package/src/components/gui/menu/main-menu.ce +294 -0
  182. package/src/components/gui/menu/options-menu.ce +35 -0
  183. package/src/components/gui/menu/skills-menu.ce +83 -0
  184. package/src/components/gui/mobile/index.ts +24 -0
  185. package/src/components/gui/mobile/mobile.ce +80 -0
  186. package/src/components/gui/notification/notification.ce +51 -0
  187. package/src/components/gui/save-load.ce +208 -0
  188. package/src/components/gui/shop/shop.ce +493 -0
  189. package/src/components/gui/title-screen.ce +163 -0
  190. package/src/components/index.ts +5 -1
  191. package/src/components/prebuilt/hp-bar.ce +255 -0
  192. package/src/components/prebuilt/index.ts +24 -0
  193. package/src/components/prebuilt/light-halo.ce +148 -0
  194. package/src/components/scenes/canvas.ce +20 -15
  195. package/src/components/scenes/draw-map.ce +58 -30
  196. package/src/components/scenes/event-layer.ce +10 -3
  197. package/src/components/scenes/transition.ce +60 -0
  198. package/src/core/setup.ts +2 -0
  199. package/src/index.ts +16 -2
  200. package/src/module.ts +145 -9
  201. package/src/presets/animation.ts +46 -0
  202. package/src/presets/faceset.ts +60 -0
  203. package/src/presets/icon.ts +17 -0
  204. package/src/presets/index.ts +9 -1
  205. package/src/presets/lpc.ts +108 -0
  206. package/src/services/AbstractSocket.ts +10 -2
  207. package/src/services/keyboardControls.ts +20 -0
  208. package/src/services/loadMap.ts +132 -3
  209. package/src/services/mmorpg.ts +113 -9
  210. package/src/services/save.ts +103 -0
  211. package/src/services/standalone.ts +110 -18
  212. package/src/utils/getEntityProp.ts +87 -0
  213. package/tsconfig.json +1 -1
  214. package/vite.config.ts +5 -3
  215. package/dist/Game/EffectManager.d.ts +0 -5
  216. package/dist/components/effects/index.d.ts +0 -4
  217. package/dist/index10.js +0 -8
  218. package/dist/index10.js.map +0 -1
  219. package/dist/index11.js +0 -10
  220. package/dist/index11.js.map +0 -1
  221. package/dist/index12.js +0 -8
  222. package/dist/index12.js.map +0 -1
  223. package/dist/index13.js.map +0 -1
  224. package/dist/index14.js +0 -50
  225. package/dist/index14.js.map +0 -1
  226. package/dist/index15.js +0 -191
  227. package/dist/index15.js.map +0 -1
  228. package/dist/index16.js.map +0 -1
  229. package/dist/index17.js.map +0 -1
  230. package/dist/index18.js +0 -31
  231. package/dist/index18.js.map +0 -1
  232. package/dist/index19.js.map +0 -1
  233. package/dist/index2.js +0 -112
  234. package/dist/index2.js.map +0 -1
  235. package/dist/index20.js.map +0 -1
  236. package/dist/index21.js.map +0 -1
  237. package/dist/index22.js +0 -109
  238. package/dist/index22.js.map +0 -1
  239. package/dist/index23.js.map +0 -1
  240. package/dist/index24.js +0 -21
  241. package/dist/index24.js.map +0 -1
  242. package/dist/index25.js.map +0 -1
  243. package/dist/index26.js.map +0 -1
  244. package/dist/index27.js.map +0 -1
  245. package/dist/index28.js +0 -25
  246. package/dist/index28.js.map +0 -1
  247. package/dist/index29.js.map +0 -1
  248. package/dist/index3.js +0 -87
  249. package/dist/index3.js.map +0 -1
  250. package/dist/index30.js.map +0 -1
  251. package/dist/index31.js.map +0 -1
  252. package/dist/index32.js.map +0 -1
  253. package/dist/index33.js +0 -316
  254. package/dist/index33.js.map +0 -1
  255. package/dist/index34.js.map +0 -1
  256. package/dist/index35.js.map +0 -1
  257. package/dist/index36.js +0 -91
  258. package/dist/index36.js.map +0 -1
  259. package/dist/index37.js +0 -61
  260. package/dist/index37.js.map +0 -1
  261. package/dist/index38.js +0 -20
  262. package/dist/index38.js.map +0 -1
  263. package/dist/index39.js +0 -20
  264. package/dist/index39.js.map +0 -1
  265. package/dist/index4.js +0 -54
  266. package/dist/index4.js.map +0 -1
  267. package/dist/index5.js +0 -15
  268. package/dist/index5.js.map +0 -1
  269. package/dist/index6.js.map +0 -1
  270. package/dist/index7.js.map +0 -1
  271. package/dist/index8.js +0 -90
  272. package/dist/index8.js.map +0 -1
  273. package/dist/index9.js +0 -76
  274. package/dist/index9.js.map +0 -1
  275. package/src/components/gui/dialogbox/itemMenu.ce +0 -23
  276. package/src/components/gui/dialogbox/selection.ce +0 -67
  277. package/src/components/scenes/element-map.ce +0 -23
  278. /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
+ }
@@ -1,7 +1,7 @@
1
1
  import { generateUID } from '@rpgjs/common';
2
2
  import { signal } from 'canvasengine';
3
3
 
4
- class EffectManager {
4
+ class AnimationManager {
5
5
  constructor() {
6
6
  this.current = signal([]);
7
7
  }
@@ -12,6 +12,7 @@ class EffectManager {
12
12
  id,
13
13
  x: player.x,
14
14
  y: player.y,
15
+ object: player,
15
16
  onFinish: () => {
16
17
  const index = this.current().findIndex((value) => value.id === id);
17
18
  this.current().splice(index, 1);
@@ -20,5 +21,5 @@ class EffectManager {
20
21
  }
21
22
  }
22
23
 
23
- export { EffectManager };
24
- //# sourceMappingURL=index19.js.map
24
+ export { AnimationManager };
25
+ //# sourceMappingURL=AnimationManager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AnimationManager.js","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"],"names":[],"mappings":";;;AAGO,MAAM,gBAAA,CAAiB;AAAA,EAAvB,WAAA,GAAA;AACL,IAAA,IAAA,CAAA,OAAA,GAAU,MAAA,CAAc,EAAE,CAAA;AAAA,EAAA;AAAA,EAE1B,aAAA,CAAc,QAAa,MAAA,EAAoD;AAC7E,IAAA,MAAM,KAAK,WAAA,EAAY;AACvB,IAAA,IAAA,CAAK,OAAA,GAAU,IAAA,CAAK;AAAA,MAClB,GAAG,MAAA;AAAA,MACH,EAAA;AAAA,MACA,GAAG,MAAA,CAAO,CAAA;AAAA,MACV,GAAG,MAAA,CAAO,CAAA;AAAA,MACV,MAAA,EAAQ,MAAA;AAAA,MACR,UAAU,MAAM;AACd,QAAA,MAAM,KAAA,GAAQ,KAAK,OAAA,EAAQ,CAAE,UAAU,CAAC,KAAA,KAAU,KAAA,CAAM,EAAA,KAAO,EAAE,CAAA;AACjE,QAAA,IAAA,CAAK,OAAA,EAAQ,CAAE,MAAA,CAAO,KAAA,EAAO,CAAC,CAAA;AAAA,MAChC;AAAA,KACD,CAAA;AAAA,EACH;AACF;;;;"}
@@ -1,4 +1,4 @@
1
- import { RpgClientObject } from './index39.js';
1
+ import { RpgClientObject } from './Object.js';
2
2
 
3
3
  class RpgClientEvent extends RpgClientObject {
4
4
  constructor() {
@@ -8,4 +8,4 @@ class RpgClientEvent extends RpgClientObject {
8
8
  }
9
9
 
10
10
  export { RpgClientEvent };
11
- //# sourceMappingURL=index30.js.map
11
+ //# sourceMappingURL=Event.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Event.js","sources":["../../src/Game/Event.ts"],"sourcesContent":["import { RpgClientObject } from \"./Object\"; \n\nexport class RpgClientEvent extends RpgClientObject {\n type = 'event'\n} "],"names":[],"mappings":";;AAEO,MAAM,uBAAuB,eAAA,CAAgB;AAAA,EAA7C,WAAA,GAAA;AAAA,IAAA,KAAA,CAAA,GAAA,SAAA,CAAA;AACH,IAAA,IAAA,CAAA,IAAA,GAAO,OAAA;AAAA,EAAA;AACX;;;;"}
@@ -1,7 +1,24 @@
1
- import { RpgCommonMap } from '@rpgjs/common';
1
+ import { RpgCommonMap, WeatherState } 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;
7
24
  }
@@ -0,0 +1,84 @@
1
+ import { RpgCommonMap } from '@rpgjs/common';
2
+ import { sync, users } from '../node_modules/.pnpm/@signe_sync@2.8.3/node_modules/@signe/sync/dist/index.js';
3
+ import { RpgClientPlayer } from './Player.js';
4
+ import { signal, computed } from 'canvasengine';
5
+ import { RpgClientEvent } from './Event.js';
6
+ import { RpgClientEngine } from '../RpgClientEngine.js';
7
+ import { inject } from '../core/inject.js';
8
+
9
+ var __defProp = Object.defineProperty;
10
+ var __decorateClass = (decorators, target, key, kind) => {
11
+ var result = void 0 ;
12
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
13
+ if (decorator = decorators[i])
14
+ result = (decorator(target, key, result) ) || result;
15
+ if (result) __defProp(target, key, result);
16
+ return result;
17
+ };
18
+ class RpgClientMap extends RpgCommonMap {
19
+ constructor() {
20
+ super();
21
+ this.engine = inject(RpgClientEngine);
22
+ this.players = signal({});
23
+ this.events = signal({});
24
+ this.currentPlayer = computed(() => this.players()[this.engine.playerIdSignal()]);
25
+ this.weatherState = signal(null);
26
+ this.localWeatherOverride = signal(null);
27
+ this.weather = computed(() => {
28
+ const local = this.localWeatherOverride();
29
+ const state = this.weatherState();
30
+ return local ?? state;
31
+ });
32
+ this.manualClientPhysicsTick = false;
33
+ const isTest = typeof process !== "undefined" && process.env?.TEST === "true" || typeof window !== "undefined" && window.__RPGJS_TEST__ === true;
34
+ this.isTestEnvironment = isTest;
35
+ if (isTest) {
36
+ this.autoTickEnabled = false;
37
+ }
38
+ }
39
+ configureClientPrediction(enabled) {
40
+ this.manualClientPhysicsTick = enabled;
41
+ this.autoTickEnabled = enabled ? false : !this.isTestEnvironment;
42
+ }
43
+ getCurrentPlayer() {
44
+ return this.currentPlayer();
45
+ }
46
+ reset(force = false) {
47
+ const currentPlayerId = this.engine.playerIdSignal();
48
+ const currentPlayer = !force && currentPlayerId ? this.players()[currentPlayerId] : void 0;
49
+ this.players.set(
50
+ currentPlayerId && currentPlayer ? { [currentPlayerId]: currentPlayer } : {}
51
+ );
52
+ this.events.set({});
53
+ this.weatherState.set(null);
54
+ this.localWeatherOverride.set(null);
55
+ this.clearPhysic();
56
+ }
57
+ getWeather() {
58
+ return this.weather();
59
+ }
60
+ setLocalWeather(next) {
61
+ this.localWeatherOverride.set(next);
62
+ }
63
+ clearLocalWeather() {
64
+ this.localWeatherOverride.set(null);
65
+ }
66
+ stepClientPhysics(deltaMs) {
67
+ if (!this.manualClientPhysicsTick) {
68
+ return 0;
69
+ }
70
+ return this.nextTick(deltaMs);
71
+ }
72
+ stepPredictionTick() {
73
+ this.forceSingleTick();
74
+ }
75
+ }
76
+ __decorateClass([
77
+ users(RpgClientPlayer)
78
+ ], RpgClientMap.prototype, "players");
79
+ __decorateClass([
80
+ sync(RpgClientEvent)
81
+ ], RpgClientMap.prototype, "events");
82
+
83
+ export { RpgClientMap };
84
+ //# sourceMappingURL=Map.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Map.js","sources":["../../src/Game/Map.ts"],"sourcesContent":["import { RpgCommonMap, type WeatherState } 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"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAQO,MAAM,qBAAqB,YAAA,CAAkB;AAAA,EAelD,WAAA,GAAc;AACZ,IAAA,KAAA,EAAM;AAfR,IAAA,IAAA,CAAA,MAAA,GAA0B,OAAO,eAAe,CAAA;AACxB,IAAA,IAAA,CAAA,OAAA,GAAU,MAAA,CAAwC,EAAE,CAAA;AACtD,IAAA,IAAA,CAAA,MAAA,GAAS,MAAA,CAAuC,EAAE,CAAA;AACxE,IAAA,IAAA,CAAA,aAAA,GAAgB,QAAA,CAAS,MAAM,IAAA,CAAK,OAAA,GAAU,IAAA,CAAK,MAAA,CAAO,cAAA,EAAiB,CAAC,CAAA;AAC5E,IAAA,IAAA,CAAA,YAAA,GAAe,OAA4B,IAAI,CAAA;AAC/C,IAAA,IAAA,CAAA,oBAAA,GAAuB,OAA4B,IAAI,CAAA;AACvD,IAAA,IAAA,CAAA,OAAA,GAAU,SAA8B,MAAM;AAC5C,MAAA,MAAM,KAAA,GAAQ,KAAK,oBAAA,E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B,IAAI,IAAI,CAAA;AAClC,IAAA,IAAA,CAAK,WAAA,EAAY;AAAA,EACnB;AAAA,EAEA,UAAA,GAAkC;AAChC,IAAA,OAAO,KAAK,OAAA,EAAQ;AAAA,EACtB;AAAA,EAEA,gBAAgB,IAAA,EAAiC;AAC/C,IAAA,IAAA,CAAK,oBAAA,CAAqB,IAAI,IAAI,CAAA;AAAA,EACpC;AAAA,EAEA,iBAAA,GAA0B;AACxB,IAAA,IAAA,CAAK,oBAAA,CAAqB,IAAI,IAAI,CAAA;AAAA,EACpC;AAAA,EAEA,kBAAkB,OAAA,EAAyB;AACzC,IAAA,IAAI,CAAC,KAAK,uBAAA,EAAyB;AACjC,MAAA,OAAO,CAAA;AAAA,IACT;AACA,IAAA,OAAO,IAAA,CAAK,SAAS,OAAO,CAAA;AAAA,EAC9B;AAAA,EAEA,kBAAA,GAA2B;AACzB,IAAA,IAAA,CAAK,eAAA,EAAgB;AAAA,EACvB;AACF;AAtE0B,eAAA,CAAA;AAAA,EAAvB,MAAM,eAAe;AAAA,CAAA,EAFX,YAAA,CAEa,SAAA,EAAA,SAAA,CAAA;AACF,eAAA,CAAA;AAAA,EAArB,KAAK,cAAc;AAAA,CAAA,EAHT,YAAA,CAGW,SAAA,EAAA,QAAA,CAAA;;;;"}
@@ -0,0 +1,129 @@
1
+ import { Hooks, RpgCommonPlayer } from '@rpgjs/common';
2
+ import { RpgClientEngine } from '../RpgClientEngine';
3
+ export declare abstract class RpgClientObject extends RpgCommonPlayer {
4
+ abstract type: string;
5
+ emitParticleTrigger: import('canvasengine').Trigger<any>;
6
+ particleName: import('canvasengine').WritableSignal<string>;
7
+ animationCurrentIndex: import('canvasengine').WritableSignal<number>;
8
+ animationIsPlaying: import('canvasengine').WritableSignal<boolean>;
9
+ _param: import('canvasengine').WritableObjectSignal<{}>;
10
+ frames: {
11
+ x: number;
12
+ y: number;
13
+ ts: number;
14
+ }[];
15
+ graphicsSignals: import('canvasengine').WritableArraySignal<any[]>;
16
+ _component: {};
17
+ flashTrigger: import('canvasengine').Trigger<any>;
18
+ constructor();
19
+ get hooks(): Hooks;
20
+ get engine(): RpgClientEngine<unknown>;
21
+ private animationSubscription?;
22
+ /**
23
+ * Trigger a flash animation on this sprite
24
+ *
25
+ * This method triggers a flash effect using CanvasEngine's flash directive.
26
+ * The flash can be configured with various options including type (alpha, tint, or both),
27
+ * duration, cycles, and color.
28
+ *
29
+ * ## Design
30
+ *
31
+ * The flash uses a trigger system that is connected to the flash directive in the
32
+ * character component. This allows for flexible configuration and can be triggered
33
+ * from both server events and client-side code.
34
+ *
35
+ * @param options - Flash configuration options
36
+ * @param options.type - Type of flash effect: 'alpha' (opacity), 'tint' (color), or 'both' (default: 'alpha')
37
+ * @param options.duration - Duration of the flash animation in milliseconds (default: 300)
38
+ * @param options.cycles - Number of flash cycles (flash on/off) (default: 1)
39
+ * @param options.alpha - Alpha value when flashing, from 0 to 1 (default: 0.3)
40
+ * @param options.tint - Tint color when flashing as hex value or color name (default: 0xffffff - white)
41
+ *
42
+ * @example
43
+ * ```ts
44
+ * // Simple flash with default settings (alpha flash)
45
+ * player.flash();
46
+ *
47
+ * // Flash with red tint
48
+ * player.flash({ type: 'tint', tint: 0xff0000 });
49
+ *
50
+ * // Flash with both alpha and tint
51
+ * player.flash({
52
+ * type: 'both',
53
+ * alpha: 0.5,
54
+ * tint: 0xff0000,
55
+ * duration: 200,
56
+ * cycles: 2
57
+ * });
58
+ *
59
+ * // Quick damage flash
60
+ * player.flash({
61
+ * type: 'tint',
62
+ * tint: 0xff0000,
63
+ * duration: 150,
64
+ * cycles: 1
65
+ * });
66
+ * ```
67
+ */
68
+ flash(options?: {
69
+ type?: 'alpha' | 'tint' | 'both';
70
+ duration?: number;
71
+ cycles?: number;
72
+ alpha?: number;
73
+ tint?: number | string;
74
+ }): void;
75
+ /**
76
+ * Reset animation state when animation changes externally
77
+ *
78
+ * This method should be called when the animation changes due to movement
79
+ * or other external factors to ensure the animation system doesn't get stuck
80
+ *
81
+ * @example
82
+ * ```ts
83
+ * // Reset when player starts moving
84
+ * player.resetAnimationState();
85
+ * ```
86
+ */
87
+ resetAnimationState(): void;
88
+ /**
89
+ * Set a custom animation for a specific number of times
90
+ *
91
+ * Plays a custom animation for the specified number of repetitions.
92
+ * The animation system prevents overlapping animations and automatically
93
+ * returns to the previous animation when complete.
94
+ *
95
+ * @param animationName - Name of the animation to play
96
+ * @param nbTimes - Number of times to repeat the animation (default: Infinity for continuous)
97
+ *
98
+ * @example
99
+ * ```ts
100
+ * // Play attack animation 3 times
101
+ * player.setAnimation('attack', 3);
102
+ *
103
+ * // Play continuous spell animation
104
+ * player.setAnimation('spell');
105
+ * ```
106
+ */
107
+ setAnimation(animationName: string, nbTimes?: number): void;
108
+ /**
109
+ * Set a custom animation with temporary graphic change
110
+ *
111
+ * Plays a custom animation for the specified number of repetitions and temporarily
112
+ * changes the player's graphic (sprite sheet) during the animation. The graphic
113
+ * is automatically reset when the animation finishes.
114
+ *
115
+ * @param animationName - Name of the animation to play
116
+ * @param graphic - The graphic(s) to temporarily use during the animation
117
+ * @param nbTimes - Number of times to repeat the animation (default: Infinity for continuous)
118
+ *
119
+ * @example
120
+ * ```ts
121
+ * // Play attack animation with temporary graphic change
122
+ * player.setAnimation('attack', 'hero_attack', 3);
123
+ * ```
124
+ */
125
+ setAnimation(animationName: string, graphic?: string | string[], nbTimes?: number): void;
126
+ showComponentAnimation(id: string, params: any): void;
127
+ isEvent(): boolean;
128
+ isPlayer(): boolean;
129
+ }
@@ -0,0 +1,218 @@
1
+ import { RpgCommonPlayer, ModulesToken } from '@rpgjs/common';
2
+ import { trigger, signal } from 'canvasengine';
3
+ import { map, filter, switchMap, from } from 'rxjs';
4
+ import { inject } from '../core/inject.js';
5
+ import { RpgClientEngine } from '../RpgClientEngine.js';
6
+ import component from '../components/dynamics/text.ce.js';
7
+
8
+ const DYNAMIC_COMPONENTS = {
9
+ text: component
10
+ };
11
+ class RpgClientObject extends RpgCommonPlayer {
12
+ constructor() {
13
+ super();
14
+ this.emitParticleTrigger = trigger();
15
+ this.particleName = signal("");
16
+ this.animationCurrentIndex = signal(0);
17
+ this.animationIsPlaying = signal(false);
18
+ this._param = signal({});
19
+ this.frames = [];
20
+ this.graphicsSignals = signal([]);
21
+ this._component = {};
22
+ // temporary component memory
23
+ this.flashTrigger = trigger();
24
+ this.hooks.callHooks("client-sprite-onInit", this).subscribe();
25
+ this._frames.observable.subscribe(({ items }) => {
26
+ if (!this.id) return;
27
+ this.frames = [...this.frames, ...items];
28
+ });
29
+ this.graphics.observable.pipe(
30
+ map(({ items }) => items),
31
+ filter((graphics) => graphics.length > 0),
32
+ switchMap((graphics) => from(Promise.all(graphics.map((graphic) => this.engine.getSpriteSheet(graphic)))))
33
+ ).subscribe((sheets) => {
34
+ this.graphicsSignals.set(sheets);
35
+ });
36
+ this.componentsTop.observable.pipe(
37
+ filter((value) => value !== null && value !== void 0),
38
+ map((value) => typeof value === "string" ? JSON.parse(value) : value)
39
+ ).subscribe(({ components }) => {
40
+ for (const component of components) {
41
+ for (const [key, value] of Object.entries(component)) {
42
+ this._component = value;
43
+ console.log(value);
44
+ const type = value.type;
45
+ if (DYNAMIC_COMPONENTS[type]) {
46
+ this.engine.addSpriteComponentInFront(DYNAMIC_COMPONENTS[type]);
47
+ }
48
+ }
49
+ }
50
+ });
51
+ this.engine.tick.pipe().subscribe(() => {
52
+ const frame = this.frames.shift();
53
+ if (frame) {
54
+ if (typeof frame.x !== "number" || typeof frame.y !== "number") return;
55
+ this.engine.scene.setBodyPosition(
56
+ this.id,
57
+ frame.x,
58
+ frame.y,
59
+ "top-left"
60
+ );
61
+ }
62
+ });
63
+ }
64
+ get hooks() {
65
+ return inject(ModulesToken);
66
+ }
67
+ get engine() {
68
+ return inject(RpgClientEngine);
69
+ }
70
+ /**
71
+ * Trigger a flash animation on this sprite
72
+ *
73
+ * This method triggers a flash effect using CanvasEngine's flash directive.
74
+ * The flash can be configured with various options including type (alpha, tint, or both),
75
+ * duration, cycles, and color.
76
+ *
77
+ * ## Design
78
+ *
79
+ * The flash uses a trigger system that is connected to the flash directive in the
80
+ * character component. This allows for flexible configuration and can be triggered
81
+ * from both server events and client-side code.
82
+ *
83
+ * @param options - Flash configuration options
84
+ * @param options.type - Type of flash effect: 'alpha' (opacity), 'tint' (color), or 'both' (default: 'alpha')
85
+ * @param options.duration - Duration of the flash animation in milliseconds (default: 300)
86
+ * @param options.cycles - Number of flash cycles (flash on/off) (default: 1)
87
+ * @param options.alpha - Alpha value when flashing, from 0 to 1 (default: 0.3)
88
+ * @param options.tint - Tint color when flashing as hex value or color name (default: 0xffffff - white)
89
+ *
90
+ * @example
91
+ * ```ts
92
+ * // Simple flash with default settings (alpha flash)
93
+ * player.flash();
94
+ *
95
+ * // Flash with red tint
96
+ * player.flash({ type: 'tint', tint: 0xff0000 });
97
+ *
98
+ * // Flash with both alpha and tint
99
+ * player.flash({
100
+ * type: 'both',
101
+ * alpha: 0.5,
102
+ * tint: 0xff0000,
103
+ * duration: 200,
104
+ * cycles: 2
105
+ * });
106
+ *
107
+ * // Quick damage flash
108
+ * player.flash({
109
+ * type: 'tint',
110
+ * tint: 0xff0000,
111
+ * duration: 150,
112
+ * cycles: 1
113
+ * });
114
+ * ```
115
+ */
116
+ flash(options) {
117
+ const flashOptions = {
118
+ type: options?.type || "alpha",
119
+ duration: options?.duration ?? 300,
120
+ cycles: options?.cycles ?? 1,
121
+ alpha: options?.alpha ?? 0.3,
122
+ tint: options?.tint ?? 16777215
123
+ };
124
+ let tintValue = flashOptions.tint;
125
+ if (typeof tintValue === "string") {
126
+ const colorMap = {
127
+ "white": 16777215,
128
+ "red": 16711680,
129
+ "green": 65280,
130
+ "blue": 255,
131
+ "yellow": 16776960,
132
+ "cyan": 65535,
133
+ "magenta": 16711935,
134
+ "black": 0
135
+ };
136
+ tintValue = colorMap[tintValue.toLowerCase()] ?? 16777215;
137
+ }
138
+ this.flashTrigger.start({
139
+ ...flashOptions,
140
+ tint: tintValue
141
+ });
142
+ }
143
+ /**
144
+ * Reset animation state when animation changes externally
145
+ *
146
+ * This method should be called when the animation changes due to movement
147
+ * or other external factors to ensure the animation system doesn't get stuck
148
+ *
149
+ * @example
150
+ * ```ts
151
+ * // Reset when player starts moving
152
+ * player.resetAnimationState();
153
+ * ```
154
+ */
155
+ resetAnimationState() {
156
+ this.animationIsPlaying.set(false);
157
+ this.animationCurrentIndex.set(0);
158
+ if (this.animationSubscription) {
159
+ this.animationSubscription.unsubscribe();
160
+ this.animationSubscription = void 0;
161
+ }
162
+ }
163
+ setAnimation(animationName, graphicOrNbTimes, nbTimes) {
164
+ if (this.animationIsPlaying()) return;
165
+ this.animationIsPlaying.set(true);
166
+ const previousAnimationName = this.animationName();
167
+ const previousGraphics = this.graphics();
168
+ this.animationCurrentIndex.set(0);
169
+ let graphic;
170
+ let finalNbTimes = Infinity;
171
+ if (typeof graphicOrNbTimes === "number") {
172
+ finalNbTimes = graphicOrNbTimes;
173
+ } else if (graphicOrNbTimes !== void 0) {
174
+ graphic = graphicOrNbTimes;
175
+ finalNbTimes = nbTimes ?? Infinity;
176
+ } else {
177
+ finalNbTimes = Infinity;
178
+ }
179
+ if (graphic !== void 0) {
180
+ if (Array.isArray(graphic)) {
181
+ this.graphics.set(graphic);
182
+ } else {
183
+ this.graphics.set([graphic]);
184
+ }
185
+ }
186
+ if (this.animationSubscription) {
187
+ this.animationSubscription.unsubscribe();
188
+ }
189
+ this.animationSubscription = this.animationCurrentIndex.observable.subscribe((index) => {
190
+ if (index >= finalNbTimes) {
191
+ this.animationCurrentIndex.set(0);
192
+ this.animationName.set(previousAnimationName);
193
+ if (graphic !== void 0) {
194
+ this.graphics.set(previousGraphics);
195
+ }
196
+ this.animationIsPlaying.set(false);
197
+ if (this.animationSubscription) {
198
+ this.animationSubscription.unsubscribe();
199
+ this.animationSubscription = void 0;
200
+ }
201
+ }
202
+ });
203
+ this.animationName.set(animationName);
204
+ }
205
+ showComponentAnimation(id, params) {
206
+ const engine = inject(RpgClientEngine);
207
+ engine.getComponentAnimation(id).displayEffect(params, this);
208
+ }
209
+ isEvent() {
210
+ return this.type === "event";
211
+ }
212
+ isPlayer() {
213
+ return this.type === "player";
214
+ }
215
+ }
216
+
217
+ export { RpgClientObject };
218
+ //# sourceMappingURL=Object.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Object.js","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\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: { x: number; y: number; ts: number }[] = [];\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 this.frames = [...this.frames, ...items];\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 get hooks() {\n return inject<Hooks>(ModulesToken);\n }\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 showComponentAnimation(id: string, params: any) {\n const engine = inject(RpgClientEngine);\n engine.getComponentAnimation(id).displayEffect(params, this);\n }\n \n isEvent(): boolean {\n return this.type === 'event';\n }\n\n isPlayer(): boolean {\n return this.type === 'player';\n }\n}\n"],"names":["TextComponent"],"mappings":";;;;;;;AAOA,MAAM,kBAAA,GAAqB;AAAA,EACzB,IAAA,EAAMA;AACR,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,GAAmB;AACjB,IAAA,OAAO,KAAK,IAAA,KAAS,OAAA;AAAA,EACvB;AAAA,EAEA,QAAA,GAAoB;AAClB,IAAA,OAAO,KAAK,IAAA,KAAS,QAAA;AAAA,EACvB;AACF;;;;"}
@@ -1,4 +1,4 @@
1
- import { RpgClientObject } from './index39.js';
1
+ import { RpgClientObject } from './Object.js';
2
2
 
3
3
  class RpgClientPlayer extends RpgClientObject {
4
4
  constructor() {
@@ -8,4 +8,4 @@ class RpgClientPlayer extends RpgClientObject {
8
8
  }
9
9
 
10
10
  export { RpgClientPlayer };
11
- //# sourceMappingURL=index29.js.map
11
+ //# sourceMappingURL=Player.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Player.js","sources":["../../src/Game/Player.ts"],"sourcesContent":["import { RpgClientObject } from \"./Object\";\n\nexport class RpgClientPlayer extends RpgClientObject {\n type = 'player'\n} "],"names":[],"mappings":";;AAEO,MAAM,wBAAwB,eAAA,CAAgB;AAAA,EAA9C,WAAA,GAAA;AAAA,IAAA,KAAA,CAAA,GAAA,SAAA,CAAA;AACH,IAAA,IAAA,CAAA,IAAA,GAAO,QAAA;AAAA,EAAA;AACX;;;;"}