@rpgjs/common 3.0.0-beta.6 → 3.0.0-beta.9
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/lib/Event.d.ts +1 -1
- package/lib/Event.js +3 -2
- package/lib/Event.js.map +1 -1
- package/lib/Game.d.ts +9 -9
- package/lib/Game.js +46 -27
- package/lib/Game.js.map +1 -1
- package/lib/Hit.d.ts +17 -5
- package/lib/Hit.js +23 -11
- package/lib/Hit.js.map +1 -1
- package/lib/Map.d.ts +67 -2
- package/lib/Map.js +87 -8
- package/lib/Map.js.map +1 -1
- package/lib/Module.d.ts +3 -1
- package/lib/Module.js +89 -60
- package/lib/Module.js.map +1 -1
- package/lib/Player.d.ts +14 -24
- package/lib/Player.js +189 -123
- package/lib/Player.js.map +1 -1
- package/lib/Plugin.d.ts +8 -1
- package/lib/Plugin.js +7 -1
- package/lib/Plugin.js.map +1 -1
- package/lib/Scheduler.js +1 -1
- package/lib/Scheduler.js.map +1 -1
- package/lib/Shape.d.ts +14 -2
- package/lib/Shape.js +78 -20
- package/lib/Shape.js.map +1 -1
- package/lib/Utils.d.ts +3 -3
- package/lib/Utils.js +11 -3
- package/lib/Utils.js.map +1 -1
- package/lib/WorldMaps.d.ts +103 -0
- package/lib/WorldMaps.js +170 -0
- package/lib/WorldMaps.js.map +1 -0
- package/lib/index.d.ts +6 -5
- package/lib/index.js +11 -7
- package/lib/index.js.map +1 -1
- package/lib/transports/io.d.ts +4 -2
- package/lib/transports/io.js +12 -5
- package/lib/transports/io.js.map +1 -1
- package/lib/workers/move.js +32 -21
- package/lib/workers/move.js.map +1 -1
- package/package.json +5 -3
package/lib/Module.js
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
exports.loadModules = exports.RpgModule = void 0;
|
|
4
13
|
const Plugin_1 = require("./Plugin");
|
|
@@ -17,69 +26,89 @@ function RpgModule(options) {
|
|
|
17
26
|
};
|
|
18
27
|
}
|
|
19
28
|
exports.RpgModule = RpgModule;
|
|
20
|
-
function loadModules(modules, obj) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
plug = [
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
if (
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
29
|
+
function loadModules(modules, obj, middleware) {
|
|
30
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
+
const { side, relations } = obj;
|
|
32
|
+
let playerProps = {};
|
|
33
|
+
for (let module of modules) {
|
|
34
|
+
if (!module)
|
|
35
|
+
continue;
|
|
36
|
+
let plug = [];
|
|
37
|
+
if (!Utils_1.isArray(module)) {
|
|
38
|
+
plug = [module];
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
plug = module;
|
|
42
|
+
}
|
|
43
|
+
const [moduleClassSides, options] = plug;
|
|
44
|
+
const moduleClass = moduleClassSides[side];
|
|
45
|
+
if (!moduleClass)
|
|
46
|
+
continue;
|
|
47
|
+
let mod;
|
|
48
|
+
if (options && side == Side.Client && options[Side.Server]) {
|
|
49
|
+
Logger_1.warning(`Data that may be sensitive (normally visible only on the server side) are made optional and visible on the client side.\nInstead, import the configuration with the server! flag into an import. Example: \n\nimport config from 'server!./config\n\n'`, options[Side.Server]);
|
|
50
|
+
}
|
|
51
|
+
if (options && !Utils_1.isClass(moduleClass) && Utils_1.isFunction(moduleClass)) {
|
|
52
|
+
mod = new (moduleClass(options[side]))();
|
|
53
|
+
}
|
|
54
|
+
else if (Utils_1.isClass(moduleClass)) {
|
|
55
|
+
mod = new moduleClass();
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
mod = moduleClass;
|
|
59
|
+
}
|
|
60
|
+
if (middleware) {
|
|
61
|
+
mod = middleware(mod);
|
|
62
|
+
if (Utils_1.isPromise(mod)) {
|
|
63
|
+
mod = yield mod;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
const { imports, maps, spritesheets, sounds, gui, scenes, engine, database, worldMaps, scalability } = mod;
|
|
67
|
+
if (imports) {
|
|
68
|
+
yield loadModules(imports, obj);
|
|
69
|
+
}
|
|
70
|
+
if (maps) {
|
|
71
|
+
Plugin_1.RpgPlugin.on(Plugin_1.HookServer.AddMap, () => maps);
|
|
72
|
+
}
|
|
73
|
+
if (worldMaps) {
|
|
74
|
+
Plugin_1.RpgPlugin.on(Plugin_1.HookServer.AddWorldMaps, () => worldMaps);
|
|
75
|
+
}
|
|
76
|
+
if (database) {
|
|
77
|
+
Plugin_1.RpgPlugin.on(Plugin_1.HookServer.AddDatabase, () => database);
|
|
78
|
+
}
|
|
79
|
+
if (spritesheets) {
|
|
80
|
+
Plugin_1.RpgPlugin.on(Plugin_1.HookClient.AddSpriteSheet, () => spritesheets);
|
|
81
|
+
}
|
|
82
|
+
if (sounds) {
|
|
83
|
+
Plugin_1.RpgPlugin.on(Plugin_1.HookClient.AddSound, () => sounds);
|
|
84
|
+
}
|
|
85
|
+
if (gui) {
|
|
86
|
+
Plugin_1.RpgPlugin.on(Plugin_1.HookClient.AddGui, () => gui);
|
|
87
|
+
}
|
|
88
|
+
const player = side == Side.Server ? mod.player : mod.sprite;
|
|
89
|
+
const loadRelations = (hook, relatioName) => {
|
|
90
|
+
if (hook) {
|
|
91
|
+
for (let method in relations[relatioName]) {
|
|
92
|
+
const hookName = relations[relatioName][method];
|
|
93
|
+
if (hook[method])
|
|
94
|
+
Plugin_1.RpgPlugin.on(hookName, hook[method]);
|
|
95
|
+
}
|
|
75
96
|
}
|
|
97
|
+
};
|
|
98
|
+
loadRelations(player, 'player');
|
|
99
|
+
if (player && player.props) {
|
|
100
|
+
playerProps = Object.assign(playerProps, player.props);
|
|
76
101
|
}
|
|
102
|
+
loadRelations(engine, 'engine');
|
|
103
|
+
if (scalability)
|
|
104
|
+
loadRelations(scalability._hooks, 'scalability');
|
|
105
|
+
if (scenes)
|
|
106
|
+
loadRelations(scenes.map, 'sceneMap');
|
|
107
|
+
}
|
|
108
|
+
return {
|
|
109
|
+
playerProps
|
|
77
110
|
};
|
|
78
|
-
|
|
79
|
-
loadRelations(engine, 'engine');
|
|
80
|
-
if (scenes)
|
|
81
|
-
loadRelations(scenes.map, 'sceneMap');
|
|
82
|
-
}
|
|
111
|
+
});
|
|
83
112
|
}
|
|
84
113
|
exports.loadModules = loadModules;
|
|
85
114
|
//# sourceMappingURL=Module.js.map
|
package/lib/Module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Module.js","sourceRoot":"","sources":["../src/Module.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Module.js","sourceRoot":"","sources":["../src/Module.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qCAA4D;AAC5D,mCAAiE;AACjE,qCAAkC;AAElC,IAAK,IAGJ;AAHD,WAAK,IAAI;IACL,yBAAiB,CAAA;IACjB,yBAAiB,CAAA;AACrB,CAAC,EAHI,IAAI,KAAJ,IAAI,QAGR;AAYD,SAAgB,SAAS,CAAI,OAAU;IACnC,OAAO,CAAC,MAAM,EAAE,EAAE;QACd,KAAK,IAAI,GAAG,IAAI,OAAO,EAAE;YACrB,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,CAAA;SACvC;IACL,CAAC,CAAA;AACL,CAAC;AAND,8BAMC;AAED,SAAsB,WAAW,CAAC,OAAO,EAAE,GAAG,EAAE,UAAqB;;QACjE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,GAAG,CAAA;QAC/B,IAAI,WAAW,GAAG,EAAE,CAAA;QACpB,KAAK,IAAI,MAAM,IAAI,OAAO,EAAE;YACxB,IAAI,CAAC,MAAM;gBAAE,SAAQ;YACrB,IAAI,IAAI,GAAQ,EAAE,CAAA;YAClB,IAAI,CAAC,eAAO,CAAC,MAAM,CAAC,EAAE;gBAClB,IAAI,GAAG,CAAC,MAAM,CAAC,CAAA;aAClB;iBACI;gBACD,IAAI,GAAG,MAAM,CAAA;aAChB;YACD,MAAM,CAAC,gBAAgB,EAAE,OAAO,CAAC,GAAG,IAAI,CAAA;YACxC,MAAM,WAAW,GAAG,gBAAgB,CAAC,IAAI,CAAC,CAAA;YAC1C,IAAI,CAAC,WAAW;gBAAE,SAAQ;YAC1B,IAAI,GAAG,CAAA;YACP,IAAI,OAAO,IAAI,IAAI,IAAI,IAAI,CAAC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aAAa,CAAC,MAAM,CAAC,GAAG,EAAE,UAAU,CAAC,CAAA;SACpD;QAED,OAAO;YACH,WAAW;SACd,CAAA;IACL,CAAC;CAAA;AA7ED,kCA6EC"}
|
package/lib/Player.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { RpgShape } from './Shape';
|
|
2
2
|
import SAT from 'sat';
|
|
3
|
-
import
|
|
3
|
+
import { TileInfo } from './Map';
|
|
4
|
+
import { RpgCommonGame } from './Game';
|
|
4
5
|
export declare type Position = {
|
|
5
6
|
x: number;
|
|
6
7
|
y: number;
|
|
@@ -16,6 +17,12 @@ export declare enum Direction {
|
|
|
16
17
|
DownLeft = 3.5,
|
|
17
18
|
UpLeft = 2.5
|
|
18
19
|
}
|
|
20
|
+
export declare const LiteralDirection: {
|
|
21
|
+
1: string;
|
|
22
|
+
2: string;
|
|
23
|
+
3: string;
|
|
24
|
+
4: string;
|
|
25
|
+
};
|
|
19
26
|
export declare enum PlayerType {
|
|
20
27
|
Player = "player",
|
|
21
28
|
Event = "event"
|
|
@@ -33,10 +40,10 @@ export declare class RpgCommonPlayer {
|
|
|
33
40
|
direction: number;
|
|
34
41
|
private collisionWith;
|
|
35
42
|
private _collisionWithTiles;
|
|
36
|
-
data: any;
|
|
37
43
|
hitbox: SAT.Box;
|
|
38
44
|
pendingMove: {
|
|
39
45
|
input: string;
|
|
46
|
+
frame: number;
|
|
40
47
|
}[];
|
|
41
48
|
/**
|
|
42
49
|
* Display/Hide the GUI attached to this sprite
|
|
@@ -57,7 +64,7 @@ export declare class RpgCommonPlayer {
|
|
|
57
64
|
RUN: number;
|
|
58
65
|
ACTION: number;
|
|
59
66
|
};
|
|
60
|
-
constructor(gameEngine:
|
|
67
|
+
constructor(gameEngine: RpgCommonGame, playerId: string);
|
|
61
68
|
get id(): string;
|
|
62
69
|
set id(str: string);
|
|
63
70
|
updateInVirtualGrid(): void;
|
|
@@ -72,10 +79,11 @@ export declare class RpgCommonPlayer {
|
|
|
72
79
|
*/
|
|
73
80
|
set position(val: Position);
|
|
74
81
|
get position(): Position;
|
|
82
|
+
get worldPositionX(): number;
|
|
83
|
+
get worldPositionY(): number;
|
|
75
84
|
set posX(val: any);
|
|
76
85
|
set posY(val: any);
|
|
77
86
|
set posZ(val: any);
|
|
78
|
-
get mapInstance(): Map;
|
|
79
87
|
/**
|
|
80
88
|
*
|
|
81
89
|
* Recovers all the colliding tiles of the current player
|
|
@@ -158,16 +166,6 @@ export declare class RpgCommonPlayer {
|
|
|
158
166
|
get wHitbox(): any;
|
|
159
167
|
get hHitbox(): any;
|
|
160
168
|
private directionToAngle;
|
|
161
|
-
defineNextPosition(direction: number, deltaTimeInt: number): Position;
|
|
162
|
-
setPosition({ x, y, tileX, tileY }: {
|
|
163
|
-
x: any;
|
|
164
|
-
y: any;
|
|
165
|
-
tileX: any;
|
|
166
|
-
tileY: any;
|
|
167
|
-
}, move?: boolean): void;
|
|
168
|
-
triggerCollisionWith(type?: number): void;
|
|
169
|
-
zCollision(other: any): boolean;
|
|
170
|
-
moveByDirection(direction: Direction, deltaTimeInt: number): boolean;
|
|
171
169
|
/**
|
|
172
170
|
* Retrieves a tile and checks if the player has a collision
|
|
173
171
|
*
|
|
@@ -211,7 +209,7 @@ export declare class RpgCommonPlayer {
|
|
|
211
209
|
* @memberof RpgSpriteLogic
|
|
212
210
|
*/
|
|
213
211
|
getTile(x: number, y: number, z?: number, hitbox?: SAT.Box): TileInfo;
|
|
214
|
-
isCollided(nextPosition: Position): boolean
|
|
212
|
+
isCollided(nextPosition: Position): Promise<boolean>;
|
|
215
213
|
/**
|
|
216
214
|
* Attach a shape to the player (and allow interaction with it)
|
|
217
215
|
*
|
|
@@ -253,8 +251,6 @@ export declare class RpgCommonPlayer {
|
|
|
253
251
|
* @memberof RpgSpriteLogic
|
|
254
252
|
*/
|
|
255
253
|
getShapes(): RpgShape[];
|
|
256
|
-
collisionWithShape(shape: RpgShape, player: RpgCommonPlayer, nextPosition?: Position): boolean;
|
|
257
|
-
move(nextPosition: Position, testCollision?: boolean): boolean;
|
|
258
254
|
/**
|
|
259
255
|
* Retrieves all shapes where the player is located
|
|
260
256
|
*
|
|
@@ -305,17 +301,11 @@ export declare class RpgCommonPlayer {
|
|
|
305
301
|
* This is the ratio between the height or width of the tile and the speed of the player.
|
|
306
302
|
*/
|
|
307
303
|
get nbPixelInTile(): any;
|
|
308
|
-
getSizeMaxShape(x?: number, y?: number): {
|
|
309
|
-
minX: number;
|
|
310
|
-
minY: number;
|
|
311
|
-
maxX: number;
|
|
312
|
-
maxY: number;
|
|
313
|
-
};
|
|
314
304
|
}
|
|
315
305
|
export interface RpgCommonPlayer {
|
|
316
306
|
readonly type: string;
|
|
317
307
|
through: boolean;
|
|
318
308
|
throughOtherPlayer: boolean;
|
|
319
|
-
|
|
309
|
+
autoChangeMap?(nextPosition: Position): Promise<boolean>;
|
|
320
310
|
execMethod(methodName: string, methodData?: any, instance?: any): any;
|
|
321
311
|
}
|