# `Cauldron2D.Replay.Viewer`
[🔗](https://github.com/jaman/cauldron/blob/v0.1.3/cauldron_2d/lib/cauldron_2d/replay/viewer.ex#L1)

Plays a `Cauldron2D.Replay` back on a clock, sending a watcher the frames one
recorded player saw.

    {:ok, viewer} = Cauldron2D.Replay.Viewer.start_link(replay: replay, game: MyGame, game_opts: [seed: 7], hz: 50, as: "alice", watcher: self())

The watcher receives `{:cauldron_frame, %{tick: n, view: view, events: events}}` for
every tick after the player `:as` has joined, exactly as a `Cauldron2D.World` sends
them, and `{:cauldron_replay, viewer, :done, state}` with the final state when the
record runs out; the viewer then stops. `pause/1`, `resume/1` and `step/1` drive it.

## Options

  * `:replay`, `:game` — the record and the game it was made with. Required
  * `:game_opts` — the game's options, as recorded. Default `[]`
  * `:hz` — the rate the world ran at, so the `dt` of a step. Default `50`
  * `:speed` — how many times faster than that to play. Default `1`
  * `:as` — the recorded player whose view is sent. Required
  * `:watcher` — the process the frames go to. Default the caller
  * `:paused?` — start paused. Default `false`

# `child_spec`

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# `pause`

```elixir
@spec pause(GenServer.server()) :: :ok
```

Stop the clock.

# `resume`

```elixir
@spec resume(GenServer.server()) :: :ok
```

Start the clock again.

# `start_link`

```elixir
@spec start_link(keyword()) :: GenServer.on_start()
```

Start a viewer; see the module documentation for the options.

# `step`

```elixir
@spec step(GenServer.server()) :: :ok
```

Run one tick while paused.

---

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