InputMap
Since 0.6
A logical action map over ctx.input; rebinding is a data edit, not a code edit.
Signature
export class InputMap {
deadzone: number
lookSensitivity: Vec2
invertLook: [boolean, boolean]
constructor(init: InputMapInit = {})
bind(action: ActionName, sources: string | string[]): this
bindAxis(axis: string, source: string): this
unbind(action: ActionName): this
sources(action: ActionName): string[]
axisSource(axis: string): string
toJSON(): InputConfig
static fromJSON(data: unknown): InputMap
static fromContract(doc: SceneInputDoc, context: string): InputMap
bound(): string[]
axis(input: InputState | null, name: string): Vec2
move(input: InputState | null): Vec2
lookParts(input: InputState | null): AxisParts
look(input: InputState | null): Vec2
action(input: InputState | null, action: ActionName): ActionState
pressed(input: InputState | null, action: ActionName): boolean
held(input: InputState | null, action: ActionName): boolean
released(input: InputState | null, action: ActionName): boolean
}
Import: import { InputMap } from "@argus/gameplay"
Members
| Member | Signature | Description |
|---|---|---|
deadzone | deadzone: number | |
lookSensitivity | lookSensitivity: Vec2 | |
invertLook | invertLook: [boolean, boolean] | |
constructor | constructor(init: InputMapInit = {}) | |
bind | bind(action: ActionName, sources: string | string[]): this | Rebind a button action to one or more source names. Returns this so calls chain. |
bindAxis | bindAxis(axis: string, source: string): this | Rebind an axis to a source axis name. |
unbind | unbind(action: ActionName): this | Drop every source for an action; it then reads as never pressed. An empty list, not a missing entry: a missing entry is the identity now, so deleting the key would rebind the action to itself rather than silence it. |
sources | sources(action: ActionName): string[] | The actions currently bound to a button, in priority order. Its own name when unbound. |
axisSource | axisSource(axis: string): string | The source a logical axis reads from (its own name when unbound). |
toJSON | toJSON(): InputConfig | The binding table as plain data, ready to store in props or a settings file. |
fromJSON | static fromJSON(data: unknown): InputMap | Rebuild a map from data (a script component's props, a saved settings blob). Unknown fields are ignored. |
fromContract | static fromContract(doc: SceneInputDoc, context: string): InputMap | Build a map from a meta.input document and one of its contexts. The identity for every action that context binds, plus the per-action deadzone the document asked for where all of them agree. Its use is a rebinding screen: read the scene's map, list actions(), let the player pick, write the edit back to the scene document. It is NOT needed to read input — the engine has already applied the map by the time ctx.input answers, so a behavior that just wants move uses new InputMap(). An unknown context, or a malformed document, yields an empty map rather than throwing. |
bound | bound(): string[] | Every action this map names, in name order. What a rebinding screen lists. |
axis | axis(input: InputState | null, name: string): Vec2 | A logical axis with the deadzone applied. Neutral when the entity has no input component. |
move | move(input: InputState | null): Vec2 | The move axis: [strafe, forward], deadzoned. |
lookParts | lookParts(input: InputState | null): AxisParts | The look axis split into its stick rate and its mouse angle, each with sensitivity and inversion applied: rate is [yaw, pitch] in -1..1 (deadzoned), delta is [yaw, pitch] in degrees this tick. What the camera rigs turn by (RigInput.look and lookDelta). |
look | look(input: InputState | null): Vec2 | The legacy look axis with sensitivity and inversion applied: [yaw, pitch] in -1..1, with the mouse folded in as a rate (so a flick is capped). Turn a view with {@link lookParts}. |
action | action(input: InputState | null, action: ActionName): ActionState | The merged state of every source bound to action. |
pressed | pressed(input: InputState | null, action: ActionName): boolean | |
held | held(input: InputState | null, action: ActionName): boolean | |
released | released(input: InputState | null, action: ActionName): boolean |