@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.
@@ -22,9 +22,39 @@ import { PlayerCtor } from '@rpgjs/common';
22
22
  * player.setGraphic(["hero_idle", "hero_walk"]);
23
23
  * ```
24
24
  */
25
- export declare function WithComponentManager<TBase extends PlayerCtor>(Base: TBase): TBase;
25
+ export declare function WithComponentManager<TBase extends PlayerCtor>(Base: TBase): new (...args: ConstructorParameters<TBase>) => InstanceType<TBase> & IComponentManager;
26
26
  /**
27
- * Type helper to extract the interface from the WithComponentManager mixin
28
- * This provides the type without duplicating method signatures
27
+ * Interface for component management capabilities
28
+ * Defines the method signature that will be available on the player
29
29
  */
30
- export type IComponentManager = InstanceType<ReturnType<typeof WithComponentManager>>;
30
+ export interface IComponentManager {
31
+ /**
32
+ * Set the graphic(s) for this player
33
+ *
34
+ * Allows setting either a single graphic or multiple graphics for the player.
35
+ * When multiple graphics are provided, they are used for animation sequences.
36
+ * The graphics system provides flexible visual representation that can be
37
+ * dynamically changed during gameplay for different states, equipment, or animations.
38
+ *
39
+ * @param graphic - Single graphic name or array of graphic names for animation sequences
40
+ * @returns void
41
+ *
42
+ * @example
43
+ * ```ts
44
+ * // Set a single graphic for static representation
45
+ * player.setGraphic("hero");
46
+ *
47
+ * // Set multiple graphics for animation sequences
48
+ * player.setGraphic(["hero_idle", "hero_walk", "hero_run"]);
49
+ *
50
+ * // Dynamic graphic changes based on equipment
51
+ * if (player.hasArmor('platemail')) {
52
+ * player.setGraphic("hero_armored");
53
+ * }
54
+ *
55
+ * // Animation sequences for different actions
56
+ * player.setGraphic(["mage_cast_1", "mage_cast_2", "mage_cast_3"]);
57
+ * ```
58
+ */
59
+ setGraphic(graphic: string | string[]): void;
60
+ }
@@ -1,3 +1,6 @@
1
+ import { RpgPlayer } from './Player';
2
+ import { Gui } from '../Gui';
3
+ import { DialogOptions, Choice } from '../Gui/DialogGui';
1
4
  import { PlayerCtor } from '@rpgjs/common';
2
5
  /**
3
6
  * GUI Manager Mixin
@@ -23,9 +26,151 @@ import { PlayerCtor } from '@rpgjs/common';
23
26
  * player.callMainMenu();
24
27
  * ```
25
28
  */
26
- export declare function WithGuiManager<TBase extends PlayerCtor>(Base: TBase): TBase;
29
+ export declare function WithGuiManager<TBase extends PlayerCtor>(Base: TBase): new (...args: ConstructorParameters<TBase>) => InstanceType<TBase> & IGuiManager;
27
30
  /**
28
- * Type helper to extract the interface from the WithGuiManager mixin
29
- * This provides the type without duplicating method signatures
31
+ * Interface for GUI management capabilities
32
+ * Defines the methods that will be available on the player
30
33
  */
