#include "component_action_on_out_of_bounds_delete.h"

/* DEPENDENCIES: Physics, ActionOnDeleteDropGoodies */

/* Sets action_on_out_of_bounds_delete component info. */
void
component_action_on_out_of_bounds_delete_init(ComponentActionOnOutOfBoundsDelete* self, Rectangle rectangle)
{
	self->rectangle = rectangle;
}

/* Ticks action_on_out_of_bounds_delete component. */
void
component_action_on_out_of_bounds_delete_tick(ComponentActionOnOutOfBoundsDelete* self, ECS* ecs)
{
	ComponentPhysics* physics;
	Rectangle physicsRectangle;

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

	component_physics_rectangle_get(physics, &physicsRectangle);

	if (!rectangle_collide(&self->rectangle, &physicsRectangle))
	{
		ComponentActionOnDeleteDropGoodies* actionOnDeleteDropGoodies;

		actionOnDeleteDropGoodies = ecs_component_get(ecs, ECS_COMPONENT_ACTION_ON_DELETE_DROP_GOODIES, self->component.id);

		if (actionOnDeleteDropGoodies)
			actionOnDeleteDropGoodies->component.isDisabled = true;

		ecs_entity_delete(ecs, self->component.id);
	}
}
