@rpgjs/server 5.0.0-alpha.29 → 5.0.0-alpha.30

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.
Files changed (51) hide show
  1. package/dist/Gui/DialogGui.d.ts +1 -0
  2. package/dist/Gui/GameoverGui.d.ts +23 -0
  3. package/dist/Gui/Gui.d.ts +6 -0
  4. package/dist/Gui/MenuGui.d.ts +22 -3
  5. package/dist/Gui/NotificationGui.d.ts +1 -2
  6. package/dist/Gui/SaveLoadGui.d.ts +13 -0
  7. package/dist/Gui/ShopGui.d.ts +24 -3
  8. package/dist/Gui/TitleGui.d.ts +23 -0
  9. package/dist/Gui/index.d.ts +9 -1
  10. package/dist/Player/GuiManager.d.ts +86 -3
  11. package/dist/Player/Player.d.ts +24 -2
  12. package/dist/RpgServer.d.ts +7 -0
  13. package/dist/RpgServerEngine.d.ts +2 -1
  14. package/dist/index.d.ts +4 -1
  15. package/dist/index.js +1621 -336
  16. package/dist/index.js.map +1 -1
  17. package/dist/presets/index.d.ts +0 -9
  18. package/dist/rooms/BaseRoom.d.ts +37 -0
  19. package/dist/rooms/lobby.d.ts +6 -1
  20. package/dist/rooms/map.d.ts +22 -1
  21. package/dist/services/save.d.ts +43 -0
  22. package/dist/storage/index.d.ts +1 -0
  23. package/dist/storage/localStorage.d.ts +23 -0
  24. package/package.json +10 -10
  25. package/src/Gui/DialogGui.ts +12 -2
  26. package/src/Gui/GameoverGui.ts +39 -0
  27. package/src/Gui/Gui.ts +23 -1
  28. package/src/Gui/MenuGui.ts +155 -6
  29. package/src/Gui/NotificationGui.ts +1 -2
  30. package/src/Gui/SaveLoadGui.ts +60 -0
  31. package/src/Gui/ShopGui.ts +145 -16
  32. package/src/Gui/TitleGui.ts +39 -0
  33. package/src/Gui/index.ts +13 -2
  34. package/src/Player/BattleManager.ts +1 -1
  35. package/src/Player/ClassManager.ts +57 -2
  36. package/src/Player/GuiManager.ts +125 -14
  37. package/src/Player/ItemManager.ts +160 -41
  38. package/src/Player/ParameterManager.ts +1 -1
  39. package/src/Player/Player.ts +87 -12
  40. package/src/Player/SkillManager.ts +145 -66
  41. package/src/Player/StateManager.ts +70 -1
  42. package/src/Player/VariableManager.ts +10 -7
  43. package/src/RpgServer.ts +8 -0
  44. package/src/index.ts +5 -2
  45. package/src/presets/index.ts +1 -10
  46. package/src/rooms/BaseRoom.ts +112 -0
  47. package/src/rooms/lobby.ts +13 -6
  48. package/src/rooms/map.ts +31 -4
  49. package/src/services/save.ts +147 -0
  50. package/src/storage/index.ts +1 -0
  51. package/src/storage/localStorage.ts +76 -0
