InputActionMap
in package
Table of Contents
Constants
- MOUSE_CLICK_VIRT_BUTTON = 10600
- Mouse click is not a real button, we simply define its value here
Properties
- $actionState : array<string, int>
- The current state of the action
- $actionStateDidPress : array<string, bool>
- Did press states (Did press is true for one update)
- $actionStateDidRelease : array<string, bool>
- Did release states (Did release is true for one update)
- $keyToAction : array<int, string>
- Input action map
Methods
- bindButton() : void
- Binds the given action key to the given button
- bindMouseClick() : void
- Binds a mouse click to the given action
- didButtonPress() : bool
- Returns true if the action button was pressed since the last update
- didButtonRelease() : bool
- Returns true if the action button was released since the last update
- handleKeySignal() : void
- Handles the given key signal to update internal action states
- handleMouseButtonSignal() : void
- Handles the given mouse button signal to update internal action states
- handleMouseClickSignal() : void
- Handles Mouse click signals to update internal action states
- importArrayMap() : void
- Imports the given array as bindings for the action map.
- isButtonDown() : bool
- Returns true if the action button is currently pressed
- isButtonUp() : bool
- Returns true if the action button is currently released
- reset() : void
- Resets the internal states to prepare for the next frame
Constants
MOUSE_CLICK_VIRT_BUTTON
Mouse click is not a real button, we simply define its value here
public
mixed
MOUSE_CLICK_VIRT_BUTTON
= 10600
Properties
$actionState
The current state of the action
private
array<string, int>
$actionState
= []
$actionStateDidPress
Did press states (Did press is true for one update)
private
array<string, bool>
$actionStateDidPress
= []
$actionStateDidRelease
Did release states (Did release is true for one update)
private
array<string, bool>
$actionStateDidRelease
= []
$keyToAction
Input action map
private
array<int, string>
$keyToAction
= []
Methods
bindButton()
Binds the given action key to the given button
public
bindButton(string $action, int $button) : void
Parameters
- $action : string
- $button : int
bindMouseClick()
Binds a mouse click to the given action
public
bindMouseClick(string $action) : void
Why an extra method and not just use MouseButton::LEFT? Because a mouse click in VISU is when you press the button and release it not to far away from the origin where the press began.
This means the click event has no current state, or did press/did release states. A mouse click either happened or it didn't. To allow keybinding on it, we simply interpret a mouse click as the RELEASE of a virtual button.
Parameters
- $action : string
didButtonPress()
Returns true if the action button was pressed since the last update
public
didButtonPress(string $action) : bool
Parameters
- $action : string
Return values
booldidButtonRelease()
Returns true if the action button was released since the last update
public
didButtonRelease(string $action) : bool
Parameters
- $action : string
Return values
boolhandleKeySignal()
Handles the given key signal to update internal action states
public
handleKeySignal(KeySignal $signal) : void
Parameters
- $signal : KeySignal
handleMouseButtonSignal()
Handles the given mouse button signal to update internal action states
public
handleMouseButtonSignal(MouseButtonSignal $signal) : void
Parameters
- $signal : MouseButtonSignal
handleMouseClickSignal()
Handles Mouse click signals to update internal action states
public
handleMouseClickSignal(MouseClickSignal $signal) : void
Parameters
- $signal : MouseClickSignal
importArrayMap()
Imports the given array as bindings for the action map.
public
importArrayMap(array<string, string> $map) : void
The array is a map from <string: action> to <string: button>, the button string in this situation will be mapped to the GLFW key constant.
We use some prefixing to make it easier to use, for example: 'jump' => '@Key::SPACE' <- @ prefix indicates a button binding 'select' => '#click' <- # prefix indicates an event binding 'movement_z' => '=Joystick::AXIS_1' <- = prefix indicates an axis binding
Parameters
- $map : array<string, string>
isButtonDown()
Returns true if the action button is currently pressed
public
isButtonDown(string $action) : bool
Parameters
- $action : string
Return values
boolisButtonUp()
Returns true if the action button is currently released
public
isButtonUp(string $action) : bool
Parameters
- $action : string
Return values
boolreset()
Resets the internal states to prepare for the next frame
public
reset() : void