feat: clone

This commit is contained in:
cha0s 2022-12-03 14:40:03 -06:00
parent e31beefec8
commit 3af4b8ac99

View File

@ -9,6 +9,8 @@ export default class Ecs {
Bundles = {};
$$ComponentLikesAndOrBundleLikes;
Components = {};
dirty = new Set();
@ -20,6 +22,7 @@ export default class Ecs {
$$systems = [];
constructor(ComponentLikesAndOrBundleLikes) {
this.$$ComponentLikesAndOrBundleLikes = ComponentLikesAndOrBundleLikes;
const Bundles = [];
for (const i in ComponentLikesAndOrBundleLikes) {
const MaybeBundle = Bundle.maybeNormalize(ComponentLikesAndOrBundleLikes[i]);
@ -81,6 +84,14 @@ export default class Ecs {
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 = {}) {
const [entity] = this.createMany([components]);
return entity;