ecs v0.1.0 ECS.Component protocol

A protocol to allow custom specific component definitions.

This protocol is intended to be used with a module with a struct representative of a component data structure, with the core value key as the “raw” data. A type key atom value is also expected for consistent component typing.

Examples

# Define a custom "name" component.
defmodule Name do
  defstruct type: :name, value: nil

  def new(name), do: %Name{value: name}
end

# Create a name component.
name = Name.new("Josh")

# Display the name.
IO.puts ECS.Component.value_of(name) # "Josh"

# Verify the type.
:name = ECS.Component.type_of(name) # :name

# Update the value.
updated_name = ECS.Component.update(name, "Boba")
IO.puts ECS.Component.value_of(updated_name) # "Boba"

Summary

Functions

Returns the type of component as an atom

Updates component’s value with update_fun

Returns the raw value of the component

Types

t :: term

Functions

type_of(component)

Returns the type of component as an atom.

update(component, update_fun)

Updates component’s value with update_fun.

value_of(component)

Returns the raw value of the component.