From 3af4b8ac99ad19c410849b57e77ac0b8b05e767b Mon Sep 17 00:00:00 2001 From: cha0s Date: Sat, 3 Dec 2022 14:40:03 -0600 Subject: [PATCH] feat: clone --- packages/ecs/src/ecs.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/packages/ecs/src/ecs.js b/packages/ecs/src/ecs.js index 1e06cda..a7ab205 100644 --- a/packages/ecs/src/ecs.js +++ b/packages/ecs/src/ecs.js @@ -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;