Saved games: a game state kept on disk under a slot name, and read back to start a
Cauldron2D.World from with its :state option.
:ok = Cauldron2D.Save.write(:my_game, "quick", Cauldron2D.World.snapshot(world))
{:ok, state} = Cauldron2D.Save.read(:my_game, "quick")
{:ok, world} = Cauldron2D.World.start_link(game: MyGame, state: state)Slots live at Cauldron2D.Paths.data(game, ["saves", slot <> ".save"]). A slot name is
one path segment; anything with a separator or .. is {:error, :bad_slot}. The
state is any term.
Summary
Functions
Forget slot.
Every slot, oldest first, with when it was written.
The file a slot is kept in.
The state kept under slot.
Keep state under slot, replacing what was there.
Types
@type slot() :: String.t()
Functions
@spec delete(Cauldron2D.Paths.game(), slot()) :: :ok | {:error, term()}
Forget slot.
@spec list(Cauldron2D.Paths.game()) :: [%{slot: slot(), at: DateTime.t()}]
Every slot, oldest first, with when it was written.
@spec path(Cauldron2D.Paths.game(), slot()) :: Path.t()
The file a slot is kept in.
@spec read(Cauldron2D.Paths.game(), slot()) :: {:ok, term()} | {:error, term()}
The state kept under slot.
@spec write(Cauldron2D.Paths.game(), slot(), term()) :: :ok | {:error, term()}
Keep state under slot, replacing what was there.