import { Component, ComponentNames } from ".";
import { Entity } from "../entities";
import { Direction } from "../interfaces";

export class GridSpawn extends Component {
  public direction: Direction;
  public spawnsLeft: number;
  public spawner: () => Entity;

  constructor(
    spawnsLeft: number,
    spawner: () => Entity,
    direction = Direction.NONE
  ) {
    super(ComponentNames.GridSpawn);

    this.spawnsLeft = spawnsLeft;
    this.direction = direction;
    this.spawner = spawner;
  }

  public spawnEntity(direction: Direction): Entity | undefined {
    if (this.spawnsLeft === 0) {
      return;
    }

    this.direction = direction;
    this.spawnsLeft -= 1;
  }
}
