#include "component_action_delete_on_touch.h"

/* DEPENDENCIES: Physics */
/* This entity associated with this component will be deleted if it touches the specified entity. */

/* Initializes delete on touch component. */
void
component_action_delete_on_touch_init(ComponentActionDeleteOnTouch* self, u32 id)
{
	self->id = id;
}

/* Ticks delete on touch component. */
void
component_action_delete_on_touch_tick(ComponentActionDeleteOnTouch* self, ECS* ecs)
{
	ComponentPhysics* physics;

	physics = ecs_component_get(ecs, ECS_COMPONENT_PHYSICS, self->component.id);

	if (physics->collisions.count == 0)
		return;

	for (s32 i = 0; i < (s32)physics->collisions.count; i++)
	{
		u32 id;

		id = *(u32*)vector_get(&physics->collisions, i);

		if (id == self->id)
		{
			ecs_entity_delete(ecs, self->component.id);
			break;
		}
	}
}
