Class GamepadManagerSingleton

A gamepadmanager to help with games / handling input from a controller GamepadManagerSingleton

License

GamepadManager does not have a license at this time. For licensing contact the author

Author

https://github.com/doubleactii

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)

Constructors

Properties

controllers: {
    [key: string]: Controller;
} = {}

Object containing all connected controllers

Type declaration

connectHandler: {
    [key: string]: ((controller) => void);
} = {}

Object containing the callback for when a controller is connected

Type declaration

  • [key: string]: ((controller) => void)
      • (controller): void
      • Parameters

        Returns void

connectedControllers: null | Set<Controller> = null

Controllers connected before an event listener caught them.

unassignedControllers: null | Set<Controller> = null

Controllers connected before an event listener caught them.

disconnectHandler: {
    [key: string]: ((controller) => void);
} = {}

Object containing the callback for when a controller is disconnected

Type declaration

  • [key: string]: ((controller) => void)
      • (controller): void
      • Parameters

        Returns void

version: string = "VERSION_REPLACE_ME"

The version of the module.

logger: any

The logger module this module uses to log errors / logs.

Methods

  • Gets the angle between two points

    Parameters

    • pStartPoint: {
          x: number;
          y: number;
      }

      The starting point

      • x: number
      • y: number
    • pEndPoint: {
          x: number;
          y: number;
      }

      The ending point

      • x: number
      • y: number

    Returns number

    The angle between the starting point and the ending point

  • This gets the first controller connected. This controller is dominant

    Returns undefined | Controller

    The first controller connected

  • Attaches a callback to the specified event.

    Parameters

    • pEvent: string

      The event to attach the callback to

    • pCallback: ((controller) => void)

      The function to be called when the event is triggered

        • (controller): void
        • Parameters

          Returns void

    Returns GamepadManagerSingleton

    The GamepadManagerSingleton instance

  • Listener function for when a gamepad is connected

    Parameters

    • pGamepadEvent: GamepadEvent

      A gamepad event

    Returns void

  • Listener function for when the gamepad is disconnected

    Parameters

    • pGamepadEvent: GamepadEvent

      A gamepad event

    Returns void

  • 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)

    Returns void