@rpgjs/common 3.0.1 → 3.2.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.
- package/LICENSE +19 -0
- package/lib/AbstractObject.d.ts +318 -0
- package/lib/AbstractObject.js +828 -0
- package/lib/AbstractObject.js.map +1 -0
- package/lib/Game.d.ts +6 -2
- package/lib/Game.js +42 -13
- package/lib/Game.js.map +1 -1
- package/lib/Hit.d.ts +4 -28
- package/lib/Hit.js +12 -15
- package/lib/Hit.js.map +1 -1
- package/lib/Hitbox.d.ts +6 -0
- package/lib/Hitbox.js +10 -0
- package/lib/Hitbox.js.map +1 -0
- package/lib/HitboxEffect.d.ts +6 -0
- package/lib/HitboxEffect.js +10 -0
- package/lib/HitboxEffect.js.map +1 -0
- package/lib/Map.d.ts +12 -0
- package/lib/Map.js +77 -4
- package/lib/Map.js.map +1 -1
- package/lib/Player.d.ts +9 -296
- package/lib/Player.js +7 -639
- package/lib/Player.js.map +1 -1
- package/lib/Scheduler.d.ts +16 -38
- package/lib/Scheduler.js +69 -76
- package/lib/Scheduler.js.map +1 -1
- package/lib/Shape.d.ts +8 -7
- package/lib/Shape.js +11 -15
- package/lib/Shape.js.map +1 -1
- package/lib/SocketEvents.d.ts +8 -0
- package/lib/SocketEvents.js +14 -0
- package/lib/SocketEvents.js.map +1 -0
- package/lib/Utils.d.ts +12 -11
- package/lib/Utils.js.map +1 -1
- package/lib/Vector2d.d.ts +19 -0
- package/lib/Vector2d.js +63 -0
- package/lib/Vector2d.js.map +1 -0
- package/lib/VirtualGrid.d.ts +2 -3
- package/lib/VirtualGrid.js.map +1 -1
- package/lib/WorldMaps.d.ts +1 -1
- package/lib/WorldMaps.js +5 -5
- package/lib/WorldMaps.js.map +1 -1
- package/lib/index.d.ts +21 -19
- package/lib/index.js +27 -30
- package/lib/index.js.map +1 -1
- package/lib/types/Hitbox.d.ts +24 -0
- package/lib/types/Hitbox.js +3 -0
- package/lib/types/Hitbox.js.map +1 -0
- package/lib/types/Player.d.ts +8 -0
- package/lib/types/Player.js +3 -0
- package/lib/types/Player.js.map +1 -0
- package/lib/types/index.d.ts +3 -0
- package/lib/types/index.js +3 -0
- package/lib/types/index.js.map +1 -0
- package/lib/workers/move.js +1 -1
- package/lib/workers/move.js.map +1 -1
- package/package.json +5 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Copyright (C) 2020 by Samuel Ronce
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
|
11
|
+
all copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
|
+
THE SOFTWARE.
|
|
@@ -0,0 +1,318 @@
|
|
|
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 } from 'rxjs';
|
|
9
|
+
declare type CollisionOptions = {
|
|
10
|
+
collision?: (event: AbstractObject) => void;
|
|
11
|
+
near?: (event: AbstractObject) => void;
|
|
12
|
+
allSearch?: boolean;
|
|
13
|
+
};
|
|
14
|
+
export declare class AbstractObject {
|
|
15
|
+
private gameEngine;
|
|
16
|
+
playerId: string;
|
|
17
|
+
map: string;
|
|
18
|
+
height: number;
|
|
19
|
+
width: number;
|
|
20
|
+
speed: number;
|
|
21
|
+
direction: number;
|
|
22
|
+
checkCollision: boolean;
|
|
23
|
+
clientModeMove: ClientMode;
|
|
24
|
+
behavior: Behavior;
|
|
25
|
+
hitbox: SAT.Box;
|
|
26
|
+
inShapes: {
|
|
27
|
+
[shapeId: string]: RpgShape;
|
|
28
|
+
};
|
|
29
|
+
disableVirtualGrid: boolean;
|
|
30
|
+
private shapes;
|
|
31
|
+
private _position;
|
|
32
|
+
private _hitboxPos;
|
|
33
|
+
private collisionWith;
|
|
34
|
+
private _collisionWithTiles;
|
|
35
|
+
private _collisionWithShapes;
|
|
36
|
+
private destroyMove$;
|
|
37
|
+
static get ACTIONS(): {
|
|
38
|
+
IDLE: number;
|
|
39
|
+
RUN: number;
|
|
40
|
+
ACTION: number;
|
|
41
|
+
};
|
|
42
|
+
constructor(gameEngine: RpgCommonGame, playerId: string);
|
|
43
|
+
get id(): string;
|
|
44
|
+
set id(str: string);
|
|
45
|
+
updateInVirtualGrid(): void;
|
|
46
|
+
get canMove(): boolean;
|
|
47
|
+
set canMove(val: boolean);
|
|
48
|
+
/**
|
|
49
|
+
* Get/Set position x, y and z of player
|
|
50
|
+
*
|
|
51
|
+
* 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.
|
|
52
|
+
*
|
|
53
|
+
* @title Get/Set position
|
|
54
|
+
* @prop { { x: number, y: number, z: number } } position
|
|
55
|
+
* @memberof Player
|
|
56
|
+
*/
|
|
57
|
+
set position(val: Position | Vector2d);
|
|
58
|
+
get position(): Vector2d;
|
|
59
|
+
get worldPositionX(): number;
|
|
60
|
+
get worldPositionY(): number;
|
|
61
|
+
set posX(val: any);
|
|
62
|
+
set posY(val: any);
|
|
63
|
+
set posZ(val: any);
|
|
64
|
+
/**
|
|
65
|
+
*
|
|
66
|
+
* Recovers all the colliding shapes of the current player
|
|
67
|
+
*
|
|
68
|
+
* @title Get Collision of shapes
|
|
69
|
+
* @since 3.2.0
|
|
70
|
+
* @readonly
|
|
71
|
+
* @prop { RpgShape[] } shapes
|
|
72
|
+
* @memberof Player
|
|
73
|
+
* @memberof RpgSpriteLogic
|
|
74
|
+
*/
|
|
75
|
+
get shapesCollision(): RpgShape[];
|
|
76
|
+
/**
|
|
77
|
+
*
|
|
78
|
+
* Recovers all the colliding tiles of the current player
|
|
79
|
+
*
|
|
80
|
+
* @title Get Collision of tiles
|
|
81
|
+
* @since 3.0.0-beta.4
|
|
82
|
+
* @readonly
|
|
83
|
+
* @prop { TileInfo[] } tiles
|
|
84
|
+
* @memberof Player
|
|
85
|
+
* @memberof RpgSpriteLogic
|
|
86
|
+
*/
|
|
87
|
+
get tilesCollision(): TileInfo[];
|
|
88
|
+
/**
|
|
89
|
+
*
|
|
90
|
+
* Recovers all other players and events colliding with the current player's hitbox
|
|
91
|
+
*
|
|
92
|
+
* @title Get Collision of other players/events
|
|
93
|
+
* @since 3.0.0-beta.4
|
|
94
|
+
* @readonly
|
|
95
|
+
* @prop { (RpgPlayer | RpgEvent)[] } otherPlayersCollision
|
|
96
|
+
* @memberof Player
|
|
97
|
+
* @memberof RpgSpriteLogic
|
|
98
|
+
*/
|
|
99
|
+
get otherPlayersCollision(): AbstractObject[];
|
|
100
|
+
/**
|
|
101
|
+
* Define the size of the player. You can set the hitbox for collisions
|
|
102
|
+
*
|
|
103
|
+
* ```ts
|
|
104
|
+
* player.setSizes({
|
|
105
|
+
* width: 32,
|
|
106
|
+
* height: 32
|
|
107
|
+
* })
|
|
108
|
+
* ```
|
|
109
|
+
*
|
|
110
|
+
* and with hitbox:
|
|
111
|
+
*
|
|
112
|
+
* ```ts
|
|
113
|
+
* player.setSizes({
|
|
114
|
+
* width: 32,
|
|
115
|
+
* height: 32,
|
|
116
|
+
* hitbox: {
|
|
117
|
+
* width: 20,
|
|
118
|
+
* height: 20
|
|
119
|
+
* }
|
|
120
|
+
* })
|
|
121
|
+
* ```
|
|
122
|
+
*
|
|
123
|
+
* @title Set Sizes
|
|
124
|
+
* @method player.setSizes(key,value)
|
|
125
|
+
* @param { { width: number, height: number, hitbox?: { width: number, height: number } } } obj
|
|
126
|
+
* @deprecated
|
|
127
|
+
* @returns {void}
|
|
128
|
+
* @memberof Player
|
|
129
|
+
*/
|
|
130
|
+
setSizes(obj: {
|
|
131
|
+
width: number;
|
|
132
|
+
height: number;
|
|
133
|
+
hitbox?: {
|
|
134
|
+
width: number;
|
|
135
|
+
height: number;
|
|
136
|
+
};
|
|
137
|
+
}): void;
|
|
138
|
+
/**
|
|
139
|
+
* Define the hitbox of the player.
|
|
140
|
+
*
|
|
141
|
+
* ```ts
|
|
142
|
+
* player.setHitbox(20, 20)
|
|
143
|
+
* ```
|
|
144
|
+
*
|
|
145
|
+
* @title Set Hitbox
|
|
146
|
+
* @method player.setHitbox(width,height)
|
|
147
|
+
* @param {number} width
|
|
148
|
+
* @param {number} height
|
|
149
|
+
* @returns {void}
|
|
150
|
+
* @memberof Player
|
|
151
|
+
*/
|
|
152
|
+
setHitbox(width: number, height: number): void;
|
|
153
|
+
set wHitbox(val: any);
|
|
154
|
+
set hHitbox(val: any);
|
|
155
|
+
get wHitbox(): any;
|
|
156
|
+
get hHitbox(): any;
|
|
157
|
+
private directionToAngle;
|
|
158
|
+
/**
|
|
159
|
+
* Retrieves a tile and checks if the player has a collision
|
|
160
|
+
*
|
|
161
|
+
* ```ts
|
|
162
|
+
* const tileInfo = player.getTile(20, 30)
|
|
163
|
+
* console.log(tileInfo)
|
|
164
|
+
* ```
|
|
165
|
+
*
|
|
166
|
+
* Example of returns:
|
|
167
|
+
*
|
|
168
|
+
```ts
|
|
169
|
+
{
|
|
170
|
+
tiles: [
|
|
171
|
+
{
|
|
172
|
+
id: 0,
|
|
173
|
+
terrain: [],
|
|
174
|
+
probability: null,
|
|
175
|
+
properties: [Object],
|
|
176
|
+
animations: [],
|
|
177
|
+
objectGroups: [],
|
|
178
|
+
image: null,
|
|
179
|
+
gid: 1
|
|
180
|
+
}
|
|
181
|
+
],
|
|
182
|
+
hasCollision: false,
|
|
183
|
+
isOverlay: undefined,
|
|
184
|
+
objectGroups: [],
|
|
185
|
+
isClimbable: undefined,
|
|
186
|
+
tileIndex: 93
|
|
187
|
+
}
|
|
188
|
+
```
|
|
189
|
+
*
|
|
190
|
+
* @title Get Tile
|
|
191
|
+
* @since 3.0.0-beta.4
|
|
192
|
+
* @method player.getTile(x,y,z?)
|
|
193
|
+
* @param {number} x
|
|
194
|
+
* @param {number} y
|
|
195
|
+
* @param {number} [z]
|
|
196
|
+
* @returns {object}
|
|
197
|
+
* @memberof Player
|
|
198
|
+
* @memberof RpgSpriteLogic
|
|
199
|
+
*/
|
|
200
|
+
getTile(x: number, y: number, z?: number, hitbox?: SAT.Box): TileInfo;
|
|
201
|
+
private collisionObjects;
|
|
202
|
+
private collisionShapes;
|
|
203
|
+
computeNextPositionByTarget(nextPosition: Vector2d, target: Vector2d): Promise<Vector2d>;
|
|
204
|
+
isCollided(nextPosition: Vector2d, options?: CollisionOptions): Promise<boolean>;
|
|
205
|
+
/**
|
|
206
|
+
* Attach a shape to the player (and allow interaction with it)
|
|
207
|
+
*
|
|
208
|
+
* ```ts
|
|
209
|
+
* import { ShapePositioning } from '@rpgjs/server'
|
|
210
|
+
*
|
|
211
|
+
* player.attachShape({
|
|
212
|
+
* width: 100,
|
|
213
|
+
* height: 100,
|
|
214
|
+
* positioning: ShapePositioning.Center
|
|
215
|
+
* })
|
|
216
|
+
* ```
|
|
217
|
+
*
|
|
218
|
+
* @title Attach Shape
|
|
219
|
+
* @method player.attachShape(parameters)
|
|
220
|
+
* @param { { width: number, height: number, positioning?, name?, properties?: object } } obj
|
|
221
|
+
* - positioning: Indicate where the shape is placed.
|
|
222
|
+
* - properties: An object in order to retrieve information when interacting with the shape
|
|
223
|
+
* - name: The name of the shape
|
|
224
|
+
* @since 3.0.0-beta.3
|
|
225
|
+
* @returns {RpgShape}
|
|
226
|
+
* @memberof Player
|
|
227
|
+
*/
|
|
228
|
+
attachShape(obj: {
|
|
229
|
+
width: number;
|
|
230
|
+
height: number;
|
|
231
|
+
positioning?: string;
|
|
232
|
+
name?: string;
|
|
233
|
+
properties?: object;
|
|
234
|
+
}): RpgShape;
|
|
235
|
+
/**
|
|
236
|
+
* Returns all shapes assigned to this player
|
|
237
|
+
*
|
|
238
|
+
* @title Get Shapes
|
|
239
|
+
* @method player.getShapes()
|
|
240
|
+
* @returns {RpgShape[]}
|
|
241
|
+
* @since 3.0.0-beta.3
|
|
242
|
+
* @memberof Player
|
|
243
|
+
* @memberof RpgSpriteLogic
|
|
244
|
+
*/
|
|
245
|
+
getShapes(): RpgShape[];
|
|
246
|
+
private autoChangeDirection;
|
|
247
|
+
/**
|
|
248
|
+
* Stops the movement of the player who moves towards his target
|
|
249
|
+
*
|
|
250
|
+
* @title Stop Move To
|
|
251
|
+
* @method player.stopMoveTo()
|
|
252
|
+
* @returns {void}
|
|
253
|
+
* @since 3.2.0
|
|
254
|
+
* @memberof MoveManager
|
|
255
|
+
*/
|
|
256
|
+
stopMoveTo(): void;
|
|
257
|
+
_moveTo(tick$: Observable<Tick>, positionTarget: AbstractObject | RpgShape | PositionXY, options?: MoveTo): Observable<Vector2d>;
|
|
258
|
+
/**
|
|
259
|
+
* Retrieves all shapes where the player is located
|
|
260
|
+
*
|
|
261
|
+
* @title Get In-Shapes
|
|
262
|
+
* @method player.getInShapes()
|
|
263
|
+
* @returns {RpgShape[]}
|
|
264
|
+
* @since 3.0.0-beta.3
|
|
265
|
+
* @memberof Player
|
|
266
|
+
*/
|
|
267
|
+
getInShapes(): RpgShape[];
|
|
268
|
+
/**
|
|
269
|
+
* Get the current direction.
|
|
270
|
+
*
|
|
271
|
+
* ```ts
|
|
272
|
+
* player.getDirection()
|
|
273
|
+
* ```
|
|
274
|
+
*
|
|
275
|
+
* @title Get Direction
|
|
276
|
+
* @method player.getDirection()
|
|
277
|
+
* @returns {Direction | number} direction
|
|
278
|
+
* @memberof Player
|
|
279
|
+
*/
|
|
280
|
+
getDirection(direction?: Direction | number): string | number;
|
|
281
|
+
/**
|
|
282
|
+
* Changes the player's direction
|
|
283
|
+
*
|
|
284
|
+
* ```ts
|
|
285
|
+
* import { Direction } from '@rpgjs/server'
|
|
286
|
+
*
|
|
287
|
+
* player.changeDirection(Direction.Left)
|
|
288
|
+
* ```
|
|
289
|
+
*
|
|
290
|
+
* @title Change direction
|
|
291
|
+
* @method player.changeDirection(direction)
|
|
292
|
+
* @param {Direction} direction
|
|
293
|
+
* @enum {string}
|
|
294
|
+
*
|
|
295
|
+
* Direction.Left | left
|
|
296
|
+
* Direction.Right | right
|
|
297
|
+
* Direction.Up | up
|
|
298
|
+
* Direction.Down | down
|
|
299
|
+
* @returns {boolean} the direction has changed
|
|
300
|
+
* @memberof Player
|
|
301
|
+
*/
|
|
302
|
+
changeDirection(direction: Direction): boolean;
|
|
303
|
+
/**
|
|
304
|
+
* Gets the necessary number of pixels to allow the player to cross a tile.
|
|
305
|
+
* This is the ratio between the height or width of the tile and the speed of the player.
|
|
306
|
+
*/
|
|
307
|
+
get nbPixelInTile(): any;
|
|
308
|
+
getSizeMaxShape(x?: number, y?: number): Box;
|
|
309
|
+
}
|
|
310
|
+
export interface AbstractObject {
|
|
311
|
+
readonly type: string;
|
|
312
|
+
through: boolean;
|
|
313
|
+
throughOtherPlayer: boolean;
|
|
314
|
+
autoChangeMap?(nextPosition: Position): Promise<boolean>;
|
|
315
|
+
execMethod(methodName: string, methodData?: any, instance?: any): any;
|
|
316
|
+
changeMap(mapName: string): any;
|
|
317
|
+
}
|
|
318
|
+
export {};
|