# `Cauldron2D.Save`
[🔗](https://github.com/jaman/cauldron/blob/v0.1.3/cauldron_2d/lib/cauldron_2d/save.ex#L1)

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.

# `slot`

```elixir
@type slot() :: String.t()
```

# `delete`

```elixir
@spec delete(Cauldron2D.Paths.game(), slot()) :: :ok | {:error, term()}
```

Forget `slot`.

# `list`

```elixir
@spec list(Cauldron2D.Paths.game()) :: [%{slot: slot(), at: DateTime.t()}]
```

Every slot, oldest first, with when it was written.

# `path`

```elixir
@spec path(Cauldron2D.Paths.game(), slot()) :: Path.t()
```

The file a slot is kept in.

# `read`

```elixir
@spec read(Cauldron2D.Paths.game(), slot()) :: {:ok, term()} | {:error, term()}
```

The state kept under `slot`.

# `write`

```elixir
@spec write(Cauldron2D.Paths.game(), slot(), term()) :: :ok | {:error, term()}
```

Keep `state` under `slot`, replacing what was there.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
