Cauldron2D.Drafter.Client.Settings (Cauldron2D.Drafter v0.3.0)

Copy Markdown View Source

A player's settings: which keys do what, whether the pointer steers, how loud things are, how the world is drawn (display, and drawing: on the graphics card or not), and the game's own options (Cauldron2D.Client.Game's options/0, its defaults under whatever was saved), and which player each game controller plays: pads, a map from a controller's name to a player number or :none (Cauldron2D.Drafter.Client.Controllers). controllers lists the controllers connected now, each %{name, player}; the client keeps it up to date for the game's menus to show, and it is not saved.

Kept per kind of client — the terminal, a desktop, a browser, a phone: a kind is any atom, :terminal the default — on disk under $XDG_CONFIG_HOME/<game>/<player>.settings for the terminal and <player>.<kind>.settings for another kind, <game> being the game's title in lower case with runs of other characters as _ (or under ~/.config), and, when the player has an account, in its props as well: settings for the terminal, settings_<kind> for another kind. load/4 reads the file over any account props; save/5 writes both.

settings = Cauldron2D.Drafter.Client.Settings.load(MyGame.Client, "alice", account_props)
settings.bindings[:launch]
Cauldron2D.Drafter.Client.Settings.load(MyGame.Client, "alice", account_props, kind: :desktop)

Summary

Types

How the world is drawn: pixels where the terminal has them, else glyphs; braille; block characters of a glyph set; or glyphs.

Where a game that can be drawn by the graphics card is drawn: :auto on the card in the pane when there is one, :software never on the card, :pane on the card in the pane, :window on the card in a window of its own.

Frames per second, or :auto for the terminal's best.

One line of the settings screen: the preset, an action's binding, or a switch or level.

t()

Functions

Add key to what action is bound to, after the keys it has; a key already there is not added twice.

Switch to preset of game, dropping individual rebindings.

The frame rate to draw at: the setting, or for :auto the terminal's best — 12 where every frame is an inline image (iTerm2's own, sixel), 20 where every frame is a kitty picture sent whole (a terminal without placements) or the session is served over ssh (link :ssh), 30 elsewhere.

The frame rates the settings screen offers: the game's frame_rates/0, else :auto, 15, 30, 50 and 60.

The settings screen's items for game, top to bottom; :drawing is there when the build has the graphics card renderer (cauldron_gpu).

The keys bound to action, as text for a screen.

Settings for player of game on a :kind of client (default :terminal): the file on disk over account_props over the defaults.

Settings for game with overrides applied over the game's first preset.

Move a 0.0–1.0 level by delta, clamped.

Where player's settings for game live, for a kind of client (default :terminal).

The presets in the order the settings screen offers them: the game's keymaps/0 order for a keyword list, by name for a map.

The account prop a kind's settings are kept under: :settings for the terminal, :settings_<kind> for another.

Bind action to key alone, in place of whatever it had.

Write the settings to disk, and to the account when accounts is given, for a :kind of client (default :terminal).

The next or previous display choice, in the order auto, braille, half, quad, sextant, octant, glyphs, wrapping.

The next or previous drawing choice, in the order auto, software, pane, window, wrapping.

The next or previous frame rate choice of game's frame_rates/1, wrapping.

The surface mode for the display setting: nil lets the terminal decide.

The map kept in account props and on disk.

Drop the last key action is bound to; an action with no keys is unchanged.

Types

display()

@type display() :: :auto | :braille | :half | :quad | :sextant | :octant | :glyphs

How the world is drawn: pixels where the terminal has them, else glyphs; braille; block characters of a glyph set; or glyphs.

drawing()

@type drawing() :: :auto | :software | :pane | :window

Where a game that can be drawn by the graphics card is drawn: :auto on the card in the pane when there is one, :software never on the card, :pane on the card in the pane, :window on the card in a window of its own.

fps()

@type fps() :: :auto | pos_integer()

Frames per second, or :auto for the terminal's best.

item()

@type item() ::
  :preset
  | {:action, Cauldron2D.Input.action()}
  | :pointer
  | :sfx
  | :music
  | :display
  | :drawing
  | :fps

