react-simple-game-engine 0.1.36 → 0.1.37
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 +7 -2
- package/lib/classes/entities/entity-sult.d.ts.map +1 -1
- package/lib/classes/entities/entity-sult.js +36 -2
- package/lib/classes/logic-component.d.ts +1 -0
- package/lib/classes/logic-component.d.ts.map +1 -1
- package/lib/classes/logic-component.js +2 -0
- package/lib/classes/scene.d.ts.map +1 -1
- package/lib/classes/scene.js +8 -12
- package/lib/classes/world-management.d.ts +8 -2
- package/lib/classes/world-management.d.ts.map +1 -1
- package/lib/classes/world-management.js +65 -30
- package/package.json +1 -1
@@ -5,13 +5,18 @@ import { WorldManagement } from "../world-management";
|
|
5
5
|
export declare abstract class EntitySult<P = any> implements Initialler<P> {
|
6
6
|
camera: Camera;
|
7
7
|
readonly tag: string;
|
8
|
-
|
8
|
+
readonly id: string;
|
9
|
+
private _layerIndex;
|
10
|
+
private _name;
|
9
11
|
private _scene;
|
10
12
|
private _worldManagement;
|
11
|
-
name: string;
|
12
13
|
constructor();
|
13
14
|
abstract update(): void;
|
14
15
|
abstract draw(): void;
|
16
|
+
get layerIndex(): number;
|
17
|
+
get name(): string;
|
18
|
+
set layerIndex(_layerIndex: number);
|
19
|
+
set name(_name: string);
|
15
20
|
get scene(): Scene<any>;
|
16
21
|
get worldManagement(): WorldManagement;
|
17
22
|
getProperty<T>(name: string): T;
|
@@ -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,MAAM,EAAE,MAAM,WAAW,CAAC;AACnC,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AACjC,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAEtD,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1,9 +1,43 @@
|
|
1
1
|
var EntitySult = /** @class */ (function () {
|
2
2
|
function EntitySult() {
|
3
3
|
this.id = "".concat(Math.random(), "-").concat(new Date().getTime());
|
4
|
-
this.
|
4
|
+
this._layerIndex = 0;
|
5
|
+
this._name = this.id;
|
5
6
|
this.tag = this.constructor.tag;
|
6
7
|
}
|
8
|
+
Object.defineProperty(EntitySult.prototype, "layerIndex", {
|
9
|
+
get: function () {
|
10
|
+
return this._layerIndex;
|
11
|
+
},
|
12
|
+
set: function (_layerIndex) {
|
13
|
+
if (this._layerIndex !== _layerIndex) {
|
14
|
+
this.worldManagement.changeEntityLayerIndex(this, _layerIndex);
|
15
|
+
}
|
16
|
+
this._layerIndex = _layerIndex;
|
17
|
+
},
|
18
|
+
enumerable: false,
|
19
|
+
configurable: true
|
20
|
+
});
|
21
|
+
Object.defineProperty(EntitySult.prototype, "name", {
|
22
|
+
get: function () {
|
23
|
+
return this._name;
|
24
|
+
},
|
25
|
+
set: function (_name) {
|
26
|
+
var _a;
|
27
|
+
var isDuplicated = (_a = this.worldManagement) === null || _a === void 0 ? void 0 : _a.getEntity(_name);
|
28
|
+
if (isDuplicated) {
|
29
|
+
console.warn("Name ".concat(_name, " is already in use"));
|
30
|
+
}
|
31
|
+
else {
|
32
|
+
if (this._name !== _name) {
|
33
|
+
this.worldManagement.changeEntityName(this, _name);
|
34
|
+
}
|
35
|
+
this._name = _name;
|
36
|
+
}
|
37
|
+
},
|
38
|
+
enumerable: false,
|
39
|
+
configurable: true
|
40
|
+
});
|
7
41
|
Object.defineProperty(EntitySult.prototype, "scene", {
|
8
42
|
get: function () {
|
9
43
|
return this._scene;
|
@@ -32,7 +66,7 @@ var EntitySult = /** @class */ (function () {
|
|
32
66
|
this._scene = worldManagement.scene;
|
33
67
|
this.camera = worldManagement.camera;
|
34
68
|
}
|
35
|
-
console.log("Active ".concat(this.tag, " entity (name : ").concat(this.
|
69
|
+
console.log("Active ".concat(this.tag, " entity (name : ").concat(this._name, ")"));
|
36
70
|
this.onActive();
|
37
71
|
};
|
38
72
|
EntitySult.prototype.onActive = function () { };
|
@@ -5,6 +5,7 @@ export declare class LogicComponent<C extends Initialler = Initialler> {
|
|
5
5
|
private readonly configale;
|
6
6
|
private readonly _isPrefab?;
|
7
7
|
private _worldManagement;
|
8
|
+
layerIndex: number;
|
8
9
|
constructor(configale: Configable<C>, _isPrefab?: boolean | undefined);
|
9
10
|
get isPrefab(): boolean | undefined;
|
10
11
|
set worldManagement(_worldManagement: WorldManagement);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"logic-component.d.ts","sourceRoot":"","sources":["../../src/classes/logic-component.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;
|
1
|
+
{"version":3,"file":"logic-component.d.ts","sourceRoot":"","sources":["../../src/classes/logic-component.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAI1D,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAErD,qBAAa,cAAc,CAAC,CAAC,SAAS,UAAU,GAAG,UAAU;IAIzD,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC;IAJ7B,OAAO,CAAC,gBAAgB,CAAmB;IAC3C,UAAU,EAAE,MAAM,CAAK;gBAEJ,SAAS,EAAE,UAAU,CAAC,CAAC,CAAC,EACxB,SAAS,CAAC,qBAAS;IAGtC,IAAI,QAAQ,wBAEX;IAED,IAAI,eAAe,CAAC,gBAAgB,EAAE,eAAe,EAMpD;IAED,MAAM,CAAC,EACL,eAAe,EACf,GAAG,YAAY,EAChB,GAAE;QACD,eAAe,CAAC,EAAE,eAAe,CAAC;KACnC,GAAG,WAAW,CAAC,CAAC,CAAM;CA6CxB"}
|
@@ -26,6 +26,7 @@ var LogicComponent = /** @class */ (function () {
|
|
26
26
|
function LogicComponent(configale, _isPrefab) {
|
27
27
|
this.configale = configale;
|
28
28
|
this._isPrefab = _isPrefab;
|
29
|
+
this.layerIndex = 0;
|
29
30
|
}
|
30
31
|
Object.defineProperty(LogicComponent.prototype, "isPrefab", {
|
31
32
|
get: function () {
|
@@ -58,6 +59,7 @@ var LogicComponent = /** @class */ (function () {
|
|
58
59
|
this.worldManagement = worldManagement;
|
59
60
|
}
|
60
61
|
if (c instanceof EntitySult) {
|
62
|
+
c["_layerIndex"] = this.layerIndex; // use _layerIndex to not trigger change index process at this step
|
61
63
|
c.preInitial(this._worldManagement);
|
62
64
|
}
|
63
65
|
if (c instanceof Entity) {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"scene.d.ts","sourceRoot":"","sources":["../../src/classes/scene.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAEtC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAErD,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;
|
1
|
+
{"version":3,"file":"scene.d.ts","sourceRoot":"","sources":["../../src/classes/scene.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAEtC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAErD,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAIlC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,CAAC,CAAC,CAAC;KACjC,GAAG,MAAM,CAAC,CAAC,CAAC;IAIb,SAAS,CAAC,MAAM,EAAE,MAAM;IAgBxB,SAAS,CAAC,MAAM;IAChB,SAAS,CAAC,QAAQ;IAElB,MAAM;CAUP"}
|
package/lib/classes/scene.js
CHANGED
@@ -139,21 +139,17 @@ var Scene = /** @class */ (function () {
|
|
139
139
|
return this.prefabs.find(function (pf) { return pf instanceof Class; });
|
140
140
|
};
|
141
141
|
Scene.prototype.bootstrap = function (camera) {
|
142
|
-
var _this = this;
|
143
142
|
this.worldManagement = new WorldManagement(camera, this);
|
144
|
-
var components = this.getComponents(camera)
|
145
|
-
|
146
|
-
comp.worldManagement = _this.worldManagement;
|
147
|
-
_this.prefabs.push(comp);
|
148
|
-
return false;
|
149
|
-
}
|
150
|
-
return true;
|
151
|
-
});
|
143
|
+
var components = this.getComponents(camera);
|
144
|
+
var layerIndex = 0;
|
152
145
|
for (var _i = 0, components_1 = components; _i < components_1.length; _i++) {
|
153
146
|
var component = components_1[_i];
|
154
|
-
|
155
|
-
|
156
|
-
|
147
|
+
component.worldManagement = this.worldManagement;
|
148
|
+
component.layerIndex = layerIndex++;
|
149
|
+
if (component.isPrefab) {
|
150
|
+
this.prefabs.push(component);
|
151
|
+
}
|
152
|
+
var entity = component.output();
|
157
153
|
this.worldManagement.addEntity(entity);
|
158
154
|
}
|
159
155
|
};
|
@@ -5,14 +5,20 @@ import { EntitySult } from "./entities/entity-sult";
|
|
5
5
|
export declare class WorldManagement {
|
6
6
|
private _camera;
|
7
7
|
private _scene;
|
8
|
-
private
|
8
|
+
private readonly entitiesHash;
|
9
|
+
private readonly entitiesPool;
|
10
|
+
private readonly entitiesName;
|
9
11
|
private _engine;
|
10
12
|
constructor(_camera: Camera, _scene: Scene);
|
11
|
-
get entities(): EntitySult<any>[];
|
12
13
|
get engine(): Engine;
|
13
14
|
get camera(): Camera;
|
14
15
|
get scene(): Scene<any>;
|
16
|
+
private iterateEntities;
|
17
|
+
private joinPool;
|
18
|
+
private outPool;
|
15
19
|
destructor(): void;
|
20
|
+
changeEntityLayerIndex(entity: EntitySult, newIndex: number): void;
|
21
|
+
changeEntityName(entity: EntitySult, newName: string): void;
|
16
22
|
getEntity<T extends EntitySult = EntitySult>(name: string): T;
|
17
23
|
addEntity(entity: EntitySult): void;
|
18
24
|
removeEntity(entity: EntitySult): void;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"world-management.d.ts","sourceRoot":"","sources":["../../src/classes/world-management.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAuB,MAAM,WAAW,CAAC;AAIxD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAGhC,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEpD,qBAAa,eAAe;
|
1
|
+
{"version":3,"file":"world-management.d.ts","sourceRoot":"","sources":["../../src/classes/world-management.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAuB,MAAM,WAAW,CAAC;AAIxD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAGhC,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEpD,qBAAa,eAAe;IAWd,OAAO,CAAC,OAAO;IAAU,OAAO,CAAC,MAAM;IAVnD,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAkC;IAC/D,OAAO,CAAC,QAAQ,CAAC,YAAY,CAGtB;IACP,OAAO,CAAC,QAAQ,CAAC,YAAY,CACxB;IAEL,OAAO,CAAC,OAAO,CAAU;gBAEL,OAAO,EAAE,MAAM,EAAU,MAAM,EAAE,KAAK;IAgD1D,IAAI,MAAM,WAET;IAED,IAAI,MAAM,WAET;IAED,IAAI,KAAK,eAER;IAED,OAAO,CAAC,eAAe;IAuBvB,OAAO,CAAC,QAAQ;IAKhB,OAAO,CAAC,OAAO;IAWf,UAAU;IAKV,sBAAsB,CAAC,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM;IAK3D,gBAAgB,CAAC,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM;IAKpD,SAAS,CAAC,CAAC,SAAS,UAAU,GAAG,UAAU,EAAE,IAAI,EAAE,MAAM,GAAG,CAAC;IAK7D,SAAS,CAAC,MAAM,EAAE,UAAU;IAW5B,YAAY,CAAC,MAAM,EAAE,UAAU;IAY/B,MAAM;IAON,IAAI;CAKL"}
|
@@ -5,19 +5,20 @@ var WorldManagement = /** @class */ (function () {
|
|
5
5
|
var _this = this;
|
6
6
|
this._camera = _camera;
|
7
7
|
this._scene = _scene;
|
8
|
-
this.
|
8
|
+
this.entitiesHash = {};
|
9
|
+
this.entitiesPool = {};
|
10
|
+
this.entitiesName = {};
|
9
11
|
this._engine = Engine.create();
|
10
12
|
Events.on(this.engine, "beforeUpdate", function () {
|
11
13
|
var gravity = _this.engine.gravity;
|
12
|
-
|
13
|
-
var entity = _a[_i];
|
14
|
+
_this.iterateEntities(function (entity) {
|
14
15
|
if (entity instanceof Entity && !entity.enabledGravity) {
|
15
16
|
Body.applyForce(entity.body, entity.position, {
|
16
17
|
x: -gravity.x * gravity.scale * entity.body.mass,
|
17
18
|
y: -gravity.y * gravity.scale * entity.body.mass,
|
18
19
|
});
|
19
20
|
}
|
20
|
-
}
|
21
|
+
});
|
21
22
|
});
|
22
23
|
Events.on(this.engine, "collisionStart", function (event) {
|
23
24
|
var pairs = event.pairs;
|
@@ -47,13 +48,6 @@ var WorldManagement = /** @class */ (function () {
|
|
47
48
|
}
|
48
49
|
});
|
49
50
|
}
|
50
|
-
Object.defineProperty(WorldManagement.prototype, "entities", {
|
51
|
-
get: function () {
|
52
|
-
return this._entities;
|
53
|
-
},
|
54
|
-
enumerable: false,
|
55
|
-
configurable: true
|
56
|
-
});
|
57
51
|
Object.defineProperty(WorldManagement.prototype, "engine", {
|
58
52
|
get: function () {
|
59
53
|
return this._engine;
|
@@ -75,47 +69,88 @@ var WorldManagement = /** @class */ (function () {
|
|
75
69
|
enumerable: false,
|
76
70
|
configurable: true
|
77
71
|
});
|
72
|
+
WorldManagement.prototype.iterateEntities = function (action) {
|
73
|
+
var _a = this, entitiesPool = _a.entitiesPool, entitiesHash = _a.entitiesHash;
|
74
|
+
var indexes = Object.keys(this.entitiesPool).map(function (idx) { return +idx; });
|
75
|
+
indexes.sort();
|
76
|
+
for (var _i = 0, indexes_1 = indexes; _i < indexes_1.length; _i++) {
|
77
|
+
var index = indexes_1[_i];
|
78
|
+
var entitiesId = entitiesPool[index];
|
79
|
+
var isBreak = false;
|
80
|
+
for (var _b = 0, entitiesId_1 = entitiesId; _b < entitiesId_1.length; _b++) {
|
81
|
+
var id = entitiesId_1[_b];
|
82
|
+
var entity = entitiesHash[id];
|
83
|
+
isBreak = action(entity);
|
84
|
+
if (isBreak) {
|
85
|
+
break;
|
86
|
+
}
|
87
|
+
}
|
88
|
+
if (isBreak) {
|
89
|
+
break;
|
90
|
+
}
|
91
|
+
}
|
92
|
+
};
|
93
|
+
WorldManagement.prototype.joinPool = function (index, entity) {
|
94
|
+
this.entitiesPool[index] = this.entitiesPool[index] || [];
|
95
|
+
this.entitiesPool[index].push(entity.id);
|
96
|
+
};
|
97
|
+
WorldManagement.prototype.outPool = function (entity) {
|
98
|
+
var pool = this.entitiesPool[entity.layerIndex];
|
99
|
+
if (!pool) {
|
100
|
+
return;
|
101
|
+
}
|
102
|
+
var delIndex = pool.indexOf(entity.id);
|
103
|
+
if (delIndex > -1) {
|
104
|
+
pool.splice(delIndex, 1);
|
105
|
+
}
|
106
|
+
};
|
78
107
|
WorldManagement.prototype.destructor = function () {
|
79
108
|
World.clear(this.engine.world, false);
|
80
109
|
Engine.clear(this.engine);
|
81
110
|
};
|
111
|
+
WorldManagement.prototype.changeEntityLayerIndex = function (entity, newIndex) {
|
112
|
+
this.outPool(entity);
|
113
|
+
this.joinPool(newIndex, entity);
|
114
|
+
};
|
115
|
+
WorldManagement.prototype.changeEntityName = function (entity, newName) {
|
116
|
+
delete this.entitiesName[entity.name];
|
117
|
+
this.entitiesName[newName] = entity.id;
|
118
|
+
};
|
82
119
|
WorldManagement.prototype.getEntity = function (name) {
|
83
|
-
|
84
|
-
return this.
|
120
|
+
var id = this.entitiesName[name];
|
121
|
+
return this.entitiesHash[id];
|
85
122
|
};
|
86
123
|
WorldManagement.prototype.addEntity = function (entity) {
|
87
|
-
|
88
|
-
this.
|
124
|
+
this.joinPool(entity.layerIndex, entity);
|
125
|
+
this.entitiesHash[entity.id] = entity;
|
126
|
+
this.entitiesName[entity.name] = entity.id;
|
89
127
|
if (entity instanceof Entity) {
|
90
128
|
World.add(this.engine.world, entity.body);
|
91
129
|
}
|
92
130
|
entity.active(this);
|
93
131
|
};
|
94
132
|
WorldManagement.prototype.removeEntity = function (entity) {
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
var child = _a[_i];
|
101
|
-
this.removeEntity(child);
|
102
|
-
}
|
133
|
+
if (entity instanceof Entity) {
|
134
|
+
World.remove(this.engine.world, entity.body);
|
135
|
+
for (var _i = 0, _a = entity.children; _i < _a.length; _i++) {
|
136
|
+
var child = _a[_i];
|
137
|
+
this.removeEntity(child);
|
103
138
|
}
|
104
|
-
this.entities.splice(this.entities.indexOf(entity), 1);
|
105
139
|
}
|
140
|
+
delete this.entitiesName[entity.name];
|
141
|
+
delete this.entitiesHash[entity.id];
|
142
|
+
this.outPool(entity);
|
106
143
|
};
|
107
144
|
WorldManagement.prototype.update = function () {
|
108
145
|
Engine.update(this.engine);
|
109
|
-
|
110
|
-
var entity = _a[_i];
|
146
|
+
this.iterateEntities(function (entity) {
|
111
147
|
entity.update();
|
112
|
-
}
|
148
|
+
});
|
113
149
|
};
|
114
150
|
WorldManagement.prototype.draw = function () {
|
115
|
-
|
116
|
-
var entity = _a[_i];
|
151
|
+
this.iterateEntities(function (entity) {
|
117
152
|
entity.draw();
|
118
|
-
}
|
153
|
+
});
|
119
154
|
};
|
120
155
|
return WorldManagement;
|
121
156
|
}());
|