Genesis.Manager (genesis v0.7.0)

View Source

The Manager is a GenServer responsible for coordinating changes to the game registry. It ensures that all changes write operations are serialized to maintain consistency, and provides functions to register aspects and prefabs that will be used by the game.

Summary

Functions

Returns a specification to start this module under a supervisor.

List all aspects registered in the game.

Lists all prefabs registered in the game.

Registers an aspect module with an optional custom alias.

Registers a new prefab definition. Prefabs are templates for creating objects with predefined aspects and properties.

Returns the ETS table name used for the given registry.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

list_aspects()

List all aspects registered in the game.

iex> Genesis.Manager.list_aspects()
[{"health", Health}, {"position", Position}]

list_prefabs()

Lists all prefabs registered in the game.

iex> Genesis.Manager.list_prefabs()
[{"Being", %Genesis.Prefab{aspects: aspects}}]

register_aspect(module_or_tuple)

Registers an aspect module with an optional custom alias.

Alias are useful to scope aspects in different domains. If only the module is provided, a default alias is used.

iex> Genesis.Manager.register_aspect(Health)
iex> Genesis.Manager.register_aspect({"prefix::health", Health})

register_prefab(attrs)

Registers a new prefab definition. Prefabs are templates for creating objects with predefined aspects and properties.

iex> Genesis.Manager.register_prefab(%{
...>   name: "Being",
...>   aspects: %{
...>     "health" => %{current: 100},
...>     "moniker" => %{name: "Being"}
...>   }
...> })

Prefabs can also inherit from other prefabs to create complex object hierarchies.

iex> Genesis.Manager.register_prefab(%{
...>   name: "Human",
...>   inherits: "Being",
...>   aspects: %{
...>     "moniker" => %{name: "Human"}
...>   }
...> })

When a prefab inherits another, it will include all aspects of the parent prefab, allowing for reusable definitions. When loading prefabs, the aspects defined by a child prefab have precedence over those defined in the parent.

start_link(args \\ %{})

table(atom)

Returns the ETS table name used for the given registry.