This function is used to get the index of a component in an entity.
int dg_entity_has_component(dg_entity_t *entity, char *name);
int index = dg_entity_has_component(entity, "score");
int dg_entity_has_component(dg_entity_t *entity, char *name)
{
dg_array_t *tmp = 0;
int index = -1;
if (!entity || !name)
return -1;
tmp = entity->components;
while (tmp) {
index++;
if (!dg_strcmp(((dg_component_t *)(tmp->data))->name, name))
return index;
tmp = tmp->next;
}
return -1;
}