Welcome to Contro's documentation!
A component is a class that exposes controls. Currently the following component classes are available:
A control belongs to a certain feature of a component, like a button. It is an object that has has three properties:
query
— a method that returns the current value of the control- the value is always of the same data type
label
— a labelstring
that can be displayed to the playertrigger
— a getter that returns a trigger control- only exists on controls with the data type
boolean
- only exists on controls with the data type
A boolean control that only returns true
once after the control value changed to true
. It then returns false
until the value has changed back to false
and then became true
again.
A compound control can be created by one of the operator functions and groups multiple controls into one that dynamically returns a relevant labels (for keyboard and mouse or gamepad) and control values.
Operator functions take in controls as arguments and are used to create compound controls. There are currently two of them:
or()
combines multiple different controls and (forboolean
's) works like||
and()
can only be used forboolean
controls and works like&&
const controlA = gamepad.button('A')
const controlB = keyboard.key('Space')
const compoundControl = or(controlA, controlB)
console.log(compoundControl.label) // 'A' or 'Space' (last used input)
console.log(compoundControl.query()) // `true` when at least one is pressed
Still have questions? Feel free to open an issue.