@rpgjs/client 5.0.0-beta.1 → 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 +1 -1
- package/dist/Game/AnimationManager.js +18 -9
- package/dist/Game/AnimationManager.js.map +1 -1
- package/dist/Game/AnimationManager.spec.d.ts +1 -0
- 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 +47 -15
- package/dist/Game/Object.js +82 -38
- 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 +78 -48
- 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 +57 -2
- package/dist/RpgClientEngine.d.ts +61 -6
- package/dist/RpgClientEngine.js +122 -14
- package/dist/RpgClientEngine.js.map +1 -1
- package/dist/Sound.js.map +1 -1
- package/dist/_virtual/{_@oxc-project_runtime@0.122.0 → _@oxc-project_runtime@0.130.0}/helpers/decorate.js +1 -1
- package/dist/_virtual/{_@oxc-project_runtime@0.122.0 → _@oxc-project_runtime@0.130.0}/helpers/decorateMetadata.js +1 -1
- package/dist/components/animations/animation.ce.js +4 -5
- package/dist/components/animations/animation.ce.js.map +1 -1
- package/dist/components/animations/hit.ce.js +19 -25
- package/dist/components/animations/hit.ce.js.map +1 -1
- package/dist/components/animations/index.js +4 -4
- package/dist/components/animations/index.js.map +1 -1
- package/dist/components/character.ce.js +406 -226
- 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 +54 -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 +33 -56
- package/dist/components/dynamics/text.ce.js.map +1 -1
- package/dist/components/gui/box.ce.js +6 -8
- package/dist/components/gui/box.ce.js.map +1 -1
- package/dist/components/gui/dialogbox/index.ce.js +53 -60
- package/dist/components/gui/dialogbox/index.ce.js.map +1 -1
- package/dist/components/gui/gameover.ce.js +39 -63
- package/dist/components/gui/gameover.ce.js.map +1 -1
- package/dist/components/gui/hud/hud.ce.js +21 -30
- package/dist/components/gui/hud/hud.ce.js.map +1 -1
- package/dist/components/gui/menu/equip-menu.ce.js +110 -164
- package/dist/components/gui/menu/equip-menu.ce.js.map +1 -1
- package/dist/components/gui/menu/exit-menu.ce.js +6 -5
- package/dist/components/gui/menu/exit-menu.ce.js.map +1 -1
- package/dist/components/gui/menu/items-menu.ce.js +49 -67
- package/dist/components/gui/menu/items-menu.ce.js.map +1 -1
- package/dist/components/gui/menu/main-menu.ce.js +72 -90
- package/dist/components/gui/menu/main-menu.ce.js.map +1 -1
- package/dist/components/gui/menu/options-menu.ce.js +5 -4
- package/dist/components/gui/menu/options-menu.ce.js.map +1 -1
- package/dist/components/gui/menu/skills-menu.ce.js +12 -17
- package/dist/components/gui/menu/skills-menu.ce.js.map +1 -1
- package/dist/components/gui/mobile/index.js +2 -2
- package/dist/components/gui/mobile/index.js.map +1 -1
- package/dist/components/gui/mobile/mobile.ce.js +5 -4
- package/dist/components/gui/mobile/mobile.ce.js.map +1 -1
- package/dist/components/gui/notification/notification.ce.js +22 -24
- package/dist/components/gui/notification/notification.ce.js.map +1 -1
- package/dist/components/gui/save-load.ce.js +70 -248
- package/dist/components/gui/save-load.ce.js.map +1 -1
- package/dist/components/gui/shop/shop.ce.js +87 -125
- package/dist/components/gui/shop/shop.ce.js.map +1 -1
- package/dist/components/gui/title-screen.ce.js +42 -68
- 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 +41 -44
- package/dist/components/prebuilt/hp-bar.ce.js.map +1 -1
- package/dist/components/prebuilt/light-halo.ce.js +35 -59
- package/dist/components/prebuilt/light-halo.ce.js.map +1 -1
- package/dist/components/scenes/canvas.ce.js +157 -21
- package/dist/components/scenes/canvas.ce.js.map +1 -1
- package/dist/components/scenes/draw-map.ce.js +19 -29
- package/dist/components/scenes/draw-map.ce.js.map +1 -1
- package/dist/components/scenes/event-layer.ce.js +9 -8
- 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 +21 -20
- package/dist/module.js +4 -1
- package/dist/module.js.map +1 -1
- package/dist/node_modules/.pnpm/{@signe_di@2.9.0 → @signe_di@3.0.1}/node_modules/@signe/di/dist/index.js +7 -117
- 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@2.9.0 → @signe_sync@3.0.1}/node_modules/@signe/sync/dist/index.js +57 -141
- 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 +27 -27
- 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 +9 -4
- package/dist/services/mmorpg.js.map +1 -1
- package/dist/services/save.js.map +1 -1
- package/dist/services/save.spec.d.ts +1 -0
- package/dist/services/standalone.js +1 -1
- package/dist/services/standalone.js.map +1 -1
- package/dist/utils/getEntityProp.js +4 -3
- package/dist/utils/getEntityProp.js.map +1 -1
- 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 +13 -14
- package/src/Game/AnimationManager.spec.ts +30 -0
- package/src/Game/AnimationManager.ts +22 -10
- package/src/Game/Map.ts +91 -2
- package/src/Game/Object.ts +148 -69
- 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 +63 -2
- package/src/RpgClientEngine.ts +173 -25
- package/src/components/character.ce +422 -15
- 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 +111 -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/gui/dialogbox/index.ce +15 -6
- 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/src/services/save.spec.ts +127 -0
- package/src/utils/getEntityProp.spec.ts +96 -0
- package/src/utils/getEntityProp.ts +4 -3
- package/src/utils/readPropValue.ts +16 -0
- package/dist/node_modules/.pnpm/@signe_di@2.9.0/node_modules/@signe/di/dist/index.js.map +0 -1
- package/dist/node_modules/.pnpm/@signe_reactive@2.8.3/node_modules/@signe/reactive/dist/index.js +0 -457
- package/dist/node_modules/.pnpm/@signe_reactive@2.8.3/node_modules/@signe/reactive/dist/index.js.map +0 -1
- package/dist/node_modules/.pnpm/@signe_reactive@2.9.0/node_modules/@signe/reactive/dist/index.js +0 -463
- package/dist/node_modules/.pnpm/@signe_reactive@2.9.0/node_modules/@signe/reactive/dist/index.js.map +0 -1
- package/dist/node_modules/.pnpm/@signe_room@2.9.0/node_modules/@signe/room/dist/index.js +0 -2191
- package/dist/node_modules/.pnpm/@signe_room@2.9.0/node_modules/@signe/room/dist/index.js.map +0 -1
- package/dist/node_modules/.pnpm/@signe_sync@2.9.0/node_modules/@signe/sync/dist/chunk-7QVYU63E.js +0 -10
- package/dist/node_modules/.pnpm/@signe_sync@2.9.0/node_modules/@signe/sync/dist/chunk-7QVYU63E.js.map +0 -1
- package/dist/node_modules/.pnpm/@signe_sync@2.9.0/node_modules/@signe/sync/dist/client/index.js +0 -91
- package/dist/node_modules/.pnpm/@signe_sync@2.9.0/node_modules/@signe/sync/dist/client/index.js.map +0 -1
- package/dist/node_modules/.pnpm/@signe_sync@2.9.0/node_modules/@signe/sync/dist/index.js.map +0 -1
- package/dist/node_modules/.pnpm/dset@3.1.4/node_modules/dset/dist/index.js +0 -14
- package/dist/node_modules/.pnpm/dset@3.1.4/node_modules/dset/dist/index.js.map +0 -1
package/dist/RpgClient.d.ts
CHANGED
|
@@ -5,6 +5,23 @@ import { RpgClientObject } from './Game/Object';
|
|
|
5
5
|
import { MapPhysicsEntityContext, MapPhysicsInitContext } from '@rpgjs/common';
|
|
6
6
|
type RpgComponent = RpgClientObject;
|
|
7
7
|
type SceneMap = Container;
|
|
8
|
+
export type SpriteComponentConfig = ComponentFunction | {
|
|
9
|
+
component: ComponentFunction;
|
|
10
|
+
props?: Record<string, any> | ((object: RpgClientObject) => Record<string, any>);
|
|
11
|
+
data?: Record<string, any> | ((object: RpgClientObject) => Record<string, any>);
|
|
12
|
+
dependencies?: (object: RpgClientObject) => any[];
|
|
13
|
+
};
|
|
14
|
+
export interface RpgSpriteBeforeRemoveContext {
|
|
15
|
+
reason?: string;
|
|
16
|
+
data?: any;
|
|
17
|
+
transition?: {
|
|
18
|
+
animation?: string;
|
|
19
|
+
graphic?: string | string[];
|
|
20
|
+
duration?: number;
|
|
21
|
+
effect?: string;
|
|
22
|
+
};
|
|
23
|
+
timeoutMs?: number;
|
|
24
|
+
}
|
|
8
25
|
export interface RpgClientEngineHooks {
|
|
9
26
|
/**
|
|
10
27
|
* When the engine is started. If you send false, you prevent the client from connecting to the server
|
|
@@ -74,7 +91,7 @@ export interface RpgSpriteHooks {
|
|
|
74
91
|
* }
|
|
75
92
|
* ```
|
|
76
93
|
*/
|
|
77
|
-
componentsBehind?:
|
|
94
|
+
componentsBehind?: SpriteComponentConfig[];
|
|
78
95
|
/**
|
|
79
96
|
* Array of components to render in front of the sprite
|
|
80
97
|
* These components will be displayed with a higher z-index than the sprite itself
|
|
@@ -88,7 +105,27 @@ export interface RpgSpriteHooks {
|
|
|
88
105
|
* }
|
|
89
106
|
* ```
|
|
90
107
|
*/
|
|
91
|
-
componentsInFront?:
|
|
108
|
+
componentsInFront?: SpriteComponentConfig[];
|
|
109
|
+
/**
|
|
110
|
+
* Reusable sprite components addressable by server-side component definitions.
|
|
111
|
+
*
|
|
112
|
+
* The server sends only the component id and serializable props. The client
|
|
113
|
+
* registry maps that id to the CanvasEngine component that renders it.
|
|
114
|
+
*
|
|
115
|
+
* @prop {Record<string, ComponentFunction>} [components]
|
|
116
|
+
* @memberof RpgSpriteHooks
|
|
117
|
+
* @example
|
|
118
|
+
* ```ts
|
|
119
|
+
* import GuildBadge from './components/guild-badge.ce'
|
|
120
|
+
*
|
|
121
|
+
* const sprite: RpgSpriteHooks = {
|
|
122
|
+
* components: {
|
|
123
|
+
* guildBadge: GuildBadge
|
|
124
|
+
* }
|
|
125
|
+
* }
|
|
126
|
+
* ```
|
|
127
|
+
*/
|
|
128
|
+
components?: Record<string, ComponentFunction>;
|
|
92
129
|
/**
|
|
93
130
|
* As soon as the sprite is initialized
|
|
94
131
|
*
|
|
@@ -103,6 +140,17 @@ export interface RpgSpriteHooks {
|
|
|
103
140
|
* @memberof RpgSpriteHooks
|
|
104
141
|
*/
|
|
105
142
|
onDestroy?: (sprite: RpgComponent) => any;
|
|
143
|
+
/**
|
|
144
|
+
* Called when a sprite removal is requested, before it disappears from the scene.
|
|
145
|
+
*
|
|
146
|
+
* Return a promise to keep the sprite visible while an animation, effect, or
|
|
147
|
+
* sound transition is running. The server still owns gameplay removal and
|
|
148
|
+
* uses the timeout carried by the remove request as a safety limit.
|
|
149
|
+
*
|
|
150
|
+
* @prop { (sprite: RpgSprite, context: RpgSpriteBeforeRemoveContext) => any } [onBeforeRemove]
|
|
151
|
+
* @memberof RpgSpriteHooks
|
|
152
|
+
*/
|
|
153
|
+
onBeforeRemove?: (sprite: RpgComponent, context: RpgSpriteBeforeRemoveContext) => any;
|
|
106
154
|
/**
|
|
107
155
|
* As soon as a data is changed on the server side (the name for example), you are able to know the new data but also the old data.
|
|
108
156
|
*
|
|
@@ -457,6 +505,13 @@ export interface RpgClient {
|
|
|
457
505
|
* ```
|
|
458
506
|
*/
|
|
459
507
|
attachToSprite?: boolean;
|
|
508
|
+
/**
|
|
509
|
+
* Vue v4 compatibility alias for `attachToSprite`.
|
|
510
|
+
*
|
|
511
|
+
* Prefer `attachToSprite` in v5 projects. This is read by `@rpgjs/vue`
|
|
512
|
+
* for Vue GUI components migrated from the v4 GUI API.
|
|
513
|
+
*/
|
|
514
|
+
rpgAttachToSprite?: boolean;
|
|
460
515
|
} | any)[];
|
|
461
516
|
/**
|
|
462
517
|
* Array containing the list of sounds
|
|
@@ -1,9 +1,19 @@
|
|
|
1
|
+
import { Trigger } from 'canvasengine';
|
|
1
2
|
import { AbstractWebsocket } from './services/AbstractSocket';
|
|
2
3
|
import { Direction } from '@rpgjs/common';
|
|
3
4
|
import { RpgClientMap } from './Game/Map';
|
|
4
5
|
import { AnimationManager } from './Game/AnimationManager';
|
|
5
6
|
import { Observable } from 'rxjs';
|
|
6
7
|
import * as PIXI from "pixi.js";
|
|
8
|
+
type ConfigurableTrigger<T> = Omit<Trigger<T>, "start"> & {
|
|
9
|
+
start(config?: T): Promise<void>;
|
|
10
|
+
};
|
|
11
|
+
type MapShakeOptions = {
|
|
12
|
+
intensity?: number;
|
|
13
|
+
duration?: number;
|
|
14
|
+
frequency?: number;
|
|
15
|
+
direction?: string;
|
|
16
|
+
};
|
|
7
17
|
export declare class RpgClientEngine<T = any> {
|
|
8
18
|
context: any;
|
|
9
19
|
private guiService;
|
|
@@ -17,7 +27,7 @@ export declare class RpgClientEngine<T = any> {
|
|
|
17
27
|
stopProcessingInput: boolean;
|
|
18
28
|
width: import('canvasengine').WritableSignal<string>;
|
|
19
29
|
height: import('canvasengine').WritableSignal<string>;
|
|
20
|
-
spritesheets: Map<string, any>;
|
|
30
|
+
spritesheets: Map<string | number, any>;
|
|
21
31
|
sounds: Map<string, any>;
|
|
22
32
|
componentAnimations: any[];
|
|
23
33
|
private spritesheetResolver?;
|
|
@@ -32,10 +42,11 @@ export declare class RpgClientEngine<T = any> {
|
|
|
32
42
|
playerIdSignal: import('canvasengine').WritableSignal<string | null>;
|
|
33
43
|
spriteComponentsBehind: import('canvasengine').WritableArraySignal<any[]>;
|
|
34
44
|
spriteComponentsInFront: import('canvasengine').WritableArraySignal<any[]>;
|
|
45
|
+
spriteComponents: Map<string, any>;
|
|
35
46
|
/** ID of the sprite that the camera should follow. null means follow the current player */
|
|
36
47
|
cameraFollowTargetId: import('canvasengine').WritableSignal<string | null>;
|
|
37
48
|
/** Trigger for map shake animation */
|
|
38
|
-
mapShakeTrigger:
|
|
49
|
+
mapShakeTrigger: ConfigurableTrigger<MapShakeOptions>;
|
|
39
50
|
controlsReady: import('canvasengine').WritableSignal<undefined>;
|
|
40
51
|
gamePause: import('canvasengine').WritableSignal<boolean>;
|
|
41
52
|
private predictionEnabled;
|
|
@@ -175,7 +186,7 @@ export declare class RpgClientEngine<T = any> {
|
|
|
175
186
|
* });
|
|
176
187
|
* ```
|
|
177
188
|
*/
|
|
178
|
-
setSpritesheetResolver(resolver: (id: string) => any | Promise<any>): void;
|
|
189
|
+
setSpritesheetResolver(resolver: (id: string | number) => any | Promise<any>): void;
|
|
179
190
|
/**
|
|
180
191
|
* Get a spritesheet by ID, using resolver if not found in cache
|
|
181
192
|
*
|
|
@@ -183,7 +194,7 @@ export declare class RpgClientEngine<T = any> {
|
|
|
183
194
|
* If not found and a resolver is set, it calls the resolver to create the spritesheet.
|
|
184
195
|
* The resolved spritesheet is automatically cached for future use.
|
|
185
196
|
*
|
|
186
|
-
* @param id - The spritesheet ID to retrieve
|
|
197
|
+
* @param id - The spritesheet ID or legacy tile ID to retrieve
|
|
187
198
|
* @returns The spritesheet if found or created, or undefined if not found and no resolver
|
|
188
199
|
* @returns Promise<any> if the resolver is asynchronous
|
|
189
200
|
*
|
|
@@ -196,7 +207,7 @@ export declare class RpgClientEngine<T = any> {
|
|
|
196
207
|
* const spritesheet = await engine.getSpriteSheet('dynamic-sprite');
|
|
197
208
|
* ```
|
|
198
209
|
*/
|
|
199
|
-
getSpriteSheet(id: string): any | Promise<any>;
|
|
210
|
+
getSpriteSheet(id: string | number): any | Promise<any>;
|
|
200
211
|
/**
|
|
201
212
|
* Add a sound to the engine
|
|
202
213
|
*
|
|
@@ -451,6 +462,30 @@ export declare class RpgClientEngine<T = any> {
|
|
|
451
462
|
props: (object: any) => any;
|
|
452
463
|
dependencies?: (object: any) => any[];
|
|
453
464
|
}): any;
|
|
465
|
+
/**
|
|
466
|
+
* Register a reusable sprite component that can be addressed by the server.
|
|
467
|
+
*
|
|
468
|
+
* Server-side component definitions only carry the component id and
|
|
469
|
+
* serializable props. The client registry maps that id to the CanvasEngine
|
|
470
|
+
* component that performs the actual rendering.
|
|
471
|
+
*
|
|
472
|
+
* @param id - Stable component id used by server component definitions
|
|
473
|
+
* @param component - CanvasEngine component to render for this id
|
|
474
|
+
* @returns The registered component
|
|
475
|
+
*
|
|
476
|
+
* @example
|
|
477
|
+
* ```ts
|
|
478
|
+
* engine.registerSpriteComponent('guildBadge', GuildBadgeComponent);
|
|
479
|
+
* ```
|
|
480
|
+
*/
|
|
481
|
+
registerSpriteComponent(id: string, component: any): any;
|
|
482
|
+
/**
|
|
483
|
+
* Get a reusable sprite component by id.
|
|
484
|
+
*
|
|
485
|
+
* @param id - Component id registered on the client
|
|
486
|
+
* @returns The CanvasEngine component, or undefined when missing
|
|
487
|
+
*/
|
|
488
|
+
getSpriteComponent(id: string): any;
|
|
454
489
|
/**
|
|
455
490
|
* Add a component animation to the engine
|
|
456
491
|
*
|
|
@@ -520,9 +555,12 @@ export declare class RpgClientEngine<T = any> {
|
|
|
520
555
|
* duration: 1000,
|
|
521
556
|
* onFinish: () => console.log('Fade complete')
|
|
522
557
|
* });
|
|
558
|
+
*
|
|
559
|
+
* // Wait until the transition component calls onFinish
|
|
560
|
+
* await engine.startTransition('fade', { duration: 1000 });
|
|
523
561
|
* ```
|
|
524
562
|
*/
|
|
525
|
-
startTransition(id: string, props?: any): void
|
|
563
|
+
startTransition(id: string, props?: any): Promise<void>;
|
|
526
564
|
processInput({ input }: {
|
|
527
565
|
input: Direction;
|
|
528
566
|
}): Promise<void>;
|
|
@@ -584,6 +622,22 @@ export declare class RpgClientEngine<T = any> {
|
|
|
584
622
|
* ```
|
|
585
623
|
*/
|
|
586
624
|
clearClientPredictionStates(): void;
|
|
625
|
+
/**
|
|
626
|
+
* Stop local movement immediately and discard pending predicted movement.
|
|
627
|
+
*
|
|
628
|
+
* Use this before a blocking action such as an A-RPG attack, dialog, dash
|
|
629
|
+
* startup, or any client-side state where already buffered movement inputs
|
|
630
|
+
* must not be replayed after server reconciliation.
|
|
631
|
+
*
|
|
632
|
+
* @param player - Player object to stop. Defaults to the current player.
|
|
633
|
+
* @returns `true` when a player was found and interrupted.
|
|
634
|
+
*
|
|
635
|
+
* @example
|
|
636
|
+
* ```ts
|
|
637
|
+
* engine.interruptCurrentPlayerMovement();
|
|
638
|
+
* ```
|
|
639
|
+
*/
|
|
640
|
+
interruptCurrentPlayerMovement(player?: any): boolean;
|
|
587
641
|
/**
|
|
588
642
|
* Trigger a flash animation on a sprite
|
|
589
643
|
*
|
|
@@ -681,3 +735,4 @@ export declare class RpgClientEngine<T = any> {
|
|
|
681
735
|
*/
|
|
682
736
|
clear(): void;
|
|
683
737
|
}
|
|
738
|
+
export {};
|
package/dist/RpgClientEngine.js
CHANGED
|
@@ -1,19 +1,24 @@
|
|
|
1
1
|
import { inject } from "./core/inject.js";
|
|
2
2
|
import { WebSocketToken } from "./services/AbstractSocket.js";
|
|
3
|
+
import { getCanMoveValue } from "./utils/readPropValue.js";
|
|
3
4
|
import { SaveClientService } from "./services/save.js";
|
|
4
5
|
import { RpgGui } from "./Gui/Gui.js";
|
|
5
|
-
import
|
|
6
|
+
import __ce_component from "./components/scenes/canvas.ce.js";
|
|
6
7
|
import { LoadMapToken } from "./services/loadMap.js";
|
|
7
8
|
import { RpgSound } from "./Sound.js";
|
|
8
9
|
import { RpgResource } from "./Resource.js";
|
|
9
|
-
import { load } from "./node_modules/.pnpm/@signe_sync@
|
|
10
|
+
import { load } from "./node_modules/.pnpm/@signe_sync@3.0.1/node_modules/@signe/sync/dist/index.js";
|
|
10
11
|
import { RpgClientMap } from "./Game/Map.js";
|
|
11
12
|
import { AnimationManager } from "./Game/AnimationManager.js";
|
|
12
13
|
import { GlobalConfigToken } from "./module.js";
|
|
13
14
|
import { PrebuiltComponentAnimations } from "./components/animations/index.js";
|
|
15
|
+
import __ce_component$1 from "./components/dynamics/text.ce.js";
|
|
16
|
+
import __ce_component$2 from "./components/dynamics/bar.ce.js";
|
|
17
|
+
import __ce_component$3 from "./components/dynamics/shape.ce.js";
|
|
18
|
+
import __ce_component$4 from "./components/dynamics/image.ce.js";
|
|
14
19
|
import { NotificationManager } from "./Gui/NotificationManager.js";
|
|
15
20
|
import { Howl, bootstrapCanvas, signal, trigger } from "canvasengine";
|
|
16
|
-
import { Direction, ModulesToken, PredictionController } from "@rpgjs/common";
|
|
21
|
+
import { Direction, ModulesToken, PredictionController, normalizeLightingState } from "@rpgjs/common";
|
|
17
22
|
import { BehaviorSubject, combineLatest, filter, lastValueFrom, switchMap, take } from "rxjs";
|
|
18
23
|
import * as PIXI from "pixi.js";
|
|
19
24
|
//#region src/RpgClientEngine.ts
|
|
@@ -30,6 +35,7 @@ var RpgClientEngine = class {
|
|
|
30
35
|
this.playerIdSignal = signal(null);
|
|
31
36
|
this.spriteComponentsBehind = signal([]);
|
|
32
37
|
this.spriteComponentsInFront = signal([]);
|
|
38
|
+
this.spriteComponents = /* @__PURE__ */ new Map();
|
|
33
39
|
this.cameraFollowTargetId = signal(null);
|
|
34
40
|
this.mapShakeTrigger = trigger();
|
|
35
41
|
this.controlsReady = signal(void 0);
|
|
@@ -72,6 +78,12 @@ var RpgClientEngine = class {
|
|
|
72
78
|
id: "animation",
|
|
73
79
|
component: PrebuiltComponentAnimations.Animation
|
|
74
80
|
});
|
|
81
|
+
this.registerSpriteComponent("rpg:text", __ce_component$1);
|
|
82
|
+
this.registerSpriteComponent("rpg:hpBar", __ce_component$2);
|
|
83
|
+
this.registerSpriteComponent("rpg:spBar", __ce_component$2);
|
|
84
|
+
this.registerSpriteComponent("rpg:bar", __ce_component$2);
|
|
85
|
+
this.registerSpriteComponent("rpg:shape", __ce_component$3);
|
|
86
|
+
this.registerSpriteComponent("rpg:image", __ce_component$4);
|
|
75
87
|
this.predictionEnabled = this.globalConfig?.prediction?.enabled !== false;
|
|
76
88
|
this.initializePredictionController();
|
|
77
89
|
}
|
|
@@ -122,7 +134,7 @@ var RpgClientEngine = class {
|
|
|
122
134
|
this.sceneMap.loadPhysic();
|
|
123
135
|
this.selector = document.body.querySelector("#rpg");
|
|
124
136
|
const bootstrapOptions = this.globalConfig?.bootstrapCanvasOptions;
|
|
125
|
-
const { app, canvasElement } = await bootstrapCanvas(this.selector,
|
|
137
|
+
const { app, canvasElement } = await bootstrapCanvas(this.selector, __ce_component, bootstrapOptions);
|
|
126
138
|
this.canvasApp = app;
|
|
127
139
|
this.canvasElement = canvasElement;
|
|
128
140
|
this.renderer = app.renderer;
|
|
@@ -163,7 +175,7 @@ var RpgClientEngine = class {
|
|
|
163
175
|
});
|
|
164
176
|
this.tickSubscriptions.push(tickSubscription);
|
|
165
177
|
await this.webSocket.connection(() => {
|
|
166
|
-
inject(SaveClientService).initialize(
|
|
178
|
+
inject(SaveClientService).initialize();
|
|
167
179
|
this.initListeners();
|
|
168
180
|
this.guiService._initialize();
|
|
169
181
|
this.startPingPong();
|
|
@@ -227,7 +239,8 @@ var RpgClientEngine = class {
|
|
|
227
239
|
if ((payload.events || this.sceneMap.events()) !== void 0) this.eventsReceived$.next(true);
|
|
228
240
|
});
|
|
229
241
|
this.webSocket.on("pong", (data) => {
|
|
230
|
-
|
|
242
|
+
const now = Date.now();
|
|
243
|
+
this.rtt = now - data.clientTime;
|
|
231
244
|
const estimatedTicksInFlight = Math.floor(this.rtt / 2 / (1e3 / 60));
|
|
232
245
|
const estimatedServerTickNow = data.serverTick + estimatedTicksInFlight;
|
|
233
246
|
if (this.inputFrameCounter > 0) this.frameOffset = estimatedServerTickNow - data.clientFrame;
|
|
@@ -235,6 +248,7 @@ var RpgClientEngine = class {
|
|
|
235
248
|
});
|
|
236
249
|
this.webSocket.on("changeMap", (data) => {
|
|
237
250
|
this.sceneResetQueued = true;
|
|
251
|
+
this.sceneMap.clearLightSpots();
|
|
238
252
|
this.cameraFollowTargetId.set(null);
|
|
239
253
|
const transferToken = typeof data?.transferToken === "string" ? data.transferToken : void 0;
|
|
240
254
|
this.loadScene(data.mapId, transferToken);
|
|
@@ -249,10 +263,15 @@ var RpgClientEngine = class {
|
|
|
249
263
|
this.notificationManager.add(data);
|
|
250
264
|
});
|
|
251
265
|
this.webSocket.on("setAnimation", (data) => {
|
|
252
|
-
const { animationName, nbTimes, object, graphic } = data;
|
|
253
|
-
const player = this.sceneMap.getObjectById(object);
|
|
254
|
-
if (
|
|
255
|
-
|
|
266
|
+
const { animationName, nbTimes, object, graphic, restoreAnimationName, restoreGraphics } = data;
|
|
267
|
+
const player = object ? this.sceneMap.getObjectById(object) : void 0;
|
|
268
|
+
if (!player) return;
|
|
269
|
+
const restoreOptions = {
|
|
270
|
+
restoreAnimationName,
|
|
271
|
+
restoreGraphics
|
|
272
|
+
};
|
|
273
|
+
if (graphic !== void 0) player.setAnimation(animationName, graphic, nbTimes, restoreOptions);
|
|
274
|
+
else player.setAnimation(animationName, nbTimes, restoreOptions);
|
|
256
275
|
});
|
|
257
276
|
this.webSocket.on("playSound", (data) => {
|
|
258
277
|
const { soundId, volume, loop } = data;
|
|
@@ -314,6 +333,10 @@ var RpgClientEngine = class {
|
|
|
314
333
|
seed: raw.seed
|
|
315
334
|
});
|
|
316
335
|
});
|
|
336
|
+
this.webSocket.on("lightingState", (data) => {
|
|
337
|
+
const raw = data && typeof data === "object" && "value" in data ? data.value : data;
|
|
338
|
+
this.sceneMap.lightingState.set(normalizeLightingState(raw));
|
|
339
|
+
});
|
|
317
340
|
this.webSocket.on("open", () => {
|
|
318
341
|
this.hooks.callHooks("client-engine-onConnected", this, this.socket).subscribe();
|
|
319
342
|
this.startPingPong();
|
|
@@ -403,7 +426,7 @@ var RpgClientEngine = class {
|
|
|
403
426
|
query: transferToken ? { transferToken } : void 0
|
|
404
427
|
});
|
|
405
428
|
await this.webSocket.reconnect(() => {
|
|
406
|
-
inject(SaveClientService).initialize(
|
|
429
|
+
inject(SaveClientService).initialize();
|
|
407
430
|
this.initListeners();
|
|
408
431
|
this.guiService._initialize();
|
|
409
432
|
});
|
|
@@ -458,7 +481,7 @@ var RpgClientEngine = class {
|
|
|
458
481
|
* If not found and a resolver is set, it calls the resolver to create the spritesheet.
|
|
459
482
|
* The resolved spritesheet is automatically cached for future use.
|
|
460
483
|
*
|
|
461
|
-
* @param id - The spritesheet ID to retrieve
|
|
484
|
+
* @param id - The spritesheet ID or legacy tile ID to retrieve
|
|
462
485
|
* @returns The spritesheet if found or created, or undefined if not found and no resolver
|
|
463
486
|
* @returns Promise<any> if the resolver is asynchronous
|
|
464
487
|
*
|
|
@@ -807,6 +830,35 @@ var RpgClientEngine = class {
|
|
|
807
830
|
return component;
|
|
808
831
|
}
|
|
809
832
|
/**
|
|
833
|
+
* Register a reusable sprite component that can be addressed by the server.
|
|
834
|
+
*
|
|
835
|
+
* Server-side component definitions only carry the component id and
|
|
836
|
+
* serializable props. The client registry maps that id to the CanvasEngine
|
|
837
|
+
* component that performs the actual rendering.
|
|
838
|
+
*
|
|
839
|
+
* @param id - Stable component id used by server component definitions
|
|
840
|
+
* @param component - CanvasEngine component to render for this id
|
|
841
|
+
* @returns The registered component
|
|
842
|
+
*
|
|
843
|
+
* @example
|
|
844
|
+
* ```ts
|
|
845
|
+
* engine.registerSpriteComponent('guildBadge', GuildBadgeComponent);
|
|
846
|
+
* ```
|
|
847
|
+
*/
|
|
848
|
+
registerSpriteComponent(id, component) {
|
|
849
|
+
this.spriteComponents.set(id, component);
|
|
850
|
+
return component;
|
|
851
|
+
}
|
|
852
|
+
/**
|
|
853
|
+
* Get a reusable sprite component by id.
|
|
854
|
+
*
|
|
855
|
+
* @param id - Component id registered on the client
|
|
856
|
+
* @returns The CanvasEngine component, or undefined when missing
|
|
857
|
+
*/
|
|
858
|
+
getSpriteComponent(id) {
|
|
859
|
+
return this.spriteComponents.get(id);
|
|
860
|
+
}
|
|
861
|
+
/**
|
|
810
862
|
* Add a component animation to the engine
|
|
811
863
|
*
|
|
812
864
|
* Component animations are temporary visual effects that can be displayed
|
|
@@ -882,13 +934,34 @@ var RpgClientEngine = class {
|
|
|
882
934
|
* duration: 1000,
|
|
883
935
|
* onFinish: () => console.log('Fade complete')
|
|
884
936
|
* });
|
|
937
|
+
*
|
|
938
|
+
* // Wait until the transition component calls onFinish
|
|
939
|
+
* await engine.startTransition('fade', { duration: 1000 });
|
|
885
940
|
* ```
|
|
886
941
|
*/
|
|
887
942
|
startTransition(id, props = {}) {
|
|
888
943
|
if (!this.guiService.exists(id)) throw new Error(`Transition with id ${id} not found. Make sure to add it using engine.addTransition() or in your module's transitions property.`);
|
|
889
|
-
|
|
944
|
+
return new Promise((resolve) => {
|
|
945
|
+
let finished = false;
|
|
946
|
+
const finish = (data) => {
|
|
947
|
+
if (finished) return;
|
|
948
|
+
finished = true;
|
|
949
|
+
props?.onFinish?.(data);
|
|
950
|
+
resolve();
|
|
951
|
+
};
|
|
952
|
+
this.guiService.display(id, {
|
|
953
|
+
...props,
|
|
954
|
+
onFinish: finish
|
|
955
|
+
});
|
|
956
|
+
});
|
|
890
957
|
}
|
|
891
958
|
async processInput({ input }) {
|
|
959
|
+
if (this.stopProcessingInput) return;
|
|
960
|
+
const currentPlayer = this.sceneMap.getCurrentPlayer();
|
|
961
|
+
if (!(!currentPlayer || getCanMoveValue(currentPlayer))) {
|
|
962
|
+
this.interruptCurrentPlayerMovement(currentPlayer);
|
|
963
|
+
return;
|
|
964
|
+
}
|
|
892
965
|
const timestamp = Date.now();
|
|
893
966
|
let frame;
|
|
894
967
|
let tick;
|
|
@@ -905,7 +978,6 @@ var RpgClientEngine = class {
|
|
|
905
978
|
input,
|
|
906
979
|
playerId: this.playerId
|
|
907
980
|
}).subscribe();
|
|
908
|
-
const currentPlayer = this.sceneMap.getCurrentPlayer();
|
|
909
981
|
const bodyReady = this.ensureCurrentPlayerBody();
|
|
910
982
|
if (currentPlayer && bodyReady) {
|
|
911
983
|
currentPlayer.changeDirection(input);
|
|
@@ -920,6 +992,8 @@ var RpgClientEngine = class {
|
|
|
920
992
|
}
|
|
921
993
|
processAction({ action }) {
|
|
922
994
|
if (this.stopProcessingInput) return;
|
|
995
|
+
const currentPlayer = this.sceneMap.getCurrentPlayer();
|
|
996
|
+
if (!(!currentPlayer || getCanMoveValue(currentPlayer))) return;
|
|
923
997
|
this.hooks.callHooks("client-engine-onInput", this, {
|
|
924
998
|
input: "action",
|
|
925
999
|
playerId: this.playerId
|
|
@@ -1008,6 +1082,11 @@ var RpgClientEngine = class {
|
|
|
1008
1082
|
}
|
|
1009
1083
|
flushPendingMovePath() {
|
|
1010
1084
|
if (!this.predictionEnabled || !this.prediction) return;
|
|
1085
|
+
const player = this.sceneMap?.getCurrentPlayer?.();
|
|
1086
|
+
if (player && !getCanMoveValue(player)) {
|
|
1087
|
+
this.interruptCurrentPlayerMovement(player);
|
|
1088
|
+
return;
|
|
1089
|
+
}
|
|
1011
1090
|
const pendingInputs = this.prediction.getPendingInputs();
|
|
1012
1091
|
if (pendingInputs.length === 0) return;
|
|
1013
1092
|
const latest = pendingInputs[pendingInputs.length - 1];
|
|
@@ -1124,6 +1203,31 @@ var RpgClientEngine = class {
|
|
|
1124
1203
|
this.lastMovePathSentFrame = 0;
|
|
1125
1204
|
}
|
|
1126
1205
|
/**
|
|
1206
|
+
* Stop local movement immediately and discard pending predicted movement.
|
|
1207
|
+
*
|
|
1208
|
+
* Use this before a blocking action such as an A-RPG attack, dialog, dash
|
|
1209
|
+
* startup, or any client-side state where already buffered movement inputs
|
|
1210
|
+
* must not be replayed after server reconciliation.
|
|
1211
|
+
*
|
|
1212
|
+
* @param player - Player object to stop. Defaults to the current player.
|
|
1213
|
+
* @returns `true` when a player was found and interrupted.
|
|
1214
|
+
*
|
|
1215
|
+
* @example
|
|
1216
|
+
* ```ts
|
|
1217
|
+
* engine.interruptCurrentPlayerMovement();
|
|
1218
|
+
* ```
|
|
1219
|
+
*/
|
|
1220
|
+
interruptCurrentPlayerMovement(player = this.sceneMap?.getCurrentPlayer?.()) {
|
|
1221
|
+
if (!player) return false;
|
|
1222
|
+
this.sceneMap?.stopMovement?.(player);
|
|
1223
|
+
this.prediction?.clearPendingInputs();
|
|
1224
|
+
this.pendingPredictionFrames = [];
|
|
1225
|
+
this.lastInputTime = 0;
|
|
1226
|
+
this.lastMovePathSentAt = Date.now();
|
|
1227
|
+
this.lastMovePathSentFrame = this.inputFrameCounter;
|
|
1228
|
+
return true;
|
|
1229
|
+
}
|
|
1230
|
+
/**
|
|
1127
1231
|
* Trigger a flash animation on a sprite
|
|
1128
1232
|
*
|
|
1129
1233
|
* This method allows you to trigger a flash effect on any sprite from client-side code.
|
|
@@ -1205,6 +1309,10 @@ var RpgClientEngine = class {
|
|
|
1205
1309
|
reconcilePrediction(authoritativeState, pendingInputs) {
|
|
1206
1310
|
const player = this.getCurrentPlayer();
|
|
1207
1311
|
if (!player) return;
|
|
1312
|
+
if (!getCanMoveValue(player)) {
|
|
1313
|
+
this.interruptCurrentPlayerMovement(player);
|
|
1314
|
+
return;
|
|
1315
|
+
}
|
|
1208
1316
|
this.sceneMap.stopMovement(player);
|
|
1209
1317
|
this.applyAuthoritativeState(authoritativeState);
|
|
1210
1318
|
if (!pendingInputs.length) return;
|