31
- export type IGuiManager = InstanceType<ReturnType<typeof WithGuiManager>>;
34
+ export interface IGuiManager {
35
+ /**
36
+ * Show a text. This is a graphical interface already built. Opens the GUI named `rpg-dialog`
37
+ *
38
+ * ```ts
39
+ * player.showText('Hello World')
40
+ * ```
41
+ *
42
+ * The method returns a promise. It is resolved when the dialog box is closed.
43
+ *
44
+ * ```ts
45
+ * await player.showText('Hello World')
46
+ * // dialog box is closed, then ...
47
+ * ```
48
+ *
49
+ * **Option: position**
50
+ *
51
+ * You can define how the dialog box is displayed:
52
+ * - top
53
+ * - middle
54
+ * - bottom
55
+ *
56
+ * (bottom by default)
57
+ *
58
+ * ```ts
59
+ * player.showText('Hello World', {
60
+ * position: 'top'
61
+ * })
62
+ * ```
63
+ *
64
+ * **Option: fullWidth**
65
+ *
66
+ * `boolean` (true by default)
67
+ *
68
+ * Indicate that the dialog box will take the full width of the screen.
69
+ *
70
+ * ```ts
71
+ * player.showText('Hello World', {
72
+ * fullWidth: true
73
+ * })
74
+ * ```
75
+ *
76
+ * **Option: autoClose**
77
+ *
78
+ * `boolean` (false by default)
79
+ *
80
+ * If false, the user will have to press Enter to close the dialog box.
81
+ *
82
+ * ```ts
83
+ * player.showText('Hello World', {
84
+ * autoClose: true
85
+ * })
86
+ * ```
87
+ *
88
+ * **Option: typewriterEffect**
89
+ *
90
+ * `boolean` (true by default)
91
+ *
92
+ * Performs a typewriter effect
93
+ *
94
+ * ```ts
95
+ * player.showText('Hello World', {
96
+ * typewriterEffect: false
97
+ * })
98
+ * ```
99
+ *
100
+ * **Option: talkWith**
101
+ *
102
+ * `RpgPlayer` (nothing by default)
103
+ *
104
+ * If you specify the event or another player, the other player will stop his or her movement and look in the player's direction.
105
+ *
106
+ * ```ts
107
+ * // Code in an event
108
+ * player.showText('Hello World', {
109
+ * talkWith: this
110
+ * })
111
+ * ```
112
+ *
113
+ * @title Show Text
114
+ * @method player.showText(text,options)
115
+ * @param {string} text
116
+ * @param {object} [options] the different options, see usage below
117
+ * @returns {Promise}
118
+ * @memberof GuiManager
119
+ */
120
+ showText(msg: string, options?: DialogOptions): Promise<any>;
121
+ /**
122
+ * Shows a dialog box with a choice. Opens the GUI named `rpg-dialog`
123
+ *
124
+ * ```ts
125
+ * const choice = await player.showChoices('What color do you prefer?', [
126
+ * { text: 'Black', value: 'black' },
127
+ * { text: 'Rather the blue', value: 'blue' },
128
+ * { text: 'I don\'t have a preference!', value: 'none' }
129
+ * ])
130
+ *
131
+ * // If the player selects the first
132
+ * console.log(choice) // { text: 'Black', value: 'black' }
133
+ * ```
134
+ *
135
+ * @title Show Choices
136
+ * @method player.showChoices(text,choices)
137
+ * @param {string} text
138
+ * @param {Array<{ text: string, value: any }>} choices
139
+ * @param {object} [options] Same options as the openDialog method
140
+ * @returns {Promise<Choice | null>}
141
+ * @memberof GuiManager
142
+ */
143
+ showChoices(msg: string, choices: Choice[], options?: DialogOptions): Promise<Choice | null>;
144
+ /**
145
+ * Displays a notification . Opens the GUI named `rpg-notification`
146
+ *
147
+ * @title Displays a notification
148
+ * @method player.showNotification()
149
+ * @param {string} message - The message to display in the notification
150
+ * @param {object} options - An object containing options for the notification
151
+ * @param {number} options.time - The time to display the notification for (in ms). Default: 2000ms
152
+ * @param {string} options.icon - The icon to display in the notification. Put the identifier of the spritesheet (defined on the client side)
153
+ * @param {string} options.sound - The sound to play when the notification is shown. Set the sound ID (defined on the client side)
154
+ * @returns {void}
155
+ * @memberof GuiManager
156
+ */
157
+ showNotification(message: string, options?: {
158
+ time?: number;
159
+ icon?: string;
160
+ sound?: string;
161
+ }): Promise<any>;
162
+ /**
163
+ * Calls main menu. Opens the GUI named `rpg-main-menu`
164
+ *
165
+ * @title Call Main Menu
166
+ * @method player.callMainMenu()
167
+ * @returns {void}
168
+ * @memberof GuiManager
169
+ */
170
+ callMainMenu(): void;
171
+ callShop(items: any[]): void;
172
+ gui(guiId: string): Gui;
173
+ removeGui(guiId: string, data?: any): void;
174
+ showAttachedGui(players?: RpgPlayer[] | RpgPlayer): void;
175
+ hideAttachedGui(players?: RpgPlayer[] | RpgPlayer): void;
176
+ }
package/dist/index.js CHANGED
@@ -25651,34 +25651,6 @@ var PrebuiltGui = /* @__PURE__ */ ((PrebuiltGui2) => {
25651
25651
 
25652
25652
  function WithComponentManager(Base) {
25653
25653
  return class extends Base {
25654
- /**
25655
- * Set the graphic(s) for this player
25656
- *
25657
- * Allows setting either a single graphic or multiple graphics for the player.
25658
- * When multiple graphics are provided, they are used for animation sequences.
25659
- * The graphics system provides flexible visual representation that can be
25660
- * dynamically changed during gameplay for different states, equipment, or animations.
25661
- *
25662
- * @param graphic - Single graphic name or array of graphic names for animation sequences
25663
- * @returns void
25664
- *
25665
- * @example
25666
- * ```ts
25667
- * // Set a single graphic for static representation
25668
- * player.setGraphic("hero");
25669
- *
25670
- * // Set multiple graphics for animation sequences
25671
- * player.setGraphic(["hero_idle", "hero_walk", "hero_run"]);
25672
- *
25673
- * // Dynamic graphic changes based on equipment
25674
- * if (player.hasArmor('platemail')) {
25675
- * player.setGraphic("hero_armored");
25676
- * }
25677
- *
25678
- * // Animation sequences for different actions
25679
- * player.setGraphic(["mage_cast_1", "mage_cast_2", "mage_cast_3"]);
25680
- * ```
25681
- */
25682
25654
  setGraphic(graphic) {
25683
25655
  if (Array.isArray(graphic)) {
25684
25656
  this.graphics.set(graphic);
@@ -26990,123 +26962,16 @@ class NotificationGui extends Gui {
26990
26962
  }
26991
26963
 
26992
26964
  function WithGuiManager(Base) {
26993
- return class extends Base {
26965
+ class GuiManagerMixin extends Base {
26994
26966
  constructor() {
26995
26967
  super(...arguments);
26996
26968
  this._gui = {};
26997
26969
  }
26998
- /**
26999
- * Show a text. This is a graphical interface already built. Opens the GUI named `rpg-dialog`
27000
- *
27001
- * ```ts
27002
- * player.showText('Hello World')
27003
- * ```
27004
- *
27005
- * The method returns a promise. It is resolved when the dialog box is closed.
27006
- *
27007
- * ```ts
27008
- * await player.showText('Hello World')
27009
- * // dialog box is closed, then ...
27010
- * ```
27011
- *
27012
- * **Option: position**
27013
- *
27014
- * You can define how the dialog box is displayed:
27015
- * - top
27016
- * - middle
27017
- * - bottom
27018
- *
27019
- * (bottom by default)
27020
- *
27021
- * ```ts
27022
- * player.showText('Hello World', {
27023
- * position: 'top'
27024
- * })
27025
- * ```
27026
- *
27027
- * **Option: fullWidth**
27028
- *
27029
- * `boolean` (true by default)
27030
- *
27031
- * Indicate that the dialog box will take the full width of the screen.
27032
- *
27033
- * ```ts
27034
- * player.showText('Hello World', {
27035
- * fullWidth: true
27036
- * })
27037
- * ```
27038
- *
27039
- * **Option: autoClose**
27040
- *
27041
- * `boolean` (false by default)
27042
- *
27043
- * If false, the user will have to press Enter to close the dialog box.
27044
- *
27045
- * ```ts
27046
- * player.showText('Hello World', {
27047
- * autoClose: true
27048
- * })
27049
- * ```
27050
- *
27051
- * **Option: typewriterEffect**
27052
- *
27053
- * `boolean` (true by default)
27054
- *
27055
- * Performs a typewriter effect
27056
- *
27057
- * ```ts
27058
- * player.showText('Hello World', {
27059
- * typewriterEffect: false
27060
- * })
27061
- * ```
27062
- *
27063
- * **Option: talkWith**
27064
- *
27065
- * `RpgPlayer` (nothing by default)
27066
- *
27067
- * If you specify the event or another player, the other player will stop his or her movement and look in the player's direction.
27068
- *
27069
- * ```ts
27070
- * // Code in an event
27071
- * player.showText('Hello World', {
27072
- * talkWith: this
27073
- * })
27074
- * ```
27075
- *
27076
- * @title Show Text
27077
- * @method player.showText(text,options)
27078
- * @param {string} text
27079
- * @param {object} [options] the different options, see usage below
27080
- * @returns {Promise}
27081
- * @memberof GuiManager
27082
- */
27083
26970
  showText(msg, options = {}) {
27084
26971
  const gui = new DialogGui(this);
27085
26972
  this._gui[gui.id] = gui;
27086
26973
  return gui.openDialog(msg, options);
27087
26974
  }
27088
- /**
27089
- * Shows a dialog box with a choice. Opens the GUI named `rpg-dialog`
27090
- *
27091
- * ```ts
27092
- * const choice = await player.showChoices('What color do you prefer?', [
27093
- * { text: 'Black', value: 'black' },
27094
- * { text: 'Rather the blue', value: 'blue' },
27095
- * { text: 'I don\'t have a preference!', value: 'none' }
27096
- * ])
27097
- *
27098
- * // If the player selects the first
27099
- * console.log(choice) // { text: 'Black', value: 'black' }
27100
- * ```
27101
- *
27102
- * @title Show Choices
27103
- * @method player.showChoices(text,choices)
27104
- * @param {string} text
27105
- * @param {Array<{ text: string, value: any }>} choices
27106
- * @param {object} [options] Same options as the openDialog method
27107
- * @returns {Promise<Choice | null>}
27108
- * @memberof GuiManager
27109
- */
27110
26975
  showChoices(msg, choices, options) {
27111
26976
  return this.showText(msg, {
27112
26977
  choices,
@@ -27116,19 +26981,6 @@ function WithGuiManager(Base) {
27116
26981
  return choices[indexSelected];
27117
26982
  });
27118
26983
  }
27119
- /**
27120
- * Displays a notification . Opens the GUI named `rpg-notification`
27121
- *
27122
- * @title Displays a notification
27123
- * @method player.showNotification()
27124
- * @param {string} message - The message to display in the notification
27125
- * @param {object} options - An object containing options for the notification
27126
- * @param {number} options.time - The time to display the notification for (in ms). Default: 2000ms
27127
- * @param {string} options.icon - The icon to display in the notification. Put the identifier of the spritesheet (defined on the client side)
27128
- * @param {string} options.sound - The sound to play when the notification is shown. Set the sound ID (defined on the client side)
27129
- * @returns {void}
27130
- * @memberof GuiManager
27131
- */
27132
26984
  showNotification(message, options = {}) {
27133
26985
  const gui = new NotificationGui(this);
27134
26986
  this._gui[gui.id] = gui;
@@ -27138,14 +26990,6 @@ function WithGuiManager(Base) {
27138
26990
  };
27139
26991
  return gui.open(data);
27140
26992
  }
27141
- /**
27142
- * Calls main menu. Opens the GUI named `rpg-main-menu`
27143
- *
27144
- * @title Call Main Menu
27145
- * @method player.callMainMenu()
27146
- * @returns {void}
27147
- * @memberof GuiManager
27148
- */
27149
26993
  callMainMenu() {
27150
26994
  const gui = new MenuGui(this);
27151
26995
  this._gui[gui.id] = gui;
@@ -27278,7 +27122,8 @@ function WithGuiManager(Base) {
27278
27122
  const _players = players || this;
27279
27123
  this._attachedGui(_players, false);
27280
27124
  }
27281
- };
27125
+ }
27126
+ return GuiManagerMixin;
27282
27127
  }
27283
27128
 
27284
27129
  function WithGoldManager(Base) {