Skip to content

Commit

Permalink
[add] (api) option to find entities with a given component attached t…
Browse files Browse the repository at this point in the history
…o them
  • Loading branch information
begla committed Jun 9, 2024
1 parent 3313e1a commit 5e5942e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
5 changes: 5 additions & 0 deletions iolite_c_api/iolite_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -2745,6 +2745,11 @@ struct io_entity_i // NOLINT
// See "Documentation" for usage details.
void (*find_entities_with_name)(const char* name, io_ref_t* entities,
io_size_t* entities_length);
// Finds all entities which have a component with the given component type
// name attached.
void (*find_entities_with_component)(const char* component_type_name,
io_ref_t* entities,
io_size_t* entities_length);

// Copies and initializes the component of the given type from the source
// entity to the given target entity.
Expand Down
16 changes: 14 additions & 2 deletions iolite_plugins/lua_plugin/init_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1946,9 +1946,9 @@ void script_init_state(sol::state& s)
s["Entity"]["find_first_entity_with_name"] = io_entity->find_first_entity_with_name;

// @function find_entities_with_name
// @summary Finds all entities with the given name and returns as table containg refs as result.
// @summary Finds all entities with the given name.
// @param name string The name of the entities to search for.
// @return table value Table containing the entities with the given name.
// @return table value Table containing the matching entities.
s["Entity"]["find_entities_with_name"] = [](const char* name) {
uint32_t num_entities;
io_entity->find_entities_with_name(name, nullptr, &num_entities);
Expand All @@ -1957,6 +1957,18 @@ void script_init_state(sol::state& s)

return entities;
};
// @function find_entities_with_component
// @summary Finds all entities with a component of the given component type name attached to them.
// @param name string The component type name.
// @return table value Table containing the matching entities.
s["Entity"]["find_entities_with_component"] = [](const char* name) {
uint32_t num_entities;
io_entity->find_entities_with_component(name, nullptr, &num_entities);
std::vector<io_ref_t> entities(num_entities);
io_entity->find_entities_with_component(name, entities.data(), &num_entities);

return entities;
};

};

Expand Down

0 comments on commit 5e5942e

Please sign in to comment.