@rpgjs/client 5.0.0-alpha.2 → 5.0.0-alpha.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Game/AnimationManager.d.ts +8 -0
- package/dist/Game/Map.d.ts +7 -1
- package/dist/Gui/Gui.d.ts +128 -5
- package/dist/RpgClient.d.ts +217 -59
- package/dist/RpgClientEngine.d.ts +345 -6
- package/dist/Sound.d.ts +199 -0
- package/dist/components/animations/index.d.ts +4 -0
- package/dist/components/dynamics/parse-value.d.ts +1 -0
- package/dist/components/gui/index.d.ts +3 -3
- package/dist/components/index.d.ts +3 -1
- package/dist/components/prebuilt/index.d.ts +18 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.js +9 -4
- package/dist/index.js.map +1 -1
- package/dist/index10.js +149 -4
- package/dist/index10.js.map +1 -1
- package/dist/index11.js +21 -7
- package/dist/index11.js.map +1 -1
- package/dist/index12.js +6 -4
- package/dist/index12.js.map +1 -1
- package/dist/index13.js +11 -14
- package/dist/index13.js.map +1 -1
- package/dist/index14.js +8 -40
- package/dist/index14.js.map +1 -1
- package/dist/index15.js +187 -180
- package/dist/index15.js.map +1 -1
- package/dist/index16.js +104 -7
- package/dist/index16.js.map +1 -1
- package/dist/index17.js +82 -372
- package/dist/index17.js.map +1 -1
- package/dist/index18.js +361 -26
- package/dist/index18.js.map +1 -1
- package/dist/index19.js +46 -20
- package/dist/index19.js.map +1 -1
- package/dist/index2.js +683 -32
- package/dist/index2.js.map +1 -1
- package/dist/index20.js +5 -2417
- package/dist/index20.js.map +1 -1
- package/dist/index21.js +383 -97
- package/dist/index21.js.map +1 -1
- package/dist/index22.js +41 -104
- package/dist/index22.js.map +1 -1
- package/dist/index23.js +21 -67
- package/dist/index23.js.map +1 -1
- package/dist/index24.js +2632 -20
- package/dist/index24.js.map +1 -1
- package/dist/index25.js +107 -34
- package/dist/index25.js.map +1 -1
- package/dist/index26.js +69 -3
- package/dist/index26.js.map +1 -1
- package/dist/index27.js +17 -318
- package/dist/index27.js.map +1 -1
- package/dist/index28.js +24 -22
- package/dist/index28.js.map +1 -1
- package/dist/index29.js +92 -8
- package/dist/index29.js.map +1 -1
- package/dist/index3.js +68 -8
- package/dist/index3.js.map +1 -1
- package/dist/index30.js +37 -7
- package/dist/index30.js.map +1 -1
- package/dist/index31.js +18 -168
- package/dist/index31.js.map +1 -1
- package/dist/index32.js +3 -499
- package/dist/index32.js.map +1 -1
- package/dist/index33.js +332 -9
- package/dist/index33.js.map +1 -1
- package/dist/index34.js +24 -4400
- package/dist/index34.js.map +1 -1
- package/dist/index35.js +6 -311
- package/dist/index35.js.map +1 -1
- package/dist/index36.js +8 -88
- package/dist/index36.js.map +1 -1
- package/dist/index37.js +182 -56
- package/dist/index37.js.map +1 -1
- package/dist/index38.js +500 -16
- package/dist/index38.js.map +1 -1
- package/dist/index39.js +10 -18
- package/dist/index39.js.map +1 -1
- package/dist/index4.js +23 -5
- package/dist/index4.js.map +1 -1
- package/dist/index40.js +7 -0
- package/dist/index40.js.map +1 -0
- package/dist/index41.js +3690 -0
- package/dist/index41.js.map +1 -0
- package/dist/index42.js +77 -0
- package/dist/index42.js.map +1 -0
- package/dist/index43.js +6 -0
- package/dist/index43.js.map +1 -0
- package/dist/index44.js +20 -0
- package/dist/index44.js.map +1 -0
- package/dist/index45.js +146 -0
- package/dist/index45.js.map +1 -0
- package/dist/index46.js +12 -0
- package/dist/index46.js.map +1 -0
- package/dist/index47.js +113 -0
- package/dist/index47.js.map +1 -0
- package/dist/index48.js +136 -0
- package/dist/index48.js.map +1 -0
- package/dist/index49.js +137 -0
- package/dist/index49.js.map +1 -0
- package/dist/index5.js +2 -1
- package/dist/index5.js.map +1 -1
- package/dist/index50.js +112 -0
- package/dist/index50.js.map +1 -0
- package/dist/index51.js +141 -0
- package/dist/index51.js.map +1 -0
- package/dist/index52.js +9 -0
- package/dist/index52.js.map +1 -0
- package/dist/index53.js +54 -0
- package/dist/index53.js.map +1 -0
- package/dist/index6.js +1 -1
- package/dist/index6.js.map +1 -1
- package/dist/index7.js +11 -3
- package/dist/index7.js.map +1 -1
- package/dist/index8.js +68 -7
- package/dist/index8.js.map +1 -1
- package/dist/index9.js +230 -15
- package/dist/index9.js.map +1 -1
- package/dist/presets/animation.d.ts +31 -0
- package/dist/presets/faceset.d.ts +30 -0
- package/dist/presets/index.d.ts +103 -0
- package/dist/presets/lpc.d.ts +89 -0
- package/dist/services/loadMap.d.ts +123 -2
- package/dist/services/mmorpg.d.ts +9 -4
- package/dist/services/standalone.d.ts +51 -2
- package/package.json +22 -18
- package/src/Game/{EffectManager.ts → AnimationManager.ts} +3 -2
- package/src/Game/Map.ts +20 -2
- package/src/Game/Object.ts +163 -9
- package/src/Gui/Gui.ts +300 -17
- package/src/RpgClient.ts +222 -58
- package/src/RpgClientEngine.ts +804 -36
- package/src/Sound.ts +253 -0
- package/src/components/{effects → animations}/animation.ce +3 -6
- package/src/components/{effects → animations}/index.ts +1 -1
- package/src/components/character.ce +165 -37
- package/src/components/dynamics/parse-value.ts +80 -0
- package/src/components/dynamics/text.ce +183 -0
- package/src/components/gui/box.ce +17 -0
- package/src/components/gui/dialogbox/index.ce +73 -35
- package/src/components/gui/dialogbox/selection.ce +16 -1
- package/src/components/gui/index.ts +3 -4
- package/src/components/index.ts +5 -1
- package/src/components/prebuilt/hp-bar.ce +255 -0
- package/src/components/prebuilt/index.ts +21 -0
- package/src/components/scenes/draw-map.ce +6 -23
- package/src/components/scenes/event-layer.ce +9 -3
- package/src/core/setup.ts +2 -0
- package/src/index.ts +5 -2
- package/src/module.ts +72 -6
- package/src/presets/animation.ts +46 -0
- package/src/presets/faceset.ts +60 -0
- package/src/presets/index.ts +7 -1
- package/src/presets/lpc.ts +108 -0
- package/src/services/loadMap.ts +132 -3
- package/src/services/mmorpg.ts +27 -5
- package/src/services/standalone.ts +68 -6
- package/tsconfig.json +1 -1
- package/vite.config.ts +1 -1
- package/dist/Game/EffectManager.d.ts +0 -5
- package/dist/components/effects/index.d.ts +0 -4
- package/src/components/scenes/element-map.ce +0 -23
- /package/src/components/{effects → animations}/hit.ce +0 -0
package/dist/Game/Map.d.ts
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import { RpgCommonMap } from '@rpgjs/common';
|
|
2
2
|
import { RpgClientPlayer } from './Player';
|
|
3
3
|
import { RpgClientEvent } from './Event';
|
|
4
|
-
|
|
4
|
+
import { RpgClientEngine } from '../RpgClientEngine';
|
|
5
|
+
export declare class RpgClientMap extends RpgCommonMap<any> {
|
|
6
|
+
engine: RpgClientEngine;
|
|
5
7
|
players: import('canvasengine').WritableObjectSignal<Record<string, RpgClientPlayer>>;
|
|
6
8
|
events: import('canvasengine').WritableObjectSignal<Record<string, RpgClientEvent>>;
|
|
9
|
+
currentPlayer: import('canvasengine').ComputedSignal<RpgClientPlayer>;
|
|
10
|
+
getCurrentPlayer(): RpgClientPlayer;
|
|
11
|
+
reset(): void;
|
|
12
|
+
stepPredictionTick(): void;
|
|
7
13
|
}
|
package/dist/Gui/Gui.d.ts
CHANGED
|
@@ -1,23 +1,146 @@
|
|
|
1
1
|
import { Context } from '@signe/di';
|
|
2
|
+
import { Signal, WritableSignal } from 'canvasengine';
|
|
3
|
+
import { Subscription } from 'rxjs';
|
|
2
4
|
interface GuiOptions {
|
|
3
|
-
name
|
|
5
|
+
name?: string;
|
|
6
|
+
id?: string;
|
|
4
7
|
component: any;
|
|
5
8
|
display?: boolean;
|
|
6
9
|
data?: any;
|
|
10
|
+
/**
|
|
11
|
+
* Auto display the GUI when added to the system
|
|
12
|
+
* @default false
|
|
13
|
+
*/
|
|
14
|
+
autoDisplay?: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Function that returns an array of Signal dependencies
|
|
17
|
+
* The GUI will only display when all dependencies are resolved (!= undefined)
|
|
18
|
+
* @returns Array of Signal dependencies
|
|
19
|
+
*/
|
|
20
|
+
dependencies?: () => Signal[];
|
|
21
|
+
}
|
|
22
|
+
interface GuiInstance {
|
|
23
|
+
name: string;
|
|
24
|
+
component: any;
|
|
25
|
+
display: WritableSignal<boolean>;
|
|
26
|
+
data: WritableSignal<any>;
|
|
27
|
+
autoDisplay: boolean;
|
|
28
|
+
dependencies?: () => Signal[];
|
|
29
|
+
subscription?: Subscription;
|
|
7
30
|
}
|
|
8
31
|
export declare class RpgGui {
|
|
9
32
|
private context;
|
|
10
33
|
private webSocket;
|
|
11
|
-
gui: import('canvasengine').
|
|
34
|
+
gui: import('canvasengine').WritableObjectSignal<Record<string, GuiInstance>>;
|
|
35
|
+
extraGuis: GuiInstance[];
|
|
36
|
+
private vueGuiInstance;
|
|
12
37
|
constructor(context: Context);
|
|
13
38
|
_initialize(): Promise<void>;
|
|
39
|
+
/**
|
|
40
|
+
* Set the VueGui instance reference for Vue component management
|
|
41
|
+
* This is called by VueGui when it's initialized
|
|
42
|
+
*
|
|
43
|
+
* @param vueGuiInstance - The VueGui instance
|
|
44
|
+
*/
|
|
45
|
+
_setVueGuiInstance(vueGuiInstance: any): void;
|
|
46
|
+
/**
|
|
47
|
+
* Notify VueGui about GUI state changes
|
|
48
|
+
* This synchronizes the Vue component display state
|
|
49
|
+
*
|
|
50
|
+
* @param guiId - The GUI component ID
|
|
51
|
+
* @param display - Display state
|
|
52
|
+
* @param data - Component data
|
|
53
|
+
*/
|
|
54
|
+
private _notifyVueGui;
|
|
55
|
+
/**
|
|
56
|
+
* Initialize Vue components in the VueGui instance
|
|
57
|
+
* This should be called after VueGui is mounted
|
|
58
|
+
*/
|
|
59
|
+
_initializeVueComponents(): void;
|
|
14
60
|
guiInteraction(guiId: string, name: string, data: any): void;
|
|
15
61
|
guiClose(guiId: string, data?: any): void;
|
|
62
|
+
/**
|
|
63
|
+
* Add a GUI component to the system
|
|
64
|
+
*
|
|
65
|
+
* By default, only CanvasEngine components (.ce files) are accepted.
|
|
66
|
+
* Vue components should be handled by the @rpgjs/vue package.
|
|
67
|
+
*
|
|
68
|
+
* @param gui - GUI configuration options
|
|
69
|
+
* @param gui.name - Name or ID of the GUI component
|
|
70
|
+
* @param gui.id - Alternative ID if name is not provided
|
|
71
|
+
* @param gui.component - The component to render (must be a CanvasEngine component)
|
|
72
|
+
* @param gui.display - Initial display state (default: false)
|
|
73
|
+
* @param gui.data - Initial data for the component
|
|
74
|
+
* @param gui.autoDisplay - Auto display when added (default: false)
|
|
75
|
+
* @param gui.dependencies - Function returning Signal dependencies
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```ts
|
|
79
|
+
* gui.add({
|
|
80
|
+
* name: 'inventory',
|
|
81
|
+
* component: InventoryComponent, // Must be a .ce component
|
|
82
|
+
* autoDisplay: true,
|
|
83
|
+
* dependencies: () => [playerSignal, inventorySignal]
|
|
84
|
+
* });
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
16
87
|
add(gui: GuiOptions): void;
|
|
17
|
-
get(id: string |
|
|
88
|
+
get(id: string): GuiInstance | undefined;
|
|
18
89
|
exists(id: string): boolean;
|
|
19
|
-
getAll():
|
|
20
|
-
|
|
90
|
+
getAll(): Record<string, GuiInstance>;
|
|
91
|
+
/**
|
|
92
|
+
* Display a GUI component
|
|
93
|
+
*
|
|
94
|
+
* Displays the GUI immediately if no dependencies are configured,
|
|
95
|
+
* or waits for all dependencies to be resolved if dependencies are present.
|
|
96
|
+
* Automatically manages subscriptions to prevent memory leaks.
|
|
97
|
+
* Works with both CanvasEngine components and Vue components.
|
|
98
|
+
*
|
|
99
|
+
* @param id - The GUI component ID
|
|
100
|
+
* @param data - Data to pass to the component
|
|
101
|
+
* @param dependencies - Optional runtime dependencies (overrides config dependencies)
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```ts
|
|
105
|
+
* // Display immediately
|
|
106
|
+
* gui.display('inventory', { items: [] });
|
|
107
|
+
*
|
|
108
|
+
* // Display with runtime dependencies
|
|
109
|
+
* gui.display('shop', { shopId: 1 }, [playerSignal, shopSignal]);
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
display(id: string, data?: {}, dependencies?: Signal[]): void;
|
|
113
|
+
/**
|
|
114
|
+
* Handle Vue component display logic
|
|
115
|
+
*
|
|
116
|
+
* @param id - GUI component ID
|
|
117
|
+
* @param data - Component data
|
|
118
|
+
* @param dependencies - Runtime dependencies
|
|
119
|
+
* @param guiInstance - GUI instance
|
|
120
|
+
*/
|
|
121
|
+
private _handleVueComponentDisplay;
|
|
122
|
+
/**
|
|
123
|
+
* Handle CanvasEngine component display logic
|
|
124
|
+
*
|
|
125
|
+
* @param id - GUI component ID
|
|
126
|
+
* @param data - Component data
|
|
127
|
+
* @param dependencies - Runtime dependencies
|
|
128
|
+
* @param guiInstance - GUI instance
|
|
129
|
+
*/
|
|
130
|
+
private _handleCanvasComponentDisplay;
|
|
131
|
+
/**
|
|
132
|
+
* Hide a GUI component
|
|
133
|
+
*
|
|
134
|
+
* Hides the GUI and cleans up any active subscriptions.
|
|
135
|
+
* Works with both CanvasEngine components and Vue components.
|
|
136
|
+
*
|
|
137
|
+
* @param id - The GUI component ID
|
|
138
|
+
*
|
|
139
|
+
* @example
|
|
140
|
+
* ```ts
|
|
141
|
+
* gui.hide('inventory');
|
|
142
|
+
* ```
|
|
143
|
+
*/
|
|
21
144
|
hide(id: string): void;
|
|
22
145
|
}
|
|
23
146
|
export {};
|
package/dist/RpgClient.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { ComponentFunction, Signal } from 'canvasengine';
|
|
1
2
|
import { RpgClientEngine } from './RpgClientEngine';
|
|
2
|
-
import { Loader } from 'pixi.js';
|
|
3
|
-
|
|
4
|
-
type RpgComponent =
|
|
5
|
-
type SceneMap =
|
|
3
|
+
import { Loader, Container } from 'pixi.js';
|
|
4
|
+
import { RpgClientObject } from './Game/Object';
|
|
5
|
+
type RpgComponent = RpgClientObject;
|
|
6
|
+
type SceneMap = Container;
|
|
6
7
|
export interface RpgClientEngineHooks {
|
|
7
8
|
/**
|
|
8
9
|
* When the engine is started. If you send false, you prevent the client from connecting to the server
|
|
@@ -10,7 +11,7 @@ export interface RpgClientEngineHooks {
|
|
|
10
11
|
* @prop { (engine: RpgClientEngine) => boolean | any } [onStart]
|
|
11
12
|
* @memberof RpgEngineHooks
|
|
12
13
|
*/
|
|
13
|
-
onStart?: (engine: RpgClientEngine) => boolean | void
|
|
14
|
+
onStart?: (engine: RpgClientEngine) => boolean | void | Promise<boolean | void>;
|
|
14
15
|
/**
|
|
15
16
|
* Each frame
|
|
16
17
|
*
|
|
@@ -59,6 +60,34 @@ export interface RpgClientEngineHooks {
|
|
|
59
60
|
onWindowResize?: () => any;
|
|
60
61
|
}
|
|
61
62
|
export interface RpgSpriteHooks {
|
|
63
|
+
/**
|
|
64
|
+
* Array of components to render behind the sprite
|
|
65
|
+
* These components will be displayed with a lower z-index than the sprite itself
|
|
66
|
+
*
|
|
67
|
+
* @prop { ComponentFunction[] } [componentsBehind]
|
|
68
|
+
* @memberof RpgSpriteHooks
|
|
69
|
+
* @example
|
|
70
|
+
* ```ts
|
|
71
|
+
* const sprite: RpgSpriteHooks = {
|
|
72
|
+
* componentsBehind: [ShadowComponent, AuraComponent]
|
|
73
|
+
* }
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
componentsBehind?: ComponentFunction[];
|
|
77
|
+
/**
|
|
78
|
+
* Array of components to render in front of the sprite
|
|
79
|
+
* These components will be displayed with a higher z-index than the sprite itself
|
|
80
|
+
*
|
|
81
|
+
* @prop { ComponentFunction[] } [componentsInFront]
|
|
82
|
+
* @memberof RpgSpriteHooks
|
|
83
|
+
* @example
|
|
84
|
+
* ```ts
|
|
85
|
+
* const sprite: RpgSpriteHooks = {
|
|
86
|
+
* componentsInFront: [HealthBarComponent, StatusEffectComponent]
|
|
87
|
+
* }
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
componentsInFront?: ComponentFunction[];
|
|
62
91
|
/**
|
|
63
92
|
* As soon as the sprite is initialized
|
|
64
93
|
*
|
|
@@ -163,14 +192,13 @@ export interface RpgClient {
|
|
|
163
192
|
* @example
|
|
164
193
|
*
|
|
165
194
|
* ```ts
|
|
166
|
-
* import { RpgClient,
|
|
195
|
+
* import { RpgClient, defineModule } from '@rpgjs/client'
|
|
167
196
|
*
|
|
168
|
-
*
|
|
197
|
+
* defineModule<RpgClient>({
|
|
169
198
|
* hooks: {
|
|
170
199
|
* player: ['onAuth']
|
|
171
200
|
* }
|
|
172
201
|
* })
|
|
173
|
-
* class RpgClientEngine { }
|
|
174
202
|
* ```
|
|
175
203
|
*
|
|
176
204
|
* Emit the hook:
|
|
@@ -207,7 +235,7 @@ export interface RpgClient {
|
|
|
207
235
|
* Object containing the hooks concerning the engine
|
|
208
236
|
*
|
|
209
237
|
* ```ts
|
|
210
|
-
* import { RpgClientEngine, RpgClientEngineHooks,
|
|
238
|
+
* import { RpgClientEngine, RpgClientEngineHooks, defineModule, RpgClient } from '@rpgjs/client'
|
|
211
239
|
*
|
|
212
240
|
* const engine: RpgClientEngineHooks = {
|
|
213
241
|
* onConnected(engine: RpgClientEngine) {
|
|
@@ -215,10 +243,9 @@ export interface RpgClient {
|
|
|
215
243
|
* }
|
|
216
244
|
* }
|
|
217
245
|
*
|
|
218
|
-
*
|
|
246
|
+
* defineModule<RpgClient>({
|
|
219
247
|
* engine
|
|
220
248
|
* })
|
|
221
|
-
* class RpgClientModule {}
|
|
222
249
|
* ```
|
|
223
250
|
*
|
|
224
251
|
* @prop {RpgClientEngineHooks} [engine]
|
|
@@ -227,99 +254,204 @@ export interface RpgClient {
|
|
|
227
254
|
engine?: RpgClientEngineHooks;
|
|
228
255
|
/**
|
|
229
256
|
* Array containing the list of spritesheets
|
|
230
|
-
*
|
|
257
|
+
* Each element is a simple object containing spritesheet definitions
|
|
231
258
|
*
|
|
232
259
|
* ```ts
|
|
233
|
-
* import {
|
|
234
|
-
*
|
|
235
|
-
* @Spritesheet({
|
|
236
|
-
* id: 'chest',
|
|
237
|
-
* image: require('./assets/chest.png'),
|
|
238
|
-
* // other options
|
|
239
|
-
* })
|
|
240
|
-
* class Chest { }
|
|
260
|
+
* import { defineModule, RpgClient } from '@rpgjs/client'
|
|
241
261
|
*
|
|
242
|
-
*
|
|
262
|
+
* defineModule<RpgClient>({
|
|
243
263
|
* spritesheets: [
|
|
244
|
-
*
|
|
264
|
+
* {
|
|
265
|
+
* id: 'chest',
|
|
266
|
+
* image: require('./assets/chest.png'),
|
|
267
|
+
* framesWidth: 32,
|
|
268
|
+
* framesHeight: 32,
|
|
269
|
+
* animations: {
|
|
270
|
+
* default: {
|
|
271
|
+
* frames: [0, 1, 2],
|
|
272
|
+
* duration: 1000
|
|
273
|
+
* }
|
|
274
|
+
* }
|
|
275
|
+
* }
|
|
245
276
|
* ]
|
|
246
277
|
* })
|
|
247
|
-
* class RpgClientEngine {}
|
|
248
278
|
* ```
|
|
249
279
|
*
|
|
250
280
|
* [Guide: Create Sprite](/guide/create-sprite.html)
|
|
251
281
|
*
|
|
252
|
-
* @prop {Array<
|
|
282
|
+
* @prop {Array<Object>} [spritesheets]
|
|
253
283
|
* @memberof RpgClient
|
|
254
284
|
* */
|
|
255
285
|
spritesheets?: any[];
|
|
256
286
|
/**
|
|
257
|
-
*
|
|
287
|
+
* Resolver function for dynamically creating spritesheets
|
|
288
|
+
*
|
|
289
|
+
* This function is called when a spritesheet is requested but not found in the cache.
|
|
290
|
+
* It can be synchronous (returns directly) or asynchronous (returns a Promise).
|
|
291
|
+
* The resolved spritesheet is automatically cached for future use.
|
|
258
292
|
*
|
|
259
293
|
* ```ts
|
|
260
|
-
* import {
|
|
261
|
-
*
|
|
262
|
-
*
|
|
263
|
-
*
|
|
264
|
-
*
|
|
265
|
-
*
|
|
266
|
-
*
|
|
267
|
-
*
|
|
268
|
-
*
|
|
269
|
-
*
|
|
294
|
+
* import { defineModule, RpgClient } from '@rpgjs/client'
|
|
295
|
+
*
|
|
296
|
+
* defineModule<RpgClient>({
|
|
297
|
+
* spritesheetResolver: (id: string) => {
|
|
298
|
+
* // Synchronous resolver
|
|
299
|
+
* if (id === 'dynamic-sprite') {
|
|
300
|
+
* return {
|
|
301
|
+
* id: 'dynamic-sprite',
|
|
302
|
+
* image: 'path/to/image.png',
|
|
303
|
+
* framesWidth: 32,
|
|
304
|
+
* framesHeight: 32
|
|
305
|
+
* };
|
|
306
|
+
* }
|
|
307
|
+
* return undefined;
|
|
308
|
+
* }
|
|
309
|
+
* })
|
|
270
310
|
*
|
|
271
|
-
*
|
|
311
|
+
* // Or asynchronous resolver
|
|
312
|
+
* defineModule<RpgClient>({
|
|
313
|
+
* spritesheetResolver: async (id: string) => {
|
|
314
|
+
* const response = await fetch(`/api/spritesheets/${id}`);
|
|
315
|
+
* const data = await response.json();
|
|
316
|
+
* return data;
|
|
317
|
+
* }
|
|
318
|
+
* })
|
|
319
|
+
* ```
|
|
320
|
+
*
|
|
321
|
+
* @prop {(id: string) => any | Promise<any>} [spritesheetResolver]
|
|
322
|
+
* @memberof RpgClient
|
|
323
|
+
* */
|
|
324
|
+
spritesheetResolver?: (id: string) => any | Promise<any>;
|
|
325
|
+
/**
|
|
326
|
+
* Resolver function for dynamically loading sounds
|
|
327
|
+
*
|
|
328
|
+
* The resolver is called when a sound is requested but not found in the cache.
|
|
329
|
+
* It can be synchronous (returns directly) or asynchronous (returns a Promise).
|
|
330
|
+
* The resolved sound is automatically cached for future use.
|
|
331
|
+
*
|
|
332
|
+
* ```ts
|
|
333
|
+
* import { defineModule, RpgClient } from '@rpgjs/client'
|
|
334
|
+
*
|
|
335
|
+
* defineModule<RpgClient>({
|
|
336
|
+
* soundResolver: (id: string) => {
|
|
337
|
+
* if (id === 'dynamic-sound') {
|
|
338
|
+
* return { id: 'dynamic-sound', src: 'path/to/sound.mp3' };
|
|
339
|
+
* }
|
|
340
|
+
* return undefined;
|
|
341
|
+
* }
|
|
342
|
+
* })
|
|
343
|
+
* ```
|
|
344
|
+
*
|
|
345
|
+
* @prop {(id: string) => any | Promise<any>} [soundResolver]
|
|
346
|
+
* @memberof RpgClient
|
|
347
|
+
* */
|
|
348
|
+
soundResolver?: (id: string) => any | Promise<any>;
|
|
349
|
+
/**
|
|
350
|
+
* Array containing the list of GUI components
|
|
351
|
+
*
|
|
352
|
+
* ```ts
|
|
353
|
+
* import { defineModule, RpgClient } from '@rpgjs/client'
|
|
354
|
+
* import InventoryComponent from './inventory.ce'
|
|
355
|
+
*
|
|
356
|
+
* defineModule<RpgClient>({
|
|
272
357
|
* gui: [
|
|
273
|
-
*
|
|
358
|
+
* {
|
|
359
|
+
* id: 'inventory',
|
|
360
|
+
* component: InventoryComponent,
|
|
361
|
+
* autoDisplay: true,
|
|
362
|
+
* dependencies: () => [playerSignal, inventorySignal]
|
|
363
|
+
* }
|
|
274
364
|
* ]
|
|
275
365
|
* })
|
|
276
|
-
* class RpgClientEngine {}
|
|
277
366
|
* ```
|
|
278
367
|
*
|
|
279
368
|
* [Guide: Create GUI](/guide/create-gui.html)
|
|
280
369
|
*
|
|
281
|
-
* @prop {Array<
|
|
370
|
+
* @prop {Array<GuiOptions>} [gui]
|
|
282
371
|
* @memberof RpgClient
|
|
283
372
|
* */
|
|
284
|
-
gui?:
|
|
373
|
+
gui?: ({
|
|
374
|
+
id: string;
|
|
375
|
+
component: ComponentFunction;
|
|
376
|
+
/**
|
|
377
|
+
* Auto display the GUI when added to the system
|
|
378
|
+
* @default false
|
|
379
|
+
*/
|
|
380
|
+
autoDisplay?: boolean;
|
|
381
|
+
/**
|
|
382
|
+
* Function that returns an array of Signal dependencies
|
|
383
|
+
* The GUI will only display when all dependencies are resolved (!= undefined)
|
|
384
|
+
*/
|
|
385
|
+
dependencies?: () => Signal[];
|
|
386
|
+
} | any)[];
|
|
285
387
|
/**
|
|
286
388
|
* Array containing the list of sounds
|
|
287
|
-
*
|
|
389
|
+
* Each element can be:
|
|
390
|
+
* - A simple object containing sound definitions
|
|
391
|
+
* - A class decorated with @Sound
|
|
288
392
|
*
|
|
289
393
|
* ```ts
|
|
290
|
-
* import {
|
|
394
|
+
* import { defineModule, RpgClient, Sound } from '@rpgjs/client'
|
|
395
|
+
*
|
|
396
|
+
* // Using simple objects
|
|
397
|
+
* defineModule<RpgClient>({
|
|
398
|
+
* sounds: [
|
|
399
|
+
* {
|
|
400
|
+
* id: 'typewriter',
|
|
401
|
+
* src: 'typewriter.wav'
|
|
402
|
+
* },
|
|
403
|
+
* {
|
|
404
|
+
* id: 'cursor',
|
|
405
|
+
* src: 'cursor.wav'
|
|
406
|
+
* }
|
|
407
|
+
* ]
|
|
408
|
+
* })
|
|
291
409
|
*
|
|
410
|
+
* // Using @Sound decorator
|
|
292
411
|
* @Sound({
|
|
293
|
-
*
|
|
294
|
-
*
|
|
295
|
-
*
|
|
412
|
+
* id: 'town-music',
|
|
413
|
+
* sound: require('./sound/town.ogg'),
|
|
414
|
+
* loop: true,
|
|
415
|
+
* volume: 0.5
|
|
416
|
+
* })
|
|
417
|
+
* export class TownMusic {}
|
|
418
|
+
*
|
|
419
|
+
* defineModule<RpgClient>({
|
|
420
|
+
* sounds: [TownMusic]
|
|
421
|
+
* })
|
|
422
|
+
*
|
|
423
|
+
* // Multiple sounds in one class
|
|
424
|
+
* @Sound({
|
|
425
|
+
* sounds: {
|
|
426
|
+
* hero: require('./assets/hero.ogg'),
|
|
427
|
+
* monster: require('./assets/monster.ogg')
|
|
428
|
+
* },
|
|
429
|
+
* loop: true
|
|
296
430
|
* })
|
|
297
|
-
* class
|
|
431
|
+
* export class CharacterSounds {}
|
|
298
432
|
*
|
|
299
|
-
*
|
|
300
|
-
* sounds: [
|
|
433
|
+
* defineModule<RpgClient>({
|
|
434
|
+
* sounds: [CharacterSounds]
|
|
301
435
|
* })
|
|
302
|
-
* class RpgClientEngine {}
|
|
303
436
|
* ```
|
|
304
437
|
*
|
|
305
|
-
* @prop {Array<Class>} [sounds]
|
|
438
|
+
* @prop {Array<Object | Class>} [sounds]
|
|
306
439
|
* @memberof RpgClient
|
|
307
440
|
* */
|
|
308
|
-
sounds?:
|
|
441
|
+
sounds?: any[];
|
|
309
442
|
/**
|
|
310
443
|
* Give the `RpgSprite` class. A Sprite represents a player or an event
|
|
311
444
|
*
|
|
312
445
|
* ```ts
|
|
313
|
-
* import { RpgSprite, RpgSpriteHooks, RpgClient,
|
|
446
|
+
* import { RpgSprite, RpgSpriteHooks, RpgClient, defineModule } from '@rpgjs/client'
|
|
314
447
|
*
|
|
315
448
|
* export const sprite: RpgSpriteHooks = {
|
|
316
449
|
* onInit(sprite: RpgSprite) {}
|
|
317
450
|
* }
|
|
318
451
|
*
|
|
319
|
-
*
|
|
452
|
+
* defineModule<RpgClient>({
|
|
320
453
|
* sprite
|
|
321
454
|
* })
|
|
322
|
-
* class RpgClientEngine {}
|
|
323
455
|
* ```
|
|
324
456
|
*
|
|
325
457
|
* @prop {RpgSpriteHooks} [sprite]
|
|
@@ -330,19 +462,18 @@ export interface RpgClient {
|
|
|
330
462
|
* Reference the scenes of the game. Here you can put your own class that inherits RpgSceneMap
|
|
331
463
|
*
|
|
332
464
|
* ```ts
|
|
333
|
-
* import { RpgSceneMapHooks, RpgClient,
|
|
465
|
+
* import { RpgSceneMapHooks, RpgClient, defineModule } from '@rpgjs/client'
|
|
334
466
|
*
|
|
335
467
|
* export const sceneMap: RpgSceneMapHooks = {
|
|
336
468
|
*
|
|
337
469
|
* }
|
|
338
470
|
*
|
|
339
|
-
*
|
|
471
|
+
* defineModule<RpgClient>({
|
|
340
472
|
* scenes: {
|
|
341
473
|
* // If you put the RpgSceneMap scene, Thhe key is called mandatory `map`
|
|
342
474
|
* map: sceneMap
|
|
343
475
|
* }
|
|
344
476
|
* })
|
|
345
|
-
* class RpgClientEngine {}
|
|
346
477
|
* ```
|
|
347
478
|
*
|
|
348
479
|
* @prop { [sceneName: string]: RpgSceneMapHooks } [scenes]
|
|
@@ -351,9 +482,36 @@ export interface RpgClient {
|
|
|
351
482
|
scenes?: {
|
|
352
483
|
map: RpgSceneMapHooks;
|
|
353
484
|
};
|
|
354
|
-
|
|
485
|
+
sceneMap?: RpgSceneMapHooks;
|
|
486
|
+
/**
|
|
487
|
+
* Array containing the list of component animations
|
|
488
|
+
* Each element defines a temporary component to display for animations like hits, effects, etc.
|
|
489
|
+
*
|
|
490
|
+
* ```ts
|
|
491
|
+
* import { defineModule, RpgClient } from '@rpgjs/client'
|
|
492
|
+
* import HitComponent from './hit.ce'
|
|
493
|
+
* import ExplosionComponent from './explosion.ce'
|
|
494
|
+
*
|
|
495
|
+
* defineModule<RpgClient>({
|
|
496
|
+
* componentAnimations: [
|
|
497
|
+
* {
|
|
498
|
+
* id: 'hit',
|
|
499
|
+
* component: HitComponent
|
|
500
|
+
* },
|
|
501
|
+
* {
|
|
502
|
+
* id: 'explosion',
|
|
503
|
+
* component: ExplosionComponent
|
|
504
|
+
* }
|
|
505
|
+
* ]
|
|
506
|
+
* })
|
|
507
|
+
* ```
|
|
508
|
+
*
|
|
509
|
+
* @prop {Array<{id: string, component: ComponentFunction}>} [componentAnimations]
|
|
510
|
+
* @memberof RpgClient
|
|
511
|
+
* */
|
|
512
|
+
componentAnimations?: {
|
|
355
513
|
id: string;
|
|
356
|
-
component:
|
|
514
|
+
component: ComponentFunction;
|
|
357
515
|
}[];
|
|
358
516
|
}
|
|
359
517
|
export {};
|