ecs v0.5.0 ECS.Entity

Functions to work with entities.

An entity is a map container of components. Components are placed in the map with their key as a converted atom based on their struct atom. The key is created by converting the struct name after Component to snakecase, delimited by underscores.

Examples

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

# Output its name.
IO.puts monster.name
#=> "Monty"

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

Summary

Functions

Attaches a component to an entity

Detaches a component at key from an entity

Returns a new entity map containing components

Sets entity component at key to value

Updates entity’s component value at key using update_fn

Functions

attach(entity, component)

Attaches a component to an entity.

detach(entity, key)

Detaches a component at key from an entity.

new(components \\ [])

Returns a new entity map containing components.

set(entity, key, value)

Sets entity component at key to value.

update(entity, key, update_fn)

Updates entity’s component value at key using update_fn.