@rpgjs/common 4.2.1 → 5.0.0-alpha.0

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 (148) hide show
  1. package/dist/Physic.d.ts +619 -0
  2. package/dist/Player.d.ts +198 -0
  3. package/{lib → dist}/Utils.d.ts +19 -2
  4. package/dist/database/Item.d.ts +10 -0
  5. package/dist/database/index.d.ts +1 -0
  6. package/dist/index.d.ts +9 -0
  7. package/dist/index.js +16741 -0
  8. package/dist/index.js.map +1 -0
  9. package/dist/modules.d.ts +92 -0
  10. package/dist/movement/MovementManager.d.ts +84 -0
  11. package/dist/movement/MovementStrategy.d.ts +39 -0
  12. package/dist/movement/index.d.ts +12 -0
  13. package/dist/movement/strategies/CompositeMovement.d.ts +76 -0
  14. package/dist/movement/strategies/Dash.d.ts +52 -0
  15. package/dist/movement/strategies/IceMovement.d.ts +87 -0
  16. package/dist/movement/strategies/Knockback.d.ts +50 -0
  17. package/dist/movement/strategies/LinearMove.d.ts +43 -0
  18. package/dist/movement/strategies/LinearRepulsion.d.ts +55 -0
  19. package/dist/movement/strategies/Oscillate.d.ts +60 -0
  20. package/dist/movement/strategies/PathFollow.d.ts +78 -0
  21. package/dist/movement/strategies/ProjectileMovement.d.ts +138 -0
  22. package/dist/movement/strategies/SeekAvoid.d.ts +27 -0
  23. package/dist/rooms/Map.d.ts +109 -0
  24. package/dist/services/updateMap.d.ts +7 -0
  25. package/package.json +17 -17
  26. package/src/Physic.ts +1644 -0
  27. package/src/Player.ts +262 -26
  28. package/src/{gui/PrebuiltGui.ts → PrebuiltGui.ts} +1 -1
  29. package/src/Utils.ts +184 -123
  30. package/src/database/Item.ts +19 -0
  31. package/src/database/index.ts +1 -0
  32. package/src/index.ts +9 -25
  33. package/src/modules.ts +230 -0
  34. package/src/movement/MovementManager.ts +142 -0
  35. package/src/movement/MovementStrategy.ts +42 -0
  36. package/src/movement/index.ts +15 -0
  37. package/src/movement/strategies/CompositeMovement.ts +173 -0
  38. package/src/movement/strategies/Dash.ts +82 -0
  39. package/src/movement/strategies/IceMovement.ts +158 -0
  40. package/src/movement/strategies/Knockback.ts +81 -0
  41. package/src/movement/strategies/LinearMove.ts +58 -0
  42. package/src/movement/strategies/LinearRepulsion.ts +128 -0
  43. package/src/movement/strategies/Oscillate.ts +144 -0
  44. package/src/movement/strategies/PathFollow.ts +156 -0
  45. package/src/movement/strategies/ProjectileMovement.ts +322 -0
  46. package/src/movement/strategies/SeekAvoid.ts +123 -0
  47. package/src/rooms/Map.ts +272 -0
  48. package/src/services/updateMap.ts +9 -0
  49. package/tests/physic.spec.ts +454 -0
  50. package/tsconfig.json +8 -3
  51. package/vite.config.ts +21 -0
  52. package/CHANGELOG.md +0 -152
  53. package/LICENSE +0 -19
  54. package/browser/manifest.json +0 -7
  55. package/browser/rpg.common.js +0 -11357
  56. package/browser/rpg.common.umd.cjs +0 -11358
  57. package/lib/AbstractObject.d.ts +0 -322
  58. package/lib/AbstractObject.js +0 -872
  59. package/lib/AbstractObject.js.map +0 -1
  60. package/lib/Color.d.ts +0 -1
  61. package/lib/Color.js +0 -25
  62. package/lib/Color.js.map +0 -1
  63. package/lib/DefaultInput.d.ts +0 -2
  64. package/lib/DefaultInput.js +0 -26
  65. package/lib/DefaultInput.js.map +0 -1
  66. package/lib/Event.d.ts +0 -3
  67. package/lib/Event.js +0 -4
  68. package/lib/Event.js.map +0 -1
  69. package/lib/EventEmitter.d.ts +0 -10
  70. package/lib/EventEmitter.js +0 -61
  71. package/lib/EventEmitter.js.map +0 -1
  72. package/lib/Game.d.ts +0 -28
  73. package/lib/Game.js +0 -127
  74. package/lib/Game.js.map +0 -1
  75. package/lib/Hit.d.ts +0 -16
  76. package/lib/Hit.js +0 -65
  77. package/lib/Hit.js.map +0 -1
  78. package/lib/Inject.d.ts +0 -9
  79. package/lib/Inject.js +0 -17
  80. package/lib/Inject.js.map +0 -1
  81. package/lib/Logger.d.ts +0 -2
  82. package/lib/Logger.js +0 -7
  83. package/lib/Logger.js.map +0 -1
  84. package/lib/Map.d.ts +0 -174
  85. package/lib/Map.js +0 -263
  86. package/lib/Map.js.map +0 -1
  87. package/lib/Module.d.ts +0 -16
  88. package/lib/Module.js +0 -139
  89. package/lib/Module.js.map +0 -1
  90. package/lib/Player.d.ts +0 -26
  91. package/lib/Player.js +0 -19
  92. package/lib/Player.js.map +0 -1
  93. package/lib/Plugin.d.ts +0 -67
  94. package/lib/Plugin.js +0 -92
  95. package/lib/Plugin.js.map +0 -1
  96. package/lib/Scheduler.d.ts +0 -26
  97. package/lib/Scheduler.js +0 -90
  98. package/lib/Scheduler.js.map +0 -1
  99. package/lib/Shape.d.ts +0 -127
  100. package/lib/Shape.js +0 -261
  101. package/lib/Shape.js.map +0 -1
  102. package/lib/Utils.js +0 -181
  103. package/lib/Utils.js.map +0 -1
  104. package/lib/Vector2d.d.ts +0 -20
  105. package/lib/Vector2d.js +0 -63
  106. package/lib/Vector2d.js.map +0 -1
  107. package/lib/VirtualGrid.d.ts +0 -26
  108. package/lib/VirtualGrid.js +0 -68
  109. package/lib/VirtualGrid.js.map +0 -1
  110. package/lib/Worker.d.ts +0 -7
  111. package/lib/Worker.js +0 -13
  112. package/lib/Worker.js.map +0 -1
  113. package/lib/WorldMaps.d.ts +0 -105
  114. package/lib/WorldMaps.js +0 -184
  115. package/lib/WorldMaps.js.map +0 -1
  116. package/lib/gui/PrebuiltGui.js +0 -29
  117. package/lib/gui/PrebuiltGui.js.map +0 -1
  118. package/lib/index.d.ts +0 -25
  119. package/lib/index.js +0 -26
  120. package/lib/index.js.map +0 -1
  121. package/lib/transports/io.d.ts +0 -22
  122. package/lib/transports/io.js +0 -82
  123. package/lib/transports/io.js.map +0 -1
  124. package/lib/workers/move.d.ts +0 -1
  125. package/lib/workers/move.js +0 -57
  126. package/lib/workers/move.js.map +0 -1
  127. package/rpg.toml +0 -11
  128. package/src/AbstractObject.ts +0 -973
  129. package/src/Color.ts +0 -29
  130. package/src/DefaultInput.ts +0 -26
  131. package/src/Event.ts +0 -3
  132. package/src/EventEmitter.ts +0 -65
  133. package/src/Game.ts +0 -159
  134. package/src/Hit.ts +0 -70
  135. package/src/Inject.ts +0 -22
  136. package/src/Logger.ts +0 -7
  137. package/src/Map.ts +0 -335
  138. package/src/Module.ts +0 -144
  139. package/src/Plugin.ts +0 -100
  140. package/src/Scheduler.ts +0 -95
  141. package/src/Shape.ts +0 -302
  142. package/src/Vector2d.ts +0 -70
  143. package/src/VirtualGrid.ts +0 -78
  144. package/src/Worker.ts +0 -17
  145. package/src/WorldMaps.ts +0 -204
  146. package/src/transports/io.ts +0 -91
  147. package/src/workers/move.ts +0 -61
  148. /package/{lib/gui → dist}/PrebuiltGui.d.ts +0 -0
