@rpgjs/client 5.0.0-alpha.9 → 5.0.0-beta.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +37 -0
- package/LICENSE +19 -0
- package/dist/Game/AnimationManager.d.ts +8 -0
- package/dist/Game/AnimationManager.js +35 -0
- package/dist/Game/AnimationManager.js.map +1 -0
- package/dist/Game/AnimationManager.spec.d.ts +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 +31 -2
- package/dist/Game/Map.js +138 -0
- package/dist/Game/Map.js.map +1 -0
- package/dist/Game/Object.d.ts +189 -0
- package/dist/Game/Object.js +255 -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 +192 -7
- package/dist/Gui/Gui.js +475 -0
- package/dist/Gui/Gui.js.map +1 -0
- package/dist/Gui/Gui.spec.d.ts +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 +295 -13
- package/dist/RpgClientEngine.d.ts +671 -15
- package/dist/RpgClientEngine.js +1442 -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.130.0/helpers/decorate.js +9 -0
- package/dist/_virtual/_@oxc-project_runtime@0.130.0/helpers/decorateMetadata.js +6 -0
- package/dist/components/animations/animation.ce.js +23 -0
- package/dist/components/animations/animation.ce.js.map +1 -0
- package/dist/components/animations/hit.ce.js +64 -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 +572 -0
- package/dist/components/character.ce.js.map +1 -0
- package/dist/components/dynamics/bar.ce.js +96 -0
- package/dist/components/dynamics/bar.ce.js.map +1 -0
- package/dist/components/dynamics/image.ce.js +23 -0
- package/dist/components/dynamics/image.ce.js.map +1 -0
- package/dist/components/dynamics/parse-value.d.ts +4 -0
- package/dist/components/dynamics/parse-value.js +63 -0
- package/dist/components/dynamics/parse-value.js.map +1 -0
- package/dist/components/dynamics/parse-value.spec.d.ts +1 -0
- package/dist/components/dynamics/shape-utils.d.ts +16 -0
- package/dist/components/dynamics/shape-utils.js +73 -0
- package/dist/components/dynamics/shape-utils.js.map +1 -0
- package/dist/components/dynamics/shape-utils.spec.d.ts +1 -0
- package/dist/components/dynamics/shape.ce.js +83 -0
- package/dist/components/dynamics/shape.ce.js.map +1 -0
- package/dist/components/dynamics/text.ce.js +50 -0
- package/dist/components/dynamics/text.ce.js.map +1 -0
- package/dist/components/gui/box.ce.js +26 -0
- package/dist/components/gui/box.ce.js.map +1 -0
- package/dist/components/gui/dialogbox/index.ce.js +198 -0
- package/dist/components/gui/dialogbox/index.ce.js.map +1 -0
- package/dist/components/gui/gameover.ce.js +169 -0
- package/dist/components/gui/gameover.ce.js.map +1 -0
- package/dist/components/gui/hud/hud.ce.js +83 -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 +427 -0
- package/dist/components/gui/menu/equip-menu.ce.js.map +1 -0
- package/dist/components/gui/menu/exit-menu.ce.js +55 -0
- package/dist/components/gui/menu/exit-menu.ce.js.map +1 -0
- package/dist/components/gui/menu/items-menu.ce.js +326 -0
- package/dist/components/gui/menu/items-menu.ce.js.map +1 -0
- package/dist/components/gui/menu/main-menu.ce.js +399 -0
- package/dist/components/gui/menu/main-menu.ce.js.map +1 -0
- package/dist/components/gui/menu/options-menu.ce.js +49 -0
- package/dist/components/gui/menu/options-menu.ce.js.map +1 -0
- package/dist/components/gui/menu/skills-menu.ce.js +102 -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 +79 -0
- package/dist/components/gui/mobile/mobile.ce.js.map +1 -0
- package/dist/components/gui/notification/notification.ce.js +62 -0
- package/dist/components/gui/notification/notification.ce.js.map +1 -0
- package/dist/components/gui/save-load.ce.js +211 -0
- package/dist/components/gui/save-load.ce.js.map +1 -0
- package/dist/components/gui/shop/shop.ce.js +614 -0
- package/dist/components/gui/shop/shop.ce.js.map +1 -0
- package/dist/components/gui/title-screen.ce.js +164 -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/player-components-utils.d.ts +67 -0
- package/dist/components/player-components-utils.js +162 -0
- package/dist/components/player-components-utils.js.map +1 -0
- package/dist/components/player-components-utils.spec.d.ts +1 -0
- package/dist/components/player-components.ce.js +188 -0
- package/dist/components/player-components.ce.js.map +1 -0
- package/dist/components/prebuilt/hp-bar.ce.js +113 -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 +70 -0
- package/dist/components/prebuilt/light-halo.ce.js.map +1 -0
- package/dist/components/scenes/canvas.ce.js +196 -0
- package/dist/components/scenes/canvas.ce.js.map +1 -0
- package/dist/components/scenes/draw-map.ce.js +79 -0
- package/dist/components/scenes/draw-map.ce.js.map +1 -0
- package/dist/components/scenes/event-layer.ce.js +29 -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/decorators/spritesheet.d.ts +1 -0
- package/dist/decorators/spritesheet.js +11 -0
- package/dist/decorators/spritesheet.js.map +1 -0
- package/dist/index.d.ts +16 -1
- package/dist/index.js +45 -14
- package/dist/module.d.ts +43 -4
- package/dist/module.js +179 -0
- package/dist/module.js.map +1 -0
- package/dist/node_modules/.pnpm/@signe_di@3.0.1/node_modules/@signe/di/dist/index.js +167 -0
- package/dist/node_modules/.pnpm/@signe_di@3.0.1/node_modules/@signe/di/dist/index.js.map +1 -0
- package/dist/node_modules/.pnpm/@signe_reactive@3.0.1/node_modules/@signe/reactive/dist/index.js +239 -0
- package/dist/node_modules/.pnpm/@signe_reactive@3.0.1/node_modules/@signe/reactive/dist/index.js.map +1 -0
- package/dist/node_modules/.pnpm/@signe_room@3.0.1/node_modules/@signe/room/dist/chunk-EUXUH3YW.js +13 -0
- package/dist/node_modules/.pnpm/@signe_room@3.0.1/node_modules/@signe/room/dist/chunk-EUXUH3YW.js.map +1 -0
- package/dist/node_modules/.pnpm/@signe_room@3.0.1/node_modules/@signe/room/dist/index.js +696 -0
- package/dist/node_modules/.pnpm/@signe_room@3.0.1/node_modules/@signe/room/dist/index.js.map +1 -0
- package/dist/node_modules/.pnpm/@signe_sync@3.0.1/node_modules/@signe/sync/dist/client/index.js +44 -0
- package/dist/node_modules/.pnpm/@signe_sync@3.0.1/node_modules/@signe/sync/dist/client/index.js.map +1 -0
- package/dist/node_modules/.pnpm/@signe_sync@3.0.1/node_modules/@signe/sync/dist/index.js +241 -0
- package/dist/node_modules/.pnpm/@signe_sync@3.0.1/node_modules/@signe/sync/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.d.ts +6 -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 +136 -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/save.spec.d.ts +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 +53 -0
- package/dist/utils/getEntityProp.js.map +1 -0
- package/dist/utils/getEntityProp.spec.d.ts +1 -0
- package/dist/utils/readPropValue.d.ts +2 -0
- package/dist/utils/readPropValue.js +13 -0
- package/dist/utils/readPropValue.js.map +1 -0
- package/package.json +14 -11
- package/src/Game/AnimationManager.spec.ts +30 -0
- package/src/Game/AnimationManager.ts +33 -0
- package/src/Game/Event.ts +1 -1
- package/src/Game/Map.ts +184 -3
- package/src/Game/Object.ts +409 -14
- package/src/Game/Player.ts +1 -1
- package/src/Gui/Gui.spec.ts +273 -0
- package/src/Gui/Gui.ts +566 -23
- package/src/Gui/NotificationManager.ts +69 -0
- package/src/Resource.ts +149 -0
- package/src/RpgClient.ts +309 -14
- package/src/RpgClientEngine.ts +1790 -63
- 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 +801 -59
- package/src/components/dynamics/bar.ce +87 -0
- package/src/components/dynamics/image.ce +20 -0
- package/src/components/dynamics/parse-value.spec.ts +83 -0
- package/src/components/dynamics/parse-value.ts +154 -0
- package/src/components/dynamics/shape-utils.spec.ts +46 -0
- package/src/components/dynamics/shape-utils.ts +61 -0
- package/src/components/dynamics/shape.ce +89 -0
- package/src/components/dynamics/text.ce +68 -0
- package/src/components/gui/box.ce +17 -0
- package/src/components/gui/dialogbox/index.ce +213 -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/player-components-utils.spec.ts +109 -0
- package/src/components/player-components-utils.ts +205 -0
- package/src/components/player-components.ce +221 -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 +185 -21
- package/src/components/scenes/draw-map.ce +55 -21
- package/src/components/scenes/event-layer.ce +8 -2
- package/src/components/scenes/transition.ce +60 -0
- package/src/core/setup.ts +2 -2
- package/src/decorators/spritesheet.ts +8 -0
- package/src/index.ts +17 -2
- package/src/module.ts +132 -10
- 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 +3 -1
- package/src/services/mmorpg.ts +106 -12
- package/src/services/save.spec.ts +127 -0
- package/src/services/save.ts +103 -0
- package/src/services/standalone.ts +110 -18
- package/src/utils/getEntityProp.spec.ts +96 -0
- package/src/utils/getEntityProp.ts +88 -0
- package/src/utils/readPropValue.ts +16 -0
- 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 -107
- 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 -181
- 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 -174
- package/dist/index32.js.map +0 -1
- package/dist/index33.js +0 -501
- package/dist/index33.js.map +0 -1
- package/dist/index34.js +0 -12
- package/dist/index34.js.map +0 -1
- package/dist/index35.js +0 -4403
- package/dist/index35.js.map +0 -1
- package/dist/index36.js +0 -316
- 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 -108
- package/dist/index8.js.map +0 -1
- package/dist/index9.js +0 -76
- package/dist/index9.js.map +0 -1
- package/src/Game/EffectManager.ts +0 -20
- 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
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
import { inject } from "../core/inject.js";
|
|
2
|
+
import { RpgClientEngine } from "../RpgClientEngine.js";
|
|
3
|
+
import { signal, trigger } from "canvasengine";
|
|
4
|
+
import { ModulesToken, RpgCommonPlayer } from "@rpgjs/common";
|
|
5
|
+
import { from, map, of, switchMap } from "rxjs";
|
|
6
|
+
//#region src/Game/Object.ts
|
|
7
|
+
var RpgClientObject = class extends RpgCommonPlayer {
|
|
8
|
+
constructor() {
|
|
9
|
+
super();
|
|
10
|
+
this.emitParticleTrigger = trigger();
|
|
11
|
+
this.particleName = signal("");
|
|
12
|
+
this.animationCurrentIndex = signal(0);
|
|
13
|
+
this.animationIsPlaying = signal(false);
|
|
14
|
+
this._param = signal({});
|
|
15
|
+
this.frames = [];
|
|
16
|
+
this.graphicsSignals = signal([]);
|
|
17
|
+
this.flashTrigger = trigger();
|
|
18
|
+
this.hooks.callHooks("client-sprite-onInit", this).subscribe();
|
|
19
|
+
this._frames.observable.subscribe(({ items }) => {
|
|
20
|
+
if (!this.id) return;
|
|
21
|
+
const nextFrames = items.flatMap((item) => Array.isArray(item) ? item : [item]);
|
|
22
|
+
this.frames = [...this.frames, ...nextFrames];
|
|
23
|
+
});
|
|
24
|
+
this.graphics.observable.pipe(map(({ items }) => items), switchMap((graphics) => {
|
|
25
|
+
if (graphics.length === 0) return of([]);
|
|
26
|
+
return from(Promise.all(graphics.map((graphic) => this.engine.getSpriteSheet(graphic))));
|
|
27
|
+
})).subscribe((sheets) => {
|
|
28
|
+
this.graphicsSignals.set(sheets);
|
|
29
|
+
});
|
|
30
|
+
this.engine.tick.pipe().subscribe(() => {
|
|
31
|
+
const frame = this.frames.shift();
|
|
32
|
+
if (frame) {
|
|
33
|
+
if (typeof frame.x !== "number" || typeof frame.y !== "number") return;
|
|
34
|
+
this.engine.scene.setBodyPosition(this.id, frame.x, frame.y, "top-left");
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Access the shared client hook registry.
|
|
40
|
+
*
|
|
41
|
+
* @returns The hook service used to register and trigger client-side hooks.
|
|
42
|
+
*/
|
|
43
|
+
get hooks() {
|
|
44
|
+
return inject(ModulesToken);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Access the current client engine instance.
|
|
48
|
+
*
|
|
49
|
+
* @returns The active {@link RpgClientEngine} instance.
|
|
50
|
+
*/
|
|
51
|
+
get engine() {
|
|
52
|
+
return inject(RpgClientEngine);
|
|
53
|
+
}
|
|
54
|
+
clearAnimationControls() {
|
|
55
|
+
if (this.animationSubscription) {
|
|
56
|
+
this.animationSubscription.unsubscribe();
|
|
57
|
+
this.animationSubscription = void 0;
|
|
58
|
+
}
|
|
59
|
+
if (this.animationResetTimeout) {
|
|
60
|
+
clearTimeout(this.animationResetTimeout);
|
|
61
|
+
this.animationResetTimeout = void 0;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
resolveAnimationWait() {
|
|
65
|
+
const resolve = this.animationWaitResolve;
|
|
66
|
+
this.animationWaitResolve = void 0;
|
|
67
|
+
resolve?.();
|
|
68
|
+
}
|
|
69
|
+
finishTemporaryAnimation() {
|
|
70
|
+
const restoreState = this.animationRestoreState;
|
|
71
|
+
this.clearAnimationControls();
|
|
72
|
+
this.animationCurrentIndex.set(0);
|
|
73
|
+
if (restoreState) {
|
|
74
|
+
this.animationName.set(restoreState.animationName);
|
|
75
|
+
this.graphics.set([...restoreState.graphics]);
|
|
76
|
+
}
|
|
77
|
+
this.animationRestoreState = void 0;
|
|
78
|
+
this.animationIsPlaying.set(false);
|
|
79
|
+
this.resolveAnimationWait();
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Trigger a flash animation on this sprite
|
|
83
|
+
*
|
|
84
|
+
* This method triggers a flash effect using CanvasEngine's flash directive.
|
|
85
|
+
* The flash can be configured with various options including type (alpha, tint, or both),
|
|
86
|
+
* duration, cycles, and color.
|
|
87
|
+
*
|
|
88
|
+
* ## Design
|
|
89
|
+
*
|
|
90
|
+
* The flash uses a trigger system that is connected to the flash directive in the
|
|
91
|
+
* character component. This allows for flexible configuration and can be triggered
|
|
92
|
+
* from both server events and client-side code.
|
|
93
|
+
*
|
|
94
|
+
* @param options - Flash configuration options
|
|
95
|
+
* @param options.type - Type of flash effect: 'alpha' (opacity), 'tint' (color), or 'both' (default: 'alpha')
|
|
96
|
+
* @param options.duration - Duration of the flash animation in milliseconds (default: 300)
|
|
97
|
+
* @param options.cycles - Number of flash cycles (flash on/off) (default: 1)
|
|
98
|
+
* @param options.alpha - Alpha value when flashing, from 0 to 1 (default: 0.3)
|
|
99
|
+
* @param options.tint - Tint color when flashing as hex value or color name (default: 0xffffff - white)
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```ts
|
|
103
|
+
* // Simple flash with default settings (alpha flash)
|
|
104
|
+
* player.flash();
|
|
105
|
+
*
|
|
106
|
+
* // Flash with red tint
|
|
107
|
+
* player.flash({ type: 'tint', tint: 0xff0000 });
|
|
108
|
+
*
|
|
109
|
+
* // Flash with both alpha and tint
|
|
110
|
+
* player.flash({
|
|
111
|
+
* type: 'both',
|
|
112
|
+
* alpha: 0.5,
|
|
113
|
+
* tint: 0xff0000,
|
|
114
|
+
* duration: 200,
|
|
115
|
+
* cycles: 2
|
|
116
|
+
* });
|
|
117
|
+
*
|
|
118
|
+
* // Quick damage flash
|
|
119
|
+
* player.flash({
|
|
120
|
+
* type: 'tint',
|
|
121
|
+
* tint: 0xff0000,
|
|
122
|
+
* duration: 150,
|
|
123
|
+
* cycles: 1
|
|
124
|
+
* });
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
127
|
+
flash(options) {
|
|
128
|
+
const flashOptions = {
|
|
129
|
+
type: options?.type || "alpha",
|
|
130
|
+
duration: options?.duration ?? 300,
|
|
131
|
+
cycles: options?.cycles ?? 1,
|
|
132
|
+
alpha: options?.alpha ?? .3,
|
|
133
|
+
tint: options?.tint ?? 16777215
|
|
134
|
+
};
|
|
135
|
+
let tintValue = flashOptions.tint;
|
|
136
|
+
if (typeof tintValue === "string") tintValue = {
|
|
137
|
+
"white": 16777215,
|
|
138
|
+
"red": 16711680,
|
|
139
|
+
"green": 65280,
|
|
140
|
+
"blue": 255,
|
|
141
|
+
"yellow": 16776960,
|
|
142
|
+
"cyan": 65535,
|
|
143
|
+
"magenta": 16711935,
|
|
144
|
+
"black": 0
|
|
145
|
+
}[tintValue.toLowerCase()] ?? 16777215;
|
|
146
|
+
this.flashTrigger.start({
|
|
147
|
+
...flashOptions,
|
|
148
|
+
tint: tintValue
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Reset animation state when animation changes externally
|
|
153
|
+
*
|
|
154
|
+
* This method should be called when the animation changes due to movement
|
|
155
|
+
* or other external factors to ensure the animation system doesn't get stuck
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* ```ts
|
|
159
|
+
* // Reset when player starts moving
|
|
160
|
+
* player.resetAnimationState();
|
|
161
|
+
* ```
|
|
162
|
+
*/
|
|
163
|
+
resetAnimationState() {
|
|
164
|
+
if (this.animationRestoreState) {
|
|
165
|
+
this.finishTemporaryAnimation();
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
this.animationIsPlaying.set(false);
|
|
169
|
+
this.animationCurrentIndex.set(0);
|
|
170
|
+
this.clearAnimationControls();
|
|
171
|
+
this.resolveAnimationWait();
|
|
172
|
+
}
|
|
173
|
+
setAnimation(animationName, graphicOrNbTimes, nbTimesOrOptions, options) {
|
|
174
|
+
let graphic;
|
|
175
|
+
let finalNbTimes = Infinity;
|
|
176
|
+
let restoreOptions = options;
|
|
177
|
+
if (typeof graphicOrNbTimes === "number") {
|
|
178
|
+
finalNbTimes = graphicOrNbTimes;
|
|
179
|
+
restoreOptions = typeof nbTimesOrOptions === "object" ? nbTimesOrOptions : options;
|
|
180
|
+
} else if (graphicOrNbTimes !== void 0) {
|
|
181
|
+
graphic = graphicOrNbTimes;
|
|
182
|
+
if (typeof nbTimesOrOptions === "number") finalNbTimes = nbTimesOrOptions;
|
|
183
|
+
else {
|
|
184
|
+
finalNbTimes = Infinity;
|
|
185
|
+
restoreOptions = nbTimesOrOptions ?? options;
|
|
186
|
+
}
|
|
187
|
+
} else finalNbTimes = Infinity;
|
|
188
|
+
if (this.animationIsPlaying()) this.finishTemporaryAnimation();
|
|
189
|
+
const waitPromise = finalNbTimes === Infinity ? Promise.resolve() : new Promise((resolve) => {
|
|
190
|
+
this.animationWaitResolve = resolve;
|
|
191
|
+
});
|
|
192
|
+
this.animationIsPlaying.set(true);
|
|
193
|
+
const previousAnimationName = restoreOptions?.restoreAnimationName ?? this.animationName();
|
|
194
|
+
const previousGraphics = restoreOptions?.restoreGraphics ? [...restoreOptions.restoreGraphics] : [...this.graphics()];
|
|
195
|
+
this.animationRestoreState = {
|
|
196
|
+
animationName: previousAnimationName,
|
|
197
|
+
graphics: previousGraphics
|
|
198
|
+
};
|
|
199
|
+
this.animationCurrentIndex.set(0);
|
|
200
|
+
if (graphic !== void 0) if (Array.isArray(graphic)) this.graphics.set(graphic);
|
|
201
|
+
else this.graphics.set([graphic]);
|
|
202
|
+
this.clearAnimationControls();
|
|
203
|
+
this.animationSubscription = this.animationCurrentIndex.observable.subscribe((index) => {
|
|
204
|
+
if (index >= finalNbTimes) this.finishTemporaryAnimation();
|
|
205
|
+
});
|
|
206
|
+
if (finalNbTimes !== Infinity) this.animationResetTimeout = setTimeout(() => {
|
|
207
|
+
if (this.animationIsPlaying()) this.finishTemporaryAnimation();
|
|
208
|
+
}, restoreOptions?.timeoutMs ?? Math.max(1e3, finalNbTimes * 1e3));
|
|
209
|
+
this.animationName.set(animationName);
|
|
210
|
+
return waitPromise;
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Display a registered component animation effect on this object.
|
|
214
|
+
*
|
|
215
|
+
* @param id - Identifier of the component animation to play.
|
|
216
|
+
* @param params - Parameters forwarded to the animation effect.
|
|
217
|
+
* @returns A promise resolved when the animation component calls `onFinish`.
|
|
218
|
+
*/
|
|
219
|
+
showComponentAnimation(id, params) {
|
|
220
|
+
return inject(RpgClientEngine).getComponentAnimation(id).displayEffect(params, this);
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Display a registered spritesheet animation effect on this object.
|
|
224
|
+
*
|
|
225
|
+
* @param graphic - Identifier of the spritesheet to use.
|
|
226
|
+
* @param animationName - Name of the animation inside the spritesheet.
|
|
227
|
+
* @returns A promise resolved when the animation component calls `onFinish`.
|
|
228
|
+
*/
|
|
229
|
+
showAnimation(graphic, animationName = "default") {
|
|
230
|
+
return this.showComponentAnimation("animation", {
|
|
231
|
+
graphic,
|
|
232
|
+
animationName
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Check whether this client object represents an event.
|
|
237
|
+
*
|
|
238
|
+
* @returns `true` if the object type is `event`, otherwise `false`.
|
|
239
|
+
*/
|
|
240
|
+
isEvent() {
|
|
241
|
+
return this._type === "event";
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Check whether this client object represents a player.
|
|
245
|
+
*
|
|
246
|
+
* @returns `true` if the object type is `player`, otherwise `false`.
|
|
247
|
+
*/
|
|
248
|
+
isPlayer() {
|
|
249
|
+
return this._type === "player";
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
//#endregion
|
|
253
|
+
export { RpgClientObject };
|
|
254
|
+
|
|
255
|
+
//# sourceMappingURL=Object.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Object.js","names":[],"sources":["../../src/Game/Object.ts"],"sourcesContent":["import { Hooks, ModulesToken, RpgCommonPlayer } from \"@rpgjs/common\";\nimport { trigger, signal, type Trigger } from \"canvasengine\";\nimport { from, map, of, Subscription, switchMap } from \"rxjs\";\nimport { inject } from \"../core/inject\";\nimport { RpgClientEngine } from \"../RpgClientEngine\";\ntype Frame = { x: number; y: number; ts: number };\n\ntype AnimationRestoreOptions = {\n restoreAnimationName?: string;\n restoreGraphics?: any[];\n timeoutMs?: number;\n};\n\ntype FlashType = 'alpha' | 'tint' | 'both';\n\ntype FlashOptions = {\n type?: FlashType;\n duration?: number;\n cycles?: number;\n alpha?: number;\n tint?: number | string;\n};\n\ntype FlashTriggerOptions = Omit<FlashOptions, \"tint\"> & {\n tint: number;\n};\n\ntype ConfigurableTrigger<T> = Omit<Trigger<T>, \"start\"> & {\n start(config?: T): Promise<void>;\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: Frame[] = [];\n graphicsSignals = signal<any[]>([]);\n flashTrigger: ConfigurableTrigger<FlashTriggerOptions> = trigger<FlashTriggerOptions>();\n private animationRestoreState?: {\n animationName: string;\n graphics: any[];\n };\n\n constructor() {\n super();\n this.hooks.callHooks(\"client-sprite-onInit\", this).subscribe();\n\n this._frames.observable.subscribe(({ items }) => {\n if (!this.id) return;\n //if (this.id == this.engine.playerIdSignal()!) return;\n const nextFrames = items.flatMap((item): Frame[] =>\n Array.isArray(item) ? item : [item]\n );\n this.frames = [...this.frames, ...nextFrames];\n });\n\n this.graphics.observable\n .pipe(\n map(({ items }) => items),\n switchMap(graphics => {\n if (graphics.length === 0) return of([]);\n return from(Promise.all(graphics.map(graphic => this.engine.getSpriteSheet(graphic))));\n })\n )\n .subscribe((sheets) => { \n this.graphicsSignals.set(sheets);\n });\n\n this.engine.tick\n .pipe\n //throttleTime(10)\n ()\n .subscribe(() => {\n const frame = this.frames.shift();\n if (frame) {\n if (typeof frame.x !== \"number\" || typeof frame.y !== \"number\") return;\n this.engine.scene.setBodyPosition(\n this.id,\n frame.x,\n frame.y,\n \"top-left\"\n );\n }\n });\n }\n\n /**\n * Access the shared client hook registry.\n *\n * @returns The hook service used to register and trigger client-side hooks.\n */\n get hooks() {\n return inject<Hooks>(ModulesToken);\n }\n\n /**\n * Access the current client engine instance.\n *\n * @returns The active {@link RpgClientEngine} instance.\n */\n get engine() {\n return inject(RpgClientEngine);\n }\n\n private animationSubscription?: Subscription;\n private animationResetTimeout?: ReturnType<typeof setTimeout>;\n private animationWaitResolve?: () => void;\n\n private clearAnimationControls() {\n if (this.animationSubscription) {\n this.animationSubscription.unsubscribe();\n this.animationSubscription = undefined;\n }\n if (this.animationResetTimeout) {\n clearTimeout(this.animationResetTimeout);\n this.animationResetTimeout = undefined;\n }\n }\n\n private resolveAnimationWait() {\n const resolve = this.animationWaitResolve;\n this.animationWaitResolve = undefined;\n resolve?.();\n }\n\n private finishTemporaryAnimation() {\n const restoreState = this.animationRestoreState;\n this.clearAnimationControls();\n this.animationCurrentIndex.set(0);\n if (restoreState) {\n this.animationName.set(restoreState.animationName);\n this.graphics.set([...restoreState.graphics]);\n }\n this.animationRestoreState = undefined;\n this.animationIsPlaying.set(false);\n this.resolveAnimationWait();\n }\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?: FlashOptions): 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 if (this.animationRestoreState) {\n this.finishTemporaryAnimation();\n return;\n }\n this.animationIsPlaying.set(false);\n this.animationCurrentIndex.set(0);\n this.clearAnimationControls();\n this.resolveAnimationWait();\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 * @param options - Restore and timeout options\n * @returns A promise resolved when a finite animation finishes, is interrupted, or times out\n *\n * @example\n * ```ts\n * // Play attack animation 3 times\n * await player.setAnimation('attack', 3);\n *\n * // Play continuous spell animation\n * player.setAnimation('spell');\n * ```\n */\n setAnimation(animationName: string, nbTimes?: number, options?: AnimationRestoreOptions): Promise<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 * @param options - Restore and timeout options\n * @returns A promise resolved when a finite animation finishes, is interrupted, or times out\n *\n * @example\n * ```ts\n * // Play attack animation with temporary graphic change\n * await player.setAnimation('attack', 'hero_attack', 3);\n * ```\n */\n setAnimation(animationName: string, graphic?: string | string[], nbTimes?: number, options?: AnimationRestoreOptions): Promise<void>;\n setAnimation(\n animationName: string,\n graphicOrNbTimes?: string | string[] | number,\n nbTimesOrOptions?: number | AnimationRestoreOptions,\n options?: AnimationRestoreOptions\n ): Promise<void> {\n let graphic: string | string[] | undefined;\n let finalNbTimes: number = Infinity;\n let restoreOptions: AnimationRestoreOptions | undefined = options;\n\n // Handle overloads\n if (typeof graphicOrNbTimes === 'number') {\n // setAnimation(animationName, nbTimes)\n finalNbTimes = graphicOrNbTimes;\n restoreOptions = typeof nbTimesOrOptions === 'object' ? nbTimesOrOptions : options;\n } else if (graphicOrNbTimes !== undefined) {\n // setAnimation(animationName, graphic, nbTimes)\n graphic = graphicOrNbTimes;\n if (typeof nbTimesOrOptions === 'number') {\n finalNbTimes = nbTimesOrOptions;\n } else {\n finalNbTimes = Infinity;\n restoreOptions = nbTimesOrOptions ?? options;\n }\n } else {\n // setAnimation(animationName) - nbTimes remains Infinity\n finalNbTimes = Infinity;\n }\n\n if (this.animationIsPlaying()) {\n this.finishTemporaryAnimation();\n }\n\n const waitPromise =\n finalNbTimes === Infinity\n ? Promise.resolve()\n : new Promise<void>((resolve) => {\n this.animationWaitResolve = resolve;\n });\n\n this.animationIsPlaying.set(true);\n const previousAnimationName =\n restoreOptions?.restoreAnimationName ?? this.animationName();\n const previousGraphics = restoreOptions?.restoreGraphics\n ? [...restoreOptions.restoreGraphics]\n : [...this.graphics()];\n this.animationRestoreState = {\n animationName: previousAnimationName,\n graphics: previousGraphics,\n };\n this.animationCurrentIndex.set(0);\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 this.clearAnimationControls();\n\n this.animationSubscription =\n this.animationCurrentIndex.observable.subscribe((index) => {\n if (index >= finalNbTimes) {\n this.finishTemporaryAnimation();\n }\n });\n\n if (finalNbTimes !== Infinity) {\n this.animationResetTimeout = setTimeout(() => {\n if (this.animationIsPlaying()) {\n this.finishTemporaryAnimation();\n }\n }, restoreOptions?.timeoutMs ?? Math.max(1000, finalNbTimes * 1000));\n }\n\n this.animationName.set(animationName);\n\n return waitPromise;\n }\n\n /**\n * Display a registered component animation effect on this object.\n *\n * @param id - Identifier of the component animation to play.\n * @param params - Parameters forwarded to the animation effect.\n * @returns A promise resolved when the animation component calls `onFinish`.\n */\n showComponentAnimation(id: string, params: any): Promise<void> {\n const engine = inject(RpgClientEngine);\n return engine.getComponentAnimation(id).displayEffect(params, this);\n }\n\n /**\n * Display a registered spritesheet animation effect on this object.\n *\n * @param graphic - Identifier of the spritesheet to use.\n * @param animationName - Name of the animation inside the spritesheet.\n * @returns A promise resolved when the animation component calls `onFinish`.\n */\n showAnimation(graphic: string, animationName: string = 'default'): Promise<void> {\n return this.showComponentAnimation('animation', {\n graphic,\n animationName,\n });\n }\n \n /**\n * Check whether this client object represents an event.\n *\n * @returns `true` if the object type is `event`, otherwise `false`.\n */\n isEvent(): boolean {\n return this._type === 'event';\n }\n\n /**\n * Check whether this client object represents a player.\n *\n * @returns `true` if the object type is `player`, otherwise `false`.\n */\n isPlayer(): boolean {\n return this._type === 'player';\n }\n}\n"],"mappings":"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"}
|
package/dist/Game/Player.d.ts
CHANGED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { RpgClientObject } from "./Object.js";
|
|
2
|
+
//#region src/Game/Player.ts
|
|
3
|
+
var RpgClientPlayer = class extends RpgClientObject {
|
|
4
|
+
constructor(..._args) {
|
|
5
|
+
super(..._args);
|
|
6
|
+
this._type = "player";
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
//#endregion
|
|
10
|
+
export { RpgClientPlayer };
|
|
11
|
+
|
|
12
|
+
//# sourceMappingURL=Player.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Player.js","names":[],"sources":["../../src/Game/Player.ts"],"sourcesContent":["import { RpgClientObject } from \"./Object\";\n\nexport class RpgClientPlayer extends RpgClientObject {\n _type = 'player'\n} "],"mappings":";;AAEA,IAAa,kBAAb,cAAqC,gBAAgB;;;eACzC;;AACZ"}
|
package/dist/Gui/Gui.d.ts
CHANGED
|
@@ -1,23 +1,208 @@
|
|
|
1
1
|
import { Context } from '@signe/di';
|
|
2
|
+
import { Signal, WritableSignal } from 'canvasengine';
|
|
3
|
+
import { Subscription } from 'rxjs';
|
|
2
4
|
interface GuiOptions {
|
|
3
|
-
name
|
|
4
|
-
|
|
5
|
+
name?: string;
|
|
6
|
+
id?: string;
|
|
7
|
+
component?: any;
|
|
5
8
|
display?: boolean;
|
|
6
9
|
data?: any;
|
|
10
|
+
/**
|
|
11
|
+
* Auto display the GUI when added to the system
|
|
12
|
+
* @default false
|
|
13
|
+
*/
|
|
14
|
+
autoDisplay?: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Function that returns an array of Signal dependencies
|
|
17
|
+
* The GUI will only display when all dependencies are resolved (!= undefined)
|
|
18
|
+
* @returns Array of Signal dependencies
|
|
19
|
+
*/
|
|
20
|
+
dependencies?: () => Signal[];
|
|
21
|
+
/**
|
|
22
|
+
* Attach the GUI to sprites instead of displaying globally
|
|
23
|
+
* When true, the GUI will be rendered in character.ce for each sprite
|
|
24
|
+
* @default false
|
|
25
|
+
*/
|
|
26
|
+
attachToSprite?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Vue v4 compatibility flag. Prefer attachToSprite in v5 projects.
|
|
29
|
+
*/
|
|
30
|
+
rpgAttachToSprite?: boolean;
|
|
31
|
+
}
|
|
32
|
+
export interface GuiInstance {
|
|
33
|
+
name: string;
|
|
34
|
+
component: any;
|
|
35
|
+
display: WritableSignal<boolean>;
|
|
36
|
+
data: WritableSignal<any>;
|
|
37
|
+
autoDisplay: boolean;
|
|
38
|
+
dependencies?: Signal[];
|
|
39
|
+
subscription?: Subscription;
|
|
40
|
+
attachToSprite?: boolean;
|
|
41
|
+
}
|
|
42
|
+
interface GuiAction {
|
|
43
|
+
guiId: string;
|
|
44
|
+
name: string;
|
|
45
|
+
data: any;
|
|
46
|
+
clientActionId: string;
|
|
7
47
|
}
|
|
48
|
+
type OptimisticReducer = (data: any, action: GuiAction) => any;
|
|
8
49
|
export declare class RpgGui {
|
|
9
50
|
private context;
|
|
10
51
|
private webSocket;
|
|
11
|
-
gui: import('canvasengine').
|
|
52
|
+
gui: import('canvasengine').WritableObjectSignal<Record<string, GuiInstance>>;
|
|
53
|
+
extraGuis: GuiInstance[];
|
|
54
|
+
private vueGuiInstance;
|
|
55
|
+
private optimisticReducers;
|
|
56
|
+
private pendingActions;
|
|
57
|
+
/**
|
|
58
|
+
* Signal tracking which player IDs should display attached GUIs
|
|
59
|
+
* Key: player ID, Value: boolean (true = show, false = hide)
|
|
60
|
+
*/
|
|
61
|
+
attachedGuiDisplayState: import('canvasengine').WritableObjectSignal<Record<string, boolean>>;
|
|
12
62
|
constructor(context: Context);
|
|
13
63
|
_initialize(): Promise<void>;
|
|
64
|
+
/**
|
|
65
|
+
* Set the VueGui instance reference for Vue component management
|
|
66
|
+
* This is called by VueGui when it's initialized
|
|
67
|
+
*
|
|
68
|
+
* @param vueGuiInstance - The VueGui instance
|
|
69
|
+
*/
|
|
70
|
+
_setVueGuiInstance(vueGuiInstance: any): void;
|
|
71
|
+
/**
|
|
72
|
+
* Notify VueGui about GUI state changes
|
|
73
|
+
* This synchronizes the Vue component display state
|
|
74
|
+
*
|
|
75
|
+
* @param guiId - The GUI component ID
|
|
76
|
+
* @param display - Display state
|
|
77
|
+
* @param data - Component data
|
|
78
|
+
*/
|
|
79
|
+
private _notifyVueGui;
|
|
80
|
+
/**
|
|
81
|
+
* Initialize Vue components in the VueGui instance
|
|
82
|
+
* This should be called after VueGui is mounted
|
|
83
|
+
*/
|
|
84
|
+
_initializeVueComponents(): void;
|
|
14
85
|
guiInteraction(guiId: string, name: string, data: any): void;
|
|
15
86
|
guiClose(guiId: string, data?: any): void;
|
|
16
|
-
|
|
17
|
-
|
|
87
|
+
/**
|
|
88
|
+
* Add a GUI component to the system
|
|
89
|
+
*
|
|
90
|
+
* By default, only CanvasEngine components (.ce files) are accepted.
|
|
91
|
+
* Vue components should be handled by the @rpgjs/vue package.
|
|
92
|
+
*
|
|
93
|
+
* @param gui - GUI configuration options
|
|
94
|
+
* @param gui.name - Name or ID of the GUI component
|
|
95
|
+
* @param gui.id - Alternative ID if name is not provided
|
|
96
|
+
* @param gui.component - The component to render (must be a CanvasEngine component)
|
|
97
|
+
* @param gui.display - Initial display state (default: false)
|
|
98
|
+
* @param gui.data - Initial data for the component
|
|
99
|
+
* @param gui.autoDisplay - Auto display when added (default: false)
|
|
100
|
+
* @param gui.dependencies - Function returning Signal dependencies
|
|
101
|
+
* @param gui.attachToSprite - Attach GUI to sprites instead of global display (default: false)
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```ts
|
|
105
|
+
* gui.add({
|
|
106
|
+
* name: 'inventory',
|
|
107
|
+
* component: InventoryComponent, // Must be a .ce component
|
|
108
|
+
* autoDisplay: true,
|
|
109
|
+
* dependencies: () => [playerSignal, inventorySignal]
|
|
110
|
+
* });
|
|
111
|
+
*
|
|
112
|
+
* // Attach to sprites
|
|
113
|
+
* gui.add({
|
|
114
|
+
* name: 'tooltip',
|
|
115
|
+
* component: TooltipComponent,
|
|
116
|
+
* attachToSprite: true
|
|
117
|
+
* });
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
120
|
+
add(gui: GuiOptions | any): void;
|
|
121
|
+
registerOptimisticReducer(guiId: string, reducer: OptimisticReducer): void;
|
|
122
|
+
/**
|
|
123
|
+
* Get all attached GUI components (attachToSprite: true)
|
|
124
|
+
*
|
|
125
|
+
* Returns all GUI instances that are configured to be attached to sprites.
|
|
126
|
+
* These GUIs should be rendered in character.ce instead of canvas.ce.
|
|
127
|
+
*
|
|
128
|
+
* @returns Array of GUI instances with attachToSprite: true
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* ```ts
|
|
132
|
+
* const attachedGuis = gui.getAttachedGuis();
|
|
133
|
+
* // Use in character.ce to render tooltips
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
136
|
+
getAttachedGuis(): GuiInstance[];
|
|
137
|
+
getVueGuis(): GuiInstance[];
|
|
138
|
+
getAttachedVueGuis(): GuiInstance[];
|
|
139
|
+
/**
|
|
140
|
+
* Check if a player should display attached GUIs
|
|
141
|
+
*
|
|
142
|
+
* @param playerId - The player ID to check
|
|
143
|
+
* @returns true if attached GUIs should be displayed for this player
|
|
144
|
+
*/
|
|
145
|
+
shouldDisplayAttachedGui(playerId: string): boolean;
|
|
146
|
+
get(id: string): GuiInstance | undefined;
|
|
18
147
|
exists(id: string): boolean;
|
|
19
|
-
getAll():
|
|
20
|
-
|
|
148
|
+
getAll(): Record<string, GuiInstance>;
|
|
149
|
+
/**
|
|
150
|
+
* Display a GUI component
|
|
151
|
+
*
|
|
152
|
+
* Displays the GUI immediately if no dependencies are configured,
|
|
153
|
+
* or waits for all dependencies to be resolved if dependencies are present.
|
|
154
|
+
* Automatically manages subscriptions to prevent memory leaks.
|
|
155
|
+
* Works with both CanvasEngine components and Vue components.
|
|
156
|
+
*
|
|
157
|
+
* @param id - The GUI component ID
|
|
158
|
+
* @param data - Data to pass to the component
|
|
159
|
+
* @param dependencies - Optional runtime dependencies (overrides config dependencies)
|
|
160
|
+
*
|
|
161
|
+
* @example
|
|
162
|
+
* ```ts
|
|
163
|
+
* // Display immediately
|
|
164
|
+
* gui.display('inventory', { items: [] });
|
|
165
|
+
*
|
|
166
|
+
* // Display with runtime dependencies
|
|
167
|
+
* gui.display('shop', { shopId: 1 }, [playerSignal, shopSignal]);
|
|
168
|
+
* ```
|
|
169
|
+
*/
|
|
170
|
+
display(id: string, data?: {}, dependencies?: Signal[]): void;
|
|
171
|
+
isDisplaying(id: string): boolean;
|
|
172
|
+
/**
|
|
173
|
+
* Handle Vue component display logic
|
|
174
|
+
*
|
|
175
|
+
* @param id - GUI component ID
|
|
176
|
+
* @param data - Component data
|
|
177
|
+
* @param dependencies - Runtime dependencies
|
|
178
|
+
* @param guiInstance - GUI instance
|
|
179
|
+
*/
|
|
180
|
+
private _handleVueComponentDisplay;
|
|
181
|
+
/**
|
|
182
|
+
* Hide a GUI component
|
|
183
|
+
*
|
|
184
|
+
* Hides the GUI and cleans up any active subscriptions.
|
|
185
|
+
* Works with both CanvasEngine components and Vue components.
|
|
186
|
+
*
|
|
187
|
+
* @param id - The GUI component ID
|
|
188
|
+
*
|
|
189
|
+
* @example
|
|
190
|
+
* ```ts
|
|
191
|
+
* gui.hide('inventory');
|
|
192
|
+
* ```
|
|
193
|
+
*/
|
|
21
194
|
hide(id: string): void;
|
|
195
|
+
private isVueComponent;
|
|
196
|
+
private isVueComponentInstance;
|
|
197
|
+
private removeCanvasGui;
|
|
198
|
+
private removeVueGui;
|
|
199
|
+
private resolveComponent;
|
|
200
|
+
private resolveGuiId;
|
|
201
|
+
private resolveAttachToSprite;
|
|
202
|
+
private toGuiState;
|
|
203
|
+
private clearPendingActions;
|
|
204
|
+
private applyReducers;
|
|
205
|
+
private applyOptimisticAction;
|
|
206
|
+
private applyServerUpdate;
|
|
22
207
|
}
|
|
23
208
|
export {};
|