Packages

Ecspanse is an Entity Component System (ECS) library for Elixir, offering a suite of features including: flexible queries with multiple filters, dynamic bidirectional relationships, versatile tagging capabilities, system event subscriptions, or asynchronous system execution.

Current section

Files

Jump to
ecspanse lib ecspanse resource state.ex
Raw

lib/ecspanse/resource/state.ex

defmodule Ecspanse.Resource.State do
@moduledoc """
A special resource provided by the framework to store a generic state.
This is a high level state, with an atom type value.
It is useful in controlling the systems execution. But its use
is not mandatory.
The initial state can be set, for example, in a startup system.
"""
use Ecspanse.Resource,
state: [value: nil]
alias __MODULE__
@type t :: %__MODULE__{
value: atom()
}
def validate(%State{value: value}) do
if is_atom(value) do
:ok
else
{:error, "Invalid state value: #{inspect(value)}. The Resource.State value must be an atom"}
end
end
end