@@ -1,322 +0,0 @@
1
- import { RpgShape } from './Shape';
2
- import SAT from 'sat';
3
- import { TileInfo } from './Map';
4
- import { RpgCommonGame } from './Game';
5
- import { Vector2d } from './Vector2d';
6
- import { Box } from './VirtualGrid';
7
- import { Behavior, ClientMode, Direction, MoveTo, Position, PositionXY, Tick } from '@rpgjs/types';
8
- import { Observable, Subject } from 'rxjs';
9
- type CollisionOptions = {
10
- collision?: (event: AbstractObject) => void;
11
- near?: (event: AbstractObject) => void;
12
- allSearch?: boolean;
13
- };
14
- export declare class AbstractObject {
15
- gameEngine: RpgCommonGame;
16
- playerId: string;
17
- map: string;
18
- height: number;
19
- width: number;
20
- speed: number;
21
- direction: number;
22
- moving: boolean;
23
- checkCollision: boolean;
24
- clientModeMove: ClientMode;
25
- behavior: Behavior;
26
- hitbox: SAT.Box;
27
- inShapes: {
28
- [shapeId: string]: RpgShape;
29
- };
30
- disableVirtualGrid: boolean;
31
- private shapes;
32
- private _position;
33
- private _hitboxPos;
34
- private collisionWith;
35
- private _collisionWithTiles;
36
- private _collisionWithShapes;
37
- private destroyMove$;
38
- _destroy$: Subject<void>;
39
- static get ACTIONS(): {
40
- IDLE: number;
41
- RUN: number;
42
- ACTION: number;
43
- };
44
- constructor(gameEngine: RpgCommonGame, playerId: string);
45
- get id(): string;
46
- set id(str: string);
47
- updateInVirtualGrid(): void;
48
- get canMove(): boolean;
49
- set canMove(val: boolean);
50
- /**
51
- * Get/Set position x, y and z of player
52
- *
53
- * z is the depth layer. By default, its value is 0. Collisions and overlays will be performed with other objects on the same z-position.
54
- *
55
- * @title Get/Set position
56
- * @prop { { x: number, y: number, z: number } } position
57
- * @memberof Player
58
- */
59
- set position(val: Position | Vector2d);
60
- get position(): Vector2d;
61
- get worldPositionX(): number;
62
- get worldPositionY(): number;
63
- set posX(val: any);
64
- set posY(val: any);
65
- set posZ(val: any);
66
- /**
67
- *
68
- * Recovers all the colliding shapes of the current player
69
- *
70
- * @title Get Collision of shapes
71
- * @since 3.2.0
72
- * @readonly
73
- * @prop { RpgShape[] } shapes
74
- * @memberof Player
75
- * @memberof RpgSpriteLogic
76
- */
77
- get shapesCollision(): RpgShape[];
78
- /**
79
- *
80
- * Recovers all the colliding tiles of the current player
81
- *
82
- * @title Get Collision of tiles
83
- * @since 3.0.0-beta.4
84
- * @readonly
85
- * @prop { TileInfo[] } tiles
86
- * @memberof Player
87
- * @memberof RpgSpriteLogic
88
- */
89
- get tilesCollision(): TileInfo[];
90
- /**
91
- *
92
- * Recovers all other players and events colliding with the current player's hitbox
93
- *
94
- * @title Get Collision of other players/events
95
- * @since 3.0.0-beta.4
96
- * @readonly
97
- * @prop { (RpgPlayer | RpgEvent)[] } otherPlayersCollision
98
- * @memberof Player
99
- * @memberof RpgSpriteLogic
100
- */
101
- get otherPlayersCollision(): AbstractObject[];
102
- /**
103
- * Define the size of the player. You can set the hitbox for collisions
104
- *
105
- * ```ts
106
- * player.setSizes({
107
- * width: 32,
108
- * height: 32
109
- * })
110
- * ```
111
- *
112
- * and with hitbox:
113
- *
114
- * ```ts
115
- * player.setSizes({
116
- * width: 32,
117
- * height: 32,
118
- * hitbox: {
119
- * width: 20,
120
- * height: 20
121
- * }
122
- * })
123
- * ```
124
- *
125
- * @title Set Sizes
126
- * @method player.setSizes(key,value)
127
- * @param { { width: number, height: number, hitbox?: { width: number, height: number } } } obj
128
- * @deprecated
129
- * @returns {void}
130
- * @memberof Player
131
- */
132
- setSizes(obj: {
133
- width: number;
134
- height: number;
135
- hitbox?: {
136
- width: number;
137
- height: number;
138
- };
139
- }): void;
140
- /**
141
- * Define the hitbox of the player.
142
- *
143
- * ```ts
144
- * player.setHitbox(20, 20)
145
- * ```
146
- *
147
- * @title Set Hitbox
148
- * @method player.setHitbox(width,height)
149
- * @param {number} width
150
- * @param {number} height
151
- * @returns {void}
152
- * @memberof Player
153
- */
154
- setHitbox(width: number, height: number): void;
155
- set wHitbox(val: any);
156
- set hHitbox(val: any);
157
- get wHitbox(): any;
158
- get hHitbox(): any;
159
- private directionToAngle;
160
- /**
161
- * Retrieves a tile and checks if the player has a collision
162
- *
163
- * ```ts
164
- * const tileInfo = player.getTile(20, 30)
165
- * console.log(tileInfo)
166
- * ```
167
- *
168
- * Example of returns:
169
- *
170
- * ```ts
171
- * {
172
- * tiles: [
173
- * {
174
- * id: 0,
175
- * terrain: [],
176
- * probability: null,
177
- * properties: [Object],
178
- * animations: [],
179
- * objectGroups: [],
180
- * image: null,
181
- * gid: 1
182
- * }
183
- * ],
184
- * hasCollision: false,
185
- * isOverlay: undefined,
186
- * objectGroups: [],
187
- * isClimbable: undefined,
188
- * tileIndex: 93
189
- * }
190
- * ```
191
- *
192
- * @title Get Tile
193
- * @since 3.0.0-beta.4
194
- * @method player.getTile(x,y,z?)
195
- * @param {number} x
196
- * @param {number} y
197
- * @param {number} [z]
198
- * @returns {object}
199
- * @memberof Player
200
- * @memberof RpgSpriteLogic
201
- */
202
- getTile(x: number, y: number, z?: number, hitbox?: SAT.Box): TileInfo;
203
- private collisionObjects;
204
- private collisionShapes;
205
- computeNextPositionByTarget(nextPosition: Vector2d, target: Vector2d): Promise<Vector2d>;
206
- isCollided(nextPosition: Vector2d, options?: CollisionOptions): Promise<boolean>;
207
- /**
208
- * Attach a shape to the player (and allow interaction with it)
209
- *
210
- * ```ts
211
- * import { ShapePositioning } from '@rpgjs/server'
212
- *
213
- * player.attachShape({
214
- * width: 100,
215
- * height: 100,
216
- * positioning: ShapePositioning.Center
217
- * })
218
- * ```
219
- *
220
- * @title Attach Shape
221
- * @method player.attachShape(parameters)
222
- * @param { { width: number, height: number, positioning?, name?, properties?: object } } obj
223
- * - positioning: Indicate where the shape is placed.
224
- * - properties: An object in order to retrieve information when interacting with the shape
225
- * - name: The name of the shape
226
- * @since 3.0.0-beta.3
227
- * @returns {RpgShape}
228
- * @memberof Player
229
- */
230
- attachShape(obj: {
231
- width: number;
232
- height: number;
233
- positioning?: string;
234
- name?: string;
235
- properties?: object;
236
- }): RpgShape;
237
- /**
238
- * Returns all shapes assigned to this player
239
- *
240
- * @title Get Shapes
241
- * @method player.getShapes()
242
- * @returns {RpgShape[]}
243
- * @since 3.0.0-beta.3
244
- * @memberof Player
245
- * @memberof RpgSpriteLogic
246
- */
247
- getShapes(): RpgShape[];
248
- private autoChangeDirection;
249
- /**
250
- * Stops the movement of the player who moves towards his target
251
- *
252
- * @title Stop Move To
253
- * @method player.stopMoveTo()
254
- * @returns {void}
255
- * @since 3.2.0
256
- * @memberof MoveManager
257
- */
258
- stopMoveTo(): void;
259
- private _lookToward;
260
- _moveTo(tick$: Observable<Tick>, positionTarget: AbstractObject | RpgShape | PositionXY, options?: MoveTo): Observable<Vector2d>;
261
- /**
262
- * Retrieves all shapes where the player is located
263
- *
264
- * @title Get In-Shapes
265
- * @method player.getInShapes()
266
- * @returns {RpgShape[]}
267
- * @since 3.0.0-beta.3
268
- * @memberof Player
269
- */
270
- getInShapes(): RpgShape[];
271
- /**
272
- * Get the current direction.
273
- *
274
- * ```ts
275
- * player.getDirection()
276
- * ```
277
- *
278
- * @title Get Direction
279
- * @method player.getDirection()
280
- * @returns {Direction | number} direction
281
- * @memberof Player
282
- */
283
- getDirection(direction?: Direction | number): string | number;
284
- /**
285
- * Changes the player's direction
286
- *
287
- * ```ts
288
- * import { Direction } from '@rpgjs/server'
289
- *
290
- * player.changeDirection(Direction.Left)
291
- * ```
292
- *
293
- * @title Change direction
294
- * @method player.changeDirection(direction)
295
- * @param {Direction} direction
296
- * @enum {string}
297
- *
298
- * Direction.Left | left
299
- * Direction.Right | right
300
- * Direction.Up | up
301
- * Direction.Down | down
302
- * @returns {boolean} the direction has changed
303
- * @memberof Player
304
- */
305
- changeDirection(direction: Direction): boolean;
306
- /**
307
- * Gets the necessary number of pixels to allow the player to cross a tile.
308
- * This is the ratio between the height or width of the tile and the speed of the player.
309
- */
310
- get nbPixelInTile(): any;
311
- getSizeMaxShape(x?: number, y?: number): Box;
312
- }
313
- export interface AbstractObject {
314
- readonly type: string;
315
- through: boolean;
316
- throughOtherPlayer: boolean;
317
- autoChangeMap?(nextPosition: Position): Promise<boolean>;
318
- execMethod(methodName: string, methodData?: any, instance?: any): any;
319
- changeMap(mapName: string): any;
320
- syncChanges(): any;
321
- }
322
- export {};