@rpgjs/server 5.0.0-alpha.8 → 5.0.0-alpha.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rpgjs/server",
3
- "version": "5.0.0-alpha.8",
3
+ "version": "5.0.0-alpha.9",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "publishConfig": {
@@ -11,7 +11,7 @@
11
11
  "license": "MIT",
12
12
  "description": "",
13
13
  "dependencies": {
14
- "@rpgjs/common": "5.0.0-alpha.8",
14
+ "@rpgjs/common": "5.0.0-alpha.9",
15
15
  "@rpgjs/database": "^4.3.0",
16
16
  "@signe/di": "^2.3.2",
17
17
  "@signe/reactive": "^2.3.2",
@@ -24,9 +24,24 @@ import { RpgCommonPlayer } from "@rpgjs/common";
24
24
  * player.setGraphic(["hero_idle", "hero_walk"]);
25
25
  * ```
26
26
  */
27
- export function WithComponentManager<TBase extends PlayerCtor>(Base: TBase) {
27
+ export function WithComponentManager<TBase extends PlayerCtor>(Base: TBase): new (...args: ConstructorParameters<TBase>) => InstanceType<TBase> & IComponentManager {
28
28
  return class extends Base {
29
- /**
29
+ setGraphic(graphic: string | string[]): void {
30
+ if (Array.isArray(graphic)) {
31
+ this.graphics.set(graphic);
32
+ } else {
33
+ this.graphics.set([graphic]);
34
+ }
35
+ }
36
+ } as unknown as any;
37
+ }
38
+
39
+ /**
40
+ * Interface for component management capabilities
41
+ * Defines the method signature that will be available on the player
42
+ */
43
+ export interface IComponentManager {
44
+ /**
30
45
  * Set the graphic(s) for this player
31
46
  *
32
47
  * Allows setting either a single graphic or multiple graphics for the player.
@@ -54,18 +69,5 @@ export function WithComponentManager<TBase extends PlayerCtor>(Base: TBase) {
54
69
  * player.setGraphic(["mage_cast_1", "mage_cast_2", "mage_cast_3"]);
55
70
  * ```
56
71
  */
57
- setGraphic(graphic: string | string[]): void {
58
- if (Array.isArray(graphic)) {
59
- this.graphics.set(graphic);
60
- } else {
61
- this.graphics.set([graphic]);
62
- }
63
- }
64
- } as unknown as TBase;
72
+ setGraphic(graphic: string | string[]): void;
65
73
  }
66
-
67
- /**
68
- * Type helper to extract the interface from the WithComponentManager mixin
69
- * This provides the type without duplicating method signatures
70
- */
71
- export type IComponentManager = InstanceType<ReturnType<typeof WithComponentManager>>;
@@ -1,18 +1,18 @@
1
1
  import { RpgPlayer } from "./Player";
2
2
  import { Gui, DialogGui, MenuGui, ShopGui, NotificationGui } from "../Gui";
3
3
  import { DialogOptions, Choice } from "../Gui/DialogGui";
4
- import { PlayerCtor } from "@rpgjs/common";
4
+ import { Constructor, PlayerCtor } from "@rpgjs/common";
5
5
 
6
6
  /**
7
7
  * GUI Manager Mixin
8
- *
8
+ *
9
9
  * Provides graphical user interface management capabilities to any class. This mixin handles
10
10
  * dialog boxes, menus, notifications, shops, and custom GUI components. It manages the
11
11
  * complete GUI system including opening, closing, and data passing between client and server.
12
- *
12
+ *
13
13
  * @param Base - The base class to extend with GUI management
14
14
  * @returns Extended class with GUI management methods
15
- *
15
+ *
16
16
  * @example
17
17
  * ```ts
18
18
  * class MyPlayer extends WithGuiManager(BasePlayer) {
@@ -21,129 +21,25 @@ import { PlayerCtor } from "@rpgjs/common";
21
21
  * // GUI system is automatically initialized
22
22
  * }
23
23
  * }
24
- *
24
+ *
25
25
  * const player = new MyPlayer();
26
26
  * await player.showText('Hello World!');
27
27
  * player.callMainMenu();
28
28
  * ```
29
29
  */
