Cauldron2D.Drafter.Client.Seats (Cauldron2D.Drafter v0.2.2)

Copy Markdown View Source

The further players a client plays on the same machine, from the game's local_seats/1: each a player of the world with its own keys and its own controller.

A seat is %{id, input, pad, last_input}. Seats join the world with frames: false, so the client receives frames only as its own player; each key event reaches every seat's input and counts where that seat's keymap binds it; a controller event reaches the one seat it is routed to. send_input/3 sends a seat's input only when it changed.

Summary

Functions

Seat index (counting from 0) after a controller event.

Every seat's input with its timed holds expired at now.

The seats keymaps describe, joined to world as "<username> 2" and on. A seat the world refuses is left out. props are the player's own join props, given to each seat with its own :username and with :seat_of, the player's own username, so the world can tell whose seat it is; input_options are those of the player's own input.

Every seat's input after a key or pointer event at now.

Every seat out of world.

Every seat holding nothing, its keys read by the keymap it had.

Every seat whose input changed sent to world, its read input passed through steer first, as the client steers its own player's.

Types

seat()

@type seat() :: %{
  id: String.t(),
  input: Cauldron2D.Input.t(),
  pad: Cauldron2D.Input.Pad.t(),
  last_input: map() | nil
}

Functions

controller(seats, index, event)

@spec controller([seat()], non_neg_integer(), map()) :: [seat()]

Seat index (counting from 0) after a controller event.

expire(seats, now)

@spec expire([seat()], integer()) :: [seat()]

Every seat's input with its timed holds expired at now.

join(world, username, props, keymaps, padmap, input_options)

The seats keymaps describe, joined to world as "<username> 2" and on. A seat the world refuses is left out. props are the player's own join props, given to each seat with its own :username and with :seat_of, the player's own username, so the world can tell whose seat it is; input_options are those of the player's own input.

key(seats, event, now)

@spec key([seat()], term(), integer()) :: [seat()]

Every seat's input after a key or pointer event at now.

leave(seats, world)

@spec leave([seat()], GenServer.server()) :: :ok

Every seat out of world.

release(seats, keymaps, input_options)

@spec release([seat()], [Cauldron2D.Input.keymap()], keyword()) :: [seat()]

Every seat holding nothing, its keys read by the keymap it had.

send_input(seats, world, steer)

@spec send_input([seat()], GenServer.server(), (map() -> map())) :: [seat()]

Every seat whose input changed sent to world, its read input passed through steer first, as the client steers its own player's.