package ecs.systems;

import ecs.components.*;
import ecs.core.Entity;
import ecs.core.System;
import res.collisions.Collider;

class CollisionSystem extends System {
	public function new() {
		super(CollisionCircle, CollisionResult, Spatial);
	}

	override function updateEntity(entity:Entity, dt:Float) {
		final spatial = entity.get(Spatial);
		final collision = entity.get(CollisionCircle);
		final collisionResult = entity.get(CollisionResult);

		collisionResult.collisions.resize(0);

		for (versus in entities) {
			if (versus != entity) {
				final vsSpatial = versus.get(Spatial);
				final vsCollision = versus.get(CollisionCircle);

				final result = Collider.collide(CIRCLE(spatial.x, spatial.y, collision.radius), CIRCLE(vsSpatial.x, vsSpatial.y, vsCollision.radius));

				if (result != NONE) {
					collisionResult.collisions.push({
						result: result,
						entity: versus
					});
				}
			}
		}
	}
}