30
- export function WithGuiManager<TBase extends PlayerCtor>(Base: TBase) {
31
- return class extends Base {
30
+ export function WithGuiManager<TBase extends PlayerCtor>(
31
+ Base: TBase
32
+ ): new (...args: ConstructorParameters<TBase>) => InstanceType<TBase> &
33
+ IGuiManager {
34
+ class GuiManagerMixin extends Base {
32
35
  _gui: { [id: string]: Gui } = {};
33
36
 
34
- /**
35
- * Show a text. This is a graphical interface already built. Opens the GUI named `rpg-dialog`
36
- *
37
- * ```ts
38
- * player.showText('Hello World')
39
- * ```
40
- *
41
- * The method returns a promise. It is resolved when the dialog box is closed.
42
- *
43
- * ```ts
44
- * await player.showText('Hello World')
45
- * // dialog box is closed, then ...
46
- * ```
47
- *
48
- * **Option: position**
49
- *
50
- * You can define how the dialog box is displayed:
51
- * - top
52
- * - middle
53
- * - bottom
54
- *
55
- * (bottom by default)
56
- *
57
- * ```ts
58
- * player.showText('Hello World', {
59
- * position: 'top'
60
- * })
61
- * ```
62
- *
63
- * **Option: fullWidth**
64
- *
65
- * `boolean` (true by default)
66
- *
67
- * Indicate that the dialog box will take the full width of the screen.
68
- *
69
- * ```ts
70
- * player.showText('Hello World', {
71
- * fullWidth: true
72
- * })
73
- * ```
74
- *
75
- * **Option: autoClose**
76
- *
77
- * `boolean` (false by default)
78
- *
79
- * If false, the user will have to press Enter to close the dialog box.
80
- *
81
- * ```ts
82
- * player.showText('Hello World', {
83
- * autoClose: true
84
- * })
85
- * ```
86
- *
87
- * **Option: typewriterEffect**
88
- *
89
- * `boolean` (true by default)
90
- *
91
- * Performs a typewriter effect
92
- *
93
- * ```ts
94
- * player.showText('Hello World', {
95
- * typewriterEffect: false
96
- * })
97
- * ```
98
- *
99
- * **Option: talkWith**
100
- *
101
- * `RpgPlayer` (nothing by default)
102
- *
103
- * If you specify the event or another player, the other player will stop his or her movement and look in the player's direction.
104
- *
105
- * ```ts
106
- * // Code in an event
107
- * player.showText('Hello World', {
108
- * talkWith: this
109
- * })
110
- * ```
111
- *
112
- * @title Show Text
113
- * @method player.showText(text,options)
114
- * @param {string} text
115
- * @param {object} [options] the different options, see usage below
116
- * @returns {Promise}
117
- * @memberof GuiManager
118
- */
119
37
  showText(msg: string, options: DialogOptions = {}): Promise<any> {
120
38
  const gui = new DialogGui(<any>this);
121
39
  this._gui[gui.id] = gui;
122
40
  return gui.openDialog(msg, options);
123
41
  }
124
42
 
125
- /**
126
- * Shows a dialog box with a choice. Opens the GUI named `rpg-dialog`
127
- *
128
- * ```ts
129
- * const choice = await player.showChoices('What color do you prefer?', [
130
- * { text: 'Black', value: 'black' },
131
- * { text: 'Rather the blue', value: 'blue' },
132
- * { text: 'I don\'t have a preference!', value: 'none' }
133
- * ])
134
- *
135
- * // If the player selects the first
136
- * console.log(choice) // { text: 'Black', value: 'black' }
137
- * ```
138
- *
139
- * @title Show Choices
140
- * @method player.showChoices(text,choices)
141
- * @param {string} text
142
- * @param {Array<{ text: string, value: any }>} choices
143
- * @param {object} [options] Same options as the openDialog method
144
- * @returns {Promise<Choice | null>}
145
- * @memberof GuiManager
146
- */
147
43
  showChoices(
148
44
  msg: string,
149
45
  choices: Choice[],
@@ -158,19 +54,6 @@ export function WithGuiManager<TBase extends PlayerCtor>(Base: TBase) {
158
54
  });
159
55
  }
160
56
 
161
- /**
162
- * Displays a notification . Opens the GUI named `rpg-notification`
163
- *
164
- * @title Displays a notification
165
- * @method player.showNotification()
166
- * @param {string} message - The message to display in the notification
167
- * @param {object} options - An object containing options for the notification
168
- * @param {number} options.time - The time to display the notification for (in ms). Default: 2000ms
169
- * @param {string} options.icon - The icon to display in the notification. Put the identifier of the spritesheet (defined on the client side)
170
- * @param {string} options.sound - The sound to play when the notification is shown. Set the sound ID (defined on the client side)
171
- * @returns {void}
172
- * @memberof GuiManager
173
- */
174
57
  showNotification(
175
58
  message: string,
176
59
  options: { time?: number; icon?: string; sound?: string } = {}
@@ -184,14 +67,6 @@ export function WithGuiManager<TBase extends PlayerCtor>(Base: TBase) {
184
67
  return gui.open(data);
185
68
  }
186
69
 
187
- /**
188
- * Calls main menu. Opens the GUI named `rpg-main-menu`
189
- *
190
- * @title Call Main Menu
191
- * @method player.callMainMenu()
192
- * @returns {void}
193
- * @memberof GuiManager
194
- */
195
70
  callMainMenu() {
196
71
  const gui = new MenuGui(<any>this);
197
72
  this._gui[gui.id] = gui;
@@ -330,11 +205,160 @@ export function WithGuiManager<TBase extends PlayerCtor>(Base: TBase) {
330
205
  const _players = players || this;
331
206
  this._attachedGui(_players as RpgPlayer[], false);
332
207
  }
333
- } as unknown as TBase;
208
+ }
209
+
210
+ return GuiManagerMixin as unknown as any;
334
211
  }
335
212
 
336
213
  /**
337
- * Type helper to extract the interface from the WithGuiManager mixin
338
- * This provides the type without duplicating method signatures
214
+ * Interface for GUI management capabilities
215
+ * Defines the methods that will be available on the player
339
216
  */
340
- export type IGuiManager = InstanceType<ReturnType<typeof WithGuiManager>>;
217
+ export interface IGuiManager {
218
+ /**
219
+ * Show a text. This is a graphical interface already built. Opens the GUI named `rpg-dialog`
220
+ *
221
+ * ```ts
222
+ * player.showText('Hello World')
223
+ * ```
224
+ *
225
+ * The method returns a promise. It is resolved when the dialog box is closed.
226
+ *
227
+ * ```ts
228
+ * await player.showText('Hello World')
229
+ * // dialog box is closed, then ...
230
+ * ```
231
+ *
232
+ * **Option: position**
233
+ *
234
+ * You can define how the dialog box is displayed:
235
+ * - top
236
+ * - middle
237
+ * - bottom
238
+ *
239
+ * (bottom by default)
240
+ *
241
+ * ```ts
242
+ * player.showText('Hello World', {
243
+ * position: 'top'
244
+ * })
245
+ * ```
246
+ *
247
+ * **Option: fullWidth**
248
+ *
249
+ * `boolean` (true by default)
250
+ *
251
+ * Indicate that the dialog box will take the full width of the screen.
252
+ *
253
+ * ```ts
254
+ * player.showText('Hello World', {
255
+ * fullWidth: true
256
+ * })
257
+ * ```
258
+ *
259
+ * **Option: autoClose**
260
+ *
261
+ * `boolean` (false by default)
262
+ *
263
+ * If false, the user will have to press Enter to close the dialog box.
264
+ *
265
+ * ```ts
266
+ * player.showText('Hello World', {
267
+ * autoClose: true
268
+ * })
269
+ * ```
270
+ *
271
+ * **Option: typewriterEffect**
272
+ *
273
+ * `boolean` (true by default)
274
+ *
275
+ * Performs a typewriter effect
276
+ *
277
+ * ```ts
278
+ * player.showText('Hello World', {
279
+ * typewriterEffect: false
280
+ * })
281
+ * ```
282
+ *
283
+ * **Option: talkWith**
284
+ *
285
+ * `RpgPlayer` (nothing by default)
286
+ *
287
+ * If you specify the event or another player, the other player will stop his or her movement and look in the player's direction.
288
+ *
289
+ * ```ts
290
+ * // Code in an event
291
+ * player.showText('Hello World', {
292
+ * talkWith: this
293
+ * })
294
+ * ```
295
+ *
296
+ * @title Show Text
297
+ * @method player.showText(text,options)
298
+ * @param {string} text
299
+ * @param {object} [options] the different options, see usage below
300
+ * @returns {Promise}
301
+ * @memberof GuiManager
302
+ */
303
+ showText(msg: string, options?: DialogOptions): Promise<any>;
304
+
305
+ /**
306
+ * Shows a dialog box with a choice. Opens the GUI named `rpg-dialog`
307
+ *
308
+ * ```ts
309
+ * const choice = await player.showChoices('What color do you prefer?', [
310
+ * { text: 'Black', value: 'black' },
311
+ * { text: 'Rather the blue', value: 'blue' },
312
+ * { text: 'I don\'t have a preference!', value: 'none' }
313
+ * ])
314
+ *
315
+ * // If the player selects the first
316
+ * console.log(choice) // { text: 'Black', value: 'black' }
317
+ * ```
318
+ *
319
+ * @title Show Choices
320
+ * @method player.showChoices(text,choices)
321
+ * @param {string} text
322
+ * @param {Array<{ text: string, value: any }>} choices
323
+ * @param {object} [options] Same options as the openDialog method
324
+ * @returns {Promise<Choice | null>}
325
+ * @memberof GuiManager
326
+ */
327
+ showChoices(
328
+ msg: string,
329
+ choices: Choice[],
330
+ options?: DialogOptions
331
+ ): Promise<Choice | null>;
332
+
333
+ /**
334
+ * Displays a notification . Opens the GUI named `rpg-notification`
335
+ *
336
+ * @title Displays a notification
337
+ * @method player.showNotification()
338
+ * @param {string} message - The message to display in the notification
339
+ * @param {object} options - An object containing options for the notification
340
+ * @param {number} options.time - The time to display the notification for (in ms). Default: 2000ms
341
+ * @param {string} options.icon - The icon to display in the notification. Put the identifier of the spritesheet (defined on the client side)
342
+ * @param {string} options.sound - The sound to play when the notification is shown. Set the sound ID (defined on the client side)
343
+ * @returns {void}
344
+ * @memberof GuiManager
345
+ */
346
+ showNotification(
347
+ message: string,
348
+ options?: { time?: number; icon?: string; sound?: string }
349
+ ): Promise<any>;
350
+ /**
351
+ * Calls main menu. Opens the GUI named `rpg-main-menu`
352
+ *
353
+ * @title Call Main Menu
354
+ * @method player.callMainMenu()
355
+ * @returns {void}
356
+ * @memberof GuiManager
357
+ */
358
+ callMainMenu(): void;
359
+ callShop(items: any[]): void;
360
+ gui(guiId: string): Gui;
361
+ removeGui(guiId: string, data?: any): void;
362
+ showAttachedGui(players?: RpgPlayer[] | RpgPlayer): void;
363
+ hideAttachedGui(players?: RpgPlayer[] | RpgPlayer): void;
364
+ }
File without changes
File without changes