One line of the settings screen: the preset, an action's binding, or a switch or level.

t()

@type t() :: %Cauldron2D.Drafter.Client.Settings{
  bindings: Cauldron2D.Input.keymap(),
  controllers: [%{name: String.t(), player: pos_integer() | nil}],
  display: display(),
  drawing: drawing(),
  fps: fps(),
  music: float(),
  options: map(),
  pads: %{required(String.t()) => pos_integer() | :none},
  pointer: boolean(),
  preset: atom(),
  sfx: float()
}

Functions

bind(settings, action, key)

Add key to what action is bound to, after the keys it has; a key already there is not added twice.

choose_preset(settings, game, preset)

@spec choose_preset(t(), module(), atom()) :: t()

Switch to preset of game, dropping individual rebindings.

frame_rate(settings, protocol, placements? \\ true, link \\ :local)

@spec frame_rate(t(), atom() | nil | :unprobed, boolean(), :local | :ssh) ::
  pos_integer()

The frame rate to draw at: the setting, or for :auto the terminal's best — 12 where every frame is an inline image (iTerm2's own, sixel), 20 where every frame is a kitty picture sent whole (a terminal without placements) or the session is served over ssh (link :ssh), 30 elsewhere.

frame_rates(game)

@spec frame_rates(module()) :: [fps()]

The frame rates the settings screen offers: the game's frame_rates/0, else :auto, 15, 30, 50 and 60.

items(game)

@spec items(module()) :: [item()]

The settings screen's items for game, top to bottom; :drawing is there when the build has the graphics card renderer (cauldron_gpu).

keys_text(settings, action)

@spec keys_text(t(), Cauldron2D.Input.action()) :: String.t()

The keys bound to action, as text for a screen.

load(game, player, account_props \\ %{}, opts \\ [])

@spec load(module(), String.t(), map(), keyword()) :: t()

Settings for player of game on a :kind of client (default :terminal): the file on disk over account_props over the defaults.

new(game, overrides \\ %{})

@spec new(module(), map()) :: t()

Settings for game with overrides applied over the game's first preset.

An override naming a preset the game no longer has starts from the first preset, and its bindings are dropped with it.

nudge(settings, level, delta)

@spec nudge(t(), :sfx | :music, number()) :: t()

Move a 0.0–1.0 level by delta, clamped.

path(game, player, kind \\ :terminal)

@spec path(module(), String.t(), atom()) :: Path.t()

Where player's settings for game live, for a kind of client (default :terminal).

presets(game)

@spec presets(module()) :: [atom()]

The presets in the order the settings screen offers them: the game's keymaps/0 order for a keyword list, by name for a map.

prop_key(kind)

@spec prop_key(atom()) :: atom()

The account prop a kind's settings are kept under: :settings for the terminal, :settings_<kind> for another.

rebind(settings, action, key)

Bind action to key alone, in place of whatever it had.

save(settings, game, player, accounts \\ nil, opts \\ [])

@spec save(t(), module(), String.t(), GenServer.server() | nil, keyword()) :: :ok

Write the settings to disk, and to the account when accounts is given, for a :kind of client (default :terminal).

step_display(settings, delta)

@spec step_display(t(), -1 | 1) :: t()

The next or previous display choice, in the order auto, braille, half, quad, sextant, octant, glyphs, wrapping.

step_drawing(settings, delta)

@spec step_drawing(t(), -1 | 1) :: t()

The next or previous drawing choice, in the order auto, software, pane, window, wrapping.

step_fps(settings, game, delta)

@spec step_fps(t(), module(), -1 | 1) :: t()

The next or previous frame rate choice of game's frame_rates/1, wrapping.

surface_mode(settings)

@spec surface_mode(t()) :: nil | :braille | :half | :quad | :sextant | :octant | :text

The surface mode for the display setting: nil lets the terminal decide.

to_props(settings)

@spec to_props(t()) :: map()

The map kept in account props and on disk.

unbind_last(settings, action)

@spec unbind_last(t(), Cauldron2D.Input.action()) :: t()

Drop the last key action is bound to; an action with no keys is unchanged.