@rpgjs/client 5.0.0-beta.7 → 5.0.0-beta.9
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 +27 -0
- package/dist/Game/AnimationManager.js.map +1 -1
- package/dist/Game/Event.js.map +1 -1
- package/dist/Game/Map.d.ts +9 -1
- package/dist/Game/Map.js +63 -5
- package/dist/Game/Map.js.map +1 -1
- package/dist/Game/Object.d.ts +17 -9
- package/dist/Game/Object.js +1 -12
- package/dist/Game/Object.js.map +1 -1
- package/dist/Game/Player.js.map +1 -1
- package/dist/Gui/Gui.d.ts +17 -4
- package/dist/Gui/Gui.js +64 -34
- package/dist/Gui/Gui.js.map +1 -1
- package/dist/Gui/Gui.spec.d.ts +1 -0
- package/dist/Gui/NotificationManager.js.map +1 -1
- package/dist/Resource.js +1 -1
- package/dist/Resource.js.map +1 -1
- package/dist/RpgClient.d.ts +35 -2
- package/dist/RpgClientEngine.d.ts +41 -5
- package/dist/RpgClientEngine.js +50 -5
- package/dist/RpgClientEngine.js.map +1 -1
- package/dist/Sound.js.map +1 -1
- package/dist/_virtual/{_@oxc-project_runtime@0.128.0 → _@oxc-project_runtime@0.130.0}/helpers/decorate.js +1 -1
- package/dist/_virtual/{_@oxc-project_runtime@0.128.0 → _@oxc-project_runtime@0.130.0}/helpers/decorateMetadata.js +1 -1
- package/dist/components/animations/animation.ce.js.map +1 -1
- package/dist/components/animations/hit.ce.js.map +1 -1
- package/dist/components/animations/index.js.map +1 -1
- package/dist/components/character.ce.js +259 -5
- package/dist/components/character.ce.js.map +1 -1
- 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 +3 -0
- package/dist/components/dynamics/parse-value.js +51 -35
- package/dist/components/dynamics/parse-value.js.map +1 -1
- 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 +28 -41
- package/dist/components/dynamics/text.ce.js.map +1 -1
- package/dist/components/gui/box.ce.js.map +1 -1
- package/dist/components/gui/dialogbox/index.ce.js +3 -3
- package/dist/components/gui/dialogbox/index.ce.js.map +1 -1
- package/dist/components/gui/gameover.ce.js +1 -1
- package/dist/components/gui/gameover.ce.js.map +1 -1
- package/dist/components/gui/hud/hud.ce.js +1 -1
- package/dist/components/gui/hud/hud.ce.js.map +1 -1
- package/dist/components/gui/menu/equip-menu.ce.js.map +1 -1
- package/dist/components/gui/menu/exit-menu.ce.js.map +1 -1
- package/dist/components/gui/menu/items-menu.ce.js.map +1 -1
- package/dist/components/gui/menu/main-menu.ce.js.map +1 -1
- package/dist/components/gui/menu/options-menu.ce.js.map +1 -1
- package/dist/components/gui/menu/skills-menu.ce.js.map +1 -1
- package/dist/components/gui/mobile/index.js.map +1 -1
- package/dist/components/gui/mobile/mobile.ce.js.map +1 -1
- package/dist/components/gui/notification/notification.ce.js.map +1 -1
- package/dist/components/gui/save-load.ce.js.map +1 -1
- package/dist/components/gui/shop/shop.ce.js +1 -1
- package/dist/components/gui/shop/shop.ce.js.map +1 -1
- package/dist/components/gui/title-screen.ce.js +2 -2
- package/dist/components/gui/title-screen.ce.js.map +1 -1
- 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.map +1 -1
- package/dist/components/prebuilt/light-halo.ce.js.map +1 -1
- package/dist/components/scenes/canvas.ce.js +147 -4
- package/dist/components/scenes/canvas.ce.js.map +1 -1
- package/dist/components/scenes/draw-map.ce.js +2 -8
- package/dist/components/scenes/draw-map.ce.js.map +1 -1
- package/dist/components/scenes/event-layer.ce.js.map +1 -1
- package/dist/core/inject.js +1 -1
- package/dist/core/inject.js.map +1 -1
- package/dist/core/setup.js +1 -1
- package/dist/core/setup.js.map +1 -1
- 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 +1 -0
- package/dist/index.js +3 -2
- package/dist/module.js +4 -1
- package/dist/module.js.map +1 -1
- package/dist/node_modules/.pnpm/{@signe_di@2.10.0 → @signe_di@3.0.1}/node_modules/@signe/di/dist/index.js +1 -1
- 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@2.9.2 → @signe_reactive@3.0.1}/node_modules/@signe/reactive/dist/index.js +15 -3
- 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@2.10.0 → @signe_room@3.0.1}/node_modules/@signe/room/dist/index.js +124 -39
- 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@2.10.0 → @signe_sync@3.0.1}/node_modules/@signe/sync/dist/client/index.js +1 -1
- 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@2.10.0 → @signe_sync@3.0.1}/node_modules/@signe/sync/dist/index.js +36 -13
- 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.map +1 -1
- package/dist/node_modules/.pnpm/partysocket@1.1.3/node_modules/partysocket/dist/chunk-S74YV6PU.js.map +1 -1
- package/dist/node_modules/.pnpm/zod@3.24.2/node_modules/zod/lib/index.js.map +1 -1
- package/dist/presets/animation.js.map +1 -1
- package/dist/presets/faceset.js.map +1 -1
- package/dist/presets/icon.js.map +1 -1
- package/dist/presets/index.js.map +1 -1
- package/dist/presets/lpc.js.map +1 -1
- package/dist/presets/rmspritesheet.js.map +1 -1
- package/dist/services/AbstractSocket.js.map +1 -1
- package/dist/services/keyboardControls.js.map +1 -1
- package/dist/services/loadMap.d.ts +6 -0
- package/dist/services/loadMap.js +1 -1
- package/dist/services/loadMap.js.map +1 -1
- package/dist/services/mmorpg.js +7 -3
- package/dist/services/mmorpg.js.map +1 -1
- package/dist/services/save.js.map +1 -1
- package/dist/services/standalone.js +1 -1
- package/dist/services/standalone.js.map +1 -1
- package/dist/utils/getEntityProp.js.map +1 -1
- package/package.json +10 -10
- package/src/Game/Map.ts +91 -2
- package/src/Game/Object.ts +22 -35
- package/src/Gui/Gui.spec.ts +273 -0
- package/src/Gui/Gui.ts +105 -50
- package/src/Resource.ts +1 -2
- package/src/RpgClient.ts +36 -2
- package/src/RpgClientEngine.ts +74 -11
- package/src/components/character.ce +318 -9
- package/src/components/dynamics/bar.ce +87 -0
- package/src/components/dynamics/image.ce +20 -0
- package/src/components/dynamics/parse-value.spec.ts +41 -0
- package/src/components/dynamics/parse-value.ts +102 -37
- 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 +34 -149
- 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/scenes/canvas.ce +165 -6
- package/src/components/scenes/draw-map.ce +2 -15
- package/src/components/scenes/event-layer.ce +1 -2
- package/src/core/setup.ts +2 -2
- package/src/decorators/spritesheet.ts +8 -0
- package/src/index.ts +1 -0
- package/src/module.ts +5 -1
- package/src/services/loadMap.ts +2 -0
- package/src/services/mmorpg.ts +8 -2
- package/dist/node_modules/.pnpm/@signe_di@2.10.0/node_modules/@signe/di/dist/index.js.map +0 -1
- package/dist/node_modules/.pnpm/@signe_reactive@2.10.0/node_modules/@signe/reactive/dist/index.js +0 -45
- package/dist/node_modules/.pnpm/@signe_reactive@2.10.0/node_modules/@signe/reactive/dist/index.js.map +0 -1
- package/dist/node_modules/.pnpm/@signe_reactive@2.9.2/node_modules/@signe/reactive/dist/index.js.map +0 -1
- package/dist/node_modules/.pnpm/@signe_room@2.10.0/node_modules/@signe/room/dist/index.js.map +0 -1
- package/dist/node_modules/.pnpm/@signe_sync@2.10.0/node_modules/@signe/sync/dist/client/index.js.map +0 -1
- package/dist/node_modules/.pnpm/@signe_sync@2.10.0/node_modules/@signe/sync/dist/index.js.map +0 -1
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# @rpgjs/client
|
|
2
|
+
|
|
3
|
+
## 5.0.0-beta.9
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- c456d25: beta.9
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [c456d25]
|
|
12
|
+
- @rpgjs/common@5.0.0-beta.9
|
|
13
|
+
- @rpgjs/server@5.0.0-beta.9
|
|
14
|
+
- @rpgjs/ui-css@5.0.0-beta.9
|
|
15
|
+
|
|
16
|
+
## 5.0.0-beta.8
|
|
17
|
+
|
|
18
|
+
### Major Changes
|
|
19
|
+
|
|
20
|
+
- 35e7fa4: beta.8
|
|
21
|
+
|
|
22
|
+
### Patch Changes
|
|
23
|
+
|
|
24
|
+
- Updated dependencies [35e7fa4]
|
|
25
|
+
- @rpgjs/common@5.0.0-beta.8
|
|
26
|
+
- @rpgjs/server@5.0.0-beta.8
|
|
27
|
+
- @rpgjs/ui-css@5.0.0-beta.8
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AnimationManager.js","names":[],"sources":["../../src/Game/AnimationManager.ts"],"sourcesContent":["import { generateUID, RpgCommonPlayer } from \"@rpgjs/common\";\nimport { signal } from \"canvasengine\";\n\nexport class AnimationManager {\n current = signal<any[]>([]);\n\n displayEffect(params: any, player: RpgCommonPlayer | { x: number, y: number }): Promise<void> {\n const id = generateUID();\n const effectParams = params ?? {};\n return new Promise<void>((resolve) => {\n let finished = false;\n const finish = (data?: any) => {\n if (finished) return;\n finished = true;\n const index = this.current().findIndex((value) => value.id === id);\n if (index !== -1) {\n this.current().splice(index, 1);\n }\n effectParams.onFinish?.(data);\n resolve();\n };\n\n this.current().push({\n ...effectParams,\n id,\n x: player.x,\n y: player.y,\n object: player,\n onFinish: finish,\n });\n });\n }\n}\n"],"mappings":";;;AAGA,IAAa,mBAAb,MAA8B;;iBAClB,OAAc,
|
|
1
|
+
{"version":3,"file":"AnimationManager.js","names":[],"sources":["../../src/Game/AnimationManager.ts"],"sourcesContent":["import { generateUID, RpgCommonPlayer } from \"@rpgjs/common\";\nimport { signal } from \"canvasengine\";\n\nexport class AnimationManager {\n current = signal<any[]>([]);\n\n displayEffect(params: any, player: RpgCommonPlayer | { x: number, y: number }): Promise<void> {\n const id = generateUID();\n const effectParams = params ?? {};\n return new Promise<void>((resolve) => {\n let finished = false;\n const finish = (data?: any) => {\n if (finished) return;\n finished = true;\n const index = this.current().findIndex((value) => value.id === id);\n if (index !== -1) {\n this.current().splice(index, 1);\n }\n effectParams.onFinish?.(data);\n resolve();\n };\n\n this.current().push({\n ...effectParams,\n id,\n x: player.x,\n y: player.y,\n object: player,\n onFinish: finish,\n });\n });\n }\n}\n"],"mappings":";;;AAGA,IAAa,mBAAb,MAA8B;;iBAClB,OAAc,CAAC,CAAC;;CAE1B,cAAc,QAAa,QAAmE;EAC5F,MAAM,KAAK,YAAY;EACvB,MAAM,eAAe,UAAU,CAAC;EAChC,OAAO,IAAI,SAAe,YAAY;GACpC,IAAI,WAAW;GACf,MAAM,UAAU,SAAe;IAC7B,IAAI,UAAU;IACd,WAAW;IACX,MAAM,QAAQ,KAAK,QAAQ,EAAE,WAAW,UAAU,MAAM,OAAO,EAAE;IACjE,IAAI,UAAU,IACZ,KAAK,QAAQ,EAAE,OAAO,OAAO,CAAC;IAEhC,aAAa,WAAW,IAAI;IAC5B,QAAQ;GACV;GAEA,KAAK,QAAQ,EAAE,KAAK;IAClB,GAAG;IACH;IACA,GAAG,OAAO;IACV,GAAG,OAAO;IACV,QAAQ;IACR,UAAU;GACZ,CAAC;EACH,CAAC;CACH;AACF"}
|
package/dist/Game/Event.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Event.js","names":[],"sources":["../../src/Game/Event.ts"],"sourcesContent":["import { RpgClientObject } from \"./Object\"; \n\nexport class RpgClientEvent extends RpgClientObject {\n _type = 'event'\n} "],"mappings":";;AAEA,IAAa,iBAAb,cAAoC,gBAAgB;;;eACxC"}
|
|
1
|
+
{"version":3,"file":"Event.js","names":[],"sources":["../../src/Game/Event.ts"],"sourcesContent":["import { RpgClientObject } from \"./Object\"; \n\nexport class RpgClientEvent extends RpgClientObject {\n _type = 'event'\n} "],"mappings":";;AAEA,IAAa,iBAAb,cAAoC,gBAAgB;;;eACxC;;AACZ"}
|
package/dist/Game/Map.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RpgCommonMap, WeatherState, MapPhysicsInitContext, MapPhysicsEntityContext } from '@rpgjs/common';
|
|
1
|
+
import { RpgCommonMap, LightSpot, LightingState, WeatherState, MapPhysicsInitContext, MapPhysicsEntityContext } from '@rpgjs/common';
|
|
2
2
|
import { RpgClientEngine } from '../RpgClientEngine';
|
|
3
3
|
export declare class RpgClientMap extends RpgCommonMap<any> {
|
|
4
4
|
engine: RpgClientEngine;
|
|
@@ -7,7 +7,10 @@ export declare class RpgClientMap extends RpgCommonMap<any> {
|
|
|
7
7
|
currentPlayer: any;
|
|
8
8
|
weatherState: any;
|
|
9
9
|
localWeatherOverride: any;
|
|
10
|
+
lightingState: any;
|
|
11
|
+
localLightSpots: any;
|
|
10
12
|
weather: any;
|
|
13
|
+
lighting: any;
|
|
11
14
|
private manualClientPhysicsTick;
|
|
12
15
|
private readonly isTestEnvironment;
|
|
13
16
|
constructor();
|
|
@@ -17,6 +20,11 @@ export declare class RpgClientMap extends RpgCommonMap<any> {
|
|
|
17
20
|
getWeather(): WeatherState | null;
|
|
18
21
|
setLocalWeather(next: WeatherState | null): void;
|
|
19
22
|
clearLocalWeather(): void;
|
|
23
|
+
getLighting(): LightingState | null;
|
|
24
|
+
addLightSpot(id: string, spot: LightSpot): void;
|
|
25
|
+
patchLightSpot(id: string, patch: Partial<LightSpot>): void;
|
|
26
|
+
removeLightSpot(id: string): void;
|
|
27
|
+
clearLightSpots(): void;
|
|
20
28
|
stepClientPhysics(deltaMs: number): number;
|
|
21
29
|
stepPredictionTick(): void;
|
|
22
30
|
protected emitPhysicsInit(context: MapPhysicsInitContext): void;
|
package/dist/Game/Map.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { inject } from "../core/inject.js";
|
|
2
|
-
import { sync, users } from "../node_modules/.pnpm/@signe_sync@
|
|
2
|
+
import { sync, users } from "../node_modules/.pnpm/@signe_sync@3.0.1/node_modules/@signe/sync/dist/index.js";
|
|
3
3
|
import { RpgClientPlayer } from "./Player.js";
|
|
4
4
|
import { RpgClientEvent } from "./Event.js";
|
|
5
|
-
import { __decorateMetadata } from "../_virtual/_@oxc-project_runtime@0.
|
|
6
|
-
import { __decorate } from "../_virtual/_@oxc-project_runtime@0.
|
|
5
|
+
import { __decorateMetadata } from "../_virtual/_@oxc-project_runtime@0.130.0/helpers/decorateMetadata.js";
|
|
6
|
+
import { __decorate } from "../_virtual/_@oxc-project_runtime@0.130.0/helpers/decorate.js";
|
|
7
7
|
import { RpgClientEngine } from "../RpgClientEngine.js";
|
|
8
8
|
import { computed, signal } from "canvasengine";
|
|
9
|
-
import { RpgCommonMap } from "@rpgjs/common";
|
|
9
|
+
import { RpgCommonMap, cloneLightingState, normalizeLightingState } from "@rpgjs/common";
|
|
10
10
|
//#region src/Game/Map.ts
|
|
11
11
|
var RpgClientMap = class extends RpgCommonMap {
|
|
12
12
|
constructor() {
|
|
@@ -17,13 +17,28 @@ var RpgClientMap = class extends RpgCommonMap {
|
|
|
17
17
|
this.currentPlayer = computed(() => this.players()[this.engine.playerIdSignal()]);
|
|
18
18
|
this.weatherState = signal(null);
|
|
19
19
|
this.localWeatherOverride = signal(null);
|
|
20
|
+
this.lightingState = signal(null);
|
|
21
|
+
this.localLightSpots = signal({});
|
|
20
22
|
this.weather = computed(() => {
|
|
21
23
|
const local = this.localWeatherOverride();
|
|
22
24
|
const state = this.weatherState();
|
|
23
25
|
return local ?? state;
|
|
24
26
|
});
|
|
27
|
+
this.lighting = computed(() => {
|
|
28
|
+
const state = cloneLightingState(this.lightingState());
|
|
29
|
+
const localSpots = Object.entries(this.localLightSpots()).map(([id, spot]) => ({
|
|
30
|
+
...spot,
|
|
31
|
+
id: spot.id ?? id
|
|
32
|
+
}));
|
|
33
|
+
if (!state && localSpots.length === 0) return null;
|
|
34
|
+
const next = { ...state ?? {} };
|
|
35
|
+
if (!state?.ambient) delete next.ambient;
|
|
36
|
+
next.spots = [...state?.spots ?? [], ...localSpots];
|
|
37
|
+
return next;
|
|
38
|
+
});
|
|
25
39
|
this.manualClientPhysicsTick = false;
|
|
26
|
-
const
|
|
40
|
+
const testGlobal = globalThis;
|
|
41
|
+
const isTest = testGlobal.process?.env?.TEST === "true" || testGlobal.__RPGJS_TEST__ === true;
|
|
27
42
|
this.isTestEnvironment = isTest;
|
|
28
43
|
if (isTest) this.autoTickEnabled = false;
|
|
29
44
|
}
|
|
@@ -41,6 +56,8 @@ var RpgClientMap = class extends RpgCommonMap {
|
|
|
41
56
|
this.events.set({});
|
|
42
57
|
this.weatherState.set(null);
|
|
43
58
|
this.localWeatherOverride.set(null);
|
|
59
|
+
this.lightingState.set(null);
|
|
60
|
+
this.localLightSpots.set({});
|
|
44
61
|
this.clearPhysic();
|
|
45
62
|
}
|
|
46
63
|
getWeather() {
|
|
@@ -52,6 +69,47 @@ var RpgClientMap = class extends RpgCommonMap {
|
|
|
52
69
|
clearLocalWeather() {
|
|
53
70
|
this.localWeatherOverride.set(null);
|
|
54
71
|
}
|
|
72
|
+
getLighting() {
|
|
73
|
+
return this.lighting();
|
|
74
|
+
}
|
|
75
|
+
addLightSpot(id, spot) {
|
|
76
|
+
const nextSpot = normalizeLightingState({ spots: [{
|
|
77
|
+
...spot,
|
|
78
|
+
id
|
|
79
|
+
}] })?.spots?.[0];
|
|
80
|
+
if (!nextSpot) return;
|
|
81
|
+
this.localLightSpots.update((spots) => ({
|
|
82
|
+
...spots,
|
|
83
|
+
[id]: nextSpot
|
|
84
|
+
}));
|
|
85
|
+
}
|
|
86
|
+
patchLightSpot(id, patch) {
|
|
87
|
+
this.localLightSpots.update((spots) => {
|
|
88
|
+
const current = spots[id];
|
|
89
|
+
if (!current) return spots;
|
|
90
|
+
return {
|
|
91
|
+
...spots,
|
|
92
|
+
[id]: {
|
|
93
|
+
...current,
|
|
94
|
+
...patch,
|
|
95
|
+
id,
|
|
96
|
+
x: patch.x ?? current.x,
|
|
97
|
+
y: patch.y ?? current.y
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
removeLightSpot(id) {
|
|
103
|
+
this.localLightSpots.update((spots) => {
|
|
104
|
+
if (!(id in spots)) return spots;
|
|
105
|
+
const next = { ...spots };
|
|
106
|
+
delete next[id];
|
|
107
|
+
return next;
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
clearLightSpots() {
|
|
111
|
+
this.localLightSpots.set({});
|
|
112
|
+
}
|
|
55
113
|
stepClientPhysics(deltaMs) {
|
|
56
114
|
if (!this.manualClientPhysicsTick) return 0;
|
|
57
115
|
return this.nextTick(deltaMs);
|
package/dist/Game/Map.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Map.js","names":[],"sources":["../../src/Game/Map.ts"],"sourcesContent":["import {\n RpgCommonMap,\n type WeatherState,\n type MapPhysicsInitContext,\n type MapPhysicsEntityContext,\n} from \"@rpgjs/common\";\nimport { sync, users } from \"@signe/sync\";\nimport { RpgClientPlayer } from \"./Player\";\nimport { Signal, signal, computed, effect } from \"canvasengine\";\nimport { RpgClientEvent } from \"./Event\";\nimport { RpgClientEngine } from \"../RpgClientEngine\";\nimport { inject } from \"../core/inject\";\n\nexport class RpgClientMap extends RpgCommonMap<any> {\n engine: RpgClientEngine = inject(RpgClientEngine)\n @users(RpgClientPlayer) players = signal<Record<string, RpgClientPlayer>>({});\n @sync(RpgClientEvent) events = signal<Record<string, RpgClientEvent>>({});\n currentPlayer = computed(() => this.players()[this.engine.playerIdSignal()!])\n weatherState = signal<WeatherState | null>(null);\n localWeatherOverride = signal<WeatherState | null>(null);\n weather = computed<WeatherState | null>(() => {\n const local = this.localWeatherOverride() \n const state = this.weatherState()\n return local ?? state\n });\n private manualClientPhysicsTick = false;\n private readonly isTestEnvironment: boolean;\n\n constructor() {\n super();\n // Détecter l'environnement de test\n const
|
|
1
|
+
{"version":3,"file":"Map.js","names":[],"sources":["../../src/Game/Map.ts"],"sourcesContent":["import {\n RpgCommonMap,\n cloneLightingState,\n normalizeLightingState,\n type LightSpot,\n type LightingState,\n type WeatherState,\n type MapPhysicsInitContext,\n type MapPhysicsEntityContext,\n} from \"@rpgjs/common\";\nimport { sync, users } from \"@signe/sync\";\nimport { RpgClientPlayer } from \"./Player\";\nimport { Signal, signal, computed, effect } from \"canvasengine\";\nimport { RpgClientEvent } from \"./Event\";\nimport { RpgClientEngine } from \"../RpgClientEngine\";\nimport { inject } from \"../core/inject\";\n\ntype TestGlobalScope = typeof globalThis & {\n process?: {\n env?: {\n TEST?: string;\n };\n };\n __RPGJS_TEST__?: boolean;\n};\n\nexport class RpgClientMap extends RpgCommonMap<any> {\n engine: RpgClientEngine = inject(RpgClientEngine)\n @users(RpgClientPlayer) players = signal<Record<string, RpgClientPlayer>>({});\n @sync(RpgClientEvent) events = signal<Record<string, RpgClientEvent>>({});\n currentPlayer = computed(() => this.players()[this.engine.playerIdSignal()!])\n weatherState = signal<WeatherState | null>(null);\n localWeatherOverride = signal<WeatherState | null>(null);\n lightingState = signal<LightingState | null>(null);\n localLightSpots = signal<Record<string, LightSpot>>({});\n weather = computed<WeatherState | null>(() => {\n const local = this.localWeatherOverride() \n const state = this.weatherState()\n return local ?? state\n });\n lighting = computed<LightingState | null>(() => {\n const state = cloneLightingState(this.lightingState());\n const localSpots = Object.entries(this.localLightSpots()).map(([id, spot]) => ({\n ...spot,\n id: spot.id ?? id,\n }));\n\n if (!state && localSpots.length === 0) {\n return null;\n }\n\n const next: LightingState = { ...(state ?? {}) };\n if (!state?.ambient) {\n delete next.ambient;\n }\n next.spots = [\n ...(state?.spots ?? []),\n ...localSpots,\n ];\n return next;\n });\n private manualClientPhysicsTick = false;\n private readonly isTestEnvironment: boolean;\n\n constructor() {\n super();\n // Détecter l'environnement de test\n const testGlobal = globalThis as TestGlobalScope;\n const isTest = testGlobal.process?.env?.TEST === 'true'\n || testGlobal.__RPGJS_TEST__ === true;\n this.isTestEnvironment = isTest;\n if (isTest) {\n this.autoTickEnabled = false;\n }\n }\n\n configureClientPrediction(enabled: boolean): void {\n this.manualClientPhysicsTick = enabled;\n this.autoTickEnabled = enabled ? false : !this.isTestEnvironment;\n }\n\n getCurrentPlayer() {\n return this.currentPlayer()\n }\n\n reset(force = false) {\n const currentPlayerId = this.engine.playerIdSignal();\n const currentPlayer = !force && currentPlayerId\n ? this.players()[currentPlayerId]\n : undefined;\n\n this.players.set(\n currentPlayerId && currentPlayer ? { [currentPlayerId]: currentPlayer } : {}\n );\n this.events.set({})\n this.weatherState.set(null);\n this.localWeatherOverride.set(null);\n this.lightingState.set(null);\n this.localLightSpots.set({});\n this.clearPhysic()\n }\n\n getWeather(): WeatherState | null {\n return this.weather();\n }\n\n setLocalWeather(next: WeatherState | null): void {\n this.localWeatherOverride.set(next);\n }\n\n clearLocalWeather(): void {\n this.localWeatherOverride.set(null);\n }\n\n getLighting(): LightingState | null {\n return this.lighting();\n }\n\n addLightSpot(id: string, spot: LightSpot): void {\n const normalized = normalizeLightingState({ spots: [{ ...spot, id }] });\n const nextSpot = normalized?.spots?.[0];\n if (!nextSpot) {\n return;\n }\n this.localLightSpots.update((spots) => ({\n ...spots,\n [id]: nextSpot,\n }));\n }\n\n patchLightSpot(id: string, patch: Partial<LightSpot>): void {\n this.localLightSpots.update((spots) => {\n const current = spots[id];\n if (!current) {\n return spots;\n }\n return {\n ...spots,\n [id]: {\n ...current,\n ...patch,\n id,\n x: patch.x ?? current.x,\n y: patch.y ?? current.y,\n },\n };\n });\n }\n\n removeLightSpot(id: string): void {\n this.localLightSpots.update((spots) => {\n if (!(id in spots)) {\n return spots;\n }\n const next = { ...spots };\n delete next[id];\n return next;\n });\n }\n\n clearLightSpots(): void {\n this.localLightSpots.set({});\n }\n\n stepClientPhysics(deltaMs: number): number {\n if (!this.manualClientPhysicsTick) {\n return 0;\n }\n return this.nextTick(deltaMs);\n }\n\n stepPredictionTick(): void {\n this.forceSingleTick();\n }\n\n protected emitPhysicsInit(context: MapPhysicsInitContext): void {\n this.engine?.emitSceneMapHook?.(\"onPhysicsInit\", this, context);\n }\n\n protected emitPhysicsEntityAdd(context: MapPhysicsEntityContext): void {\n this.engine?.emitSceneMapHook?.(\"onPhysicsEntityAdd\", this, context);\n }\n\n protected emitPhysicsEntityRemove(context: MapPhysicsEntityContext): void {\n this.engine?.emitSceneMapHook?.(\"onPhysicsEntityRemove\", this, context);\n }\n\n protected emitPhysicsReset(): void {\n this.engine?.emitSceneMapHook?.(\"onPhysicsReset\", this);\n }\n}\n"],"mappings":";;;;;;;;;;AA0BA,IAAa,eAAb,cAAkC,aAAkB;CAsClD,cAAc;EACZ,MAAM;gBAtCkB,OAAO,eAAe;iBACd,OAAwC,CAAC,CAAC;gBAC7C,OAAuC,CAAC,CAAC;uBACxD,eAAe,KAAK,QAAQ,EAAE,KAAK,OAAO,eAAe,EAAG;sBAC7D,OAA4B,IAAI;8BACxB,OAA4B,IAAI;uBACvC,OAA6B,IAAI;yBAC/B,OAAkC,CAAC,CAAC;iBAC5C,eAAoC;GAC5C,MAAM,QAAQ,KAAK,qBAAqB;GACxC,MAAM,QAAQ,KAAK,aAAa;GAChC,OAAO,SAAS;EAClB,CAAC;kBACU,eAAqC;GAC9C,MAAM,QAAQ,mBAAmB,KAAK,cAAc,CAAC;GACrD,MAAM,aAAa,OAAO,QAAQ,KAAK,gBAAgB,CAAC,EAAE,KAAK,CAAC,IAAI,WAAW;IAC7E,GAAG;IACH,IAAI,KAAK,MAAM;GACjB,EAAE;GAEF,IAAI,CAAC,SAAS,WAAW,WAAW,GAClC,OAAO;GAGT,MAAM,OAAsB,EAAE,GAAI,SAAS,CAAC,EAAG;GAC/C,IAAI,CAAC,OAAO,SACV,OAAO,KAAK;GAEd,KAAK,QAAQ,CACX,GAAI,OAAO,SAAS,CAAC,GACrB,GAAG,UACL;GACA,OAAO;EACT,CAAC;iCACiC;EAMhC,MAAM,aAAa;EACnB,MAAM,SAAS,WAAW,SAAS,KAAK,SAAS,UAC5C,WAAW,mBAAmB;EACnC,KAAK,oBAAoB;EACzB,IAAI,QACF,KAAK,kBAAkB;CAE3B;CAEA,0BAA0B,SAAwB;EAChD,KAAK,0BAA0B;EAC/B,KAAK,kBAAkB,UAAU,QAAQ,CAAC,KAA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V,OAAO;GAET,MAAM,OAAO,EAAE,GAAG,MAAM;GACxB,OAAO,KAAK;GACZ,OAAO;EACT,CAAC;CACH;CAEA,kBAAwB;EACtB,KAAK,gBAAgB,IAAI,CAAC,CAAC;CAC7B;CAEA,kBAAkB,SAAyB;EACzC,IAAI,CAAC,KAAK,yBACR,OAAO;EAET,OAAO,KAAK,SAAS,OAAO;CAC9B;CAEA,qBAA2B;EACzB,KAAK,gBAAgB;CACvB;CAEA,gBAA0B,SAAsC;EAC9D,KAAK,QAAQ,mBAAmB,iBAAiB,MAAM,OAAO;CAChE;CAEA,qBAA+B,SAAwC;EACrE,KAAK,QAAQ,mBAAmB,sBAAsB,MAAM,OAAO;CACrE;CAEA,wBAAkC,SAAwC;EACxE,KAAK,QAAQ,mBAAmB,yBAAyB,MAAM,OAAO;CACxE;CAEA,mBAAmC;EACjC,KAAK,QAAQ,mBAAmB,kBAAkB,IAAI;CACxD;AACF;YAlKG,MAAM,eAAe,GAAA,mBAAA,eAAA,MAAA,CAAA,GAAA,aAAA,WAAA,WAAA,KAAA,CAAA;YACrB,KAAK,cAAc,GAAA,mBAAA,eAAA,MAAA,CAAA,GAAA,aAAA,WAAA,UAAA,KAAA,CAAA"}
|
package/dist/Game/Object.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Hooks, RpgCommonPlayer } from '@rpgjs/common';
|
|
2
|
+
import { Trigger } from 'canvasengine';
|
|
2
3
|
import { RpgClientEngine } from '../RpgClientEngine';
|
|
3
4
|
type Frame = {
|
|
4
5
|
x: number;
|
|
@@ -10,6 +11,20 @@ type AnimationRestoreOptions = {
|
|
|
10
11
|
restoreGraphics?: any[];
|
|
11
12
|
timeoutMs?: number;
|
|
12
13
|
};
|
|
14
|
+
type FlashType = 'alpha' | 'tint' | 'both';
|
|
15
|
+
type FlashOptions = {
|
|
16
|
+
type?: FlashType;
|
|
17
|
+
duration?: number;
|
|
18
|
+
cycles?: number;
|
|
19
|
+
alpha?: number;
|
|
20
|
+
tint?: number | string;
|
|
21
|
+
};
|
|
22
|
+
type FlashTriggerOptions = Omit<FlashOptions, "tint"> & {
|
|
23
|
+
tint: number;
|
|
24
|
+
};
|
|
25
|
+
type ConfigurableTrigger<T> = Omit<Trigger<T>, "start"> & {
|
|
26
|
+
start(config?: T): Promise<void>;
|
|
27
|
+
};
|
|
13
28
|
export declare abstract class RpgClientObject extends RpgCommonPlayer {
|
|
14
29
|
abstract _type: string;
|
|
15
30
|
emitParticleTrigger: any;
|
|
@@ -19,8 +34,7 @@ export declare abstract class RpgClientObject extends RpgCommonPlayer {
|
|
|
19
34
|
_param: any;
|
|
20
35
|
frames: Frame[];
|
|
21
36
|
graphicsSignals: any;
|
|
22
|
-
|
|
23
|
-
flashTrigger: any;
|
|
37
|
+
flashTrigger: ConfigurableTrigger<FlashTriggerOptions>;
|
|
24
38
|
private animationRestoreState?;
|
|
25
39
|
constructor();
|
|
26
40
|
/**
|
|
@@ -87,13 +101,7 @@ export declare abstract class RpgClientObject extends RpgCommonPlayer {
|
|
|
87
101
|
* });
|
|
88
102
|
* ```
|
|
89
103
|
*/
|
|
90
|
-
flash(options?:
|
|
91
|
-
type?: 'alpha' | 'tint' | 'both';
|
|
92
|
-
duration?: number;
|
|
93
|
-
cycles?: number;
|
|
94
|
-
alpha?: number;
|
|
95
|
-
tint?: number | string;
|
|
96
|
-
}): void;
|
|
104
|
+
flash(options?: FlashOptions): void;
|
|
97
105
|
/**
|
|
98
106
|
* Reset animation state when animation changes externally
|
|
99
107
|
*
|
package/dist/Game/Object.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { inject } from "../core/inject.js";
|
|
2
|
-
import __ce_component from "../components/dynamics/text.ce.js";
|
|
3
2
|
import { RpgClientEngine } from "../RpgClientEngine.js";
|
|
4
3
|
import { signal, trigger } from "canvasengine";
|
|
5
4
|
import { ModulesToken, RpgCommonPlayer } from "@rpgjs/common";
|
|
6
|
-
import {
|
|
5
|
+
import { from, map, of, switchMap } from "rxjs";
|
|
7
6
|
//#region src/Game/Object.ts
|
|
8
|
-
var DYNAMIC_COMPONENTS = { text: __ce_component };
|
|
9
7
|
var RpgClientObject = class extends RpgCommonPlayer {
|
|
10
8
|
constructor() {
|
|
11
9
|
super();
|
|
@@ -16,7 +14,6 @@ var RpgClientObject = class extends RpgCommonPlayer {
|
|
|
16
14
|
this._param = signal({});
|
|
17
15
|
this.frames = [];
|
|
18
16
|
this.graphicsSignals = signal([]);
|
|
19
|
-
this._component = {};
|
|
20
17
|
this.flashTrigger = trigger();
|
|
21
18
|
this.hooks.callHooks("client-sprite-onInit", this).subscribe();
|
|
22
19
|
this._frames.observable.subscribe(({ items }) => {
|
|
@@ -30,14 +27,6 @@ var RpgClientObject = class extends RpgCommonPlayer {
|
|
|
30
27
|
})).subscribe((sheets) => {
|
|
31
28
|
this.graphicsSignals.set(sheets);
|
|
32
29
|
});
|
|
33
|
-
this.componentsTop.observable.pipe(filter((value) => value !== null && value !== void 0), map((value) => typeof value === "string" ? JSON.parse(value) : value)).subscribe(({ components }) => {
|
|
34
|
-
for (const component of components) for (const [key, value] of Object.entries(component)) {
|
|
35
|
-
this._component = value;
|
|
36
|
-
console.log(value);
|
|
37
|
-
const type = value.type;
|
|
38
|
-
if (DYNAMIC_COMPONENTS[type]) this.engine.addSpriteComponentInFront(DYNAMIC_COMPONENTS[type]);
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
30
|
this.engine.tick.pipe().subscribe(() => {
|
|
42
31
|
const frame = this.frames.shift();
|
|
43
32
|
if (frame) {
|
package/dist/Game/Object.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Object.js","names":[],"sources":["../../src/Game/Object.ts"],"sourcesContent":["import { Hooks, ModulesToken, RpgCommonPlayer } from \"@rpgjs/common\";\nimport { trigger, signal, effect } from \"canvasengine\";\nimport { filter, from, map, of, Subscription, switchMap } from \"rxjs\";\nimport { inject } from \"../core/inject\";\nimport { RpgClientEngine } from \"../RpgClientEngine\";\nimport TextComponent from \"../components/dynamics/text.ce\";\n\nconst DYNAMIC_COMPONENTS = {\n text: TextComponent,\n}\n\ntype Frame = { x: number; y: number; ts: number };\n\ntype AnimationRestoreOptions = {\n restoreAnimationName?: string;\n restoreGraphics?: any[];\n timeoutMs?: number;\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 _component = {} // temporary component memory\n flashTrigger = trigger();\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.componentsTop.observable\n .pipe(\n filter(value => value !== null && value !== undefined),\n map((value) => typeof value === 'string' ? JSON.parse(value) : value),\n )\n .subscribe(({components}) => {\n for (const component of components) {\n for (const [key, value] of Object.entries(component)) {\n this._component = value as any; // temporary component memory\n console.log(value)\n const type = (value as any).type as keyof typeof DYNAMIC_COMPONENTS;\n if (DYNAMIC_COMPONENTS[type]) {\n this.engine.addSpriteComponentInFront(DYNAMIC_COMPONENTS[type]);\n }\n }\n }\n });\n\n this.engine.tick\n .pipe\n //throttleTime(10)\n ()\n .subscribe(() => {\n const frame = this.frames.shift();\n if (frame) {\n if (typeof frame.x !== \"number\" || typeof frame.y !== \"number\") return;\n this.engine.scene.setBodyPosition(\n this.id,\n frame.x,\n frame.y,\n \"top-left\"\n );\n }\n });\n }\n\n /**\n * Access the shared client hook registry.\n *\n * @returns The hook service used to register and trigger client-side hooks.\n */\n get hooks() {\n return inject<Hooks>(ModulesToken);\n }\n\n /**\n * Access the current client engine instance.\n *\n * @returns The active {@link RpgClientEngine} instance.\n */\n get engine() {\n return inject(RpgClientEngine);\n }\n\n private animationSubscription?: Subscription;\n 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?: {\n type?: 'alpha' | 'tint' | 'both';\n duration?: number;\n cycles?: number;\n alpha?: number;\n tint?: number | string;\n }): void {\n const flashOptions = {\n type: options?.type || 'alpha',\n duration: options?.duration ?? 300,\n cycles: options?.cycles ?? 1,\n alpha: options?.alpha ?? 0.3,\n tint: options?.tint ?? 0xffffff,\n };\n \n // Convert color name to hex if needed\n let tintValue = flashOptions.tint;\n if (typeof tintValue === 'string') {\n // Common color name to hex mapping\n const colorMap: Record<string, number> = {\n 'white': 0xffffff,\n 'red': 0xff0000,\n 'green': 0x00ff00,\n 'blue': 0x0000ff,\n 'yellow': 0xffff00,\n 'cyan': 0x00ffff,\n 'magenta': 0xff00ff,\n 'black': 0x000000,\n };\n tintValue = colorMap[tintValue.toLowerCase()] ?? 0xffffff;\n }\n \n this.flashTrigger.start({\n ...flashOptions,\n tint: tintValue,\n });\n }\n\n /**\n * Reset animation state when animation changes externally\n *\n * This method should be called when the animation changes due to movement\n * or other external factors to ensure the animation system doesn't get stuck\n *\n * @example\n * ```ts\n * // Reset when player starts moving\n * player.resetAnimationState();\n * ```\n */\n resetAnimationState() {\n 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":";;;;;;;AAOA,IAAM,qBAAqB,EACzB,MAAM,gBACP;AAUD,IAAsB,kBAAtB,cAA8C,gBAAgB;CAgB5D,cAAc;EACZ,OAAO;6BAfa,SAAS;sBAChB,OAAO,GAAG;+BACD,OAAO,EAAE;4BACZ,OAAO,MAAM;gBACzB,OAAO,EAAE,CAAC;gBACD,EAAE;yBACF,OAAc,EAAE,CAAC;oBACtB,EAAE;sBACA,SAAS;EAQtB,KAAK,MAAM,UAAU,wBAAwB,KAAK,CAAC,WAAW;EAE9D,KAAK,QAAQ,WAAW,WAAW,EAAE,YAAY;GAC/C,IAAI,CAAC,KAAK,IAAI;GAEd,MAAM,aAAa,MAAM,SAAS,SAChC,MAAM,QAAQ,KAAK,GAAG,OAAO,CAAC,KAAK,CACpC;GACD,KAAK,SAAS,CAAC,GAAG,KAAK,QAAQ,GAAG,WAAW;IAC7C;EAEF,KAAK,SAAS,WACb,KACC,KAAK,EAAE,YAAY,MAAM,EACzB,WAAU,aAAY;GACpB,IAAI,SAAS,WAAW,GAAG,OAAO,GAAG,EAAE,CAAC;GACxC,OAAO,KAAK,QAAQ,IAAI,SAAS,KAAI,YAAW,KAAK,OAAO,eAAe,QAAQ,CAAC,CAAC,CAAC;IACtF,CACH,CACA,WAAW,WAAW;GACrB,KAAK,gBAAgB,IAAI,OAAO;IAChC;EAEF,KAAK,cAAc,WAClB,KACC,QAAO,UAAS,UAAU,QAAQ,UAAU,KAAA,EAAU,EACtD,KAAK,UAAU,OAAO,UAAU,WAAW,KAAK,MAAM,MAAM,GAAG,MAAM,CACtE,CACA,WAAW,EAAC,iBAAgB;GAC3B,KAAK,MAAM,aAAa,YACtB,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,UAAU,EAAE;IACpD,KAAK,aAAa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AI,QAAQ;OAE1B,KAAK,SAAS,IAAI,CAAC,QAAQ,CAAC;EAIhC,KAAK,wBAAwB;EAE7B,KAAK,wBACH,KAAK,sBAAsB,WAAW,WAAW,UAAU;GACzD,IAAI,SAAS,cACX,KAAK,0BAA0B;IAEjC;EAEJ,IAAI,iBAAiB,UACnB,KAAK,wBAAwB,iBAAiB;GAC5C,IAAI,KAAK,oBAAoB,EAC3B,KAAK,0BAA0B;KAEhC,gBAAgB,aAAa,KAAK,IAAI,KAAM,eAAe,IAAK,CAAC;EAGtE,KAAK,cAAc,IAAI,cAAc;EAErC,OAAO;;;;;;;;;CAUT,uBAAuB,IAAY,QAA4B;EAE7D,OADe,OAAO,gBACf,CAAO,sBAAsB,GAAG,CAAC,cAAc,QAAQ,KAAK;;;;;;;;;CAUrE,cAAc,SAAiB,gBAAwB,WAA0B;EAC/E,OAAO,KAAK,uBAAuB,aAAa;GAC9C;GACA;GACD,CAAC;;;;;;;CAQJ,UAAmB;EACjB,OAAO,KAAK,UAAU;;;;;;;CAQxB,WAAoB;EAClB,OAAO,KAAK,UAAU"}
|
|
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":";;;;;;AA+BA,IAAsB,kBAAtB,cAA8C,gBAAgB;CAe5D,cAAc;EACZ,MAAM;6BAdc,QAAQ;sBACf,OAAO,EAAE;+BACA,OAAO,CAAC;4BACX,OAAO,KAAK;gBACxB,OAAO,CAAC,CAAC;gBACA,CAAC;yBACD,OAAc,CAAC,CAAC;sBACuB,QAA6B;EAQpF,KAAK,MAAM,UAAU,wBAAwB,IAAI,EAAE,UAAU;EAE7D,KAAK,QAAQ,WAAW,WAAW,EAAE,YAAY;GAC/C,IAAI,CAAC,KAAK,IAAI;GAEd,MAAM,aAAa,MAAM,SAAS,SAChC,MAAM,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uBAAuB;EAC9B,CAAC;EAEP,KAAK,mBAAmB,IAAI,IAAI;EAChC,MAAM,wBACJ,gBAAgB,wBAAwB,KAAK,cAAc;EAC7D,MAAM,mBAAmB,gBAAgB,kBACrC,CAAC,GAAG,eAAe,eAAe,IAClC,CAAC,GAAG,KAAK,SAAS,CAAC;EACvB,KAAK,wBAAwB;GAC3B,eAAe;GACf,UAAU;EACZ;EACA,KAAK,sBAAsB,IAAI,CAAC;EAGhC,IAAI,YAAY,KAAA,GACd,IAAI,MAAM,QAAQ,OAAO,GACvB,KAAK,SAAS,IAAI,OAAO;OAEzB,KAAK,SAAS,IAAI,CAAC,OAAO,CAAC;EAI/B,KAAK,uBAAuB;EAE5B,KAAK,wBACH,KAAK,sBAAsB,WAAW,WAAW,UAAU;GACzD,IAAI,SAAS,cACX,KAAK,yBAAyB;EAElC,CAAC;EAEH,IAAI,iBAAiB,UACnB,KAAK,wBAAwB,iBAAiB;GAC5C,IAAI,KAAK,mBAAmB,GAC1B,KAAK,yBAAyB;EAElC,GAAG,gBAAgB,aAAa,KAAK,IAAI,KAAM,eAAe,GAAI,CAAC;EAGrE,KAAK,cAAc,IAAI,aAAa;EAEpC,OAAO;CACT;;;;;;;;CASA,uBAAuB,IAAY,QAA4B;EAE7D,OADe,OAAO,eACf,EAAO,sBAAsB,EAAE,EAAE,cAAc,QAAQ,IAAI;CACpE;;;;;;;;CASA,cAAc,SAAiB,gBAAwB,WAA0B;EAC/E,OAAO,KAAK,uBAAuB,aAAa;GAC9C;GACA;EACF,CAAC;CACH;;;;;;CAOA,UAAmB;EACjB,OAAO,KAAK,UAAU;CACxB;;;;;;CAOA,WAAoB;EAClB,OAAO,KAAK,UAAU;CACxB;AACF"}
|
package/dist/Game/Player.js.map
CHANGED
|
@@ -1 +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"}
|
|
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
|
@@ -4,7 +4,7 @@ import { Subscription } from 'rxjs';
|
|
|
4
4
|
interface GuiOptions {
|
|
5
5
|
name?: string;
|
|
6
6
|
id?: string;
|
|
7
|
-
component
|
|
7
|
+
component?: any;
|
|
8
8
|
display?: boolean;
|
|
9
9
|
data?: any;
|
|
10
10
|
/**
|
|
@@ -24,14 +24,18 @@ interface GuiOptions {
|
|
|
24
24
|
* @default false
|
|
25
25
|
*/
|
|
26
26
|
attachToSprite?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Vue v4 compatibility flag. Prefer attachToSprite in v5 projects.
|
|
29
|
+
*/
|
|
30
|
+
rpgAttachToSprite?: boolean;
|
|
27
31
|
}
|
|
28
|
-
interface GuiInstance {
|
|
32
|
+
export interface GuiInstance {
|
|
29
33
|
name: string;
|
|
30
34
|
component: any;
|
|
31
35
|
display: WritableSignal<boolean>;
|
|
32
36
|
data: WritableSignal<any>;
|
|
33
37
|
autoDisplay: boolean;
|
|
34
|
-
dependencies?:
|
|
38
|
+
dependencies?: Signal[];
|
|
35
39
|
subscription?: Subscription;
|
|
36
40
|
attachToSprite?: boolean;
|
|
37
41
|
}
|
|
@@ -113,7 +117,7 @@ export declare class RpgGui {
|
|
|
113
117
|
* });
|
|
114
118
|
* ```
|
|
115
119
|
*/
|
|
116
|
-
add(gui: GuiOptions): void;
|
|
120
|
+
add(gui: GuiOptions | any): void;
|
|
117
121
|
registerOptimisticReducer(guiId: string, reducer: OptimisticReducer): void;
|
|
118
122
|
/**
|
|
119
123
|
* Get all attached GUI components (attachToSprite: true)
|
|
@@ -130,6 +134,8 @@ export declare class RpgGui {
|
|
|
130
134
|
* ```
|
|
131
135
|
*/
|
|
132
136
|
getAttachedGuis(): GuiInstance[];
|
|
137
|
+
getVueGuis(): GuiInstance[];
|
|
138
|
+
getAttachedVueGuis(): GuiInstance[];
|
|
133
139
|
/**
|
|
134
140
|
* Check if a player should display attached GUIs
|
|
135
141
|
*
|
|
@@ -187,6 +193,13 @@ export declare class RpgGui {
|
|
|
187
193
|
*/
|
|
188
194
|
hide(id: string): void;
|
|
189
195
|
private isVueComponent;
|
|
196
|
+
private isVueComponentInstance;
|
|
197
|
+
private removeCanvasGui;
|
|
198
|
+
private removeVueGui;
|
|
199
|
+
private resolveComponent;
|
|
200
|
+
private resolveGuiId;
|
|
201
|
+
private resolveAttachToSprite;
|
|
202
|
+
private toGuiState;
|
|
190
203
|
private clearPendingActions;
|
|
191
204
|
private applyReducers;
|
|
192
205
|
private applyOptimisticAction;
|
package/dist/Gui/Gui.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { inject } from "../node_modules/.pnpm/@signe_di@
|
|
1
|
+
import { inject } from "../node_modules/.pnpm/@signe_di@3.0.1/node_modules/@signe/di/dist/index.js";
|
|
2
2
|
import { WebSocketToken } from "../services/AbstractSocket.js";
|
|
3
3
|
import __ce_component from "../components/gui/dialogbox/index.ce.js";
|
|
4
4
|
import __ce_component$1 from "../components/gui/shop/shop.ce.js";
|
|
@@ -146,6 +146,7 @@ var RpgGui = class {
|
|
|
146
146
|
*/
|
|
147
147
|
_setVueGuiInstance(vueGuiInstance) {
|
|
148
148
|
this.vueGuiInstance = vueGuiInstance;
|
|
149
|
+
this._initializeVueComponents();
|
|
149
150
|
}
|
|
150
151
|
/**
|
|
151
152
|
* Notify VueGui about GUI state changes
|
|
@@ -156,35 +157,16 @@ var RpgGui = class {
|
|
|
156
157
|
* @param data - Component data
|
|
157
158
|
*/
|
|
158
159
|
_notifyVueGui(guiId, display, data = {}) {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
this.vueGuiInstance.vm.gui[guiId] = {
|
|
163
|
-
name: guiId,
|
|
164
|
-
display,
|
|
165
|
-
data,
|
|
166
|
-
attachToSprite: extraGui.attachToSprite || false
|
|
167
|
-
};
|
|
168
|
-
this.vueGuiInstance.vm.gui = Object.assign({}, this.vueGuiInstance.vm.gui);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
160
|
+
const extraGui = this.extraGuis.find((gui) => gui.name === guiId);
|
|
161
|
+
if (!extraGui) return;
|
|
162
|
+
this.vueGuiInstance?.updateGuiState?.(this.toGuiState(extraGui, display, data));
|
|
171
163
|
}
|
|
172
164
|
/**
|
|
173
165
|
* Initialize Vue components in the VueGui instance
|
|
174
166
|
* This should be called after VueGui is mounted
|
|
175
167
|
*/
|
|
176
168
|
_initializeVueComponents() {
|
|
177
|
-
|
|
178
|
-
this.extraGuis.forEach((gui) => {
|
|
179
|
-
this.vueGuiInstance.vm.gui[gui.name] = {
|
|
180
|
-
name: gui.name,
|
|
181
|
-
display: gui.display(),
|
|
182
|
-
data: gui.data(),
|
|
183
|
-
attachToSprite: gui.attachToSprite || false
|
|
184
|
-
};
|
|
185
|
-
});
|
|
186
|
-
this.vueGuiInstance.vm.gui = Object.assign({}, this.vueGuiInstance.vm.gui);
|
|
187
|
-
}
|
|
169
|
+
this.vueGuiInstance?.initializeGuiStates?.(this.extraGuis.map((gui) => this.toGuiState(gui)));
|
|
188
170
|
}
|
|
189
171
|
guiInteraction(guiId, name, data) {
|
|
190
172
|
const clientActionId = globalThis.crypto?.randomUUID?.() || `${Date.now()}-${Math.random()}`;
|
|
@@ -244,24 +226,34 @@ var RpgGui = class {
|
|
|
244
226
|
* ```
|
|
245
227
|
*/
|
|
246
228
|
add(gui) {
|
|
247
|
-
const
|
|
229
|
+
const component = this.resolveComponent(gui);
|
|
230
|
+
const guiId = this.resolveGuiId(gui, component);
|
|
248
231
|
if (!guiId) throw new Error("GUI must have a name or id");
|
|
232
|
+
const attachToSprite = this.resolveAttachToSprite(gui, component);
|
|
249
233
|
const guiInstance = {
|
|
250
234
|
name: guiId,
|
|
251
|
-
component
|
|
235
|
+
component,
|
|
252
236
|
display: signal(gui.display || false),
|
|
253
237
|
data: signal(gui.data || {}),
|
|
254
238
|
autoDisplay: gui.autoDisplay || false,
|
|
255
239
|
dependencies: gui.dependencies ? gui.dependencies() : [],
|
|
256
|
-
attachToSprite
|
|
240
|
+
attachToSprite
|
|
257
241
|
};
|
|
258
|
-
if (
|
|
259
|
-
|
|
260
|
-
this.extraGuis.
|
|
261
|
-
if (
|
|
242
|
+
if (this.isVueComponentInstance(guiInstance)) {
|
|
243
|
+
this.removeCanvasGui(guiId);
|
|
244
|
+
const existingIndex = this.extraGuis.findIndex((existing) => existing.name === guiId);
|
|
245
|
+
if (existingIndex >= 0) {
|
|
246
|
+
this.extraGuis[existingIndex].subscription?.unsubscribe();
|
|
247
|
+
this.extraGuis[existingIndex] = guiInstance;
|
|
248
|
+
} else this.extraGuis.push(guiInstance);
|
|
249
|
+
this._initializeVueComponents();
|
|
250
|
+
if (guiInstance.autoDisplay) this.display(guiId, gui.data);
|
|
251
|
+
else this._notifyVueGui(guiId, guiInstance.display(), guiInstance.data());
|
|
262
252
|
return;
|
|
263
253
|
}
|
|
254
|
+
this.removeVueGui(guiId);
|
|
264
255
|
this.gui()[guiId] = guiInstance;
|
|
256
|
+
this._initializeVueComponents();
|
|
265
257
|
if (guiInstance.autoDisplay && typeof gui.component === "function") this.display(guiId, gui.data);
|
|
266
258
|
}
|
|
267
259
|
registerOptimisticReducer(guiId, reducer) {
|
|
@@ -283,8 +275,13 @@ var RpgGui = class {
|
|
|
283
275
|
* ```
|
|
284
276
|
*/
|
|
285
277
|
getAttachedGuis() {
|
|
286
|
-
|
|
287
|
-
|
|
278
|
+
return Object.values(this.gui()).filter((gui) => gui.attachToSprite === true);
|
|
279
|
+
}
|
|
280
|
+
getVueGuis() {
|
|
281
|
+
return [...this.extraGuis];
|
|
282
|
+
}
|
|
283
|
+
getAttachedVueGuis() {
|
|
284
|
+
return this.extraGuis.filter((gui) => gui.attachToSprite === true);
|
|
288
285
|
}
|
|
289
286
|
/**
|
|
290
287
|
* Check if a player should display attached GUIs
|
|
@@ -358,7 +355,7 @@ var RpgGui = class {
|
|
|
358
355
|
guiInstance.subscription.unsubscribe();
|
|
359
356
|
guiInstance.subscription = void 0;
|
|
360
357
|
}
|
|
361
|
-
const deps = dependencies.length > 0 ? dependencies : guiInstance.dependencies
|
|
358
|
+
const deps = dependencies.length > 0 ? dependencies : guiInstance.dependencies ?? [];
|
|
362
359
|
if (deps.length > 0) {
|
|
363
360
|
guiInstance.subscription = combineLatest(deps.map((dependency) => dependency.observable)).subscribe((values) => {
|
|
364
361
|
if (values.every((value) => value !== void 0)) {
|
|
@@ -399,6 +396,39 @@ var RpgGui = class {
|
|
|
399
396
|
isVueComponent(id) {
|
|
400
397
|
return this.extraGuis.some((gui) => gui.name === id);
|
|
401
398
|
}
|
|
399
|
+
isVueComponentInstance(gui) {
|
|
400
|
+
return typeof gui.component !== "function";
|
|
401
|
+
}
|
|
402
|
+
removeCanvasGui(guiId) {
|
|
403
|
+
const current = this.gui();
|
|
404
|
+
if (!(guiId in current)) return;
|
|
405
|
+
const next = { ...current };
|
|
406
|
+
delete next[guiId];
|
|
407
|
+
this.gui.set(next);
|
|
408
|
+
}
|
|
409
|
+
removeVueGui(guiId) {
|
|
410
|
+
const removed = this.extraGuis.filter((existing) => existing.name === guiId);
|
|
411
|
+
removed.forEach((gui) => gui.subscription?.unsubscribe());
|
|
412
|
+
if (removed.length > 0) this.extraGuis = this.extraGuis.filter((existing) => existing.name !== guiId);
|
|
413
|
+
}
|
|
414
|
+
resolveComponent(gui) {
|
|
415
|
+
return gui?.component ?? gui;
|
|
416
|
+
}
|
|
417
|
+
resolveGuiId(gui, component) {
|
|
418
|
+
return gui?.name || gui?.id || component?.name || component?.__name;
|
|
419
|
+
}
|
|
420
|
+
resolveAttachToSprite(gui, component) {
|
|
421
|
+
return !!(gui?.attachToSprite || gui?.rpgAttachToSprite || component?.attachToSprite || component?.rpgAttachToSprite);
|
|
422
|
+
}
|
|
423
|
+
toGuiState(gui, display = gui.display(), data = gui.data()) {
|
|
424
|
+
return {
|
|
425
|
+
name: gui.name,
|
|
426
|
+
component: gui.component,
|
|
427
|
+
display,
|
|
428
|
+
data,
|
|
429
|
+
attachToSprite: gui.attachToSprite || false
|
|
430
|
+
};
|
|
431
|
+
}
|
|
402
432
|
clearPendingActions(guiId) {
|
|
403
433
|
this.pendingActions.delete(guiId);
|
|
404
434
|
}
|