Genesis.World (genesis v0.7.0)

View Source

World is a GenServer that manages the lifecycle of objects in the game. It is responsible for creating, cloning, and destroying objects. It also manages the event routing logic for object's aspects, ensuring that events are dispatched and handled correctly.

Summary

Functions

Returns a specification to start this module under a supervisor.

Clones an object with all its aspects. The clone object will be created in the current world.

Creates a new object in the world.

Creates a new object from a prefab. The prefab must be registered before it can be used.

Destroys an object from the world. Returns :ok if the object was successfully destroyed, or :noop if the object doesn't exist.

Fetches the aspects of an object.

Fetches the aspects of an object in the world.

List all objects with their respective aspects.

Sends a message to an object.

Starts the World process.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

clone(world, object)

Clones an object with all its aspects. The clone object will be created in the current world.

create(world)

Creates a new object in the world.

create(world, name)

Creates a new object from a prefab. The prefab must be registered before it can be used.

destroy(world, object)

Destroys an object from the world. Returns :ok if the object was successfully destroyed, or :noop if the object doesn't exist.

fetch(object)

Fetches the aspects of an object.

fetch(world, object)

Fetches the aspects of an object in the world.

list_objects(opts \\ [])

List all objects with their respective aspects.

Options

  • :aspects_as - Specifies how to represent the aspects of each object. Can be :list (default) to return a list of aspect structs, or :map to return a map where keys are aspect aliases and values are aspect structs.

Examples

iex> Genesis.World.list_objects(aspects_as: :list)
[{1, [%Health{current: 100}]}]

iex> Genesis.World.list_objects(aspects_as: :map)
[{1, %{"health" => %Health{current: 100}}}]

send(world, object, event, args \\ %{})

Sends a message to an object.

The event will be dispatched to all aspects currently attached to the object that should handle the event which will be processed in order of registration.

start_link(opts \\ [])

Starts the World process.