Actions beta
Class of @v12-engine/client
export declare class Actions<C = unknown>The actions of a game (client.keys) or a tool: what each is on now, the player's own keys in the place of those it comes with, and which of them an event is. Whoever listens to the keyboard feeds it (keyDown, keyUp, release); the rest asks it (is, held) or is told (on, ActionDef.run).
What is read (bindings, list, key) are signals: a component that reads one follows it, and other code does with the client's watch
Members
constructor
constructor(defs: readonly ActionDef<C>[]);Constructs a new instance of the Actions class
add
add(id: string, added: BindingLike): void;One more key for an action
bind
bind(id: string, bindings: readonly BindingLike[]): void;Puts an action on these keys, in the place of all it was on. None is no key at all
bindings
bindings(id: string): readonly Binding[];The keys an action is on now: the player's own, or those it comes with. Also for a name that is no action here but has keys of the player's (a button of the command card, card:<its id>): none until they are set
changed
changed(id?: string): boolean;Whether the player set keys of their own for an action, or (no id) for any
context
context?: C;What the actions act on (ActionDef.run): the client, for a game's. Set by whoever makes it
def
def(id: string): ActionDef<C> | undefined;An action, as it is defined
defaults
defaults(id: string): readonly Binding[];The keys an action comes with
define
define(def: ActionDef<C>, options?: {
before?: string;
}): void;One more action, as the game or the tool goes: asked after those there are, or before the one named (before). One of the same id takes that one's place, where it was. The keys the player gave that id are its own again
forget
forget(id: string): void;Takes an action away: its keys do nothing of it any more. The keys the player gave it are kept, should it come back
held
held(id: string): boolean;Whether an action that is held is down now
hold
hold(by: string, id: string): void;Marks a held action as down, by the key or button that holds it: what its own listener does for a pointer's button
is
is(id: string, event: Pressed): boolean;Whether an event is an action: its key or button pressed, with what is held as the action has it
kept
kept(): KeptBindings;The player's own keys, as plain data: what is kept, and what load takes
key
key(id: string): string;The first key of an action, as shown: for a tooltip, a key cap. Nothing when it has none
keyDown
keyDown(event: KeyboardEvent, among?: (def: ActionDef<C>) => boolean): boolean;A key pressed: the first action it is that takes it does it. True when one did (the key is then the game's, not the page's). A key held down that repeats does nothing again but what says it repeats (ActionDef.repeat), and stays the game's. among asks only the actions it says yes to: for one who asks some of them before something else has the key, and the rest after
keys
keys(id: string): string[];Every key of an action, as shown
keyUp
keyUp(event: KeyboardEvent): boolean;A key let go of: what it held is over. True when it held something
letGo
letGo(by: string, event?: KeyboardEvent | PointerEvent): boolean;What a key or button held is over
list
readonly list: Accessor<readonly ActionDef<C>[]>;Every action there is, in the order they are asked
load
load(kept: KeptBindings | undefined): void;Puts the player's keys as they were kept. Not told to onChange: it is what was kept already
match
match(event: Pressed, pointer?: boolean): ActionDef<C>[];The actions an event is, in the order they are asked
on
on(id: string, listener: (press: ActionPress) => boolean | void): () => void;Told when an action is pressed (and let go of, for one that is held). True takes it: the action does nothing else. Gives back what stops it
onChange
onChange(listener: (kept: KeptBindings) => void): () => void;Told each time the player's keys change, with all of them. Gives back what stops it
press
press(id: string, options?: {
shift?: boolean;
}): boolean;Does an action in code, as its key would: a button of the game's own for it
release
release(): void;Everything held is let go of: the window lost the keyboard, the player's hands were taken off
remove
remove(id: string, removed: BindingLike): void;One key of an action's less
reset
reset(id?: string): void;Puts an action, or every one, back on the keys it comes with
run
run(def: ActionDef<C>, press: ActionPress): boolean;Does an action: who listens is told, then what it does itself. False when it was not its to do now
sharing
sharing(id: string): SharedKey<C>[];The other actions on a key of an action's. clash where both count at the same time (see ActionDef.when), so that the one asked first always has the key; the others have it each in its own time, which is said and no fault
show
show(shown: BindingLike): string;How a binding is shown to the player