@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.
- package/dist/Game/AnimationManager.d.ts +8 -0
- package/dist/Game/AnimationManager.js +26 -0
- package/dist/Game/AnimationManager.js.map +1 -0
- package/dist/Game/Event.d.ts +1 -1
- package/dist/Game/Event.js +12 -0
- package/dist/Game/Event.js.map +1 -0
- package/dist/Game/Map.d.ts +23 -2
- package/dist/Game/Map.js +80 -0
- package/dist/Game/Map.js.map +1 -0
- package/dist/Game/Object.d.ts +157 -0
- package/dist/Game/Object.js +211 -0
- package/dist/Game/Object.js.map +1 -0
- package/dist/Game/Player.d.ts +1 -1
- package/dist/Game/Player.js +12 -0
- package/dist/Game/Player.js.map +1 -0
- package/dist/Gui/Gui.d.ts +177 -5
- package/dist/Gui/Gui.js +445 -0
- package/dist/Gui/Gui.js.map +1 -0
- package/dist/Gui/NotificationManager.d.ts +23 -0
- package/dist/Gui/NotificationManager.js +49 -0
- package/dist/Gui/NotificationManager.js.map +1 -0
- package/dist/Resource.d.ts +97 -0
- package/dist/Resource.js +133 -0
- package/dist/Resource.js.map +1 -0
- package/dist/RpgClient.d.ts +290 -58
- package/dist/RpgClientEngine.d.ts +649 -9
- package/dist/RpgClientEngine.js +1334 -0
- package/dist/RpgClientEngine.js.map +1 -0
- package/dist/Sound.d.ts +199 -0
- package/dist/Sound.js +167 -0
- package/dist/Sound.js.map +1 -0
- package/dist/_virtual/_@oxc-project_runtime@0.122.0/helpers/decorate.js +9 -0
- package/dist/_virtual/_@oxc-project_runtime@0.122.0/helpers/decorateMetadata.js +6 -0
- package/dist/components/animations/animation.ce.js +24 -0
- package/dist/components/animations/animation.ce.js.map +1 -0
- package/dist/components/animations/hit.ce.js +70 -0
- package/dist/components/animations/hit.ce.js.map +1 -0
- package/dist/components/animations/index.d.ts +4 -0
- package/dist/components/animations/index.js +11 -0
- package/dist/components/animations/index.js.map +1 -0
- package/dist/components/character.ce.js +392 -0
- package/dist/components/character.ce.js.map +1 -0
- package/dist/components/dynamics/parse-value.d.ts +1 -0
- package/dist/components/dynamics/parse-value.js +44 -0
- package/dist/components/dynamics/parse-value.js.map +1 -0
- package/dist/components/dynamics/text.ce.js +73 -0
- package/dist/components/dynamics/text.ce.js.map +1 -0
- package/dist/components/gui/box.ce.js +28 -0
- package/dist/components/gui/box.ce.js.map +1 -0
- package/dist/components/gui/dialogbox/index.ce.js +205 -0
- package/dist/components/gui/dialogbox/index.ce.js.map +1 -0
- package/dist/components/gui/gameover.ce.js +193 -0
- package/dist/components/gui/gameover.ce.js.map +1 -0
- package/dist/components/gui/hud/hud.ce.js +92 -0
- package/dist/components/gui/hud/hud.ce.js.map +1 -0
- package/dist/components/gui/index.d.ts +15 -3
- package/dist/components/gui/index.js +14 -0
- package/dist/components/gui/menu/equip-menu.ce.js +481 -0
- package/dist/components/gui/menu/equip-menu.ce.js.map +1 -0
- package/dist/components/gui/menu/exit-menu.ce.js +54 -0
- package/dist/components/gui/menu/exit-menu.ce.js.map +1 -0
- package/dist/components/gui/menu/items-menu.ce.js +344 -0
- package/dist/components/gui/menu/items-menu.ce.js.map +1 -0
- package/dist/components/gui/menu/main-menu.ce.js +417 -0
- package/dist/components/gui/menu/main-menu.ce.js.map +1 -0
- package/dist/components/gui/menu/options-menu.ce.js +48 -0
- package/dist/components/gui/menu/options-menu.ce.js.map +1 -0
- package/dist/components/gui/menu/skills-menu.ce.js +107 -0
- package/dist/components/gui/menu/skills-menu.ce.js.map +1 -0
- package/dist/components/gui/mobile/index.d.ts +8 -0
- package/dist/components/gui/mobile/index.js +21 -0
- package/dist/components/gui/mobile/index.js.map +1 -0
- package/dist/components/gui/mobile/mobile.ce.js +78 -0
- package/dist/components/gui/mobile/mobile.ce.js.map +1 -0
- package/dist/components/gui/notification/notification.ce.js +64 -0
- package/dist/components/gui/notification/notification.ce.js.map +1 -0
- package/dist/components/gui/save-load.ce.js +389 -0
- package/dist/components/gui/save-load.ce.js.map +1 -0
- package/dist/components/gui/shop/shop.ce.js +652 -0
- package/dist/components/gui/shop/shop.ce.js.map +1 -0
- package/dist/components/gui/title-screen.ce.js +190 -0
- package/dist/components/gui/title-screen.ce.js.map +1 -0
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.js +4 -0
- package/dist/components/prebuilt/hp-bar.ce.js +116 -0
- package/dist/components/prebuilt/hp-bar.ce.js.map +1 -0
- package/dist/components/prebuilt/index.d.ts +19 -0
- package/dist/components/prebuilt/index.js +2 -0
- package/dist/components/prebuilt/light-halo.ce.js +94 -0
- package/dist/components/prebuilt/light-halo.ce.js.map +1 -0
- package/dist/components/scenes/canvas.ce.js +60 -0
- package/dist/components/scenes/canvas.ce.js.map +1 -0
- package/dist/components/scenes/draw-map.ce.js +89 -0
- package/dist/components/scenes/draw-map.ce.js.map +1 -0
- package/dist/components/scenes/event-layer.ce.js +28 -0
- package/dist/components/scenes/event-layer.ce.js.map +1 -0
- package/dist/core/inject.js +18 -0
- package/dist/core/inject.js.map +1 -0
- package/dist/core/setup.js +16 -0
- package/dist/core/setup.js.map +1 -0
- package/dist/index.d.ts +15 -1
- package/dist/index.js +44 -14
- package/dist/module.d.ts +43 -4
- package/dist/module.js +176 -0
- package/dist/module.js.map +1 -0
- package/dist/node_modules/.pnpm/@signe_di@2.9.0/node_modules/@signe/di/dist/index.js +277 -0
- package/dist/node_modules/.pnpm/@signe_di@2.9.0/node_modules/@signe/di/dist/index.js.map +1 -0
- package/dist/node_modules/.pnpm/@signe_reactive@2.8.3/node_modules/@signe/reactive/dist/index.js +457 -0
- package/dist/node_modules/.pnpm/@signe_reactive@2.8.3/node_modules/@signe/reactive/dist/index.js.map +1 -0
- package/dist/node_modules/.pnpm/@signe_reactive@2.9.0/node_modules/@signe/reactive/dist/index.js +463 -0
- package/dist/node_modules/.pnpm/@signe_reactive@2.9.0/node_modules/@signe/reactive/dist/index.js.map +1 -0
- package/dist/node_modules/.pnpm/@signe_room@2.9.0/node_modules/@signe/room/dist/index.js +2191 -0
- package/dist/node_modules/.pnpm/@signe_room@2.9.0/node_modules/@signe/room/dist/index.js.map +1 -0
- package/dist/node_modules/.pnpm/@signe_sync@2.9.0/node_modules/@signe/sync/dist/chunk-7QVYU63E.js +10 -0
- package/dist/node_modules/.pnpm/@signe_sync@2.9.0/node_modules/@signe/sync/dist/chunk-7QVYU63E.js.map +1 -0
- package/dist/node_modules/.pnpm/@signe_sync@2.9.0/node_modules/@signe/sync/dist/client/index.js +91 -0
- package/dist/node_modules/.pnpm/@signe_sync@2.9.0/node_modules/@signe/sync/dist/client/index.js.map +1 -0
- package/dist/node_modules/.pnpm/@signe_sync@2.9.0/node_modules/@signe/sync/dist/index.js +325 -0
- package/dist/node_modules/.pnpm/@signe_sync@2.9.0/node_modules/@signe/sync/dist/index.js.map +1 -0
- package/dist/node_modules/.pnpm/dset@3.1.4/node_modules/dset/dist/index.js +14 -0
- package/dist/node_modules/.pnpm/dset@3.1.4/node_modules/dset/dist/index.js.map +1 -0
- package/dist/node_modules/.pnpm/partysocket@1.1.3/node_modules/partysocket/dist/chunk-HAC622V3.js +115 -0
- package/dist/node_modules/.pnpm/partysocket@1.1.3/node_modules/partysocket/dist/chunk-HAC622V3.js.map +1 -0
- package/dist/node_modules/.pnpm/partysocket@1.1.3/node_modules/partysocket/dist/chunk-S74YV6PU.js +401 -0
- package/dist/node_modules/.pnpm/partysocket@1.1.3/node_modules/partysocket/dist/chunk-S74YV6PU.js.map +1 -0
- package/dist/node_modules/.pnpm/partysocket@1.1.3/node_modules/partysocket/dist/index.js +2 -0
- package/dist/node_modules/.pnpm/zod@3.24.2/node_modules/zod/lib/index.js +3756 -0
- package/dist/node_modules/.pnpm/zod@3.24.2/node_modules/zod/lib/index.js.map +1 -0
- package/dist/presets/animation.d.ts +31 -0
- package/dist/presets/animation.js +39 -0
- package/dist/presets/animation.js.map +1 -0
- package/dist/presets/faceset.d.ts +30 -0
- package/dist/presets/faceset.js +51 -0
- package/dist/presets/faceset.js.map +1 -0
- package/dist/presets/icon.d.ts +20 -0
- package/dist/presets/icon.js +15 -0
- package/dist/presets/icon.js.map +1 -0
- package/dist/presets/index.d.ts +123 -0
- package/dist/presets/index.js +17 -0
- package/dist/presets/index.js.map +1 -0
- package/dist/presets/lpc.d.ts +89 -0
- package/dist/presets/lpc.js +98 -0
- package/dist/presets/lpc.js.map +1 -0
- package/dist/presets/rmspritesheet.js +42 -0
- package/dist/presets/rmspritesheet.js.map +1 -0
- package/dist/services/AbstractSocket.d.ts +9 -5
- package/dist/services/AbstractSocket.js +11 -0
- package/dist/services/AbstractSocket.js.map +1 -0
- package/dist/services/keyboardControls.d.ts +15 -0
- package/dist/services/keyboardControls.js +23 -0
- package/dist/services/keyboardControls.js.map +1 -0
- package/dist/services/loadMap.js +123 -0
- package/dist/services/loadMap.js.map +1 -0
- package/dist/services/mmorpg.d.ts +21 -9
- package/dist/services/mmorpg.js +131 -0
- package/dist/services/mmorpg.js.map +1 -0
- package/dist/services/save.d.ts +19 -0
- package/dist/services/save.js +77 -0
- package/dist/services/save.js.map +1 -0
- package/dist/services/standalone.d.ts +67 -7
- package/dist/services/standalone.js +168 -0
- package/dist/services/standalone.js.map +1 -0
- package/dist/utils/getEntityProp.d.ts +39 -0
- package/dist/utils/getEntityProp.js +52 -0
- package/dist/utils/getEntityProp.js.map +1 -0
- package/package.json +13 -9
- package/src/Game/{EffectManager.ts → AnimationManager.ts} +3 -2
- package/src/Game/Event.ts +1 -1
- package/src/Game/Map.ts +95 -3
- package/src/Game/Object.ts +330 -14
- package/src/Game/Player.ts +1 -1
- package/src/Gui/Gui.ts +506 -18
- package/src/Gui/NotificationManager.ts +69 -0
- package/src/Resource.ts +150 -0
- package/src/RpgClient.ts +300 -58
- package/src/RpgClientEngine.ts +1707 -48
- package/src/Sound.ts +253 -0
- package/src/components/{effects → animations}/animation.ce +3 -6
- package/src/components/{effects → animations}/index.ts +1 -1
- package/src/components/character.ce +406 -40
- package/src/components/dynamics/parse-value.ts +80 -0
- package/src/components/dynamics/text.ce +183 -0
- package/src/components/gui/box.ce +17 -0
- package/src/components/gui/dialogbox/index.ce +204 -187
- package/src/components/gui/gameover.ce +158 -0
- package/src/components/gui/hud/hud.ce +61 -0
- package/src/components/gui/index.ts +30 -4
- package/src/components/gui/menu/equip-menu.ce +410 -0
- package/src/components/gui/menu/exit-menu.ce +41 -0
- package/src/components/gui/menu/items-menu.ce +317 -0
- package/src/components/gui/menu/main-menu.ce +294 -0
- package/src/components/gui/menu/options-menu.ce +35 -0
- package/src/components/gui/menu/skills-menu.ce +83 -0
- package/src/components/gui/mobile/index.ts +24 -0
- package/src/components/gui/mobile/mobile.ce +80 -0
- package/src/components/gui/notification/notification.ce +51 -0
- package/src/components/gui/save-load.ce +208 -0
- package/src/components/gui/shop/shop.ce +493 -0
- package/src/components/gui/title-screen.ce +163 -0
- package/src/components/index.ts +3 -0
- package/src/components/prebuilt/hp-bar.ce +255 -0
- package/src/components/prebuilt/index.ts +24 -0
- package/src/components/prebuilt/light-halo.ce +148 -0
- package/src/components/scenes/canvas.ce +20 -15
- package/src/components/scenes/draw-map.ce +60 -13
- package/src/components/scenes/event-layer.ce +9 -2
- package/src/components/scenes/transition.ce +60 -0
- package/src/index.ts +16 -2
- package/src/module.ts +145 -9
- package/src/presets/animation.ts +46 -0
- package/src/presets/faceset.ts +60 -0
- package/src/presets/icon.ts +17 -0
- package/src/presets/index.ts +9 -1
- package/src/presets/lpc.ts +108 -0
- package/src/services/AbstractSocket.ts +10 -2
- package/src/services/keyboardControls.ts +20 -0
- package/src/services/loadMap.ts +1 -1
- package/src/services/mmorpg.ts +100 -12
- package/src/services/save.ts +103 -0
- package/src/services/standalone.ts +110 -18
- package/src/utils/getEntityProp.ts +87 -0
- package/tsconfig.json +1 -1
- package/vite.config.ts +4 -2
- package/dist/Game/EffectManager.d.ts +0 -5
- package/dist/components/effects/index.d.ts +0 -4
- package/dist/index.js.map +0 -1
- package/dist/index10.js +0 -8
- package/dist/index10.js.map +0 -1
- package/dist/index11.js +0 -10
- package/dist/index11.js.map +0 -1
- package/dist/index12.js +0 -8
- package/dist/index12.js.map +0 -1
- package/dist/index13.js +0 -17
- package/dist/index13.js.map +0 -1
- package/dist/index14.js +0 -91
- package/dist/index14.js.map +0 -1
- package/dist/index15.js +0 -50
- package/dist/index15.js.map +0 -1
- package/dist/index16.js +0 -191
- package/dist/index16.js.map +0 -1
- package/dist/index17.js +0 -9
- package/dist/index17.js.map +0 -1
- package/dist/index18.js +0 -387
- package/dist/index18.js.map +0 -1
- package/dist/index19.js +0 -31
- package/dist/index19.js.map +0 -1
- package/dist/index2.js +0 -112
- package/dist/index2.js.map +0 -1
- package/dist/index20.js +0 -24
- package/dist/index20.js.map +0 -1
- package/dist/index21.js +0 -2421
- package/dist/index21.js.map +0 -1
- package/dist/index22.js +0 -114
- package/dist/index22.js.map +0 -1
- package/dist/index23.js +0 -109
- package/dist/index23.js.map +0 -1
- package/dist/index24.js +0 -71
- package/dist/index24.js.map +0 -1
- package/dist/index25.js +0 -21
- package/dist/index25.js.map +0 -1
- package/dist/index26.js +0 -41
- package/dist/index26.js.map +0 -1
- package/dist/index27.js +0 -5
- package/dist/index27.js.map +0 -1
- package/dist/index28.js +0 -322
- package/dist/index28.js.map +0 -1
- package/dist/index29.js +0 -27
- package/dist/index29.js.map +0 -1
- package/dist/index3.js +0 -87
- package/dist/index3.js.map +0 -1
- package/dist/index30.js +0 -11
- package/dist/index30.js.map +0 -1
- package/dist/index31.js +0 -11
- package/dist/index31.js.map +0 -1
- package/dist/index32.js +0 -12
- package/dist/index32.js.map +0 -1
- package/dist/index33.js +0 -4403
- package/dist/index33.js.map +0 -1
- package/dist/index34.js +0 -316
- package/dist/index34.js.map +0 -1
- package/dist/index35.js +0 -174
- package/dist/index35.js.map +0 -1
- package/dist/index36.js +0 -501
- package/dist/index36.js.map +0 -1
- package/dist/index37.js +0 -61
- package/dist/index37.js.map +0 -1
- package/dist/index38.js +0 -20
- package/dist/index38.js.map +0 -1
- package/dist/index39.js +0 -20
- package/dist/index39.js.map +0 -1
- package/dist/index4.js +0 -67
- package/dist/index4.js.map +0 -1
- package/dist/index5.js +0 -16
- package/dist/index5.js.map +0 -1
- package/dist/index6.js +0 -17
- package/dist/index6.js.map +0 -1
- package/dist/index7.js +0 -39
- package/dist/index7.js.map +0 -1
- package/dist/index8.js +0 -90
- package/dist/index8.js.map +0 -1
- package/dist/index9.js +0 -76
- package/dist/index9.js.map +0 -1
- package/src/components/gui/dialogbox/itemMenu.ce +0 -23
- package/src/components/gui/dialogbox/selection.ce +0 -67
- /package/src/components/{effects → animations}/hit.ce +0 -0
package/src/Game/Object.ts
CHANGED
|
@@ -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
|
|
6
|
-
emitParticleTrigger = trigger()
|
|
7
|
-
particleName = signal(
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
+
}
|
package/src/Game/Player.ts
CHANGED