@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.
Files changed (101) hide show
  1. package/dist/Gui/DialogGui.d.ts +5 -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 +28 -3
  8. package/dist/Gui/TitleGui.d.ts +23 -0
  9. package/dist/Gui/index.d.ts +10 -1
  10. package/dist/Player/BattleManager.d.ts +34 -12
  11. package/dist/Player/ClassManager.d.ts +46 -13
  12. package/dist/Player/ComponentManager.d.ts +123 -0
  13. package/dist/Player/Components.d.ts +345 -0
  14. package/dist/Player/EffectManager.d.ts +86 -0
  15. package/dist/Player/ElementManager.d.ts +104 -0
  16. package/dist/Player/GoldManager.d.ts +22 -0
  17. package/dist/Player/GuiManager.d.ts +259 -0
  18. package/dist/Player/ItemFixture.d.ts +6 -0
  19. package/dist/Player/ItemManager.d.ts +450 -9
  20. package/dist/Player/MoveManager.d.ts +324 -69
  21. package/dist/Player/ParameterManager.d.ts +344 -14
  22. package/dist/Player/Player.d.ts +460 -8
  23. package/dist/Player/SkillManager.d.ts +197 -15
  24. package/dist/Player/StateManager.d.ts +89 -25
  25. package/dist/Player/VariableManager.d.ts +74 -0
  26. package/dist/RpgServer.d.ts +502 -64
  27. package/dist/RpgServerEngine.d.ts +2 -1
  28. package/dist/decorators/event.d.ts +46 -0
  29. package/dist/decorators/map.d.ts +287 -0
  30. package/dist/index.d.ts +10 -0
  31. package/dist/index.js +21653 -20900
  32. package/dist/index.js.map +1 -1
  33. package/dist/logs/log.d.ts +2 -3
  34. package/dist/module.d.ts +43 -1
  35. package/dist/presets/index.d.ts +0 -9
  36. package/dist/rooms/BaseRoom.d.ts +132 -0
  37. package/dist/rooms/lobby.d.ts +10 -2
  38. package/dist/rooms/map.d.ts +1236 -17
  39. package/dist/services/save.d.ts +43 -0
  40. package/dist/storage/index.d.ts +1 -0
  41. package/dist/storage/localStorage.d.ts +23 -0
  42. package/package.json +14 -10
  43. package/src/Gui/DialogGui.ts +19 -4
  44. package/src/Gui/GameoverGui.ts +39 -0
  45. package/src/Gui/Gui.ts +23 -1
  46. package/src/Gui/MenuGui.ts +155 -6
  47. package/src/Gui/NotificationGui.ts +1 -2
  48. package/src/Gui/SaveLoadGui.ts +60 -0
  49. package/src/Gui/ShopGui.ts +146 -16
  50. package/src/Gui/TitleGui.ts +39 -0
  51. package/src/Gui/index.ts +15 -2
  52. package/src/Player/BattleManager.ts +91 -49
  53. package/src/Player/ClassManager.ts +118 -50
  54. package/src/Player/ComponentManager.ts +425 -19
  55. package/src/Player/Components.ts +380 -0
  56. package/src/Player/EffectManager.ts +81 -44
  57. package/src/Player/ElementManager.ts +109 -86
  58. package/src/Player/GoldManager.ts +32 -35
  59. package/src/Player/GuiManager.ts +308 -150
  60. package/src/Player/ItemFixture.ts +4 -5
  61. package/src/Player/ItemManager.ts +774 -355
  62. package/src/Player/MoveManager.ts +1544 -774
  63. package/src/Player/ParameterManager.ts +546 -104
  64. package/src/Player/Player.ts +1163 -88
  65. package/src/Player/SkillManager.ts +520 -195
  66. package/src/Player/StateManager.ts +170 -182
  67. package/src/Player/VariableManager.ts +101 -63
  68. package/src/RpgServer.ts +525 -63
  69. package/src/core/context.ts +1 -0
  70. package/src/decorators/event.ts +61 -0
  71. package/src/decorators/map.ts +327 -0
  72. package/src/index.ts +11 -1
  73. package/src/logs/log.ts +10 -3
  74. package/src/module.ts +126 -3
  75. package/src/presets/index.ts +1 -10
  76. package/src/rooms/BaseRoom.ts +232 -0
  77. package/src/rooms/lobby.ts +25 -7
  78. package/src/rooms/map.ts +2502 -194
  79. package/src/services/save.ts +147 -0
  80. package/src/storage/index.ts +1 -0
  81. package/src/storage/localStorage.ts +76 -0
  82. package/tests/battle.spec.ts +375 -0
  83. package/tests/change-map.spec.ts +72 -0
  84. package/tests/class.spec.ts +274 -0
  85. package/tests/effect.spec.ts +219 -0
  86. package/tests/element.spec.ts +221 -0
  87. package/tests/event.spec.ts +80 -0
  88. package/tests/gold.spec.ts +99 -0
  89. package/tests/item.spec.ts +609 -0
  90. package/tests/module.spec.ts +38 -0
  91. package/tests/move.spec.ts +601 -0
  92. package/tests/player-param.spec.ts +28 -0
  93. package/tests/prediction-reconciliation.spec.ts +182 -0
  94. package/tests/random-move.spec.ts +65 -0
  95. package/tests/skill.spec.ts +658 -0
  96. package/tests/state.spec.ts +467 -0
  97. package/tests/variable.spec.ts +185 -0
  98. package/tests/world-maps.spec.ts +896 -0
  99. package/vite.config.ts +16 -0
  100. package/dist/Player/Event.d.ts +0 -0
  101. package/src/Player/Event.ts +0 -0
