Cauldron2D.Wx.Input (Cauldron2D.Wx v0.1.3)

Copy Markdown View Source

The keys and buttons a desktop player holds, as the input message the server takes.

input = Cauldron2D.Wx.Input.new(%{?A => :left, 315 => :jump, {:mouse, :left} => :act}, steering: [:left, :right])
{input, handled?} = Cauldron2D.Wx.Input.press(input, ?A)
Cauldron2D.Wx.Input.state(input)

Keys are wx key codes (?A, 32, 315 for the up arrow); buttons {:mouse, :left | :right | :middle}. A held key of a steering action clears the aim, so the keys take over from the pointer until it moves again, as the other clients do.

Summary

Functions

The pointer moved to a world position.

A mouse button went down or up.

Every key let go, as when the window loses focus.

An input reading keymap; :steering names the actions the pointer also drives.

A key went down; {input, whether the key meant anything}.

A key came up; {input, whether the key meant anything}.

What to send: the actions held, by name, and the aim as a pair.

Types

t()

@type t() :: %Cauldron2D.Wx.Input{
  aim: {number(), number()} | nil,
  held: MapSet.t(atom()),
  keymap: map(),
  steering: [atom()]
}

Functions

aim(input, aim)

@spec aim(t(), {number(), number()} | nil) :: t()

The pointer moved to a world position.

button(input, button, down?)

@spec button(t(), :left | :right | :middle, boolean()) :: t()

A mouse button went down or up.

drop(input)

@spec drop(t()) :: t()

Every key let go, as when the window loses focus.

new(keymap, opts \\ [])

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

An input reading keymap; :steering names the actions the pointer also drives.

press(input, key)

@spec press(t(), integer()) :: {t(), boolean()}

A key went down; {input, whether the key meant anything}.

release(input, key)

@spec release(t(), integer()) :: {t(), boolean()}

A key came up; {input, whether the key meant anything}.

state(input)

@spec state(t()) :: %{held: [String.t()], aim: [number()] | nil}

What to send: the actions held, by name, and the aim as a pair.