View Source Ecspanse.Resource behaviour (ECSpanse v0.7.2)
Resources are global components that don't belong to any entity.
They are best used for configuration, global state, statistics, etc.
Resources are defined by invoking use Ecspanse.Resource in their module definition.
Options
:state- a list with all the resource state struct keys and their initial values (if any). For example:[:player_count, max_players: 100]
There are two ways of providing the resources with their initial state:
At compile time, when invoking the
use Ecspanse.Resource, by providing the:stateoption.defmodule Demo.Resources.PlayerCount do use Ecspanse.Resource, state: [player_count: 0, max_players: 100] endAt runtime when creating the resources from specs:
t:Ecspanse.Resource.resource_spec()Ecspanse.Command.insert_resource!({Demo.Resources.Lobby, [max_players: 50]})
There are some special resources that are created automatically by the framework:
Ecspanse.Resource.FPS- tracks the frames per second.Ecspanse.Resource.State- a high level state implementation.
Note
Resources can be created, updated or deleted only from sysnchronous systems.
Summary
Types
A resource_spec is the definition required to create a resource.
Callbacks
Optional callback to validate the resource state.
Types
Callbacks
Optional callback to validate the resource state.
See Ecspanse.Component.validate/1 for more details.
Functions
Utility function. Returns all the resources and their state.
This function is intended for use only in testing and development environments.