@@ -1,16 +1,41 @@
1
- import { RpgPlayer } from './Player/Player';
1
+ import { MapOptions } from './decorators/map';
2
+ import { RpgPlayer, RpgEvent } from './Player/Player';
2
3
  import { RpgMap } from './rooms/map';
3
4
  import { RpgServerEngine } from './RpgServerEngine';
4
- type RpgShape = any;
5
- type RpgClassMap<T> = any;
6
- type RpgClassEvent<T> = any;
7
- type RpgEvent = any;
5
+ import { WorldMapConfig, RpgShape, MapPhysicsInitContext, MapPhysicsEntityContext } from '../../common/src';
6
+ type RpgClassMap<T> = new () => T;
7
+ type RpgClassEvent<T> = RpgEvent;
8
8
  type MatchMakerOption = any;
9
9
  type RpgMatchMaker = any;
10
10
  type IStoreState = any;
11
- type TiledMap = any;
12
- type WorldMap = any;
13
- type MapOptions = any;
11
+ /**
12
+ * Interface for world map configuration
13
+ *
14
+ * Represents a world that contains multiple maps with their spatial relationships.
15
+ * This is typically used with Tiled Map Editor's world files.
16
+ *
17
+ * @interface WorldMap
18
+ * @example
19
+ * ```ts
20
+ * const worldMap: WorldMap = {
21
+ * id: 'my-world',
22
+ * maps: [
23
+ * { id: 'map1', worldX: 0, worldY: 0, width: 800, height: 600 },
24
+ * { id: 'map2', worldX: 800, worldY: 0, width: 800, height: 600 }
25
+ * ]
26
+ * }
27
+ * ```
28
+ */
29
+ export interface WorldMap {
30
+ /** Optional world identifier */
31
+ id?: string;
32
+ /** Array of map configurations that belong to this world */
33
+ maps: WorldMapConfig[];
34
+ /** Only show adjacent maps (used by Tiled Map Editor) */
35
+ onlyShowAdjacentMaps?: boolean;
36
+ /** Type identifier (used by Tiled Map Editor, should be 'world') */
37
+ type?: 'world';
38
+ }
14
39
  export interface RpgServerEngineHooks {
15
40
  /**
16
41
  * When the server starts
@@ -143,6 +168,13 @@ export interface RpgPlayerHooks {
143
168
  */
144
169
  onConnected?: (player: RpgPlayer) => any;
145
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
+ /**
146
178
  * When the player presses a key on the client side
147
179
  *
148
180
  * @prop { (player: RpgPlayer, data: { input: Direction | Control | string, moving: boolean }) => any } [onInput]
@@ -210,19 +242,348 @@ export interface RpgPlayerHooks {
210
242
  */
211
243
  canChangeMap?: (player: RpgPlayer, nextMap: RpgClassMap<RpgMap>) => boolean | Promise<boolean>;
212
244
  }
