sesopenko ECS v1.0.2 Sesopenko.ECS.Repository View Source
Provides data operations for entities and their components.
Example Usage:
# Instantiate repository:
{:ok, pid} = Sesopenko.ECS.Repository.start_link()
# Create an entity with given component data:
{:ok, entity_id} = Sesopenko.ECS.Repository.add_entity(pid, %{
first_component_type: %{
data: 1,
other: 2,
},
second_component_type: %{
something: "foo",
other_think: [1, 2, 3]
}
})
# Fetch the entity:
{:ok, entity_component_data} = Sesopenko.ECS.Repository.fetch_entity(pid, entity_id)
# Get a complete list of entity data for a given component type:
component_type = :second_component_type
{:ok, component_data_list} = Sesopenko.ECS.Repository.list_data_for_component_type(pid, component_type)
Link to this section Summary
Functions
Adds an entity.
Returns a specification to start this module under a supervisor.
Fetches an entity by entity id.
Provides a list of all data for a given component type.
Starts a Repository process link which can be used to query against.
Link to this section Types
component_data_set()
View Sourcecomponent_data_set() :: %{required(component_type()) => component_data()}
Link to this section Functions
add_entity(pid, component_map)
View Sourceadd_entity(pid(), component_data_set()) :: type :: {:ok, entity_id()}
Adds an entity.
The input component_data_set
must be a map, keyed by component type atoms.
The component data for each key can be any native elixir type.
Example usage:
{:ok, entity_id} = Sesopenko.ECS.Repository.add_entity(pid, %{
first_component_type: %{
data: 1,
other: 2,
},
second_component_type: %{
something: "foo",
other_think: [1, 2, 3]
}
})
Returns a specification to start this module under a supervisor.
See Supervisor
.
fetch_entity(pid, entity_id)
View Sourcefetch_entity(pid(), entity_id()) :: {:ok, component_data_set()}
Fetches an entity by entity id.
Example usage:
entity_id = "7533af4e-5531-11ea-9263-000c292c6160"
{:ok, entity_component_data} = Sesopenko.ECS.Repository.fetch_entity(pid, entity_id)
The return is a map()
keyed by component type, with each value being a map()
of component data.
list_data_for_component_type(pid, component_type)
View Sourcelist_data_for_component_type(pid(), component_type()) :: {:ok, [component_data()]}
Provides a list of all data for a given component type.
Example usage:
component_type = :bears_fruit
{:ok, component_data_list} = Sesopenko.ECS.Repository.list_data_for_component_type(pid, component_type)
Starts a Repository process link which can be used to query against.
Usage:
pid = Sesopenko.ECS.Repository.start_link()