tecs.controller#

Overview#

Functions#

installfunction#

function(exclusive world: ecs.World): ControlManager

Installs a logical controller manager in a world that already owns input.

Arguments#

exclusive world - ecs.World

the world whose input and gamepad polling the manager shares.

Returns#

ControlManager

the new manager, also available through of.

Raises#

Type Condition
string when input is not installed or a controller manager already exists.

newManagerfunction#

function(state: input.Input): ControlManager

Creates a standalone manager over an existing input state.

Arguments#

state - input.Input

the input state supplying physical controls and capture layers.

Returns#

ControlManager

a new manager; callers refresh its device assignments themselves.

offunction#

function(borrows world: ecs.World): ControlManager?

Returns a world's installed logical controller manager.

Arguments#

borrows world - ecs.World

the world to inspect.

Returns#

ControlManager?

the installed manager, or nil when none is installed.

Types#

Bindingstype#

type Bindings = {
    controls: {[string]: {string}},
    pairs: {[string]: {string}}?
}

Defines actions and optional four-direction movement pairs.

Members#

fields

controlsfield#

controls: {[string]: {string}}

Caller-writable. Maps action names to ordered binding lists. The controller copies the lists; the first nonzero binding supplies a value.

pairsfield#

pairs: {[string]: {string}}?

Caller-writable. Maps pair names to exactly four existing actions in left, right, up, down order. Nil defines no pairs.

Controllerrecord#

record Controller

Represents one player's logical input over a manager's shared input state.

Members#

bindingsfield#

bindings: Bindings

Read-only. Reports a copy of the current mapping. Change mappings with rebind; callers must not edit the returned tables.

gamepadfield#

gamepad: tecs.input.Gamepad?

Read-only. Reports the assigned gamepad, or nil when none is assigned. A disconnected object stays harmless until the manager refreshes it.

deadzonefield#

deadzone: number

Read-only. Reports the axis magnitude threshold configured at creation or through resetGamepad.

autofield#

auto: boolean

Read-only. Reports whether the manager automatically assigns a gamepad.

onGamepadChangedfield#

onGamepadChanged: (function(player: Controller, current: tecs.input.Gamepad?, previous: tecs.input.Gamepad?): nil)?

Caller-writable. Receives this controller, the new gamepad and the old gamepad after assignment changes. Nil disables notification.

isPressedmethod#

function(borrows self: Controller, action: string): boolean

Reports a press from any bound digital input in the active edge tier.

Arguments#
borrows self - Controller
the player whose input to read.
action - string
the logical action name; an unknown name reads false.
Returns#
boolean

whether a bound key, mouse button or gamepad button was pressed.

Raises#
Type Condition
string when evaluation reaches a hat binding that Input cannot read.

isDownmethod#

function(borrows self: Controller, action: string): boolean

Reports whether an action has a nonzero value.

Arguments#
borrows self - Controller
the player whose input to read.
action - string
the logical action name; an unknown name reads false.
Returns#
boolean

whether any binding supplies a nonzero value.

Raises#
Type Condition
string when evaluation reaches a hat binding that Input cannot read.

isReleasedmethod#

function(borrows self: Controller, action: string): boolean

Reports a release from any bound digital input in the active edge tier.

Arguments#
borrows self - Controller
the player whose input to read.
action - string
the logical action name; an unknown name reads false.
Returns#
boolean

whether a bound key, mouse button or gamepad button was released.

Raises#
Type Condition
string when evaluation reaches a hat binding that Input cannot read.

getRawmethod#

function(borrows self: Controller, action: string): number

Returns the first nonzero binding value in declaration order. axes, or the signed value for raw axes, after deadzone filtering.

Arguments#
borrows self - Controller
the player whose input to read.
action - string
the logical action name; an unknown name reads zero.
Returns#
number

zero or one for digital bindings, zero to one for directional

Raises#
Type Condition
string when evaluation reaches a hat binding that Input cannot read.

getPairmethod#

function(borrows self: Controller, name: string): (number, number)

Returns right minus left and down minus up for a movement pair.

Arguments#
borrows self - Controller
the player whose input to read.
name - string
the configured pair name; an unknown name reads zeroes.
Returns#
number
the horizontal value clamped to minus one through one.
number
the vertical value clamped to minus one through one.
Raises#
Type Condition
string when a pair's evaluation reaches a hat binding that Input cannot read.

getPairNormalizedmethod#