245
+ /**
246
+ * Event hooks interface for handling various event lifecycle methods
247
+ *
248
+ * @interface RpgEventHooks
249
+ * @since 4.0.0
250
+ */
213
251
  export interface RpgEventHooks {
252
+ /**
253
+ * Called as soon as the event is created on the map
254
+ *
255
+ * @param {RpgEvent} event - The event instance being initialized
256
+ * @returns {any}
257
+ * @memberof RpgEventHooks
258
+ * @example
259
+ * ```ts
260
+ * const eventHooks: RpgEventHooks = {
261
+ * onInit(event) {
262
+ * console.log(`Event ${event.name} initialized`)
263
+ * event.graphic('default-sprite')
264
+ * }
265
+ * }
266
+ * ```
267
+ */
214
268
  onInit?: (event: RpgEvent) => any;
269
+ /**
270
+ * Called when the event collides with a player and the player presses the action key
271
+ *
272
+ * @param {RpgEvent} event - The event being interacted with
273
+ * @param {RpgPlayer} player - The player performing the action
274
+ * @returns {any}
275
+ * @memberof RpgEventHooks
276
+ * @example
277
+ * ```ts
278
+ * const eventHooks: RpgEventHooks = {
279
+ * onAction(event, player) {
280
+ * player.showText('You activated the chest!')
281
+ * player.addItem('POTION', 1)
282
+ * }
283
+ * }
284
+ * ```
285
+ */
215
286
  onAction?: (event: RpgEvent, player: RpgPlayer) => any;
287
+ /**
288
+ * Called before an event object is created and added to the map
289
+ * Allows modification of event properties before instantiation
290
+ *
291
+ * @param {any} object - The event object data before creation
292
+ * @param {RpgMap} map - The map where the event will be created
293
+ * @returns {any}
294
+ * @memberof RpgEventHooks
295
+ * @example
296
+ * ```ts
297
+ * const eventHooks: RpgEventHooks = {
298
+ * onBeforeCreated(object, map) {
299
+ * // Modify event properties based on map conditions
300
+ * if (map.id === 'dungeon') {
301
+ * object.graphic = 'monster-sprite'
302
+ * }
303
+ * }
304
+ * }
305
+ * ```
306
+ */
216
307
  onBeforeCreated?: (object: any, map: RpgMap) => any;
308
+ /**
309
+ * Called when a player or another event enters a shape attached to this event
310
+ *
311
+ * @param {RpgEvent} event - The event with the attached shape
312
+ * @param {RpgPlayer} player - The player entering the shape
313
+ * @param {RpgShape} shape - The shape being entered
314
+ * @returns {any}
315
+ * @since 4.1.0
316
+ * @memberof RpgEventHooks
317
+ * @example
318
+ * ```ts
319
+ * const eventHooks: RpgEventHooks = {
320
+ * onDetectInShape(event, player, shape) {
321
+ * console.log(`Player ${player.name} entered detection zone`)
322
+ * player.showText('You are being watched...')
323
+ * }
324
+ * }
325
+ * ```
326
+ */
217
327
  onDetectInShape?: (event: RpgEvent, player: RpgPlayer, shape: RpgShape) => any;
328
+ /**
329
+ * Called when a player or another event leaves a shape attached to this event
330
+ *
331
+ * @param {RpgEvent} event - The event with the attached shape
332
+ * @param {RpgPlayer} player - The player leaving the shape
333
+ * @param {RpgShape} shape - The shape being left
334
+ * @returns {any}
335
+ * @since 4.1.0
336
+ * @memberof RpgEventHooks
337
+ * @example
338
+ * ```ts
339
+ * const eventHooks: RpgEventHooks = {
340
+ * onDetectOutShape(event, player, shape) {
341
+ * console.log(`Player ${player.name} left detection zone`)
342
+ * player.showText('You escaped the watch...')
343
+ * }
344
+ * }
345
+ * ```
346
+ */
218
347
  onDetectOutShape?: (event: RpgEvent, player: RpgPlayer, shape: RpgShape) => any;
348
+ /**
349
+ * Called when the event enters a shape on the map
350
+ *
351
+ * @param {RpgEvent} event - The event entering the shape
352
+ * @param {RpgShape} shape - The shape being entered
353
+ * @returns {any}
354
+ * @memberof RpgEventHooks
355
+ * @example
356
+ * ```ts
357
+ * const eventHooks: RpgEventHooks = {
358
+ * onInShape(event, shape) {
359
+ * console.log(`Event entered shape: ${shape.id}`)
360
+ * event.speed = 1 // Slow down in this area
361
+ * }
362
+ * }
363
+ * ```
364
+ */
219
365
  onInShape?: (event: RpgEvent, shape: RpgShape) => any;
366
+ /**
367
+ * Called when the event leaves a shape on the map
368
+ *
369
+ * @param {RpgEvent} event - The event leaving the shape
370
+ * @param {RpgShape} shape - The shape being left
371
+ * @returns {any}
372
+ * @memberof RpgEventHooks
373
+ * @example
374
+ * ```ts
375
+ * const eventHooks: RpgEventHooks = {
376
+ * onOutShape(event, shape) {
377
+ * console.log(`Event left shape: ${shape.id}`)
378
+ * event.speed = 3 // Resume normal speed
379
+ * }
380
+ * }
381
+ * ```
382
+ */
220
383
  onOutShape?: (event: RpgEvent, shape: RpgShape) => any;
384
+ /**
385
+ * Called when the event collides with a player (without requiring action key press)
386
+ *
387
+ * @param {RpgEvent} event - The event touching the player
388
+ * @param {RpgPlayer} player - The player being touched
389
+ * @returns {any}
390
+ * @memberof RpgEventHooks
391
+ * @example
392
+ * ```ts
393
+ * const eventHooks: RpgEventHooks = {
394
+ * onPlayerTouch(event, player) {
395
+ * player.hp -= 10 // Damage on touch
396
+ * player.showText('Ouch! You touched a spike!')
397
+ * }
398
+ * }
399
+ * ```
400
+ */
221
401
  onPlayerTouch?: (event: RpgEvent, player: RpgPlayer) => any;
402
+ /**
403
+ * Called whenever any event on the map (including itself) is executed or changes state
404
+ * Useful for creating reactive events that respond to map state changes
405
+ *
406
+ * @param {RpgEvent} event - The event listening for changes
407
+ * @param {RpgPlayer} player - The player involved in the change
408
+ * @returns {any}
409
+ * @memberof RpgEventHooks
410
+ * @example
411
+ * ```ts
412
+ * const eventHooks: RpgEventHooks = {
413
+ * onChanges(event, player) {
414
+ * // Change chest graphic based on game state
415
+ * if (player.getVariable('BATTLE_END')) {
416
+ * event.graphic('chest-open')
417
+ * } else {
418
+ * event.graphic('chest-close')
419
+ * }
420
+ * }
421
+ * }
422
+ * ```
423
+ */
222
424
  onChanges?: (event: RpgEvent, player: RpgPlayer) => any;
223
425
  }
