import { System, SystemNames } from ".";
import { Game } from "..";
import { Life as LifeComponent, ComponentNames } from "../components";

export class Life extends System {
  constructor() {
    super(SystemNames.Life);
  }

  public update(_dt: number, game: Game) {
    game.forEachEntityWithComponent(ComponentNames.Life, (entity) => {
      const life = entity.getComponent<LifeComponent>(ComponentNames.Life);
      if (!life.alive) {
        game.removeEntity(entity.id);
      }
    });
  }
}