function(borrows self: Controller, name: string): (number, number)

Limits a movement pair to unit length while preserving smaller inputs.

Arguments#
borrows self - Controller
the player whose input to read.
name - string
the configured pair name; an unknown name reads zeroes.
Returns#
number
the horizontal value with diagonal speed limited.
number
the vertical value with partial analog magnitude preserved.
Raises#
Type Condition
string when a pair's evaluation reaches a hat binding that Input cannot read.

rebindmethod#

function(exclusive self: Controller, bindings: Bindings)

Validates, compiles and copies a replacement mapping atomically.

Arguments#
exclusive self - Controller
the player whose mapping to replace.
bindings - Bindings
the complete replacement actions and pairs.
Raises#
Type Condition
string when a name, binding source, device control or pair is invalid.

setGamepadmethod#

function(self: Controller, gamepad: tecs.input.Gamepad?)

Assigns a gamepad manually and disables automatic assignment. to leave this player with keyboard and mouse controls only.

Arguments#
self - Controller
the player whose gamepad to change.
gamepad - tecs.input.Gamepad?
a connected device owned by the manager's input, or nil
Raises#
Type Condition
string when the gamepad is disconnected or belongs to another input.

resetGamepadmethod#

function(self: Controller, config: GamepadConfig?)

Resets assignment and optionally enables automatic assignment. is disconnected or belongs to another input.

Arguments#
self - Controller
the player whose assignment to reset.
config - GamepadConfig?
the new assignment policy, or nil to disable gamepad input.
Raises#
Type Condition
string when the deadzone is outside zero to one or the gamepad

notifyWithRumblemethod#

function(
    borrows self: Controller,
    strength: number?,
    seconds: number?
): boolean

Plays a brief identification rumble on this player's gamepad.

Arguments#
borrows self - Controller
the player whose gamepad to identify.
strength - number?
the motor strength from zero to one, defaulting to 0.5.
seconds - number?
the duration in seconds, defaulting to 0.2; zero stops it.
Returns#
boolean

whether the gamepad accepted the effect.

Raises#
Type Condition
string when strength or duration is non-finite or outside its range.

ControlManagerrecord#

record ControlManager

Owns the logical controllers that share one input state.

Members#

controllersfield#

controllers: {Controller}

Read-only. Reports the manager's controller list in creation order. Callers must use addController and removeController to change it.

addControllermethod#

function(
    self: ControlManager,
    bindings: Bindings,
    config: GamepadConfig?
): Controller

Creates and registers one player's copied mapping. an axis deadzone of 0.5.

Arguments#
self - ControlManager
the manager that owns the player.
bindings - Bindings
the logical actions and optional movement pairs.
config - GamepadConfig?
the gamepad policy, defaulting to manual assignment and
Returns#
Controller

the newly registered controller.

Raises#
Type Condition
string when the mapping, deadzone or selected gamepad is invalid.

removeControllermethod#

function(self: ControlManager, player: Controller)

Removes a player, clears its gamepad and disables automatic assignment.

Arguments#
self - ControlManager
the manager to update.
player - Controller
the controller to remove; an absent controller is ignored.

getmethod#

function(borrows self: ControlManager, index: integer): Controller?

Returns a player by its current position in the controller list.

Arguments#
borrows self - ControlManager
the manager to read.
index - integer
the one-based player index.
Returns#
Controller?

the controller, or nil when no player occupies that index.

refreshDevicesmethod#

function(self: ControlManager)

Clears disconnected assignments and fills automatic players in order. input polls gamepads in Ingress; standalone managers call this directly.

Arguments#
self - ControlManager

the manager to refresh. Installed managers refresh after

GamepadConfigtype#

type GamepadConfig = {
    gamepad: tecs.input.Gamepad?,
    auto: boolean?,
    deadzone: number?
}

Configures one player's gamepad assignment and axis filtering.

Members#

gamepadfield#

gamepad: tecs.input.Gamepad?

Caller-writable. Selects a connected gamepad from the manager's tecs.input.Input. Nil leaves assignment to auto.

autofield#

auto: boolean?

Caller-writable. Enables exclusive automatic assignment of an available gamepad. Nil defaults to false; an explicit gamepad wins.

deadzonefield#

deadzone: number?

Caller-writable. Sets the minimum axis magnitude from zero to one. Nil defaults to 0.5 when creating a controller and preserves the current threshold when resetting its assignment.