426
+ /**
427
+ * Map hooks interface for handling map lifecycle events
428
+ *
429
+ * These hooks are global hooks that apply to all maps in the game.
430
+ * They are defined in the RpgModule configuration and executed for every map instance.
431
+ *
432
+ * @interface RpgMapHooks
433
+ * @since 4.0.0
434
+ */
224
435
  export interface RpgMapHooks {
225
- onBeforeUpdate<T = RpgMap>(mapData: any, map: T): T;
436
+ /**
437
+ * Called before a map is updated with new data
438
+ * Allows modification of map data before the update is applied
439
+ *
440
+ * The `mapData` parameter contains the loaded map data (retrieved from request body)
441
+ * You can modify the map before the update is processed
442
+ *
443
+ * @template T - Type of the incoming map data
444
+ * @template U - Type of the map instance (defaults to RpgMap)
445
+ * @param {T} mapData - The map data loaded from external source (e.g., request body)
446
+ * @param {U} map - The current map instance being updated
447
+ * @returns {U | Promise<U>} The modified map instance or a promise resolving to it
448
+ * @memberof RpgMapHooks
449
+ * @example
450
+ * ```ts
451
+ * const mapHooks: RpgMapHooks = {
452
+ * onBeforeUpdate(mapData, map) {
453
+ * // Modify map properties based on incoming data
454
+ * if (mapData.weather === 'rain') {
455
+ * map.setWeatherEffect('rain')
456
+ * }
457
+ *
458
+ * // Add custom properties from external data
459
+ * map.customProperty = mapData.customValue
460
+ *
461
+ * return map
462
+ * }
463
+ * }
464
+ * ```
465
+ *
466
+ * @example
467
+ * ```ts
468
+ * // Async example with database operations
469
+ * const mapHooks: RpgMapHooks = {
470
+ * async onBeforeUpdate(mapData, map) {
471
+ * // Load additional data from database
472
+ * const additionalData = await database.getMapExtras(map.id)
473
+ *
474
+ * // Apply modifications
475
+ * map.events = [...map.events, ...additionalData.events]
476
+ * map.npcs = additionalData.npcs
477
+ *
478
+ * return map
479
+ * }
480
+ * }
481
+ * ```
482
+ */
483
+ onBeforeUpdate<T, U = RpgMap>(mapData: T, map: U): U | Promise<U>;
484
+ /**
485
+ * Called when a map is loaded and initialized
486
+ *
487
+ * This hook is executed once when the map data is loaded and ready.
488
+ * It applies to all maps globally. Use this to initialize map-specific properties
489
+ * or setup that should happen for every map.
490
+ *
491
+ * @param {RpgMap} map - The map instance that was loaded
492
+ * @returns {any}
493
+ * @memberof RpgMapHooks
494
+ * @example
495
+ * ```ts
496
+ * const mapHooks: RpgMapHooks = {
497
+ * onLoad(map: RpgMap) {
498
+ * console.log(`Map ${map.id} loaded`)
499
+ * // Initialize global map properties
500
+ * }
501
+ * }
502
+ * ```
503
+ */
504
+ onLoad?: (map: RpgMap) => any;
505
+ /**
506
+ * Called when a player joins any map
507
+ *
508
+ * This hook is executed each time a player joins any map in the game.
509
+ * It applies globally to all maps. Use this to perform actions that should
510
+ * happen whenever a player enters any map.
511
+ *
512
+ * @param {RpgPlayer} player - The player joining the map
513
+ * @param {RpgMap} map - The map instance the player joined
514
+ * @returns {any}
515
+ * @memberof RpgMapHooks
516
+ * @example
517
+ * ```ts
518
+ * const mapHooks: RpgMapHooks = {
519
+ * onJoin(player: RpgPlayer, map: RpgMap) {
520
+ * console.log(`${player.name} joined map ${map.id}`)
521
+ * // Perform global actions when player joins any map
522
+ * }
523
+ * }
524
+ * ```
525
+ */
526
+ onJoin?: (player: RpgPlayer, map: RpgMap) => any;
527
+ /**
528
+ * Called when a player leaves any map
529
+ *
530
+ * This hook is executed each time a player leaves any map in the game.
531
+ * It applies globally to all maps. Use this to perform cleanup or actions
532
+ * that should happen whenever a player exits any map.
533
+ *
534
+ * @param {RpgPlayer} player - The player leaving the map
535
+ * @param {RpgMap} map - The map instance the player left
536
+ * @returns {any}
537
+ * @memberof RpgMapHooks
538
+ * @example
539
+ * ```ts
540
+ * const mapHooks: RpgMapHooks = {
541
+ * onLeave(player: RpgPlayer, map: RpgMap) {
542
+ * console.log(`${player.name} left map ${map.id}`)
543
+ * // Perform global cleanup when player leaves any map
544
+ * }
545
+ * }
546
+ * ```
547
+ */
548
+ onLeave?: (player: RpgPlayer, map: RpgMap) => any;
549
+ /**
550
+ * Called when the map physics world is initialized.
551
+ *
552
+ * This hook runs each time `loadPhysic()` prepares the physics world, after static
553
+ * map hitboxes are created and before dynamic player/event bodies are hydrated.
554
+ *
555
+ * @param {RpgMap} map - The map instance
556
+ * @param {MapPhysicsInitContext} context - Physics initialization context
557
+ * @returns {any}
558
+ * @memberof RpgMapHooks
559
+ */
560
+ onPhysicsInit?: (map: RpgMap, context: MapPhysicsInitContext) => any;
561
+ /**
562
+ * Called when a dynamic character physics body is added to the map.
563
+ *
564
+ * @param {RpgMap} map - The map instance
565
+ * @param {MapPhysicsEntityContext} context - Added entity context
566
+ * @returns {any}
567
+ * @memberof RpgMapHooks
568
+ */
569
+ onPhysicsEntityAdd?: (map: RpgMap, context: MapPhysicsEntityContext) => any;
570
+ /**
571
+ * Called when a dynamic character physics body is removed from the map.
572
+ *
573
+ * @param {RpgMap} map - The map instance
574
+ * @param {MapPhysicsEntityContext} context - Removed entity context
575
+ * @returns {any}
576
+ * @memberof RpgMapHooks
577
+ */
578
+ onPhysicsEntityRemove?: (map: RpgMap, context: MapPhysicsEntityContext) => any;
579
+ /**
580
+ * Called when the map physics world is reset (before reload).
581
+ *
582
+ * @param {RpgMap} map - The map instance
583
+ * @returns {any}
584
+ * @memberof RpgMapHooks
585
+ */
586
+ onPhysicsReset?: (map: RpgMap) => any;
226
587
  }
