feat: clone
This commit is contained in:
parent
e31beefec8
commit
3af4b8ac99
|
@ -9,6 +9,8 @@ export default class Ecs {
|
||||||
|
|
||||||
Bundles = {};
|
Bundles = {};
|
||||||
|
|
||||||
|
$$ComponentLikesAndOrBundleLikes;
|
||||||
|
|
||||||
Components = {};
|
Components = {};
|
||||||
|
|
||||||
dirty = new Set();
|
dirty = new Set();
|
||||||
|
@ -20,6 +22,7 @@ export default class Ecs {
|
||||||
$$systems = [];
|
$$systems = [];
|
||||||
|
|
||||||
constructor(ComponentLikesAndOrBundleLikes) {
|
constructor(ComponentLikesAndOrBundleLikes) {
|
||||||
|
this.$$ComponentLikesAndOrBundleLikes = ComponentLikesAndOrBundleLikes;
|
||||||
const Bundles = [];
|
const Bundles = [];
|
||||||
for (const i in ComponentLikesAndOrBundleLikes) {
|
for (const i in ComponentLikesAndOrBundleLikes) {
|
||||||
const MaybeBundle = Bundle.maybeNormalize(ComponentLikesAndOrBundleLikes[i]);
|
const MaybeBundle = Bundle.maybeNormalize(ComponentLikesAndOrBundleLikes[i]);
|
||||||
|
@ -81,6 +84,14 @@ export default class Ecs {
|
||||||
this.$$systems.push(wrappedSystem);
|
this.$$systems.push(wrappedSystem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
clone() {
|
||||||
|
const view = new DataView(new ArrayBuffer(this.sizeOf(this.entities, true)));
|
||||||
|
this.encode(this.entities, view);
|
||||||
|
const ecs = new this.constructor(this.$$ComponentLikesAndOrBundleLikes);
|
||||||
|
ecs.decode(view);
|
||||||
|
return ecs;
|
||||||
|
}
|
||||||
|
|
||||||
create(components = {}) {
|
create(components = {}) {
|
||||||
const [entity] = this.createMany([components]);
|
const [entity] = this.createMany([components]);
|
||||||
return entity;
|
return entity;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user