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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (305) hide show
  1. package/dist/Game/AnimationManager.d.ts +8 -0
  2. package/dist/Game/AnimationManager.js +26 -0
  3. package/dist/Game/AnimationManager.js.map +1 -0
  4. package/dist/Game/Event.d.ts +1 -1
  5. package/dist/Game/Event.js +12 -0
  6. package/dist/Game/Event.js.map +1 -0
  7. package/dist/Game/Map.d.ts +23 -2
  8. package/dist/Game/Map.js +80 -0
  9. package/dist/Game/Map.js.map +1 -0
  10. package/dist/Game/Object.d.ts +157 -0
  11. package/dist/Game/Object.js +211 -0
  12. package/dist/Game/Object.js.map +1 -0
  13. package/dist/Game/Player.d.ts +1 -1
  14. package/dist/Game/Player.js +12 -0
  15. package/dist/Game/Player.js.map +1 -0
  16. package/dist/Gui/Gui.d.ts +177 -5
  17. package/dist/Gui/Gui.js +445 -0
  18. package/dist/Gui/Gui.js.map +1 -0
  19. package/dist/Gui/NotificationManager.d.ts +23 -0
  20. package/dist/Gui/NotificationManager.js +49 -0
  21. package/dist/Gui/NotificationManager.js.map +1 -0
  22. package/dist/Resource.d.ts +97 -0
  23. package/dist/Resource.js +133 -0
  24. package/dist/Resource.js.map +1 -0
  25. package/dist/RpgClient.d.ts +290 -58
  26. package/dist/RpgClientEngine.d.ts +649 -9
  27. package/dist/RpgClientEngine.js +1334 -0
  28. package/dist/RpgClientEngine.js.map +1 -0
  29. package/dist/Sound.d.ts +199 -0
  30. package/dist/Sound.js +167 -0
  31. package/dist/Sound.js.map +1 -0
  32. package/dist/_virtual/_@oxc-project_runtime@0.122.0/helpers/decorate.js +9 -0
  33. package/dist/_virtual/_@oxc-project_runtime@0.122.0/helpers/decorateMetadata.js +6 -0
  34. package/dist/components/animations/animation.ce.js +24 -0
  35. package/dist/components/animations/animation.ce.js.map +1 -0
  36. package/dist/components/animations/hit.ce.js +70 -0
  37. package/dist/components/animations/hit.ce.js.map +1 -0
  38. package/dist/components/animations/index.d.ts +4 -0
  39. package/dist/components/animations/index.js +11 -0
  40. package/dist/components/animations/index.js.map +1 -0
  41. package/dist/components/character.ce.js +392 -0
  42. package/dist/components/character.ce.js.map +1 -0
  43. package/dist/components/dynamics/parse-value.d.ts +1 -0
  44. package/dist/components/dynamics/parse-value.js +44 -0
  45. package/dist/components/dynamics/parse-value.js.map +1 -0
  46. package/dist/components/dynamics/text.ce.js +73 -0
  47. package/dist/components/dynamics/text.ce.js.map +1 -0
  48. package/dist/components/gui/box.ce.js +28 -0
  49. package/dist/components/gui/box.ce.js.map +1 -0
  50. package/dist/components/gui/dialogbox/index.ce.js +205 -0
  51. package/dist/components/gui/dialogbox/index.ce.js.map +1 -0
  52. package/dist/components/gui/gameover.ce.js +193 -0
  53. package/dist/components/gui/gameover.ce.js.map +1 -0
  54. package/dist/components/gui/hud/hud.ce.js +92 -0
  55. package/dist/components/gui/hud/hud.ce.js.map +1 -0
  56. package/dist/components/gui/index.d.ts +15 -3
  57. package/dist/components/gui/index.js +14 -0
  58. package/dist/components/gui/menu/equip-menu.ce.js +481 -0
  59. package/dist/components/gui/menu/equip-menu.ce.js.map +1 -0
  60. package/dist/components/gui/menu/exit-menu.ce.js +54 -0
  61. package/dist/components/gui/menu/exit-menu.ce.js.map +1 -0
  62. package/dist/components/gui/menu/items-menu.ce.js +344 -0
  63. package/dist/components/gui/menu/items-menu.ce.js.map +1 -0
  64. package/dist/components/gui/menu/main-menu.ce.js +417 -0
  65. package/dist/components/gui/menu/main-menu.ce.js.map +1 -0
  66. package/dist/components/gui/menu/options-menu.ce.js +48 -0
  67. package/dist/components/gui/menu/options-menu.ce.js.map +1 -0
  68. package/dist/components/gui/menu/skills-menu.ce.js +107 -0
  69. package/dist/components/gui/menu/skills-menu.ce.js.map +1 -0
  70. package/dist/components/gui/mobile/index.d.ts +8 -0
  71. package/dist/components/gui/mobile/index.js +21 -0
  72. package/dist/components/gui/mobile/index.js.map +1 -0
  73. package/dist/components/gui/mobile/mobile.ce.js +78 -0
  74. package/dist/components/gui/mobile/mobile.ce.js.map +1 -0
  75. package/dist/components/gui/notification/notification.ce.js +64 -0
  76. package/dist/components/gui/notification/notification.ce.js.map +1 -0
  77. package/dist/components/gui/save-load.ce.js +389 -0
  78. package/dist/components/gui/save-load.ce.js.map +1 -0
  79. package/dist/components/gui/shop/shop.ce.js +652 -0
  80. package/dist/components/gui/shop/shop.ce.js.map +1 -0
  81. package/dist/components/gui/title-screen.ce.js +190 -0
  82. package/dist/components/gui/title-screen.ce.js.map +1 -0
  83. package/dist/components/index.d.ts +1 -0
  84. package/dist/components/index.js +4 -0
  85. package/dist/components/prebuilt/hp-bar.ce.js +116 -0
  86. package/dist/components/prebuilt/hp-bar.ce.js.map +1 -0
  87. package/dist/components/prebuilt/index.d.ts +19 -0
  88. package/dist/components/prebuilt/index.js +2 -0
  89. package/dist/components/prebuilt/light-halo.ce.js +94 -0
  90. package/dist/components/prebuilt/light-halo.ce.js.map +1 -0
  91. package/dist/components/scenes/canvas.ce.js +60 -0
  92. package/dist/components/scenes/canvas.ce.js.map +1 -0
  93. package/dist/components/scenes/draw-map.ce.js +89 -0
  94. package/dist/components/scenes/draw-map.ce.js.map +1 -0
  95. package/dist/components/scenes/event-layer.ce.js +28 -0
  96. package/dist/components/scenes/event-layer.ce.js.map +1 -0
  97. package/dist/core/inject.js +18 -0
  98. package/dist/core/inject.js.map +1 -0
  99. package/dist/core/setup.js +16 -0
  100. package/dist/core/setup.js.map +1 -0
  101. package/dist/index.d.ts +15 -1
  102. package/dist/index.js +44 -14
  103. package/dist/module.d.ts +43 -4
  104. package/dist/module.js +176 -0
  105. package/dist/module.js.map +1 -0
  106. package/dist/node_modules/.pnpm/@signe_di@2.9.0/node_modules/@signe/di/dist/index.js +277 -0
  107. package/dist/node_modules/.pnpm/@signe_di@2.9.0/node_modules/@signe/di/dist/index.js.map +1 -0
  108. package/dist/node_modules/.pnpm/@signe_reactive@2.8.3/node_modules/@signe/reactive/dist/index.js +457 -0
  109. package/dist/node_modules/.pnpm/@signe_reactive@2.8.3/node_modules/@signe/reactive/dist/index.js.map +1 -0
  110. package/dist/node_modules/.pnpm/@signe_reactive@2.9.0/node_modules/@signe/reactive/dist/index.js +463 -0
  111. package/dist/node_modules/.pnpm/@signe_reactive@2.9.0/node_modules/@signe/reactive/dist/index.js.map +1 -0
  112. package/dist/node_modules/.pnpm/@signe_room@2.9.0/node_modules/@signe/room/dist/index.js +2191 -0
  113. package/dist/node_modules/.pnpm/@signe_room@2.9.0/node_modules/@signe/room/dist/index.js.map +1 -0
  114. package/dist/node_modules/.pnpm/@signe_sync@2.9.0/node_modules/@signe/sync/dist/chunk-7QVYU63E.js +10 -0
  115. package/dist/node_modules/.pnpm/@signe_sync@2.9.0/node_modules/@signe/sync/dist/chunk-7QVYU63E.js.map +1 -0
  116. package/dist/node_modules/.pnpm/@signe_sync@2.9.0/node_modules/@signe/sync/dist/client/index.js +91 -0
  117. package/dist/node_modules/.pnpm/@signe_sync@2.9.0/node_modules/@signe/sync/dist/client/index.js.map +1 -0
  118. package/dist/node_modules/.pnpm/@signe_sync@2.9.0/node_modules/@signe/sync/dist/index.js +325 -0
  119. package/dist/node_modules/.pnpm/@signe_sync@2.9.0/node_modules/@signe/sync/dist/index.js.map +1 -0
  120. package/dist/node_modules/.pnpm/dset@3.1.4/node_modules/dset/dist/index.js +14 -0
  121. package/dist/node_modules/.pnpm/dset@3.1.4/node_modules/dset/dist/index.js.map +1 -0
  122. package/dist/node_modules/.pnpm/partysocket@1.1.3/node_modules/partysocket/dist/chunk-HAC622V3.js +115 -0
  123. package/dist/node_modules/.pnpm/partysocket@1.1.3/node_modules/partysocket/dist/chunk-HAC622V3.js.map +1 -0
  124. package/dist/node_modules/.pnpm/partysocket@1.1.3/node_modules/partysocket/dist/chunk-S74YV6PU.js +401 -0
  125. package/dist/node_modules/.pnpm/partysocket@1.1.3/node_modules/partysocket/dist/chunk-S74YV6PU.js.map +1 -0
  126. package/dist/node_modules/.pnpm/partysocket@1.1.3/node_modules/partysocket/dist/index.js +2 -0
  127. package/dist/node_modules/.pnpm/zod@3.24.2/node_modules/zod/lib/index.js +3756 -0
  128. package/dist/node_modules/.pnpm/zod@3.24.2/node_modules/zod/lib/index.js.map +1 -0
  129. package/dist/presets/animation.d.ts +31 -0
  130. package/dist/presets/animation.js +39 -0
  131. package/dist/presets/animation.js.map +1 -0
  132. package/dist/presets/faceset.d.ts +30 -0
  133. package/dist/presets/faceset.js +51 -0
  134. package/dist/presets/faceset.js.map +1 -0
  135. package/dist/presets/icon.d.ts +20 -0
  136. package/dist/presets/icon.js +15 -0
  137. package/dist/presets/icon.js.map +1 -0
  138. package/dist/presets/index.d.ts +123 -0
  139. package/dist/presets/index.js +17 -0
  140. package/dist/presets/index.js.map +1 -0
  141. package/dist/presets/lpc.d.ts +89 -0
  142. package/dist/presets/lpc.js +98 -0
  143. package/dist/presets/lpc.js.map +1 -0
  144. package/dist/presets/rmspritesheet.js +42 -0
  145. package/dist/presets/rmspritesheet.js.map +1 -0
  146. package/dist/services/AbstractSocket.d.ts +9 -5
  147. package/dist/services/AbstractSocket.js +11 -0
  148. package/dist/services/AbstractSocket.js.map +1 -0
  149. package/dist/services/keyboardControls.d.ts +15 -0
  150. package/dist/services/keyboardControls.js +23 -0
  151. package/dist/services/keyboardControls.js.map +1 -0
  152. package/dist/services/loadMap.js +123 -0
  153. package/dist/services/loadMap.js.map +1 -0
  154. package/dist/services/mmorpg.d.ts +21 -9
  155. package/dist/services/mmorpg.js +131 -0
  156. package/dist/services/mmorpg.js.map +1 -0
  157. package/dist/services/save.d.ts +19 -0
  158. package/dist/services/save.js +77 -0
  159. package/dist/services/save.js.map +1 -0
  160. package/dist/services/standalone.d.ts +67 -7
  161. package/dist/services/standalone.js +168 -0
  162. package/dist/services/standalone.js.map +1 -0
  163. package/dist/utils/getEntityProp.d.ts +39 -0
  164. package/dist/utils/getEntityProp.js +52 -0
  165. package/dist/utils/getEntityProp.js.map +1 -0
  166. package/package.json +13 -9
  167. package/src/Game/{EffectManager.ts → AnimationManager.ts} +3 -2
  168. package/src/Game/Event.ts +1 -1
  169. package/src/Game/Map.ts +95 -3
  170. package/src/Game/Object.ts +330 -14
  171. package/src/Game/Player.ts +1 -1
  172. package/src/Gui/Gui.ts +506 -18
  173. package/src/Gui/NotificationManager.ts +69 -0
  174. package/src/Resource.ts +150 -0
  175. package/src/RpgClient.ts +300 -58
  176. package/src/RpgClientEngine.ts +1707 -48
  177. package/src/Sound.ts +253 -0
  178. package/src/components/{effects → animations}/animation.ce +3 -6
  179. package/src/components/{effects → animations}/index.ts +1 -1
  180. package/src/components/character.ce +406 -40
  181. package/src/components/dynamics/parse-value.ts +80 -0
  182. package/src/components/dynamics/text.ce +183 -0
  183. package/src/components/gui/box.ce +17 -0
  184. package/src/components/gui/dialogbox/index.ce +204 -187
  185. package/src/components/gui/gameover.ce +158 -0
  186. package/src/components/gui/hud/hud.ce +61 -0
  187. package/src/components/gui/index.ts +30 -4
  188. package/src/components/gui/menu/equip-menu.ce +410 -0
  189. package/src/components/gui/menu/exit-menu.ce +41 -0
  190. package/src/components/gui/menu/items-menu.ce +317 -0
  191. package/src/components/gui/menu/main-menu.ce +294 -0
  192. package/src/components/gui/menu/options-menu.ce +35 -0
  193. package/src/components/gui/menu/skills-menu.ce +83 -0
  194. package/src/components/gui/mobile/index.ts +24 -0
  195. package/src/components/gui/mobile/mobile.ce +80 -0
  196. package/src/components/gui/notification/notification.ce +51 -0
  197. package/src/components/gui/save-load.ce +208 -0
  198. package/src/components/gui/shop/shop.ce +493 -0
  199. package/src/components/gui/title-screen.ce +163 -0
  200. package/src/components/index.ts +3 -0
  201. package/src/components/prebuilt/hp-bar.ce +255 -0
  202. package/src/components/prebuilt/index.ts +24 -0
  203. package/src/components/prebuilt/light-halo.ce +148 -0
  204. package/src/components/scenes/canvas.ce +20 -15
  205. package/src/components/scenes/draw-map.ce +60 -13
  206. package/src/components/scenes/event-layer.ce +9 -2
  207. package/src/components/scenes/transition.ce +60 -0
  208. package/src/index.ts +16 -2
  209. package/src/module.ts +145 -9
  210. package/src/presets/animation.ts +46 -0
  211. package/src/presets/faceset.ts +60 -0
  212. package/src/presets/icon.ts +17 -0
  213. package/src/presets/index.ts +9 -1
  214. package/src/presets/lpc.ts +108 -0
  215. package/src/services/AbstractSocket.ts +10 -2
  216. package/src/services/keyboardControls.ts +20 -0
  217. package/src/services/loadMap.ts +1 -1
  218. package/src/services/mmorpg.ts +100 -12
  219. package/src/services/save.ts +103 -0
  220. package/src/services/standalone.ts +110 -18
  221. package/src/utils/getEntityProp.ts +87 -0
  222. package/tsconfig.json +1 -1
  223. package/vite.config.ts +4 -2
  224. package/dist/Game/EffectManager.d.ts +0 -5
  225. package/dist/components/effects/index.d.ts +0 -4
  226. package/dist/index.js.map +0 -1
  227. package/dist/index10.js +0 -8
  228. package/dist/index10.js.map +0 -1
  229. package/dist/index11.js +0 -10
  230. package/dist/index11.js.map +0 -1
  231. package/dist/index12.js +0 -8
  232. package/dist/index12.js.map +0 -1
  233. package/dist/index13.js +0 -17
  234. package/dist/index13.js.map +0 -1
  235. package/dist/index14.js +0 -91
  236. package/dist/index14.js.map +0 -1
  237. package/dist/index15.js +0 -50
  238. package/dist/index15.js.map +0 -1
  239. package/dist/index16.js +0 -191
  240. package/dist/index16.js.map +0 -1
  241. package/dist/index17.js +0 -9
  242. package/dist/index17.js.map +0 -1
  243. package/dist/index18.js +0 -387
  244. package/dist/index18.js.map +0 -1
  245. package/dist/index19.js +0 -31
  246. package/dist/index19.js.map +0 -1
  247. package/dist/index2.js +0 -112
  248. package/dist/index2.js.map +0 -1
  249. package/dist/index20.js +0 -24
  250. package/dist/index20.js.map +0 -1
  251. package/dist/index21.js +0 -2421
  252. package/dist/index21.js.map +0 -1
  253. package/dist/index22.js +0 -114
  254. package/dist/index22.js.map +0 -1
  255. package/dist/index23.js +0 -109
  256. package/dist/index23.js.map +0 -1
  257. package/dist/index24.js +0 -71
  258. package/dist/index24.js.map +0 -1
  259. package/dist/index25.js +0 -21
  260. package/dist/index25.js.map +0 -1
  261. package/dist/index26.js +0 -41
  262. package/dist/index26.js.map +0 -1
  263. package/dist/index27.js +0 -5
  264. package/dist/index27.js.map +0 -1
  265. package/dist/index28.js +0 -322
  266. package/dist/index28.js.map +0 -1
  267. package/dist/index29.js +0 -27
  268. package/dist/index29.js.map +0 -1
  269. package/dist/index3.js +0 -87
  270. package/dist/index3.js.map +0 -1
  271. package/dist/index30.js +0 -11
  272. package/dist/index30.js.map +0 -1
  273. package/dist/index31.js +0 -11
  274. package/dist/index31.js.map +0 -1
  275. package/dist/index32.js +0 -12
  276. package/dist/index32.js.map +0 -1
  277. package/dist/index33.js +0 -4403
  278. package/dist/index33.js.map +0 -1
  279. package/dist/index34.js +0 -316
  280. package/dist/index34.js.map +0 -1
  281. package/dist/index35.js +0 -174
  282. package/dist/index35.js.map +0 -1
  283. package/dist/index36.js +0 -501
  284. package/dist/index36.js.map +0 -1
  285. package/dist/index37.js +0 -61
  286. package/dist/index37.js.map +0 -1
  287. package/dist/index38.js +0 -20
  288. package/dist/index38.js.map +0 -1
  289. package/dist/index39.js +0 -20
  290. package/dist/index39.js.map +0 -1
  291. package/dist/index4.js +0 -67
  292. package/dist/index4.js.map +0 -1
  293. package/dist/index5.js +0 -16
  294. package/dist/index5.js.map +0 -1
  295. package/dist/index6.js +0 -17
  296. package/dist/index6.js.map +0 -1
  297. package/dist/index7.js +0 -39
  298. package/dist/index7.js.map +0 -1
  299. package/dist/index8.js +0 -90
  300. package/dist/index8.js.map +0 -1
  301. package/dist/index9.js +0 -76
  302. package/dist/index9.js.map +0 -1
  303. package/src/components/gui/dialogbox/itemMenu.ce +0 -23
  304. package/src/components/gui/dialogbox/selection.ce +0 -67
  305. /package/src/components/{effects → animations}/hit.ce +0 -0
