From 917465a35fcc38878ad1c7196209b0ccd3db0c21 Mon Sep 17 00:00:00 2001 From: cha0s Date: Mon, 5 Aug 2024 03:06:31 -0500 Subject: [PATCH] refactor: consolidate --- app/react/components/pixi/entities.jsx | 3 +-- app/react/components/pixi/entity.js | 16 +++++++--------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/app/react/components/pixi/entities.jsx b/app/react/components/pixi/entities.jsx index 3705ad9..a752d38 100644 --- a/app/react/components/pixi/entities.jsx +++ b/app/react/components/pixi/entities.jsx @@ -48,8 +48,7 @@ export default function Entities({monopolizers, particleWorker}) { entities.current[id].setMainEntity(); } } - entities.current[id].update(payload[id]); - entities.current[id].addToContainer(containerRef.current); + entities.current[id].update(payload[id], containerRef.current); } }, [debug, ecs, mainEntity]) useEffect(() => { diff --git a/app/react/components/pixi/entity.js b/app/react/components/pixi/entity.js index 85b9ff8..a9e1049 100644 --- a/app/react/components/pixi/entity.js +++ b/app/react/components/pixi/entity.js @@ -28,14 +28,6 @@ export default class Entity { this.debug.addChild(this.colliderAabb); this.debug.addChild(this.visibleAabb); } - addToContainer(container) { - if (this.attached || !container) { - return; - } - container.addChild(this.container); - container.addChild(this.debug); - this.attached = true; - } static async loadAsset(source = '') { if (!this.assets['']) { const {Texture} = await import('@pixi/core'); @@ -98,7 +90,7 @@ export default class Entity { } return texture; } - update({Direction, Light, Position, Sprite, VisibleAabb}) { + update({Direction, Light, Position, Sprite, VisibleAabb}, container) { if (Light) { if (!this.light) { this.light = new PointLight( @@ -190,5 +182,11 @@ export default class Entity { if (this.isMainEntity) { this.interactionAabb.redraw(this.entity.Interacts.aabb()); } + if (this.attached || !container) { + return; + } + container.addChild(this.container); + container.addChild(this.debug); + this.attached = true; } }