GamepadManagerSingleton
A gamepadmanager to help with games / handling input from a controller
TODO:
- Currently bluetooth gamepads when disconnecting (PS4 only) do no fire a disconnected event. Manually calling `this.gamepad.vibrationActuator.reset()` can force it to call a disconnect event, but this is a messy way of checking each tick to see if the gamepad is still connected. It also will cancel ongoing vibrations. Find a fix. (This is a GamepadAPI issue/OS issue/not code wise issue)
Static Method Summary
Static Public Methods | ||
public static |
Gets the angle between two points |
Constructor Summary
Public Constructor | ||
public |
Creates the instance and assigns event handlers to gamepad events |
Member Summary
Public Members | ||
public |
Object containing the callback for when a controller is connected |
|
public |
connectedControllers: Set<Controller> | null Controllers connected before an event listener caught them. |
|
public |
Object containing all connected controllers |
|
public |
Object containing the callback for when a controller is disconnected |
|
public |
unassignedControllers: Set<Controller> | null Controllers connected before an event listener caught them. |
|
public |
version: * The version of the module. |
Private Members | ||
private |
The logger module this module uses to log errors / logs. |
Method Summary
Public Methods | ||
public |
|
|
public |
getMainController(): Gamepad This gets the first controller connected. |
|
public |
handleGamepadConnected(pGamepadEvent: pGamepadEvent) Listener function for when a gamepad is connected |
|
public |
handleGamepadDisconnected(pGamepadEvent: pGamepadEvent) Listener function for when the gamepad is disconnected |
|
public |
on(pEvent: Object, pCallback: Function): GamepadManagerSingleton Attaches a callback to the specified event. |
|
public |
Get the latest game state of the connected gamepads (Chrome only saves snapshots of the state, we have to keep polling to get updated states) |
Static Public Methods
Public Constructors
Public Members
public connectHandler: Object source
Object containing the callback for when a controller is connected
public connectedControllers: Set<Controller> | null source
Controllers connected before an event listener caught them.
public disconnectHandler: Object source
Object containing the callback for when a controller is disconnected
public unassignedControllers: Set<Controller> | null source
Controllers connected before an event listener caught them.
Private Members
Public Methods
public getMainController(): Gamepad source
This gets the first controller connected. This controller is dominant
Return:
Gamepad | The first controller connected |
public handleGamepadConnected(pGamepadEvent: pGamepadEvent) source
Listener function for when a gamepad is connected
Params:
Name | Type | Attribute | Description |
pGamepadEvent | pGamepadEvent | A gamepad event |
public handleGamepadDisconnected(pGamepadEvent: pGamepadEvent) source
Listener function for when the gamepad is disconnected
Params:
Name | Type | Attribute | Description |
pGamepadEvent | pGamepadEvent | A gamepad event |
public on(pEvent: Object, pCallback: Function): GamepadManagerSingleton source
Attaches a callback to the specified event.
public pollGamepadState() source
Get the latest game state of the connected gamepads (Chrome only saves snapshots of the state, we have to keep polling to get updated states)