@@ -1,16 +1,332 @@
1
- import { RpgCommonPlayer } from "@rpgjs/common";
2
- import { trigger, signal } from "canvasengine";
1
+ import { Hooks, ModulesToken, RpgCommonPlayer } from "@rpgjs/common";
2
+ import { trigger, signal, effect } from "canvasengine";
3
+ import { filter, from, map, Subscription, switchMap } from "rxjs";
4
+ import { inject } from "../core/inject";
5
+ import { RpgClientEngine } from "../RpgClientEngine";
6
+ import TextComponent from "../components/dynamics/text.ce";
7
+
8
+ const DYNAMIC_COMPONENTS = {
9
+ text: TextComponent,
10
+ }
11
+
12
+ type Frame = { x: number; y: number; ts: number };
3
13
 
4
14
  export abstract class RpgClientObject extends RpgCommonPlayer {
5
- abstract type: string;
6
- emitParticleTrigger = trigger()
7
- particleName = signal('')
8
-
9
- flash(color: string, duration: number = 100) {
10
- const lastTint = this.tint()
11
- this.tint.set(color);
12
- setTimeout(() => {
13
- this.tint.set(lastTint)
14
- }, duration)
15
- }
16
- }
15
+ abstract _type: string;
16
+ emitParticleTrigger = trigger();
17
+ particleName = signal("");
18
+ animationCurrentIndex = signal(0);
19
+ animationIsPlaying = signal(false);
20
+ _param = signal({});
21
+ frames: Frame[] = [];
22
+ graphicsSignals = signal<any[]>([]);
23
+ _component = {} // temporary component memory
24
+ flashTrigger = trigger();
25
+
26
+ constructor() {
27
+ super();
28
+ this.hooks.callHooks("client-sprite-onInit", this).subscribe();
29
+
30
+ this._frames.observable.subscribe(({ items }) => {
31
+ if (!this.id) return;
32
+ //if (this.id == this.engine.playerIdSignal()!) return;
33
+ const nextFrames = items.flatMap((item): Frame[] =>
34
+ Array.isArray(item) ? item : [item]
35
+ );
36
+ this.frames = [...this.frames, ...nextFrames];
37
+ });
38
+
39
+ this.graphics.observable
40
+ .pipe(
41
+ map(({ items }) => items),
42
+ filter(graphics => graphics.length > 0),
43
+ switchMap(graphics => from(Promise.all(graphics.map(graphic => this.engine.getSpriteSheet(graphic)))))
44
+ )
45
+ .subscribe((sheets) => {
46
+ this.graphicsSignals.set(sheets);
47
+ });
48
+
49
+ this.componentsTop.observable
50
+ .pipe(
51
+ filter(value => value !== null && value !== undefined),
52
+ map((value) => typeof value === 'string' ? JSON.parse(value) : value),
53
+ )
54
+ .subscribe(({components}) => {
55
+ for (const component of components) {
56
+ for (const [key, value] of Object.entries(component)) {
57
+ this._component = value as any; // temporary component memory
58
+ console.log(value)
59
+ const type = (value as any).type as keyof typeof DYNAMIC_COMPONENTS;
60
+ if (DYNAMIC_COMPONENTS[type]) {
61
+ this.engine.addSpriteComponentInFront(DYNAMIC_COMPONENTS[type]);
62
+ }
63
+ }
64
+ }
65
+ });
66
+
67
+ this.engine.tick
68
+ .pipe
69
+ //throttleTime(10)
70
+ ()
71
+ .subscribe(() => {
72
+ const frame = this.frames.shift();
73
+ if (frame) {
74
+ if (typeof frame.x !== "number" || typeof frame.y !== "number") return;
75
+ this.engine.scene.setBodyPosition(
76
+ this.id,
77
+ frame.x,
78
+ frame.y,
79
+ "top-left"
80
+ );
81
+ }
82
+ });
83
+ }
84
+
85
+ /**
86
+ * Access the shared client hook registry.
87
+ *
88
+ * @returns The hook service used to register and trigger client-side hooks.
89
+ */
90
+ get hooks() {
91
+ return inject<Hooks>(ModulesToken);
92
+ }
93
+
94
+ /**
95
+ * Access the current client engine instance.
96
+ *
97
+ * @returns The active {@link RpgClientEngine} instance.
98
+ */
99
+ get engine() {
100
+ return inject(RpgClientEngine);
101
+ }
102
+
103
+ private animationSubscription?: Subscription;
104
+
105
+ /**
106
+ * Trigger a flash animation on this sprite
107
+ *
108
+ * This method triggers a flash effect using CanvasEngine's flash directive.
109
+ * The flash can be configured with various options including type (alpha, tint, or both),
110
+ * duration, cycles, and color.
111
+ *
112
+ * ## Design
113
+ *
114
+ * The flash uses a trigger system that is connected to the flash directive in the
115
+ * character component. This allows for flexible configuration and can be triggered
116
+ * from both server events and client-side code.
117
+ *
118
+ * @param options - Flash configuration options
119
+ * @param options.type - Type of flash effect: 'alpha' (opacity), 'tint' (color), or 'both' (default: 'alpha')
120
+ * @param options.duration - Duration of the flash animation in milliseconds (default: 300)
121
+ * @param options.cycles - Number of flash cycles (flash on/off) (default: 1)
122
+ * @param options.alpha - Alpha value when flashing, from 0 to 1 (default: 0.3)
123
+ * @param options.tint - Tint color when flashing as hex value or color name (default: 0xffffff - white)
124
+ *
125
+ * @example
126
+ * ```ts
127
+ * // Simple flash with default settings (alpha flash)
128
+ * player.flash();
129
+ *
130
+ * // Flash with red tint
131
+ * player.flash({ type: 'tint', tint: 0xff0000 });
132
+ *
133
+ * // Flash with both alpha and tint
134
+ * player.flash({
135
+ * type: 'both',
136
+ * alpha: 0.5,
137
+ * tint: 0xff0000,
138
+ * duration: 200,
139
+ * cycles: 2
140
+ * });
141
+ *
142
+ * // Quick damage flash
143
+ * player.flash({
144
+ * type: 'tint',
145
+ * tint: 0xff0000,
146
+ * duration: 150,
147
+ * cycles: 1
148
+ * });
149
+ * ```
150
+ */
151
+ flash(options?: {
152
+ type?: 'alpha' | 'tint' | 'both';
153
+ duration?: number;
154
+ cycles?: number;
155
+ alpha?: number;
156
+ tint?: number | string;
157
+ }): void {
158
+ const flashOptions = {
159
+ type: options?.type || 'alpha',
160
+ duration: options?.duration ?? 300,
161
+ cycles: options?.cycles ?? 1,
162
+ alpha: options?.alpha ?? 0.3,
163
+ tint: options?.tint ?? 0xffffff,
164
+ };
165
+
166
+ // Convert color name to hex if needed
167
+ let tintValue = flashOptions.tint;
168
+ if (typeof tintValue === 'string') {
169
+ // Common color name to hex mapping
170
+ const colorMap: Record<string, number> = {
171
+ 'white': 0xffffff,
172
+ 'red': 0xff0000,
173
+ 'green': 0x00ff00,
174
+ 'blue': 0x0000ff,
175
+ 'yellow': 0xffff00,
176
+ 'cyan': 0x00ffff,
177
+ 'magenta': 0xff00ff,
178
+ 'black': 0x000000,
179
+ };
180
+ tintValue = colorMap[tintValue.toLowerCase()] ?? 0xffffff;
181
+ }
182
+
183
+ this.flashTrigger.start({
184
+ ...flashOptions,
185
+ tint: tintValue,
186
+ });
187
+ }
188
+
189
+ /**
190
+ * Reset animation state when animation changes externally
191
+ *
192
+ * This method should be called when the animation changes due to movement
193
+ * or other external factors to ensure the animation system doesn't get stuck
194
+ *
195
+ * @example
196
+ * ```ts
197
+ * // Reset when player starts moving
198
+ * player.resetAnimationState();
199
+ * ```
200
+ */
201
+ resetAnimationState() {
202
+ this.animationIsPlaying.set(false);
203
+ this.animationCurrentIndex.set(0);
204
+ if (this.animationSubscription) {
205
+ this.animationSubscription.unsubscribe();
206
+ this.animationSubscription = undefined;
207
+ }
208
+ }
209
+
210
+ /**
211
+ * Set a custom animation for a specific number of times
212
+ *
213
+ * Plays a custom animation for the specified number of repetitions.
214
+ * The animation system prevents overlapping animations and automatically
215
+ * returns to the previous animation when complete.
216
+ *
217
+ * @param animationName - Name of the animation to play
218
+ * @param nbTimes - Number of times to repeat the animation (default: Infinity for continuous)
219
+ *
220
+ * @example
221
+ * ```ts
222
+ * // Play attack animation 3 times
223
+ * player.setAnimation('attack', 3);
224
+ *
225
+ * // Play continuous spell animation
226
+ * player.setAnimation('spell');
227
+ * ```
228
+ */
229
+ setAnimation(animationName: string, nbTimes?: number): void;
230
+ /**
231
+ * Set a custom animation with temporary graphic change
232
+ *
233
+ * Plays a custom animation for the specified number of repetitions and temporarily
234
+ * changes the player's graphic (sprite sheet) during the animation. The graphic
235
+ * is automatically reset when the animation finishes.
236
+ *
237
+ * @param animationName - Name of the animation to play
238
+ * @param graphic - The graphic(s) to temporarily use during the animation
239
+ * @param nbTimes - Number of times to repeat the animation (default: Infinity for continuous)
240
+ *
241
+ * @example
242
+ * ```ts
243
+ * // Play attack animation with temporary graphic change
244
+ * player.setAnimation('attack', 'hero_attack', 3);
245
+ * ```
246
+ */
247
+ setAnimation(animationName: string, graphic?: string | string[], nbTimes?: number): void;
248
+ setAnimation(animationName: string, graphicOrNbTimes?: string | string[] | number, nbTimes?: number): void {
249
+ if (this.animationIsPlaying()) return;
250
+ this.animationIsPlaying.set(true);
251
+ const previousAnimationName = this.animationName();
252
+ const previousGraphics = this.graphics();
253
+ this.animationCurrentIndex.set(0);
254
+
255
+ let graphic: string | string[] | undefined;
256
+ let finalNbTimes: number = Infinity;
257
+
258
+ // Handle overloads
259
+ if (typeof graphicOrNbTimes === 'number') {
260
+ // setAnimation(animationName, nbTimes)
261
+ finalNbTimes = graphicOrNbTimes;
262
+ } else if (graphicOrNbTimes !== undefined) {
263
+ // setAnimation(animationName, graphic, nbTimes)
264
+ graphic = graphicOrNbTimes;
265
+ finalNbTimes = nbTimes ?? Infinity;
266
+ } else {
267
+ // setAnimation(animationName) - nbTimes remains Infinity
268
+ finalNbTimes = Infinity;
269
+ }
270
+
271
+ // Temporarily change graphic if provided
272
+ if (graphic !== undefined) {
273
+ if (Array.isArray(graphic)) {
274
+ this.graphics.set(graphic);
275
+ } else {
276
+ this.graphics.set([graphic]);
277
+ }
278
+ }
279
+
280
+ // Clean up any existing subscription
281
+ if (this.animationSubscription) {
282
+ this.animationSubscription.unsubscribe();
283
+ }
284
+
285
+ this.animationSubscription =
286
+ this.animationCurrentIndex.observable.subscribe((index) => {
287
+ if (index >= finalNbTimes) {
288
+ this.animationCurrentIndex.set(0);
289
+ this.animationName.set(previousAnimationName);
290
+ // Reset graphic to previous value if it was changed
291
+ if (graphic !== undefined) {
292
+ this.graphics.set(previousGraphics);
293
+ }
294
+ this.animationIsPlaying.set(false);
295
+ if (this.animationSubscription) {
296
+ this.animationSubscription.unsubscribe();
297
+ this.animationSubscription = undefined;
298
+ }
299
+ }
300
+ });
301
+ this.animationName.set(animationName);
302
+ }
303
+
304
+ /**
305
+ * Display a registered component animation effect on this object.
306
+ *
307
+ * @param id - Identifier of the component animation to play.
308
+ * @param params - Parameters forwarded to the animation effect.
309
+ */
310
+ showComponentAnimation(id: string, params: any) {
311
+ const engine = inject(RpgClientEngine);
312
+ engine.getComponentAnimation(id).displayEffect(params, this);
313
+ }
314
+
315
+ /**
316
+ * Check whether this client object represents an event.
317
+ *
318
+ * @returns `true` if the object type is `event`, otherwise `false`.
319
+ */
320
+ isEvent(): boolean {
321
+ return this._type === 'event';
322
+ }
323
+
324
+ /**
325
+ * Check whether this client object represents a player.
326
+ *
327
+ * @returns `true` if the object type is `player`, otherwise `false`.
328
+ */
329
+ isPlayer(): boolean {
330
+ return this._type === 'player';
331
+ }
332
+ }
@@ -1,5 +1,5 @@
1
1
  import { RpgClientObject } from "./Object";
2
2
 
3
3
  export class RpgClientPlayer extends RpgClientObject {
4
- type = 'player'
4
+ _type = 'player'
5
5
  }