ecs v0.2.1 ECS.Component protocol
A protocol to allow custom specific component definitions.
The default Any implementation assumes a struct definition with a value
property that represents the primary raw data. Components can be customized
with any other structure by implementing this protocol directly.
The Any implementation of type_of/1
returns an atom of the interpreted name
of the component struct, where anything before and including “Component.” in
the component’s name will be ignored. For example, “ECS.Component.Test.String”
would have a calculated type atom of :string_test
.
Example
# Define a custom "name" component.
defmodule Component.Name do
defstruct value: nil
def new(name), do: %__MODULE__{value: name}
end
Summary
Functions
Sets the underlying value of the component
to value
Converts a component struct to a “type” atom
Updates the underlying value of the component
using update_fn
Retrieves the underlying value of the component
Types
t :: term
Functions
Sets the underlying value of the component
to value
.
Example
Component.Name.new(nil)
|> ECS.Component.set("Josh")
#=> "Josh"
Converts a component struct to a “type” atom.
Example
Component.Name.new("Josh")
|> ECS.Component.type_of
#=> :name
Updates the underlying value of the component
using update_fn
.
Example
Component.Name.new("Josh")
|> ECS.Component.update(&("#{&1} F"))
#=> %Component.Name{value: "Josh F"}