refactor: consolidate

This commit is contained in:
cha0s 2024-08-05 03:06:31 -05:00
parent 14add7e8bb
commit 917465a35f
2 changed files with 8 additions and 11 deletions

View File

@ -48,8 +48,7 @@ export default function Entities({monopolizers, particleWorker}) {
entities.current[id].setMainEntity(); entities.current[id].setMainEntity();
} }
} }
entities.current[id].update(payload[id]); entities.current[id].update(payload[id], containerRef.current);
entities.current[id].addToContainer(containerRef.current);
} }
}, [debug, ecs, mainEntity]) }, [debug, ecs, mainEntity])
useEffect(() => { useEffect(() => {

View File

@ -28,14 +28,6 @@ export default class Entity {
this.debug.addChild(this.colliderAabb); this.debug.addChild(this.colliderAabb);
this.debug.addChild(this.visibleAabb); 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 = '') { static async loadAsset(source = '') {
if (!this.assets['']) { if (!this.assets['']) {
const {Texture} = await import('@pixi/core'); const {Texture} = await import('@pixi/core');
@ -98,7 +90,7 @@ export default class Entity {
} }
return texture; return texture;
} }
update({Direction, Light, Position, Sprite, VisibleAabb}) { update({Direction, Light, Position, Sprite, VisibleAabb}, container) {
if (Light) { if (Light) {
if (!this.light) { if (!this.light) {
this.light = new PointLight( this.light = new PointLight(
@ -190,5 +182,11 @@ export default class Entity {
if (this.isMainEntity) { if (this.isMainEntity) {
this.interactionAabb.redraw(this.entity.Interacts.aabb()); this.interactionAabb.redraw(this.entity.Interacts.aabb());
} }
if (this.attached || !container) {
return;
}
container.addChild(this.container);
container.addChild(this.debug);
this.attached = true;
} }
} }