227
588
  export interface RpgServer {
228
589
  /**
@@ -235,14 +596,14 @@ export interface RpgServer {
235
596
  * @example
236
597
  *
237
598
  * ```ts
238
- * import { RpgServer, RpgModule } from '@rpgjs/server'
599
+ * import { RpgServer } from '@rpgjs/server'
600
+ * import { defineModule } from '@rpgjs/common'
239
601
  *
240
- * @RpgModule<RpgServer>({
602
+ * export default defineModule<RpgServer>({
241
603
  * hooks: {
242
604
  * player: ['onAuth']
243
605
  * }
244
606
  * })
245
- * class RpgServerEngine { }
246
607
  * ```
247
608
  *
248
609
  * Emit the hook:
@@ -281,18 +642,18 @@ export interface RpgServer {
281
642
  * Object containing the hooks concerning the engine
282
643
  *
283
644
  * ```ts
284
- * import { RpgServerEngine, RpgServerEngineHooks, RpgModule, RpgClient } from '@rpgjs/server'
645
+ * import { RpgServerEngine, RpgServerEngineHooks, RpgServer } from '@rpgjs/server'
646
+ * import { defineModule } from '@rpgjs/common'
285
647
  *
286
- * const engine: RpgEngineHooks = {
648
+ * const engine: RpgServerEngineHooks = {
287
649
  * onStart(server: RpgServerEngine) {
288
650
  * console.log('server is started')
289
651
  * }
290
652
  * }
291
653
  *
292
- * @RpgModule<RpgServer>({
654
+ * export default defineModule<RpgServer>({
293
655
  * engine
294
656
  * })
295
- * class RpgServerModule {}
296
657
  * ```
297
658
  *
298
659
  * @prop {RpgServerEngineHooks} [engine]
@@ -303,7 +664,8 @@ export interface RpgServer {
303
664
  * Give the `player` object hooks. Each time a player connects, an instance of `RpgPlayer` is created.
304
665
  *
305
666
  * ```ts
306
- * import { RpgPlayer, RpgServer, RpgPlayerHooks, RpgModule } from '@rpgjs/server'
667
+ * import { RpgPlayer, RpgServer, RpgPlayerHooks } from '@rpgjs/server'
668
+ * import { defineModule } from '@rpgjs/common'
307
669
  *
308
670
  * const player: RpgPlayerHooks = {
309
671
  * onConnected(player: RpgPlayer) {
@@ -311,10 +673,9 @@ export interface RpgServer {
311
673
  * }
312
674
  * }
313
675
  *
314
- * @RpgModule<RpgServer>({
676
+ * export default defineModule<RpgServer>({
315
677
  * player
316
678
  * })
317
- * class RpgServerEngine { }
318
679
  * ```
319
680
  *
320
681
  * @prop {RpgClassPlayer<RpgPlayer>} [player]
@@ -325,27 +686,29 @@ export interface RpgServer {
325
686
  * References all data in the server. it is mainly used to retrieve data according to their identifier
326
687
  *
327
688
  * ```ts
328
- * import { RpgServer, RpgModule } from '@rpgjs/server'
689
+ * import { RpgServer } from '@rpgjs/server'
690
+ * import { defineModule } from '@rpgjs/common'
329
691
  * import { Potion } from 'my-database/items/potion'
330
692
  *
331
- * @RpgModule<RpgServer>({
693
+ * export default defineModule<RpgServer>({
332
694
  * database: {
333
695
  * Potion
334
696
  * }
335
697
  * })
336
- * class RpgServerEngine { }
337
698
  * ```
338
699
  *
339
- * @prop { { [dataName]: data } } [database]
700
+ * @prop { { [dataName]: data } | (engine: RpgMap) => { [dataName]: data } | Promise<{ [dataName]: data }> } [database]
340
701
  * @memberof RpgServer
341
702
  * */
342
- database?: object | any[];
703
+ database?: object | any[] | ((engine: RpgMap) => object | any[] | Promise<object | any[]>);
343
704
  /**
344
- * Array of all maps. Each element is an `RpgMap` class
705
+ * Array of all maps. Each element can be either a class (decorated with `@MapData` or not) or a `MapOptions` object
345
706
  *
346
707
  * ```ts
347
- * import { RpgMap, MapData, RpgServer, RpgModule } from '@rpgjs/server'
708
+ * import { RpgMap, MapData, RpgServer } from '@rpgjs/server'
709
+ * import { defineModule } from '@rpgjs/common'
348
710
  *
711
+ * // Class that extends RpgMap (optional)
349
712
  * @MapData({
350
713
  * id: 'town',
351
714
  * file: require('./tmx/mymap.tmx'),
@@ -353,18 +716,29 @@ export interface RpgServer {
353
716
  * })
354
717
  * class TownMap extends RpgMap { }
355
718
  *
356
- * @RpgModule<RpgServer>({
719
+ * // Or a simple class without extending RpgMap
720
+ * @MapData({
721
+ * id: 'map',
722
+ * file: '',
723
+ * events: [{ event: Event() }]
724
+ * })
725
+ * class SimpleMap {}
726
+ *
727
+ * export default defineModule<RpgServer>({
357
728
  * maps: [
358
- * TownMap
729
+ * TownMap,
730
+ * SimpleMap
359
731
  * ]
360
732
  * })
361
- * class RpgServerEngine { }
362
733
  * ```
363
734
  *
364
735
  * It is possible to just give the object as well
365
736
  *
366
737
  * ```ts
367
- * @RpgModule<RpgServer>({
738
+ * import { RpgServer } from '@rpgjs/server'
739
+ * import { defineModule } from '@rpgjs/common'
740
+ *
741
+ * export default defineModule<RpgServer>({
368
742
  * maps: [
369
743
  * {
370
744
  * id: 'town',
@@ -373,24 +747,64 @@ export interface RpgServer {
373
747
  * }
374
748
  * ]
375
749
  * })
376
- * class RpgServerEngine { }
377
750
  * ```
378
751
  *
379
752
  * Since version 3.0.0-beta.8, you can just pass the path to the file. The identifier will then be the name of the file
380
753
  *
381
754
  * ```ts
382
- * @RpgModule<RpgServer>({
755
+ * import { RpgServer } from '@rpgjs/server'
756
+ * import { defineModule } from '@rpgjs/common'
757
+ *
758
+ * export default defineModule<RpgServer>({
383
759
  * maps: [
384
760
  * require('./tmx/mymap.tmx') // id is "mymap"
385
761
  * ]
386
762
  * })
387
- * class RpgServerEngine { }
388
763
  * ```
389
764
  *
390
- * @prop {RpgClassMap<RpgMap>[]} [maps]
765
+ * @prop {(new () => any) | MapOptions)[]} [maps]
391
766
  * @memberof RpgServer
392
767
  * */
393
- maps?: RpgClassMap<RpgMap>[] | MapOptions[] | string[] | TiledMap[];
768
+ maps?: ((new () => any) | MapOptions)[];
769
+ /**
770
+ * Global map hooks that apply to all maps in the game
771
+ *
772
+ * These hooks are executed for every map instance and allow you to define
773
+ * global behavior that should happen for all maps. They are different from
774
+ * map-specific hooks defined in `@MapData` which only apply to a specific map class.
775
+ *
776
+ * ```ts
777
+ * import { RpgServer, RpgMapHooks, RpgMap, RpgPlayer } from '@rpgjs/server'
778
+ * import { defineModule } from '@rpgjs/common'
779
+ *
780
+ * const mapHooks: RpgMapHooks = {
781
+ * onLoad(map: RpgMap) {
782
+ * console.log(`Map ${map.id} loaded`)
783
+ * // Initialize global map properties
784
+ * },
785
+ * onJoin(player: RpgPlayer, map: RpgMap) {
786
+ * console.log(`${player.name} joined map ${map.id}`)
787
+ * // Perform global actions when player joins any map
788
+ * },
789
+ * onLeave(player: RpgPlayer, map: RpgMap) {
790
+ * console.log(`${player.name} left map ${map.id}`)
791
+ * // Perform global cleanup when player leaves any map
792
+ * },
793
+ * onBeforeUpdate(mapData, map) {
794
+ * // Modify map data before update
795
+ * return map
796
+ * }
797
+ * }
798
+ *
799
+ * export default defineModule<RpgServer>({
800
+ * map: mapHooks
801
+ * })
802
+ * ```
803
+ *
804
+ * @prop {RpgMapHooks} [map]
805
+ * @memberof RpgServer
806
+ * @since 4.0.0
807
+ * */
394
808
  map?: RpgMapHooks;
395
809
  event?: RpgEventHooks;
396
810
  /**
@@ -403,41 +817,62 @@ export interface RpgServer {
403
817
  */
404
818
  events?: RpgClassEvent<RpgEvent>[];
405
819
  /**
406
- * Loads the content of a `.world` file from Tiled Map Editor into the map scene
820
+ * Array of world map configurations
407
821
  *
408
- * > Note, that if the map already exists (i.e. you have already defined an RpgMap), the world will retrieve the already existing map. Otherwise it will create a new map
822
+ * Loads the content of a `.world` file from Tiled Map Editor into the map scene.
823
+ * Each world contains multiple maps with their spatial relationships.
409
824
  *
410
- * @prop {object[]} [worldMaps]
411
- * object is
412
- * ```ts
413
- * {
414
- * id?: string
415
- * maps: {
416
- * id?: string
417
- * properties?: object
418
- * fileName: string;
419
- height: number;
420
- width: number;
421
- x: number;
422
- y: number;
423
- * }[],
424
- onlyShowAdjacentMaps: boolean, // only for Tiled Map Editor
425
- type: 'world' // only for Tiled Map Editor
426
- * }
427
- * ```
825
+ * > Note: If a map already exists (i.e. you have already defined an RpgMap),
826
+ * > the world will retrieve the already existing map. Otherwise it will create a new map.
827
+ *
828
+ * @prop {WorldMap[]} [worldMaps]
428
829
  * @since 3.0.0-beta.8
830
+ * @memberof RpgServer
429
831
  * @example
430
832
  * ```ts
833
+ * import { RpgServer } from '@rpgjs/server'
834
+ * import { defineModule } from '@rpgjs/common'
431
835
  * import myworld from 'myworld.world'
432
836
  *
433
- * @RpgModule<RpgServer>({
434
- * worldMaps: [
435
- * myworld
436
- * ]
837
+ * export default defineModule<RpgServer>({
838
+ * worldMaps: [
839
+ * myworld
840
+ * ]
841
+ * })
842
+ * ```
843
+ *
844
+ * @example
845
+ * ```ts
846
+ * import { RpgServer } from '@rpgjs/server'
847
+ * import { defineModule } from '@rpgjs/common'
848
+ *
849
+ * // Manual world configuration
850
+ * export default defineModule<RpgServer>({
851
+ * worldMaps: [
852
+ * {
853
+ * id: 'my-world',
854
+ * maps: [
855
+ * {
856
+ * id: 'map1',
857
+ * worldX: 0,
858
+ * worldY: 0,
859
+ * width: 800,
860
+ * height: 600,
861
+ * tileWidth: 32,
862
+ * tileHeight: 32
863
+ * },
864
+ * {
865
+ * id: 'map2',
866
+ * worldX: 800,
867
+ * worldY: 0,
868
+ * width: 800,
869
+ * height: 600
870
+ * }
871
+ * ]
872
+ * }
873
+ * ]
437
874
  * })
438
- * class RpgServerEngine { }
439
875
  * ```
440
- * @memberof RpgServer
441
876
  */
442
877
  worldMaps?: WorldMap[];
443
878
  /**
@@ -460,11 +895,12 @@ export interface RpgServer {
460
895
  * Example:
461
896
  *
462
897
  * ```ts
463
- * import { RpgModule, RpgServer, Presets } from '@rpgjs/server'
898
+ * import { RpgServer, Presets } from '@rpgjs/server'
899
+ * import { defineModule } from '@rpgjs/common'
464
900
  *
465
901
  * const { ATK, PDEF } = Presets
466
902
  *
467
- * @RpgModule<RpgServer>({
903
+ * export default defineModule<RpgServer>({
468
904
  * damageFormulas: {
469
905
  * damagePhysic(a, b) {
470
906
  * let damage = a[ATK] - b[PDEF]
@@ -473,7 +909,6 @@ export interface RpgServer {
473
909
  * }
474
910
  * }
475
911
  * })
476
- * class RpgServerEngine { }
477
912
  * ```
478
913
  * @prop {object} damageFormulas
479
914
  * @memberof RpgServer
@@ -492,5 +927,8 @@ export interface RpgServer {
492
927
  doChangeServer(store: IStoreState, matchMaker: RpgMatchMaker, player: RpgPlayer): Promise<boolean> | boolean;
493
928
  };
494
929
  };
930
+ throttleSync?: number;
931
+ throttleStorage?: number;
932
+ sessionExpiryTime?: number;
495
933
  }
496
934
  export {};