ecs v0.1.0 ECS.Entity

Functions to work with entities.

An entity is an agent-based container for a map of components.

Examples

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

# Output its name.
IO.puts ECS.Entity.get(monster, :name) # "monster"

# Attach an attack component to the monster.
ECS.Entity.attach(monster, 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 a component of cmp_type

Checks whether entity has component types cmp_types

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_type)

Checks whether an entity has a component of cmp_type.

has_all?(entity, cmp_types)

Checks whether entity has component types cmp_types.

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.