ecs v0.4.0 ECS.Entity

Functions to work with entities.

An entity is an agent-based container for a map of components. Components are placed in the map with their key as their struct reference atom.

Examples

# Create a monster entity.
monster = ECS.Entity.new([
  Component.Health.new(100),
  Component.Name.new("Monty")
])

# Output its name.
monster
|> ECS.Entity.get(Component.Name)
|> IO.puts
#=> "Monty"

# Attach an attack component to the monster.
monster
|> ECS.Entity.attach(Component.Attack.new(:melee, 24))

Summary

Functions

Attaches a component to an entity

Detaches a component of type cmp_type from an entity

Retrieves a component’s value of type cmp_type from an entity

Checks whether an entity has component(s) of cmp_type

Returns a new agent pid wrapping components as a map

Sets entity component of cmp_type to value

Updates entity’s component value of cmp_type using update_fn

Functions

attach(entity, component)

Attaches a component to an entity.

detach(entity, cmp_type)

Detaches a component of type cmp_type from an entity.

get(entity, cmp_type)

Retrieves a component’s value of type cmp_type from an entity.

has?(entity, cmp_types)

Checks whether an entity has component(s) of cmp_type.

new(components)

Returns a new agent pid wrapping components as a map.

set(entity, cmp_type, value)

Sets entity component of cmp_type to value.

update(entity, cmp_type, update_fn)

Updates entity’s component value of cmp_type using update_fn.