import { PixiRepresentation } from "../../Components/rendering/pixiRepresentation";
import { Not, Entity, System } from "ecsy";
import { DebugRect } from "../../Components/rendering/debugRect";
import { SpriteRenderer } from "../../Components/rendering/spriteRenderer";
import globals from "../../globals";
import { DebugLine } from "../../Components/rendering/debugLine";


export class PixiCleanupSystem extends System {

  priority: 99

  // This method will get called on every frame by default
  execute(delta : number) {
    this.queries.oldRepresentations.results.forEach((entity:Entity) => {
      globals.app.stage.removeChild(entity.getComponent(PixiRepresentation).value)
      entity.removeComponent(PixiRepresentation)
      entity.remove()
    });
  }

  static queries = {
    oldRepresentations: {
      // add all draw components here as not thingy otherwise your representation will be killed
      components: [ PixiRepresentation, Not(DebugRect), Not(SpriteRenderer), Not(DebugLine)] 
    },
  }
  queries: any;
}