@rpgjs/server 5.0.0-alpha.9 → 5.0.0-beta.1

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 (114) 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 +44 -32
  11. package/dist/Player/ClassManager.d.ts +24 -4
  12. package/dist/Player/ComponentManager.d.ts +95 -32
  13. package/dist/Player/Components.d.ts +345 -0
  14. package/dist/Player/EffectManager.d.ts +50 -4
  15. package/dist/Player/ElementManager.d.ts +77 -4
  16. package/dist/Player/GoldManager.d.ts +1 -1
  17. package/dist/Player/GuiManager.d.ts +87 -4
  18. package/dist/Player/ItemFixture.d.ts +1 -1
  19. package/dist/Player/ItemManager.d.ts +431 -4
  20. package/dist/Player/MoveManager.d.ts +301 -34
  21. package/dist/Player/ParameterManager.d.ts +364 -28
  22. package/dist/Player/Player.d.ts +558 -14
  23. package/dist/Player/SkillManager.d.ts +187 -13
  24. package/dist/Player/StateManager.d.ts +75 -4
  25. package/dist/Player/VariableManager.d.ts +62 -4
  26. package/dist/RpgServer.d.ts +278 -63
  27. package/dist/RpgServerEngine.d.ts +2 -1
  28. package/dist/decorators/event.d.ts +46 -0
  29. package/dist/decorators/map.d.ts +299 -0
  30. package/dist/index.d.ts +10 -0
  31. package/dist/index.js +17920 -29711
  32. package/dist/index.js.map +1 -1
  33. package/dist/logs/log.d.ts +2 -3
  34. package/dist/module-CaCW1SDh.js +11018 -0
  35. package/dist/module-CaCW1SDh.js.map +1 -0
  36. package/dist/module.d.ts +43 -1
  37. package/dist/node/connection.d.ts +51 -0
  38. package/dist/node/index.d.ts +5 -0
  39. package/dist/node/index.js +551 -0
  40. package/dist/node/index.js.map +1 -0
  41. package/dist/node/map.d.ts +16 -0
  42. package/dist/node/room.d.ts +21 -0
  43. package/dist/node/transport.d.ts +28 -0
  44. package/dist/node/types.d.ts +47 -0
  45. package/dist/presets/index.d.ts +0 -9
  46. package/dist/rooms/BaseRoom.d.ts +132 -0
  47. package/dist/rooms/lobby.d.ts +10 -2
  48. package/dist/rooms/map.d.ts +1359 -32
  49. package/dist/services/save.d.ts +43 -0
  50. package/dist/storage/index.d.ts +1 -0
  51. package/dist/storage/localStorage.d.ts +23 -0
  52. package/package.json +25 -10
  53. package/src/Gui/DialogGui.ts +19 -4
  54. package/src/Gui/GameoverGui.ts +39 -0
  55. package/src/Gui/Gui.ts +23 -1
  56. package/src/Gui/MenuGui.ts +155 -6
  57. package/src/Gui/NotificationGui.ts +1 -2
  58. package/src/Gui/SaveLoadGui.ts +60 -0
  59. package/src/Gui/ShopGui.ts +146 -16
  60. package/src/Gui/TitleGui.ts +39 -0
  61. package/src/Gui/index.ts +15 -2
  62. package/src/Player/BattleManager.ts +39 -56
  63. package/src/Player/ClassManager.ts +82 -74
  64. package/src/Player/ComponentManager.ts +394 -32
  65. package/src/Player/Components.ts +380 -0
  66. package/src/Player/EffectManager.ts +50 -96
  67. package/src/Player/ElementManager.ts +74 -152
  68. package/src/Player/GuiManager.ts +125 -14
  69. package/src/Player/ItemManager.ts +747 -341
  70. package/src/Player/MoveManager.ts +1532 -750
  71. package/src/Player/ParameterManager.ts +636 -106
  72. package/src/Player/Player.ts +1273 -79
  73. package/src/Player/SkillManager.ts +558 -197
  74. package/src/Player/StateManager.ts +131 -258
  75. package/src/Player/VariableManager.ts +85 -157
  76. package/src/RpgServer.ts +293 -62
  77. package/src/decorators/event.ts +61 -0
  78. package/src/decorators/map.ts +343 -0
  79. package/src/index.ts +11 -1
  80. package/src/logs/log.ts +10 -3
  81. package/src/module.ts +126 -3
  82. package/src/node/connection.ts +254 -0
  83. package/src/node/index.ts +22 -0
  84. package/src/node/map.ts +328 -0
  85. package/src/node/room.ts +63 -0
  86. package/src/node/transport.ts +532 -0
  87. package/src/node/types.ts +61 -0
  88. package/src/presets/index.ts +1 -10
  89. package/src/rooms/BaseRoom.ts +232 -0
  90. package/src/rooms/lobby.ts +25 -7
  91. package/src/rooms/map.ts +2682 -206
  92. package/src/services/save.ts +147 -0
  93. package/src/storage/index.ts +1 -0
  94. package/src/storage/localStorage.ts +76 -0
  95. package/tests/battle.spec.ts +375 -0
  96. package/tests/change-map.spec.ts +72 -0
  97. package/tests/class.spec.ts +274 -0
  98. package/tests/custom-websocket.spec.ts +127 -0
  99. package/tests/effect.spec.ts +219 -0
  100. package/tests/element.spec.ts +221 -0
  101. package/tests/event.spec.ts +80 -0
  102. package/tests/gold.spec.ts +99 -0
  103. package/tests/item.spec.ts +609 -0
  104. package/tests/module.spec.ts +38 -0
  105. package/tests/move.spec.ts +601 -0
  106. package/tests/node-transport.spec.ts +223 -0
  107. package/tests/player-param.spec.ts +45 -0
  108. package/tests/prediction-reconciliation.spec.ts +182 -0
  109. package/tests/random-move.spec.ts +65 -0
  110. package/tests/skill.spec.ts +658 -0
  111. package/tests/state.spec.ts +467 -0
  112. package/tests/variable.spec.ts +185 -0
  113. package/tests/world-maps.spec.ts +896 -0
  114. package/vite.config.ts +36 -3