@@ -17,6 +17,7 @@ export interface DialogOptions {
17
17
  tranparent?: boolean;
18
18
  typewriterEffect?: boolean;
19
19
  talkWith?: RpgPlayer;
20
+ speaker?: string;
20
21
  face?: {
21
22
  id: string;
22
23
  expression: string;
@@ -0,0 +1,23 @@
1
+ import { Gui } from './Gui';
2
+ import { RpgPlayer } from '../Player/Player';
3
+ export interface GameoverEntry {
4
+ id: string;
5
+ label: string;
6
+ disabled?: boolean;
7
+ }
8
+ export interface GameoverGuiOptions {
9
+ entries?: GameoverEntry[];
10
+ title?: string;
11
+ subtitle?: string;
12
+ saveLoad?: Record<string, any>;
13
+ localActions?: boolean;
14
+ }
15
+ export interface GameoverGuiSelection {
16
+ id?: string;
17
+ index?: number;
18
+ entry?: GameoverEntry;
19
+ }
20
+ export declare class GameoverGui extends Gui {
21
+ constructor(player: RpgPlayer);
22
+ open(options?: GameoverGuiOptions): Promise<GameoverGuiSelection | null>;
23
+ }
package/dist/Gui/Gui.d.ts CHANGED
@@ -4,10 +4,16 @@ export declare class Gui {
4
4
  protected player: RpgPlayer;
5
5
  private _close;
6
6
  private _blockPlayerInput;
7
+ private _events;
7
8
  constructor(id: string, player: RpgPlayer);
8
9
  open(data?: any, { waitingAction, blockPlayerInput }?: {
9
10
  waitingAction?: boolean | undefined;
10
11
  blockPlayerInput?: boolean | undefined;
11
12
  }): Promise<any>;
13
+ on(event: string, callback: (data: any) => void): void;
14
+ emit(event: string, data: any): Promise<any>;
12
15
  close(data?: any): void;
16
+ update(data?: any, { clientActionId }?: {
17
+ clientActionId?: string;
18
+ }): void;
13
19
  }
@@ -1,7 +1,26 @@
1
1
  import { Gui } from './Gui';
2
2
  import { RpgPlayer } from '../Player/Player';
3
- import { IGui } from '../Interfaces/Gui';
4
- export declare class MenuGui extends Gui implements IGui {
3
+ import { SaveSlot } from './SaveLoadGui';
4
+ export type MenuEntryId = 'items' | 'skills' | 'equip' | 'options' | 'save' | 'exit';
5
+ export interface MenuEntry {
6
+ id: MenuEntryId;
7
+ label: string;
8
+ disabled?: boolean;
9
+ }
10
+ export interface MenuGuiOptions {
11
+ menus?: MenuEntry[];
12
+ disabled?: MenuEntryId[];
13
+ saveSlots?: SaveSlot[];
14
+ saveMaxSlots?: number;
15
+ saveShowAutoSlot?: boolean;
16
+ saveAutoSlotIndex?: number;
17
+ saveAutoSlotLabel?: string;
18
+ }
19
+ export declare class MenuGui extends Gui {
20
+ private menuOptions;
5
21
  constructor(player: RpgPlayer);
6
- open(): Promise<any>;
22
+ private buildSaveLoad;
23
+ private buildMenuData;
24
+ private refreshMenu;
25
+ open(options?: MenuGuiOptions): Promise<any>;
7
26
  }
@@ -1,6 +1,5 @@
1
1
  import { Gui } from './Gui';
2
2
  import { RpgPlayer } from '../Player/Player';
3
- import { IGui } from '../Interfaces/Gui';
4
- export declare class NotificationGui extends Gui implements IGui {
3
+ export declare class NotificationGui extends Gui {
5
4
  constructor(player: RpgPlayer);
6
5
  }
@@ -0,0 +1,13 @@
1
+ import { SaveSlot } from '../../../common/src';
2
+ import { Gui } from './Gui';
3
+ import { RpgPlayer } from '../Player/Player';
4
+ export type SaveLoadMode = 'save' | 'load';
5
+ export type { SaveSlot } from '../../../common/src';
6
+ export interface SaveLoadOptions {
7
+ mode?: SaveLoadMode;
8
+ maxSlots?: number;
9
+ }
10
+ export declare class SaveLoadGui extends Gui {
11
+ constructor(player: RpgPlayer);
12
+ open(slots?: SaveSlot[], options?: SaveLoadOptions): Promise<number | null>;
13
+ }
@@ -1,7 +1,28 @@
1
1
  import { Gui } from './Gui';
2
2
  import { RpgPlayer } from '../Player/Player';
3
- import { IGui } from '../Interfaces/Gui';
4
- export declare class ShopGui extends Gui implements IGui {
3
+ export type ShopSellList = Record<string, number> | Array<{
4
+ id: string;
5
+ multiplier: number;
6
+ }>;
7
+ export interface ShopGuiOptions {
8
+ items: any[];
9
+ sell?: ShopSellList;
10
+ sellMultiplier?: number;
11
+ message?: string;
12
+ face?: {
13
+ id: string;
14
+ expression?: string;
15
+ };
16
+ }
17
+ export declare class ShopGui extends Gui {
18
+ private itemsInput;
19
+ private sellMultipliers;
20
+ private baseSellMultiplier;
21
+ private messageInput?;
22
+ private faceInput?;
5
23
  constructor(player: RpgPlayer);
6
- open(items: any[]): Promise<any>;
24
+ private normalizeSellMultipliers;
25
+ private buildShopData;
26
+ private refreshShop;
27
+ open(itemsOrOptions: any[] | ShopGuiOptions): Promise<any>;
7
28
  }
@@ -0,0 +1,23 @@
1
+ import { Gui } from './Gui';
2
+ import { RpgPlayer } from '../Player/Player';
3
+ export interface TitleEntry {
4
+ id: string;
5
+ label: string;
6
+ disabled?: boolean;
7
+ }
8
+ export interface TitleGuiOptions {
9
+ entries?: TitleEntry[];
10
+ title?: string;
11
+ subtitle?: string;
12
+ version?: string;
13
+ showPressStart?: boolean;
14
+ }
15
+ export interface TitleGuiSelection {
16
+ id?: string;
17
+ index?: number;
18
+ entry?: TitleEntry;
19
+ }
20
+ export declare class TitleGui extends Gui {
21
+ constructor(player: RpgPlayer);
22
+ open(options?: TitleGuiOptions): Promise<TitleGuiSelection | null>;
23
+ }
@@ -3,5 +3,13 @@ import { DialogGui } from './DialogGui';
3
3
  import { MenuGui } from './MenuGui';
4
4
  import { ShopGui } from './ShopGui';
5
5
  import { NotificationGui } from './NotificationGui';
6
- export { Gui, DialogGui, MenuGui, ShopGui, NotificationGui };
6
+ import { SaveLoadGui } from './SaveLoadGui';
7
+ import { TitleGui } from './TitleGui';
8
+ import { GameoverGui } from './GameoverGui';
9
+ export { Gui, DialogGui, MenuGui, ShopGui, NotificationGui, SaveLoadGui, TitleGui, GameoverGui };
7
10
  export { DialogPosition } from './DialogGui';
11
+ export type { SaveLoadMode, SaveLoadOptions, SaveSlot } from './SaveLoadGui';
12
+ export type { MenuEntryId, MenuEntry, MenuGuiOptions } from './MenuGui';
13
+ export type { ShopGuiOptions, ShopSellList } from './ShopGui';
14
+ export type { TitleEntry, TitleGuiOptions, TitleGuiSelection } from './TitleGui';
15
+ export type { GameoverEntry, GameoverGuiOptions, GameoverGuiSelection } from './GameoverGui';
@@ -1,6 +1,9 @@
1
1
  import { RpgPlayer } from './Player';
2
2
  import { Gui } from '../Gui';
3
3
  import { DialogOptions, Choice } from '../Gui/DialogGui';
4
+ import { SaveLoadOptions, SaveSlot } from '../Gui/SaveLoadGui';
5
+ import { MenuGuiOptions } from '../Gui/MenuGui';
6
+ import { GameoverGuiOptions, GameoverGuiSelection } from '../Gui/GameoverGui';
4
7
  import { PlayerCtor } from '../../../common/src';
5
8
  /**
6
9
  * GUI Manager Mixin
@@ -158,18 +161,98 @@ export interface IGuiManager {
158
161
  time?: number;
159
162
  icon?: string;
160
163
  sound?: string;
164
+ type?: "info" | "warn" | "error";
161
165
  }): Promise<any>;
166
+ /**
167
+ * Display a save/load slots screen. Opens the GUI named `rpg-save`
168
+ *
169
+ * ```ts
170
+ * const index = await player.showSaveLoad(slots, { mode: 'save' })
171
+ * ```
172
+ *
173
+ * @title Show Save/Load
174
+ * @method player.showSaveLoad(slots,options)
175
+ * @param {Array<object>} slots
176
+ * @param {object} [options]
177
+ * @returns {Promise<number | null>}
178
+ * @memberof GuiManager
179
+ */
180
+ showSaveLoad(slots?: SaveSlot[], options?: SaveLoadOptions): Promise<number | null>;
181
+ /**
182
+ * Display a save slots screen. Opens the GUI named `rpg-save`
183
+ *
184
+ * ```ts
185
+ * const index = await player.showSave(slots)
186
+ * ```
187
+ *
188
+ * @title Show Save
189
+ * @method player.showSave(slots,options)
190
+ * @param {Array<object>} slots
191
+ * @param {object} [options]
192
+ * @returns {Promise<number | null>}
193
+ * @memberof GuiManager
194
+ */
195
+ showSave(slots?: SaveSlot[], options?: SaveLoadOptions): Promise<number | null>;
196
+ /**
197
+ * Display a load slots screen. Opens the GUI named `rpg-save`
198
+ *
199
+ * ```ts
200
+ * const index = await player.showLoad(slots)
201
+ * ```
202
+ *
203
+ * @title Show Load
204
+ * @method player.showLoad(slots,options)
205
+ * @param {Array<object>} slots
206
+ * @param {object} [options]
207
+ * @returns {Promise<number | null>}
208
+ * @memberof GuiManager
209
+ */
210
+ showLoad(slots?: SaveSlot[], options?: SaveLoadOptions): Promise<number | null>;
162
211
  /**
163
212
  * Calls main menu. Opens the GUI named `rpg-main-menu`
164
213
  *
165
214
  * @title Call Main Menu
166
- * @method player.callMainMenu()
215
+ * @method player.callMainMenu(options)
216
+ * @param {object} [options]
167
217
  * @returns {void}
168
218
  * @memberof GuiManager
169
219
  */
170
- callMainMenu(): void;
171
- callShop(items: any[]): void;
220
+ callMainMenu(options?: MenuGuiOptions): void;
221
+ /**
222
+ * Calls game over menu. Opens the GUI named `rpg-gameover`
223
+ *
224
+ * ```ts
225
+ * const selection = await player.callGameover()
226
+ * if (selection?.id === 'title') {
227
+ * await player.gui('rpg-title-screen').open()
228
+ * }
229
+ * if (selection?.id === 'load') {
230
+ * await player.showLoad()
231
+ * }
232
+ * ```
233
+ *
234
+ * @title Call Game Over Menu
235
+ * @method player.callGameover(options)
236
+ * @param {object} [options]
237
+ * @returns {Promise<GameoverGuiSelection | null>}
238
+ * @memberof GuiManager
239
+ */
240
+ callGameover(options?: GameoverGuiOptions): Promise<GameoverGuiSelection | null>;
241
+ callShop(items: any[] | {
242
+ items: any[];
243
+ sell?: Record<string, number> | Array<{
244
+ id: string;
245
+ multiplier: number;
246
+ }>;
247
+ sellMultiplier?: number;
248
+ message?: string;
249
+ face?: {
250
+ id: string;
251
+ expression?: string;
252
+ };
253
+ }): void;
172
254
  gui(guiId: string): Gui;
255
+ getGui(guiId: string): Gui;
173
256
  removeGui(guiId: string, data?: any): void;
174
257
  showAttachedGui(players?: RpgPlayer[] | RpgPlayer): void;
175
258
  hideAttachedGui(players?: RpgPlayer[] | RpgPlayer): void;
@@ -16,6 +16,7 @@ import { ISkillManager } from './SkillManager';
16
16
  import { IBattleManager } from './BattleManager';
17
17
  import { IClassManager } from './ClassManager';
18
18
  import { IStateManager } from './StateManager';
19
+ import { SaveRequestContext, SaveSlotIndex, SaveSlotMeta } from '../services/save';
19
20
  declare const RpgPlayer_base: Constructor<RpgCommonPlayer>;
20
21
  /**
21
22
  * RPG Player class with component management capabilities
@@ -126,8 +127,29 @@ export declare class RpgPlayer extends RpgPlayer_base {
126
127
  }): Promise<false | undefined>;
127
128
  getCurrentMap<T extends RpgMap = RpgMap>(): T | null;
128
129
  emit(type: string, value?: any): void;
129
- save(): Promise<string>;
130
- load(snapshot: string): Promise<void>;
130
+ snapshot(): Record<string, any>;
131
+ applySnapshot(snapshot: string | object): Promise<any>;
132
+ save(slot?: SaveSlotIndex, meta?: SaveSlotMeta, context?: SaveRequestContext): Promise<{
133
+ index: number;
134
+ meta: import('../../../common/src').SaveSlotMeta;
135
+ } | null>;
136
+ load(slot?: SaveSlotIndex, context?: SaveRequestContext, options?: {
137
+ changeMap?: boolean;
138
+ }): Promise<{
139
+ ok: boolean;
140
+ slot?: undefined;
141
+ index?: undefined;
142
+ } | {
143
+ ok: boolean;
144
+ slot: {
145
+ [key: string]: any;
146
+ level?: number;
147
+ exp?: number;
148
+ map?: string;
149
+ date?: string;
150
+ };
151
+ index: number;
152
+ }>;
131
153
  /**
132
154
  * @deprecated Use setGraphicAnimation instead.
133
155
  * @param animationName - The name of the animation to play (e.g., 'attack', 'skill', 'walk')
@@ -168,6 +168,13 @@ export interface RpgPlayerHooks {
168
168
  */
169
169
  onConnected?: (player: RpgPlayer) => any;
170
170
  /**
171
+ * When the player starts the game from the lobby
172
+ *
173
+ * @prop { (player: RpgPlayer) => any } [onStart]
174
+ * @memberof RpgPlayerHooks
175
+ */
176
+ onStart?: (player: RpgPlayer) => any;
177
+ /**
171
178
  * When the player presses a key on the client side
172
179
  *
173
180
  * @prop { (player: RpgPlayer, data: { input: Direction | Control | string, moving: boolean }) => any } [onInput]
@@ -1,5 +1,6 @@
1
1
  import { Server } from '@signe/room';
2
+ import { RpgMap } from './rooms/map';
2
3
  import { LobbyRoom } from './rooms/lobby';
3
4
  export declare class RpgServerEngine extends Server {
4
- rooms: (typeof LobbyRoom)[];
5
+ rooms: (typeof RpgMap | typeof LobbyRoom)[];
5
6
  }
package/dist/index.d.ts CHANGED
@@ -10,7 +10,10 @@ export * from './rooms/map';
10
10
  export * from './presets';
11
11
  export * from '@signe/reactive';
12
12
  export * from './Gui';
13
- export { RpgShape, RpgModule } from '../../common/src';
13
+ export * from './services/save';
14
+ export * from './storage';
15
+ export { RpgShape, RpgModule, MAXHP, MAXSP, ATK, PDEF, SDEF, STR, AGI, INT, DEX } from '../../common/src';
14
16
  export * from './decorators/event';
15
17
  export * from './decorators/map';
16
18
  export * from './Player/MoveManager';
19
+ export * from './presets';