package ecs.systems;

import ecs.components.Death;
import ecs.components.EntityContainer;
import ecs.components.Spatial;
import ecs.core.Entity;
import ecs.core.System;
import entities.ExplosionEntity;

class DeathSystem extends System {
	public function new() {
		super(Death);
	}

	override function updateEntity(entity:Entity, dt:Float) {
		engine.remove(entity);

		final death = entity.get(Death);

		final entityContainer = entity.get(EntityContainer);

		if (entityContainer != null)
			engine.add(entityContainer.entity);

		switch (death.type) {
			case EXPLOSION:
				final spatial = entity.get(Spatial);
				if (spatial != null)
					engine.add(new ExplosionEntity(spatial.x, spatial.y));
		}
	}
}
