@rpgjs/server 5.0.0-alpha.4 → 5.0.0-alpha.41
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/Gui/DialogGui.d.ts +5 -0
- package/dist/Gui/GameoverGui.d.ts +23 -0
- package/dist/Gui/Gui.d.ts +6 -0
- package/dist/Gui/MenuGui.d.ts +22 -3
- package/dist/Gui/NotificationGui.d.ts +1 -2
- package/dist/Gui/SaveLoadGui.d.ts +13 -0
- package/dist/Gui/ShopGui.d.ts +28 -3
- package/dist/Gui/TitleGui.d.ts +23 -0
- package/dist/Gui/index.d.ts +10 -1
- package/dist/Player/BattleManager.d.ts +34 -12
- package/dist/Player/ClassManager.d.ts +46 -13
- package/dist/Player/ComponentManager.d.ts +123 -0
- package/dist/Player/Components.d.ts +345 -0
- package/dist/Player/EffectManager.d.ts +86 -0
- package/dist/Player/ElementManager.d.ts +104 -0
- package/dist/Player/GoldManager.d.ts +22 -0
- package/dist/Player/GuiManager.d.ts +259 -0
- package/dist/Player/ItemFixture.d.ts +6 -0
- package/dist/Player/ItemManager.d.ts +450 -9
- package/dist/Player/MoveManager.d.ts +324 -69
- package/dist/Player/ParameterManager.d.ts +344 -14
- package/dist/Player/Player.d.ts +460 -8
- package/dist/Player/SkillManager.d.ts +197 -15
- package/dist/Player/StateManager.d.ts +89 -25
- package/dist/Player/VariableManager.d.ts +74 -0
- package/dist/RpgServer.d.ts +502 -64
- package/dist/RpgServerEngine.d.ts +2 -1
- package/dist/decorators/event.d.ts +46 -0
- package/dist/decorators/map.d.ts +287 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +21653 -20900
- package/dist/index.js.map +1 -1
- package/dist/logs/log.d.ts +2 -3
- package/dist/module.d.ts +43 -1
- package/dist/presets/index.d.ts +0 -9
- package/dist/rooms/BaseRoom.d.ts +132 -0
- package/dist/rooms/lobby.d.ts +10 -2
- package/dist/rooms/map.d.ts +1236 -17
- package/dist/services/save.d.ts +43 -0
- package/dist/storage/index.d.ts +1 -0
- package/dist/storage/localStorage.d.ts +23 -0
- package/package.json +14 -10
- package/src/Gui/DialogGui.ts +19 -4
- package/src/Gui/GameoverGui.ts +39 -0
- package/src/Gui/Gui.ts +23 -1
- package/src/Gui/MenuGui.ts +155 -6
- package/src/Gui/NotificationGui.ts +1 -2
- package/src/Gui/SaveLoadGui.ts +60 -0
- package/src/Gui/ShopGui.ts +146 -16
- package/src/Gui/TitleGui.ts +39 -0
- package/src/Gui/index.ts +15 -2
- package/src/Player/BattleManager.ts +91 -49
- package/src/Player/ClassManager.ts +118 -50
- package/src/Player/ComponentManager.ts +425 -19
- package/src/Player/Components.ts +380 -0
- package/src/Player/EffectManager.ts +81 -44
- package/src/Player/ElementManager.ts +109 -86
- package/src/Player/GoldManager.ts +32 -35
- package/src/Player/GuiManager.ts +308 -150
- package/src/Player/ItemFixture.ts +4 -5
- package/src/Player/ItemManager.ts +774 -355
- package/src/Player/MoveManager.ts +1544 -774
- package/src/Player/ParameterManager.ts +546 -104
- package/src/Player/Player.ts +1163 -88
- package/src/Player/SkillManager.ts +520 -195
- package/src/Player/StateManager.ts +170 -182
- package/src/Player/VariableManager.ts +101 -63
- package/src/RpgServer.ts +525 -63
- package/src/core/context.ts +1 -0
- package/src/decorators/event.ts +61 -0
- package/src/decorators/map.ts +327 -0
- package/src/index.ts +11 -1
- package/src/logs/log.ts +10 -3
- package/src/module.ts +126 -3
- package/src/presets/index.ts +1 -10
- package/src/rooms/BaseRoom.ts +232 -0
- package/src/rooms/lobby.ts +25 -7
- package/src/rooms/map.ts +2502 -194
- package/src/services/save.ts +147 -0
- package/src/storage/index.ts +1 -0
- package/src/storage/localStorage.ts +76 -0
- package/tests/battle.spec.ts +375 -0
- package/tests/change-map.spec.ts +72 -0
- package/tests/class.spec.ts +274 -0
- package/tests/effect.spec.ts +219 -0
- package/tests/element.spec.ts +221 -0
- package/tests/event.spec.ts +80 -0
- package/tests/gold.spec.ts +99 -0
- package/tests/item.spec.ts +609 -0
- package/tests/module.spec.ts +38 -0
- package/tests/move.spec.ts +601 -0
- package/tests/player-param.spec.ts +28 -0
- package/tests/prediction-reconciliation.spec.ts +182 -0
- package/tests/random-move.spec.ts +65 -0
- package/tests/skill.spec.ts +658 -0
- package/tests/state.spec.ts +467 -0
- package/tests/variable.spec.ts +185 -0
- package/tests/world-maps.spec.ts +896 -0
- package/vite.config.ts +16 -0
- package/dist/Player/Event.d.ts +0 -0
- package/src/Player/Event.ts +0 -0
package/src/Player/GuiManager.ts
CHANGED
|
@@ -1,132 +1,48 @@
|
|
|
1
1
|
import { RpgPlayer } from "./Player";
|
|
2
|
-
import { Gui, DialogGui, MenuGui, ShopGui, NotificationGui } from "../Gui";
|
|
2
|
+
import { Gui, DialogGui, MenuGui, ShopGui, NotificationGui, SaveLoadGui, GameoverGui } from "../Gui";
|
|
3
3
|
import { DialogOptions, Choice } from "../Gui/DialogGui";
|
|
4
|
-
import {
|
|
4
|
+
import { SaveLoadOptions, SaveSlot } from "../Gui/SaveLoadGui";
|
|
5
|
+
import { MenuGuiOptions } from "../Gui/MenuGui";
|
|
6
|
+
import { GameoverGuiOptions, GameoverGuiSelection } from "../Gui/GameoverGui";
|
|
7
|
+
import { Constructor, PlayerCtor } from "@rpgjs/common";
|
|
5
8
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
/**
|
|
10
|
+
* GUI Manager Mixin
|
|
11
|
+
*
|
|
12
|
+
* Provides graphical user interface management capabilities to any class. This mixin handles
|
|
13
|
+
* dialog boxes, menus, notifications, shops, and custom GUI components. It manages the
|
|
14
|
+
* complete GUI system including opening, closing, and data passing between client and server.
|
|
15
|
+
*
|
|
16
|
+
* @param Base - The base class to extend with GUI management
|
|
17
|
+
* @returns Extended class with GUI management methods
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* class MyPlayer extends WithGuiManager(BasePlayer) {
|
|
22
|
+
* constructor() {
|
|
23
|
+
* super();
|
|
24
|
+
* // GUI system is automatically initialized
|
|
25
|
+
* }
|
|
26
|
+
* }
|
|
27
|
+
*
|
|
28
|
+
* const player = new MyPlayer();
|
|
29
|
+
* await player.showText('Hello World!');
|
|
30
|
+
* player.callMainMenu();
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export function WithGuiManager<TBase extends PlayerCtor>(
|
|
12
34
|
Base: TBase
|
|
13
|
-
)
|
|
14
|
-
|
|
35
|
+
): new (...args: ConstructorParameters<TBase>) => InstanceType<TBase> &
|
|
36
|
+
IGuiManager {
|
|
37
|
+
class GuiManagerMixin extends Base {
|
|
15
38
|
_gui: { [id: string]: Gui } = {};
|
|
16
39
|
|
|
17
|
-
/**
|
|
18
|
-
* Show a text. This is a graphical interface already built. Opens the GUI named `rpg-dialog`
|
|
19
|
-
*
|
|
20
|
-
* ```ts
|
|
21
|
-
* player.showText('Hello World')
|
|
22
|
-
* ```
|
|
23
|
-
*
|
|
24
|
-
* The method returns a promise. It is resolved when the dialog box is closed.
|
|
25
|
-
*
|
|
26
|
-
* ```ts
|
|
27
|
-
* await player.showText('Hello World')
|
|
28
|
-
* // dialog box is closed, then ...
|
|
29
|
-
* ```
|
|
30
|
-
*
|
|
31
|
-
* **Option: position**
|
|
32
|
-
*
|
|
33
|
-
* You can define how the dialog box is displayed:
|
|
34
|
-
* - top
|
|
35
|
-
* - middle
|
|
36
|
-
* - bottom
|
|
37
|
-
*
|
|
38
|
-
* (bottom by default)
|
|
39
|
-
*
|
|
40
|
-
* ```ts
|
|
41
|
-
* player.showText('Hello World', {
|
|
42
|
-
* position: 'top'
|
|
43
|
-
* })
|
|
44
|
-
* ```
|
|
45
|
-
*
|
|
46
|
-
* **Option: fullWidth**
|
|
47
|
-
*
|
|
48
|
-
* `boolean` (true by default)
|
|
49
|
-
*
|
|
50
|
-
* Indicate that the dialog box will take the full width of the screen.
|
|
51
|
-
*
|
|
52
|
-
* ```ts
|
|
53
|
-
* player.showText('Hello World', {
|
|
54
|
-
* fullWidth: true
|
|
55
|
-
* })
|
|
56
|
-
* ```
|
|
57
|
-
*
|
|
58
|
-
* **Option: autoClose**
|
|
59
|
-
*
|
|
60
|
-
* `boolean` (false by default)
|
|
61
|
-
*
|
|
62
|
-
* If false, the user will have to press Enter to close the dialog box.
|
|
63
|
-
*
|
|
64
|
-
* ```ts
|
|
65
|
-
* player.showText('Hello World', {
|
|
66
|
-
* autoClose: true
|
|
67
|
-
* })
|
|
68
|
-
* ```
|
|
69
|
-
*
|
|
70
|
-
* **Option: typewriterEffect**
|
|
71
|
-
*
|
|
72
|
-
* `boolean` (true by default)
|
|
73
|
-
*
|
|
74
|
-
* Performs a typewriter effect
|
|
75
|
-
*
|
|
76
|
-
* ```ts
|
|
77
|
-
* player.showText('Hello World', {
|
|
78
|
-
* typewriterEffect: false
|
|
79
|
-
* })
|
|
80
|
-
* ```
|
|
81
|
-
*
|
|
82
|
-
* **Option: talkWith**
|
|
83
|
-
*
|
|
84
|
-
* `RpgPlayer` (nothing by default)
|
|
85
|
-
*
|
|
86
|
-
* If you specify the event or another player, the other player will stop his or her movement and look in the player's direction.
|
|
87
|
-
*
|
|
88
|
-
* ```ts
|
|
89
|
-
* // Code in an event
|
|
90
|
-
* player.showText('Hello World', {
|
|
91
|
-
* talkWith: this
|
|
92
|
-
* })
|
|
93
|
-
* ```
|
|
94
|
-
*
|
|
95
|
-
* @title Show Text
|
|
96
|
-
* @method player.showText(text,options)
|
|
97
|
-
* @param {string} text
|
|
98
|
-
* @param {object} [options] the different options, see usage below
|
|
99
|
-
* @returns {Promise}
|
|
100
|
-
* @memberof GuiManager
|
|
101
|
-
*/
|
|
102
40
|
showText(msg: string, options: DialogOptions = {}): Promise<any> {
|
|
103
41
|
const gui = new DialogGui(<any>this);
|
|
104
42
|
this._gui[gui.id] = gui;
|
|
105
43
|
return gui.openDialog(msg, options);
|
|
106
44
|
}
|
|
107
45
|
|
|
108
|
-
/**
|
|
109
|
-
* Shows a dialog box with a choice. Opens the GUI named `rpg-dialog`
|
|
110
|
-
*
|
|
111
|
-
* ```ts
|
|
112
|
-
* const choice = await player.showChoices('What color do you prefer?', [
|
|
113
|
-
* { text: 'Black', value: 'black' },
|
|
114
|
-
* { text: 'Rather the blue', value: 'blue' },
|
|
115
|
-
* { text: 'I don\'t have a preference!', value: 'none' }
|
|
116
|
-
* ])
|
|
117
|
-
*
|
|
118
|
-
* // If the player selects the first
|
|
119
|
-
* console.log(choice) // { text: 'Black', value: 'black' }
|
|
120
|
-
* ```
|
|
121
|
-
*
|
|
122
|
-
* @title Show Choices
|
|
123
|
-
* @method player.showChoices(text,choices)
|
|
124
|
-
* @param {string} text
|
|
125
|
-
* @param {Array<{ text: string, value: any }>} choices
|
|
126
|
-
* @param {object} [options] Same options as the openDialog method
|
|
127
|
-
* @returns {Promise<Choice | null>}
|
|
128
|
-
* @memberof GuiManager
|
|
129
|
-
*/
|
|
130
46
|
showChoices(
|
|
131
47
|
msg: string,
|
|
132
48
|
choices: Choice[],
|
|
@@ -141,44 +57,44 @@ export function WithGuiManager<TBase extends Constructor<RpgCommonPlayer>>(
|
|
|
141
57
|
});
|
|
142
58
|
}
|
|
143
59
|
|
|
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
60
|
showNotification(
|
|
158
61
|
message: string,
|
|
159
|
-
options: { time?: number; icon?: string; sound?: string } = {}
|
|
62
|
+
options: { time?: number; icon?: string; sound?: string; type?: "info" | "warn" | "error" } = {}
|
|
160
63
|
): Promise<any> {
|
|
161
|
-
|
|
162
|
-
this._gui[gui.id] = gui;
|
|
163
|
-
const data = {
|
|
64
|
+
this.emit('notification', {
|
|
164
65
|
message,
|
|
165
66
|
...options,
|
|
166
|
-
};
|
|
167
|
-
return
|
|
67
|
+
});
|
|
68
|
+
return Promise.resolve(true);
|
|
168
69
|
}
|
|
169
70
|
|
|
170
|
-
|
|
171
|
-
* Calls main menu. Opens the GUI named `rpg-main-menu`
|
|
172
|
-
*
|
|
173
|
-
* @title Call Main Menu
|
|
174
|
-
* @method player.callMainMenu()
|
|
175
|
-
* @returns {void}
|
|
176
|
-
* @memberof GuiManager
|
|
177
|
-
*/
|
|
178
|
-
callMainMenu() {
|
|
71
|
+
callMainMenu(options: MenuGuiOptions = {}) {
|
|
179
72
|
const gui = new MenuGui(<any>this);
|
|
180
73
|
this._gui[gui.id] = gui;
|
|
181
|
-
return gui.open();
|
|
74
|
+
return gui.open(options);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
callGameover(options: GameoverGuiOptions = {}): Promise<GameoverGuiSelection | null> {
|
|
78
|
+
const gui = new GameoverGui(<any>this);
|
|
79
|
+
this._gui[gui.id] = gui;
|
|
80
|
+
return gui.open(options);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
showSaveLoad(slots: SaveSlot[] = [], options: SaveLoadOptions = {}): Promise<number | null> {
|
|
84
|
+
const gui = new SaveLoadGui(<any>this);
|
|
85
|
+
this._gui[gui.id] = gui;
|
|
86
|
+
return gui.open(slots, options).then((index) => {
|
|
87
|
+
if (typeof index !== 'number') return null;
|
|
88
|
+
return index;
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
showSave(slots: SaveSlot[] = [], options: SaveLoadOptions = {}): Promise<number | null> {
|
|
93
|
+
return this.showSaveLoad(slots, { ...options, mode: 'save' });
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
showLoad(slots: SaveSlot[] = [], options: SaveLoadOptions = {}): Promise<number | null> {
|
|
97
|
+
return this.showSaveLoad(slots, { ...options, mode: 'load' });
|
|
182
98
|
}
|
|
183
99
|
|
|
184
100
|
/**
|
|
@@ -189,7 +105,13 @@ export function WithGuiManager<TBase extends Constructor<RpgCommonPlayer>>(
|
|
|
189
105
|
* @returns {void}
|
|
190
106
|
* @memberof GuiManager
|
|
191
107
|
*/
|
|
192
|
-
callShop(items: any[]
|
|
108
|
+
callShop(items: any[] | {
|
|
109
|
+
items: any[]
|
|
110
|
+
sell?: Record<string, number> | Array<{ id: string; multiplier: number }>
|
|
111
|
+
sellMultiplier?: number
|
|
112
|
+
message?: string
|
|
113
|
+
face?: { id: string; expression?: string }
|
|
114
|
+
}) {
|
|
193
115
|
const gui = new ShopGui(<any>this);
|
|
194
116
|
this._gui[gui.id] = gui;
|
|
195
117
|
return gui.open(items);
|
|
@@ -236,6 +158,10 @@ export function WithGuiManager<TBase extends Constructor<RpgCommonPlayer>>(
|
|
|
236
158
|
return gui;
|
|
237
159
|
}
|
|
238
160
|
|
|
161
|
+
getGui(guiId: string) {
|
|
162
|
+
return this._gui[guiId];
|
|
163
|
+
}
|
|
164
|
+
|
|
239
165
|
/**
|
|
240
166
|
* Closes the GUI and removes it from memory
|
|
241
167
|
*
|
|
@@ -253,11 +179,11 @@ export function WithGuiManager<TBase extends Constructor<RpgCommonPlayer>>(
|
|
|
253
179
|
}
|
|
254
180
|
}
|
|
255
181
|
|
|
256
|
-
|
|
182
|
+
_attachedGui(players: RpgPlayer[] | RpgPlayer, display: boolean) {
|
|
257
183
|
if (!Array.isArray(players)) {
|
|
258
184
|
players = [players] as RpgPlayer[];
|
|
259
185
|
}
|
|
260
|
-
this.emit("gui.tooltip", {
|
|
186
|
+
(this as any).emit("gui.tooltip", {
|
|
261
187
|
players: (players as RpgPlayer[]).map((player) => player.id),
|
|
262
188
|
display,
|
|
263
189
|
});
|
|
@@ -313,5 +239,237 @@ export function WithGuiManager<TBase extends Constructor<RpgCommonPlayer>>(
|
|
|
313
239
|
const _players = players || this;
|
|
314
240
|
this._attachedGui(_players as RpgPlayer[], false);
|
|
315
241
|
}
|
|
316
|
-
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
return GuiManagerMixin as unknown as any;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Interface for GUI management capabilities
|
|
249
|
+
* Defines the methods that will be available on the player
|
|
250
|
+
*/
|
|
251
|
+
export interface IGuiManager {
|
|
252
|
+
/**
|
|
253
|
+
* Show a text. This is a graphical interface already built. Opens the GUI named `rpg-dialog`
|
|
254
|
+
*
|
|
255
|
+
* ```ts
|
|
256
|
+
* player.showText('Hello World')
|
|
257
|
+
* ```
|
|
258
|
+
*
|
|
259
|
+
* The method returns a promise. It is resolved when the dialog box is closed.
|
|
260
|
+
*
|
|
261
|
+
* ```ts
|
|
262
|
+
* await player.showText('Hello World')
|
|
263
|
+
* // dialog box is closed, then ...
|
|
264
|
+
* ```
|
|
265
|
+
*
|
|
266
|
+
* **Option: position**
|
|
267
|
+
*
|
|
268
|
+
* You can define how the dialog box is displayed:
|
|
269
|
+
* - top
|
|
270
|
+
* - middle
|
|
271
|
+
* - bottom
|
|
272
|
+
*
|
|
273
|
+
* (bottom by default)
|
|
274
|
+
*
|
|
275
|
+
* ```ts
|
|
276
|
+
* player.showText('Hello World', {
|
|
277
|
+
* position: 'top'
|
|
278
|
+
* })
|
|
279
|
+
* ```
|
|
280
|
+
*
|
|
281
|
+
* **Option: fullWidth**
|
|
282
|
+
*
|
|
283
|
+
* `boolean` (true by default)
|
|
284
|
+
*
|
|
285
|
+
* Indicate that the dialog box will take the full width of the screen.
|
|
286
|
+
*
|
|
287
|
+
* ```ts
|
|
288
|
+
* player.showText('Hello World', {
|
|
289
|
+
* fullWidth: true
|
|
290
|
+
* })
|
|
291
|
+
* ```
|
|
292
|
+
*
|
|
293
|
+
* **Option: autoClose**
|
|
294
|
+
*
|
|
295
|
+
* `boolean` (false by default)
|
|
296
|
+
*
|
|
297
|
+
* If false, the user will have to press Enter to close the dialog box.
|
|
298
|
+
*
|
|
299
|
+
* ```ts
|
|
300
|
+
* player.showText('Hello World', {
|
|
301
|
+
* autoClose: true
|
|
302
|
+
* })
|
|
303
|
+
* ```
|
|
304
|
+
*
|
|
305
|
+
* **Option: typewriterEffect**
|
|
306
|
+
*
|
|
307
|
+
* `boolean` (true by default)
|
|
308
|
+
*
|
|
309
|
+
* Performs a typewriter effect
|
|
310
|
+
*
|
|
311
|
+
* ```ts
|
|
312
|
+
* player.showText('Hello World', {
|
|
313
|
+
* typewriterEffect: false
|
|
314
|
+
* })
|
|
315
|
+
* ```
|
|
316
|
+
*
|
|
317
|
+
* **Option: talkWith**
|
|
318
|
+
*
|
|
319
|
+
* `RpgPlayer` (nothing by default)
|
|
320
|
+
*
|
|
321
|
+
* If you specify the event or another player, the other player will stop his or her movement and look in the player's direction.
|
|
322
|
+
*
|
|
323
|
+
* ```ts
|
|
324
|
+
* // Code in an event
|
|
325
|
+
* player.showText('Hello World', {
|
|
326
|
+
* talkWith: this
|
|
327
|
+
* })
|
|
328
|
+
* ```
|
|
329
|
+
*
|
|
330
|
+
* @title Show Text
|
|
331
|
+
* @method player.showText(text,options)
|
|
332
|
+
* @param {string} text
|
|
333
|
+
* @param {object} [options] the different options, see usage below
|
|
334
|
+
* @returns {Promise}
|
|
335
|
+
* @memberof GuiManager
|
|
336
|
+
*/
|
|
337
|
+
showText(msg: string, options?: DialogOptions): Promise<any>;
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* Shows a dialog box with a choice. Opens the GUI named `rpg-dialog`
|
|
341
|
+
*
|
|
342
|
+
* ```ts
|
|
343
|
+
* const choice = await player.showChoices('What color do you prefer?', [
|
|
344
|
+
* { text: 'Black', value: 'black' },
|
|
345
|
+
* { text: 'Rather the blue', value: 'blue' },
|
|
346
|
+
* { text: 'I don\'t have a preference!', value: 'none' }
|
|
347
|
+
* ])
|
|
348
|
+
*
|
|
349
|
+
* // If the player selects the first
|
|
350
|
+
* console.log(choice) // { text: 'Black', value: 'black' }
|
|
351
|
+
* ```
|
|
352
|
+
*
|
|
353
|
+
* @title Show Choices
|
|
354
|
+
* @method player.showChoices(text,choices)
|
|
355
|
+
* @param {string} text
|
|
356
|
+
* @param {Array<{ text: string, value: any }>} choices
|
|
357
|
+
* @param {object} [options] Same options as the openDialog method
|
|
358
|
+
* @returns {Promise<Choice | null>}
|
|
359
|
+
* @memberof GuiManager
|
|
360
|
+
*/
|
|
361
|
+
showChoices(
|
|
362
|
+
msg: string,
|
|
363
|
+
choices: Choice[],
|
|
364
|
+
options?: DialogOptions
|
|
365
|
+
): Promise<Choice | null>;
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
* Displays a notification . Opens the GUI named `rpg-notification`
|
|
369
|
+
*
|
|
370
|
+
* @title Displays a notification
|
|
371
|
+
* @method player.showNotification()
|
|
372
|
+
* @param {string} message - The message to display in the notification
|
|
373
|
+
* @param {object} options - An object containing options for the notification
|
|
374
|
+
* @param {number} options.time - The time to display the notification for (in ms). Default: 2000ms
|
|
375
|
+
* @param {string} options.icon - The icon to display in the notification. Put the identifier of the spritesheet (defined on the client side)
|
|
376
|
+
* @param {string} options.sound - The sound to play when the notification is shown. Set the sound ID (defined on the client side)
|
|
377
|
+
* @returns {void}
|
|
378
|
+
* @memberof GuiManager
|
|
379
|
+
*/
|
|
380
|
+
showNotification(
|
|
381
|
+
message: string,
|
|
382
|
+
options?: { time?: number; icon?: string; sound?: string; type?: "info" | "warn" | "error" }
|
|
383
|
+
): Promise<any>;
|
|
384
|
+
|
|
385
|
+
/**
|
|
386
|
+
* Display a save/load slots screen. Opens the GUI named `rpg-save`
|
|
387
|
+
*
|
|
388
|
+
* ```ts
|
|
389
|
+
* const index = await player.showSaveLoad(slots, { mode: 'save' })
|
|
390
|
+
* ```
|
|
391
|
+
*
|
|
392
|
+
* @title Show Save/Load
|
|
393
|
+
* @method player.showSaveLoad(slots,options)
|
|
394
|
+
* @param {Array<object>} slots
|
|
395
|
+
* @param {object} [options]
|
|
396
|
+
* @returns {Promise<number | null>}
|
|
397
|
+
* @memberof GuiManager
|
|
398
|
+
*/
|
|
399
|
+
showSaveLoad(slots?: SaveSlot[], options?: SaveLoadOptions): Promise<number | null>;
|
|
400
|
+
|
|
401
|
+
/**
|
|
402
|
+
* Display a save slots screen. Opens the GUI named `rpg-save`
|
|
403
|
+
*
|
|
404
|
+
* ```ts
|
|
405
|
+
* const index = await player.showSave(slots)
|
|
406
|
+
* ```
|
|
407
|
+
*
|
|
408
|
+
* @title Show Save
|
|
409
|
+
* @method player.showSave(slots,options)
|
|
410
|
+
* @param {Array<object>} slots
|
|
411
|
+
* @param {object} [options]
|
|
412
|
+
* @returns {Promise<number | null>}
|
|
413
|
+
* @memberof GuiManager
|
|
414
|
+
*/
|
|
415
|
+
showSave(slots?: SaveSlot[], options?: SaveLoadOptions): Promise<number | null>;
|
|
416
|
+
|
|
417
|
+
/**
|
|
418
|
+
* Display a load slots screen. Opens the GUI named `rpg-save`
|
|
419
|
+
*
|
|
420
|
+
* ```ts
|
|
421
|
+
* const index = await player.showLoad(slots)
|
|
422
|
+
* ```
|
|
423
|
+
*
|
|
424
|
+
* @title Show Load
|
|
425
|
+
* @method player.showLoad(slots,options)
|
|
426
|
+
* @param {Array<object>} slots
|
|
427
|
+
* @param {object} [options]
|
|
428
|
+
* @returns {Promise<number | null>}
|
|
429
|
+
* @memberof GuiManager
|
|
430
|
+
*/
|
|
431
|
+
showLoad(slots?: SaveSlot[], options?: SaveLoadOptions): Promise<number | null>;
|
|
432
|
+
/**
|
|
433
|
+
* Calls main menu. Opens the GUI named `rpg-main-menu`
|
|
434
|
+
*
|
|
435
|
+
* @title Call Main Menu
|
|
436
|
+
* @method player.callMainMenu(options)
|
|
437
|
+
* @param {object} [options]
|
|
438
|
+
* @returns {void}
|
|
439
|
+
* @memberof GuiManager
|
|
440
|
+
*/
|
|
441
|
+
callMainMenu(options?: MenuGuiOptions): void;
|
|
442
|
+
|
|
443
|
+
/**
|
|
444
|
+
* Calls game over menu. Opens the GUI named `rpg-gameover`
|
|
445
|
+
*
|
|
446
|
+
* ```ts
|
|
447
|
+
* const selection = await player.callGameover()
|
|
448
|
+
* if (selection?.id === 'title') {
|
|
449
|
+
* await player.gui('rpg-title-screen').open()
|
|
450
|
+
* }
|
|
451
|
+
* if (selection?.id === 'load') {
|
|
452
|
+
* await player.showLoad()
|
|
453
|
+
* }
|
|
454
|
+
* ```
|
|
455
|
+
*
|
|
456
|
+
* @title Call Game Over Menu
|
|
457
|
+
* @method player.callGameover(options)
|
|
458
|
+
* @param {object} [options]
|
|
459
|
+
* @returns {Promise<GameoverGuiSelection | null>}
|
|
460
|
+
* @memberof GuiManager
|
|
461
|
+
*/
|
|
462
|
+
callGameover(options?: GameoverGuiOptions): Promise<GameoverGuiSelection | null>;
|
|
463
|
+
callShop(items: any[] | {
|
|
464
|
+
items: any[]
|
|
465
|
+
sell?: Record<string, number> | Array<{ id: string; multiplier: number }>
|
|
466
|
+
sellMultiplier?: number
|
|
467
|
+
message?: string
|
|
468
|
+
face?: { id: string; expression?: string }
|
|
469
|
+
}): void;
|
|
470
|
+
gui(guiId: string): Gui;
|
|
471
|
+
getGui(guiId: string): Gui;
|
|
472
|
+
removeGui(guiId: string, data?: any): void;
|
|
473
|
+
showAttachedGui(players?: RpgPlayer[] | RpgPlayer): void;
|
|
474
|
+
hideAttachedGui(players?: RpgPlayer[] | RpgPlayer): void;
|
|
317
475
|
}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { ItemInstance } from "@rpgjs/database";
|
|
2
|
-
import {
|
|
3
|
-
export class ItemFixture {}
|
|
2
|
+
import { PlayerCtor } from "@rpgjs/common";
|
|
4
3
|
|
|
5
|
-
export function WithItemFixture<TBase extends
|
|
4
|
+
export function WithItemFixture<TBase extends PlayerCtor>(
|
|
6
5
|
Base: TBase
|
|
7
6
|
) {
|
|
8
|
-
return class extends Base
|
|
7
|
+
return class extends Base {
|
|
9
8
|
protected getFeature(name, prop): any {
|
|
10
9
|
const array = {};
|
|
11
10
|
for (let item of this.equipments()) {
|
|
@@ -21,7 +20,7 @@ export function WithItemFixture<TBase extends Constructor<RpgCommonPlayer>>(
|
|
|
21
20
|
}
|
|
22
21
|
return Object.values(array);
|
|
23
22
|
}
|
|
24
|
-
};
|
|
23
|
+
} as unknown as TBase;
|
|
25
24
|
}
|
|
26
25
|
|
|
27
26
|
export interface ItemFixture {
|