react-simple-game-engine 0.0.43 → 0.0.46
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/classes/entities/entity-sult.d.ts +12 -1
- package/lib/classes/entities/entity-sult.d.ts.map +1 -1
- package/lib/classes/entities/entity-sult.js +24 -0
- package/lib/classes/entities/entity.d.ts +5 -10
- package/lib/classes/entities/entity.d.ts.map +1 -1
- package/lib/classes/entities/entity.js +19 -8
- package/lib/classes/particle-system.d.ts +1 -4
- package/lib/classes/particle-system.d.ts.map +1 -1
- package/lib/classes/particle-system.js +0 -3
- package/lib/classes/scene.js +2 -2
- package/lib/classes/world-management.d.ts +7 -1
- package/lib/classes/world-management.d.ts.map +1 -1
- package/lib/classes/world-management.js +28 -4
- package/package.json +1 -1
@@ -1,9 +1,20 @@
|
|
1
1
|
import { Initialler } from "../../export-interfaces";
|
2
|
+
import { Camera } from "../camera";
|
3
|
+
import { Scene } from "../scene";
|
2
4
|
import { WorldManagement } from "../world-management";
|
3
5
|
export declare abstract class EntitySult<P = any> implements Initialler<P> {
|
6
|
+
camera: Camera;
|
7
|
+
private readonly id;
|
8
|
+
readonly tag: string;
|
9
|
+
private _scene;
|
10
|
+
private _worldManagement;
|
11
|
+
constructor();
|
4
12
|
abstract update(): void;
|
5
13
|
abstract draw(): void;
|
6
|
-
|
14
|
+
get scene(): Scene<any>;
|
15
|
+
get worldManagement(): WorldManagement;
|
16
|
+
active(worldManagement: WorldManagement): void;
|
17
|
+
onActive(): void;
|
7
18
|
initial(params: P): void;
|
8
19
|
}
|
9
20
|
//# sourceMappingURL=entity-sult.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"entity-sult.d.ts","sourceRoot":"","sources":["../../../src/classes/entities/entity-sult.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAEtD,8BAAsB,UAAU,CAAC,CAAC,GAAG,GAAG,CAAE,YAAW,UAAU,CAAC,CAAC,CAAC;
|
1
|
+
{"version":3,"file":"entity-sult.d.ts","sourceRoot":"","sources":["../../../src/classes/entities/entity-sult.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACnC,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AACjC,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAEtD,8BAAsB,UAAU,CAAC,CAAC,GAAG,GAAG,CAAE,YAAW,UAAU,CAAC,CAAC,CAAC;IACzD,MAAM,EAAG,MAAM,CAAC;IACvB,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAsD;IACzE,SAAgB,GAAG,EAAG,MAAM,CAAC;IAE7B,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,gBAAgB,CAAmB;;IAM3C,QAAQ,CAAC,MAAM,IAAI,IAAI;IACvB,QAAQ,CAAC,IAAI,IAAI,IAAI;IAErB,IAAI,KAAK,eAER;IAED,IAAI,eAAe,oBAElB;IAED,MAAM,CAAC,eAAe,EAAE,eAAe;IAQvC,QAAQ;IACR,OAAO,CAAC,MAAM,EAAE,CAAC;CAClB"}
|
@@ -1,6 +1,30 @@
|
|
1
1
|
var EntitySult = /** @class */ (function () {
|
2
2
|
function EntitySult() {
|
3
|
+
this.id = "".concat(Math.random(), "-").concat(new Date().getTime());
|
4
|
+
this.tag = this.constructor.tag;
|
3
5
|
}
|
6
|
+
Object.defineProperty(EntitySult.prototype, "scene", {
|
7
|
+
get: function () {
|
8
|
+
return this._scene;
|
9
|
+
},
|
10
|
+
enumerable: false,
|
11
|
+
configurable: true
|
12
|
+
});
|
13
|
+
Object.defineProperty(EntitySult.prototype, "worldManagement", {
|
14
|
+
get: function () {
|
15
|
+
return this._worldManagement;
|
16
|
+
},
|
17
|
+
enumerable: false,
|
18
|
+
configurable: true
|
19
|
+
});
|
20
|
+
EntitySult.prototype.active = function (worldManagement) {
|
21
|
+
console.log("Initted ".concat(this.tag, " entity (id : ").concat(this.id, ")"));
|
22
|
+
this._worldManagement = worldManagement;
|
23
|
+
this._scene = this.scene;
|
24
|
+
this.camera = worldManagement.camera;
|
25
|
+
this.onActive();
|
26
|
+
};
|
27
|
+
EntitySult.prototype.onActive = function () { };
|
4
28
|
EntitySult.prototype.initial = function (params) { };
|
5
29
|
return EntitySult;
|
6
30
|
}());
|
@@ -1,24 +1,19 @@
|
|
1
1
|
import Matter from "matter-js";
|
2
|
-
import { Camera } from "../camera";
|
3
|
-
import { WorldManagement } from "../world-management";
|
4
2
|
import { Sprite } from "../sprites/sprite";
|
5
3
|
import { CreateBodyDefine, EntityInitial, EntityPrepare, MasterBody, Sound } from "../../export-types";
|
6
4
|
import { EntitySult } from "./entity-sult";
|
7
5
|
export declare abstract class Entity<SpriteType extends Sprite<any> = any> extends EntitySult<EntityInitial<Entity>> {
|
8
6
|
private _body;
|
9
7
|
private _sprite;
|
10
|
-
private
|
11
|
-
|
12
|
-
camera: Camera;
|
13
|
-
protected worldManagement: WorldManagement;
|
14
|
-
protected sound?: Sound;
|
15
|
-
constructor();
|
8
|
+
private _children;
|
9
|
+
sound?: Sound;
|
16
10
|
set sprite(sprite: SpriteType);
|
17
11
|
get sprite(): SpriteType;
|
18
12
|
get position(): Matter.Vector;
|
19
13
|
get body(): MasterBody;
|
20
|
-
|
21
|
-
|
14
|
+
get children(): EntitySult<any>[];
|
15
|
+
addChild(entity: EntitySult): void;
|
16
|
+
removeChild(entity: EntitySult): void;
|
22
17
|
createBody(transform: CreateBodyDefine["transform"], options?: CreateBodyDefine["bodyOptions"]): MasterBody;
|
23
18
|
protected abstract onCreateBody(transform: CreateBodyDefine["transform"] | undefined, options?: CreateBodyDefine["bodyOptions"]): Matter.Body;
|
24
19
|
initial({ sound, transform, sprite: spriteComponent, bodyOptions, }: EntityInitial<this>): void;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"entity.d.ts","sourceRoot":"","sources":["../../../src/classes/entities/entity.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,WAAW,CAAC;AAE/B,OAAO,EAAE,MAAM,EAAE,MAAM,
|
1
|
+
{"version":3,"file":"entity.d.ts","sourceRoot":"","sources":["../../../src/classes/entities/entity.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,WAAW,CAAC;AAE/B,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAG3C,OAAO,EACL,gBAAgB,EAChB,aAAa,EACb,aAAa,EACb,UAAU,EACV,KAAK,EACN,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,8BAAsB,MAAM,CAC1B,UAAU,SAAS,MAAM,CAAC,GAAG,CAAC,GAAG,GAAG,CACpC,SAAQ,UAAU,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;IACzC,OAAO,CAAC,KAAK,CAAc;IAC3B,OAAO,CAAC,OAAO,CAAc;IAC7B,OAAO,CAAC,SAAS,CAAoB;IAE9B,KAAK,CAAC,EAAE,KAAK,CAAC;IAErB,IAAI,MAAM,CAAC,MAAM,EAAE,UAAU,EAG5B;IAED,IAAI,MAAM,IALS,UAAU,CAO5B;IAED,IAAI,QAAQ,kBAEX;IAED,IAAI,IAAI,eAEP;IAED,IAAI,QAAQ,sBAEX;IAED,QAAQ,CAAC,MAAM,EAAE,UAAU;IAK3B,WAAW,CAAC,MAAM,EAAE,UAAU;IAQ9B,UAAU,CACR,SAAS,EAAE,gBAAgB,CAAC,WAAW,CAAC,EACxC,OAAO,CAAC,EAAE,gBAAgB,CAAC,aAAa,CAAC;IAO3C,SAAS,CAAC,QAAQ,CAAC,YAAY,CAC7B,SAAS,EAAE,gBAAgB,CAAC,WAAW,CAAC,GAAG,SAAS,EACpD,OAAO,CAAC,EAAE,gBAAgB,CAAC,aAAa,CAAC,GACxC,MAAM,CAAC,IAAI;IAEd,OAAO,CAAC,EACN,KAAK,EACL,SAAc,EACd,MAAM,EAAE,eAAe,EACvB,WAAgB,GACjB,EAAE,aAAa,CAAC,IAAI,CAAC;IAgCtB,SAAS,CAAC,QAAQ,CAAC,SAAS,IAAI,aAAa,CAAC,IAAI,CAAC;IACnD,SAAS,CAAC,SAAS,IAAI,aAAa,CAAC,IAAI,CAAC;IAI1C,MAAM;IAGN,QAAQ;IAER,IAAI;IAIJ,QAAQ,CAAC,0BAA0B,IAAI;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE;IAExE,WAAW,CAAC,MAAM,EAAE,MAAM;IAC1B,cAAc,CAAC,MAAM,EAAE,MAAM;IAC7B,iBAAiB,CAAC,MAAM,EAAE,MAAM;CACjC"}
|
@@ -40,9 +40,8 @@ import { EntitySult } from "./entity-sult";
|
|
40
40
|
var Entity = /** @class */ (function (_super) {
|
41
41
|
__extends(Entity, _super);
|
42
42
|
function Entity() {
|
43
|
-
var _this = _super.
|
44
|
-
_this.
|
45
|
-
_this.tag = _this.constructor.tag;
|
43
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
44
|
+
_this._children = [];
|
46
45
|
return _this;
|
47
46
|
}
|
48
47
|
Object.defineProperty(Entity.prototype, "sprite", {
|
@@ -70,12 +69,24 @@ var Entity = /** @class */ (function (_super) {
|
|
70
69
|
enumerable: false,
|
71
70
|
configurable: true
|
72
71
|
});
|
73
|
-
Entity.prototype
|
74
|
-
|
75
|
-
|
76
|
-
|
72
|
+
Object.defineProperty(Entity.prototype, "children", {
|
73
|
+
get: function () {
|
74
|
+
return this._children;
|
75
|
+
},
|
76
|
+
enumerable: false,
|
77
|
+
configurable: true
|
78
|
+
});
|
79
|
+
Entity.prototype.addChild = function (entity) {
|
80
|
+
this.children.push(entity);
|
81
|
+
this.worldManagement.addEntity(entity);
|
82
|
+
};
|
83
|
+
Entity.prototype.removeChild = function (entity) {
|
84
|
+
var delIndex = this.children.indexOf(entity);
|
85
|
+
if (delIndex > -1) {
|
86
|
+
this.children.splice(delIndex, 1);
|
87
|
+
this.worldManagement.removeEntity(entity);
|
88
|
+
}
|
77
89
|
};
|
78
|
-
Entity.prototype.onActive = function () { };
|
79
90
|
Entity.prototype.createBody = function (transform, options) {
|
80
91
|
this._body = this.onCreateBody(transform, options);
|
81
92
|
this._body.entity = this;
|
@@ -1,5 +1,4 @@
|
|
1
1
|
import p5 from "p5";
|
2
|
-
import { Camera } from "./camera";
|
3
2
|
import { EntitySult } from "./entities/entity-sult";
|
4
3
|
import { Particle, ParticleInitialParams } from "./particle";
|
5
4
|
declare type ParticleClass = {
|
@@ -8,9 +7,9 @@ declare type ParticleClass = {
|
|
8
7
|
declare type ParticleOptions = Omit<ParticleInitialParams, "vec" | "angle" | "camera"> & {
|
9
8
|
x?: number;
|
10
9
|
y?: number;
|
11
|
-
particleClass?: ParticleClass;
|
12
10
|
};
|
13
11
|
declare type ParticleSystemInitialParams = {
|
12
|
+
particleClass?: ParticleClass;
|
14
13
|
particleOptions?: ParticleOptions;
|
15
14
|
quantityPerFrame?: number;
|
16
15
|
vecWeight?: number;
|
@@ -23,8 +22,6 @@ export declare class ParticleSystem extends EntitySult<ParticleSystemInitialPara
|
|
23
22
|
private particleClass;
|
24
23
|
quantityPerFrame: number;
|
25
24
|
vecWeight: number;
|
26
|
-
camera: Camera;
|
27
|
-
active(): void;
|
28
25
|
initial({ forces, particleOptions, ...params }: ParticleSystemInitialParams): void;
|
29
26
|
update(): void;
|
30
27
|
draw(): void;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"particle-system.d.ts","sourceRoot":"","sources":["../../src/classes/particle-system.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AAEpB,OAAO,EAAE,
|
1
|
+
{"version":3,"file":"particle-system.d.ts","sourceRoot":"","sources":["../../src/classes/particle-system.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AAEpB,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAE7D,aAAK,aAAa,GAAG;IACnB,KAAK,GAAG,IAAI,EAAE,qBAAqB,CAAC,OAAO,QAAQ,CAAC,GAAG,QAAQ,CAAC;CACjE,CAAC;AAEF,aAAK,eAAe,GAAG,IAAI,CACzB,qBAAqB,EACrB,KAAK,GAAG,OAAO,GAAG,QAAQ,CAC3B,GAAG;IACF,CAAC,CAAC,EAAE,MAAM,CAAC;IACX,CAAC,CAAC,EAAE,MAAM,CAAC;CACZ,CAAC;AAEF,aAAK,2BAA2B,GAAG;IACjC,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B,eAAe,CAAC,EAAE,eAAe,CAAC;IAClC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,EAAE,CAAC,MAAM,EAAE,CAAC;CACtB,CAAC;AAEF,qBAAa,cAAe,SAAQ,UAAU,CAAC,2BAA2B,CAAC;IACzE,OAAO,CAAC,SAAS,CAAkB;IACnC,OAAO,CAAC,MAAM,CAAmB;IACjC,OAAO,CAAC,eAAe,CAGrB;IACF,OAAO,CAAC,aAAa,CAA2B;IAEzC,gBAAgB,EAAE,MAAM,CAAM;IAC9B,SAAS,EAAE,MAAM,CAAK;IAE7B,OAAO,CAAC,EACN,MAAM,EACN,eAAoB,EACpB,GAAG,MAAM,EACV,EAAE,2BAA2B;IAS9B,MAAM;IAyBN,IAAI;CAKL"}
|
@@ -54,9 +54,6 @@ var ParticleSystem = /** @class */ (function (_super) {
|
|
54
54
|
_this.vecWeight = 5;
|
55
55
|
return _this;
|
56
56
|
}
|
57
|
-
ParticleSystem.prototype.active = function () {
|
58
|
-
console.log("Initted particle system", this.particles.length);
|
59
|
-
};
|
60
57
|
ParticleSystem.prototype.initial = function (_a) {
|
61
58
|
var _b;
|
62
59
|
var forces = _a.forces, _c = _a.particleOptions, particleOptions = _c === void 0 ? {} : _c, params = __rest(_a, ["forces", "particleOptions"]);
|
package/lib/classes/scene.js
CHANGED
@@ -116,11 +116,11 @@ var Scene = /** @class */ (function () {
|
|
116
116
|
}); });
|
117
117
|
};
|
118
118
|
Scene.prototype.bootstrap = function (camera) {
|
119
|
-
this.worldManagement = new WorldManagement();
|
119
|
+
this.worldManagement = new WorldManagement(camera, this);
|
120
120
|
var components = this.getComponents(camera);
|
121
121
|
for (var _i = 0, components_1 = components; _i < components_1.length; _i++) {
|
122
122
|
var component = components_1[_i];
|
123
|
-
var entity = component.output(
|
123
|
+
var entity = component.output();
|
124
124
|
this.worldManagement.addEntity(entity);
|
125
125
|
}
|
126
126
|
};
|
@@ -1,8 +1,14 @@
|
|
1
|
+
import { Camera } from "./camera";
|
1
2
|
import { EntitySult } from "./entities/entity-sult";
|
3
|
+
import { Scene } from "./scene";
|
2
4
|
export declare class WorldManagement {
|
5
|
+
private _camera;
|
6
|
+
private _scene;
|
3
7
|
private entities;
|
4
8
|
private engine;
|
5
|
-
constructor();
|
9
|
+
constructor(_camera: Camera, _scene: Scene);
|
10
|
+
get camera(): Camera;
|
11
|
+
get scene(): Scene<any>;
|
6
12
|
destructor(): void;
|
7
13
|
addEntity(entity: EntitySult): void;
|
8
14
|
removeEntity(entity: EntitySult): void;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"world-management.d.ts","sourceRoot":"","sources":["../../src/classes/world-management.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"world-management.d.ts","sourceRoot":"","sources":["../../src/classes/world-management.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC,qBAAa,eAAe;IAId,OAAO,CAAC,OAAO;IAAU,OAAO,CAAC,MAAM;IAHnD,OAAO,CAAC,QAAQ,CAAoB;IACpC,OAAO,CAAC,MAAM,CAAU;gBAEJ,OAAO,EAAE,MAAM,EAAU,MAAM,EAAE,KAAK;IAqC1D,IAAI,MAAM,WAET;IAED,IAAI,KAAK,eAER;IAED,UAAU;IAKV,SAAS,CAAC,MAAM,EAAE,UAAU;IAS5B,YAAY,CAAC,MAAM,EAAE,UAAU;IAa/B,MAAM;IAON,IAAI;CAKL"}
|
@@ -1,7 +1,9 @@
|
|
1
1
|
import { Engine, World, Events } from "matter-js";
|
2
2
|
import { Entity } from "./entities/entity";
|
3
3
|
var WorldManagement = /** @class */ (function () {
|
4
|
-
function WorldManagement() {
|
4
|
+
function WorldManagement(_camera, _scene) {
|
5
|
+
this._camera = _camera;
|
6
|
+
this._scene = _scene;
|
5
7
|
this.entities = [];
|
6
8
|
this.engine = Engine.create();
|
7
9
|
Events.on(this.engine, "collisionStart", function (event) {
|
@@ -32,11 +34,26 @@ var WorldManagement = /** @class */ (function () {
|
|
32
34
|
}
|
33
35
|
});
|
34
36
|
}
|
37
|
+
Object.defineProperty(WorldManagement.prototype, "camera", {
|
38
|
+
get: function () {
|
39
|
+
return this._camera;
|
40
|
+
},
|
41
|
+
enumerable: false,
|
42
|
+
configurable: true
|
43
|
+
});
|
44
|
+
Object.defineProperty(WorldManagement.prototype, "scene", {
|
45
|
+
get: function () {
|
46
|
+
return this._scene;
|
47
|
+
},
|
48
|
+
enumerable: false,
|
49
|
+
configurable: true
|
50
|
+
});
|
35
51
|
WorldManagement.prototype.destructor = function () {
|
36
52
|
World.clear(this.engine.world, false);
|
37
53
|
Engine.clear(this.engine);
|
38
54
|
};
|
39
55
|
WorldManagement.prototype.addEntity = function (entity) {
|
56
|
+
// temp pass modifier
|
40
57
|
this.entities.push(entity);
|
41
58
|
if (entity instanceof Entity) {
|
42
59
|
World.add(this.engine.world, entity.body);
|
@@ -44,10 +61,17 @@ var WorldManagement = /** @class */ (function () {
|
|
44
61
|
entity.active(this);
|
45
62
|
};
|
46
63
|
WorldManagement.prototype.removeEntity = function (entity) {
|
47
|
-
|
48
|
-
|
64
|
+
var delIndex = this.entities.indexOf(entity);
|
65
|
+
if (delIndex > -1) {
|
66
|
+
if (entity instanceof Entity) {
|
67
|
+
World.remove(this.engine.world, entity.body);
|
68
|
+
for (var _i = 0, _a = entity.children; _i < _a.length; _i++) {
|
69
|
+
var child = _a[_i];
|
70
|
+
this.removeEntity(child);
|
71
|
+
}
|
72
|
+
}
|
73
|
+
this.entities.splice(this.entities.indexOf(entity), 1);
|
49
74
|
}
|
50
|
-
this.entities.splice(this.entities.indexOf(entity), 1);
|
51
75
|
};
|
52
76
|
WorldManagement.prototype.update = function () {
|
53
77
|
Engine.update(this.engine);
|