#include "component_character.h"

/* DEPENDENCIES: Sprite, Physics, Health, Allegiance */

/* Sets character component info, with an atlas. */
void
component_character_init
(
	ComponentCharacter* self,
	ECS* ecs,
	Texture texture,
	ivec2 frameSize,
	ivec2 atlasSize,
	vec2 size,
	vec2 physicsSize,
	vec3 position,
	f32 friction,
	f32 velocityMax,
	AllegianceType allegianceType,
	u32 healthValue,
	bool isBounce,
	bool isAffectedByGravity,
	bool isSolid
)
{
	ComponentGameObject* gameObject;
	ComponentHealth* health;
	ComponentAllegiance* allegiance;
	
	gameObject = ecs_component_get(ecs, ECS_COMPONENT_GAME_OBJECT, self->component.id);
	health = ecs_component_get(ecs, ECS_COMPONENT_HEALTH, self->component.id);
	allegiance = ecs_component_get(ecs, ECS_COMPONENT_ALLEGIANCE, self->component.id);
	
	component_game_object_atlas_init
	(
		gameObject,
		ecs,
		texture,
		frameSize,
		atlasSize,
		size,
		physicsSize,
		position,
		friction,
		velocityMax,
		isBounce,
		isAffectedByGravity,
		isSolid
	);

	component_health_init(health, healthValue);
	component_allegiance_init(allegiance, allegianceType);
}

/* Runs on character add. */
void
component_character_add(ComponentCharacter* self, ECS* ecs)
{
	ecs_component_add(ecs, ECS_COMPONENT_GAME_OBJECT, self->component.id);
	ecs_component_add(ecs, ECS_COMPONENT_ALLEGIANCE, self->component.id);
	ecs_component_add(ecs, ECS_COMPONENT_HEALTH, self->component.id);
	ecs_component_add(ecs, ECS_COMPONENT_LEVEL, self->component.id);
}

/* Runs on character deletion. */
void
component_character_delete(ComponentCharacter* self, ECS* ecs)
{
	ecs_component_delete(ecs, ECS_COMPONENT_GAME_OBJECT, self->component.id);
	ecs_component_delete(ecs, ECS_COMPONENT_ALLEGIANCE, self->component.id);
	ecs_component_delete(ecs, ECS_COMPONENT_HEALTH, self->component.id);
	ecs_component_delete(ecs, ECS_COMPONENT_LEVEL, self->component.id);
}