@@ -0,0 +1,299 @@
1
+ import { WeatherState } from '../../../common/src';
2
+ import { MapEventDefinition, MapEventPlacement } from '../rooms/map';
3
+ export interface MapOptions {
4
+ /**
5
+ * Map identifier. Allows to go to the map (for example with player.changeMap())
6
+ *
7
+ * @prop {string} [id]
8
+ * @memberof MapData
9
+ * */
10
+ id?: string;
11
+ /**
12
+ * the path to the .tmx file (Tiled Map Editor)
13
+ *
14
+ * Remember to use `require()` function
15
+ *
16
+ * ```ts
17
+ * import { MapData, RpgMap } from '@rpgjs/server'
18
+ *
19
+ * @MapData({
20
+ * id: 'town',
21
+ * file: require('./tmx/town.tmx')
22
+ * })
23
+ * class TownMap extends RpgMap { }
24
+ * ```
25
+ * @prop {string} file
26
+ * @memberof MapData
27
+ * */
28
+ file?: any;
29
+ /**
30
+ * The name of the map.
31
+ * @prop {string} [name]
32
+ * @memberof MapData
33
+ * */
34
+ name?: string;
35
+ /**
36
+ * Map events. This is an array containing `RpgEvent` classes.
37
+ * You can also give an object that will indicate the positions of the event on the map.
38
+ *
39
+ * ```ts
40
+ * import { MapData, RpgMap, EventData, RpgEvent } from '@rpgjs/server'
41
+ *
42
+ * @EventData({
43
+ * name: 'Ev-1'
44
+ * })
45
+ * class NpcEvent extends RpgEvent { }
46
+ *
47
+ * @MapData({
48
+ * id: 'medieval',
49
+ * file: require('./tmx/town.tmx'),
50
+ * events: [NpcEvent]
51
+ * })
52
+ * class TownMap extends RpgMap {}
53
+ * ```
54
+ *
55
+ * If the positions are not defined, the event will be placed on a Tiled Map Editor shape ([/guide/create-event.html#position-the-event-on-the-map](Guide)). Otherwise, it will be placed at `{x:0, y:0 }`
56
+ *
57
+ * You can give positions:
58
+ *
59
+ * ```ts
60
+ * events: [{ event: NpcEvent, x: 10, y: 30 }]
61
+ * ```
62
+ *
63
+ * For object-based events, put the hooks in the `event` property and keep map placement
64
+ * (`x`, `y`, `id`) at the wrapper level:
65
+ *
66
+ * ```ts
67
+ * events: [{
68
+ * x: 200,
69
+ * y: 120,
70
+ * event: {
71
+ * onInit() {
72
+ * this.setGraphic('female')
73
+ * }
74
+ * }
75
+ * }]
76
+ * ```
77
+ *
78
+ * @prop {(MapEventDefinition | MapEventPlacement)[]} [events]
79
+ * @memberof MapData
80
+ * */
81
+ events?: (MapEventDefinition | MapEventPlacement)[];
82
+ /**
83
+ * The sounds that will be played when the map is open. Sounds must be defined on the client side. Then, put the name of the sound identifier
84
+ *
85
+ * So, it is possible to play several sounds (in loop or not) on the card. You can put a background music (BGM) and a background noise (BGS) for example
86
+ *
87
+ * ```ts
88
+ * sounds: ['my-bgm', 'my-bgs']
89
+ * ```
90
+ *
91
+ * And client side:
92
+ *
93
+ * ```ts
94
+ * import { Sound } from '@rpgjs/client'
95
+ *
96
+ * @Sound({
97
+ * sounds: {
98
+ * 'my-bgm': require('./assets/bgm.ogg'),
99
+ * 'my-bgs': require('./assets/bgs.ogg')
100
+ * },
101
+ * loop: true
102
+ * })
103
+ * export class Sounds {}
104
+ * ```
105
+ *
106
+ * See [https://docs.rpgjs.dev/classes/sound.html#properties](RpgSound Decorator)
107
+ *
108
+ * @prop {Array<string>} [sounds]
109
+ * @memberof MapData
110
+ * */
111
+ sounds?: string[];
112
+ /**
113
+ * Initial weather state for this map.
114
+ *
115
+ * This value is applied when the map is loaded and can later be updated
116
+ * at runtime with `map.setWeather()` from server logic.
117
+ *
118
+ * ```ts
119
+ * @MapData({
120
+ * id: 'forest',
121
+ * file: require('./tmx/forest.tmx'),
122
+ * weather: {
123
+ * effect: 'fog',
124
+ * preset: 'rpgForestFog',
125
+ * params: { density: 1.2, height: 0.75 },
126
+ * transitionMs: 1200
127
+ * }
128
+ * })
129
+ * class ForestMap extends RpgMap {}
130
+ * ```
131
+ */
132
+ weather?: WeatherState | null;
133
+ /**
134
+ * Whether to stop all sounds before playing the map sounds when a player joins.
135
+ *
136
+ * If set to `true`, all currently playing sounds will be stopped before playing the new map sounds.
137
+ * This prevents sound overlap when changing maps.
138
+ *
139
+ * By default, this is `false`, meaning sounds from the previous map will continue playing.
140
+ *
141
+ * ```ts
142
+ * @MapData({
143
+ * id: 'battle-map',
144
+ * sounds: ['battle-theme'],
145
+ * stopAllSoundsBeforeJoin: true // Stop all sounds before playing battle theme
146
+ * })
147
+ * class BattleMap extends RpgMap {}
148
+ * ```
149
+ *
150
+ * @prop {boolean} [stopAllSoundsBeforeJoin=false]
151
+ * @memberof MapData
152
+ * @since 5.0.0
153
+ * */
154
+ stopAllSoundsBeforeJoin?: boolean;
155
+ /**
156
+ * Specify which properties will be synchronized with the client. On the client side, you can retrieve the values synchronized with the valueChanges property on the scene
157
+ *
158
+ * You must create the schema:
159
+ *
160
+ * ```ts
161
+ * import { MapData, RpgMap } from '@rpgjs/server'
162
+ *
163
+ * @MapData({
164
+ * id: 'medieval',
165
+ * file: require('./tmx/town.tmx'),
166
+ * syncSchema: {
167
+ * count: Number
168
+ * }
169
+ * })
170
+ * export class TownMap extends RpgMap {
171
+ * count: number = 0
172
+ *
173
+ * onLoad() {}
174
+ *
175
+ * onJoin() {
176
+ * this.count++
177
+ * }
178
+ *
179
+ * onLeave(player) {
180
+ * super.onLeave(player)
181
+ * this.count--
182
+ * }
183
+ * }
184
+ *
185
+ * ```
186
+ *
187
+ * If you want to change the scheme of players and events, consider overwriting the existing scheme
188
+ *
189
+ * ```ts
190
+ * import { MapData, RpgMap, RpgPlayer } from '@rpgjs/server'
191
+ *
192
+ *
193
+ * declare module '@rpgjs/server' {
194
+ * export interface RpgPlayer {
195
+ * customProp: string
196
+ * }
197
+ * }
198
+ *
199
+ * @MapData({
200
+ * id: 'medieval',
201
+ * file: require('./tmx/town.tmx'),
202
+ * syncSchema: {
203
+ * users: [
204
+ * {
205
+ * customProp: String,
206
+ * ...RpgPlayer.schemas
207
+ * }
208
+ * ]
209
+ * }
210
+ * })
211
+ * export class TownMap extends RpgMap {}
212
+ * ```
213
+ *
214
+ * The properties are called `users` and `events`. Their scheme is identical and defined in `RpgPlayer.schemas`. To write schematics, refer to the [documentation of the simple-room](https://github.com/RSamaium/simple-room) module
215
+ *
216
+ * @prop {object} [syncSchema]
217
+ * @memberof MapData
218
+ * */
219
+ syncSchema?: any;
220
+ /**
221
+ * Decreases the RAM of the map. In this case, some instructions will be different.
222
+ *
223
+ * `map.getTileByIndex()` will not return all tiles of an index but only the tile of the highest layer
224
+ *
225
+ * > You can also use the `low-memory` property in Tiled maps
226
+ *
227
+ * @prop {boolean} [lowMemory=false]
228
+ * @since 3.1.0
229
+ * @memberof MapData
230
+ * */
231
+ lowMemory?: boolean;
232
+ /**
233
+ * Called when the map is loaded and initialized
234
+ *
235
+ * This hook is executed once when the map data is loaded and ready.
236
+ * Use this to initialize map-specific properties or setup.
237
+ *
238
+ * @prop { () => any } [onLoad]
239
+ * @memberof MapData
240
+ * @example
241
+ * ```ts
242
+ * @MapData({
243
+ * id: 'town',
244
+ * file: require('./tmx/town.tmx'),
245
+ * onLoad() {
246
+ * console.log('Town map loaded')
247
+ * // Initialize map properties
248
+ * }
249
+ * })
250
+ * class TownMap extends RpgMap {}
251
+ * ```
252
+ * */
253
+ onLoad?: () => any;
254
+ /**
255
+ * Called when a player joins the map
256
+ *
257
+ * This hook is executed each time a player joins the map.
258
+ * Use this to perform actions when a player enters the map.
259
+ *
260
+ * @prop { (player: RpgPlayer) => any } [onJoin]
261
+ * @memberof MapData
262
+ * @example
263
+ * ```ts
264
+ * @MapData({
265
+ * id: 'town',
266
+ * file: require('./tmx/town.tmx'),
267
+ * onJoin(player: RpgPlayer) {
268
+ * console.log(`${player.name} joined the town`)
269
+ * // Perform actions when player joins
270
+ * }
271
+ * })
272
+ * class TownMap extends RpgMap {}
273
+ * ```
274
+ * */
275
+ onJoin?: (player: RpgPlayer) => any;
276
+ /**
277
+ * Called when a player leaves the map
278
+ *
279
+ * This hook is executed each time a player leaves the map.
280
+ * Use this to perform cleanup or actions when a player exits the map.
281
+ *
282
+ * @prop { (player: RpgPlayer) => any } [onLeave]
283
+ * @memberof MapData
284
+ * @example
285
+ * ```ts
286
+ * @MapData({
287
+ * id: 'town',
288
+ * file: require('./tmx/town.tmx'),
289
+ * onLeave(player: RpgPlayer) {
290
+ * console.log(`${player.name} left the town`)
291
+ * // Perform cleanup when player leaves
292
+ * }
293
+ * })
294
+ * class TownMap extends RpgMap {}
295
+ * ```
296
+ * */
297
+ onLeave?: (player: RpgPlayer) => any;
298
+ }
299
+ export declare function MapData(options: MapOptions): (target: any) => void;
package/dist/index.d.ts CHANGED
@@ -4,6 +4,16 @@ export * from './RpgServer';
4
4
  export * from './core/setup';
5
5
  export * from './core/inject';
6
6
  export * from './Player/Player';
7
+ export * from './Player/Components';
7
8
  export * from './module';
8
9
  export * from './rooms/map';
9
10
  export * from './presets';
11
+ export * from '@signe/reactive';
12
+ export * from './Gui';
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';
16
+ export * from './decorators/event';
17
+ export * from './decorators/map';
18
+ export * from './Player/MoveManager';
19
+ export * from './presets';