constructor()

in src/input.service.ts [134:182]


  constructor(public pad: Gamepad) {
    const left = new DirectionalDebouncer(() => {
      /* left joystick                                 */
      return (
        this.pad.axes[0] < -XboxGamepadWrapper.joystickThreshold ||
        this.pad.buttons[Direction.LEFT].pressed
      );
    });
    const right = new DirectionalDebouncer(() => {
      /* right joystick                               */
      return (
        this.pad.axes[0] > XboxGamepadWrapper.joystickThreshold ||
        this.pad.buttons[Direction.RIGHT].pressed
      );
    });
    const up = new DirectionalDebouncer(() => {
      /* up joystick                                   */
      return (
        this.pad.axes[1] < -XboxGamepadWrapper.joystickThreshold ||
        this.pad.buttons[Direction.UP].pressed
      );
    });
    const down = new DirectionalDebouncer(() => {
      /* down joystick                                */
      return (
        this.pad.axes[1] > XboxGamepadWrapper.joystickThreshold ||
        this.pad.buttons[Direction.DOWN].pressed
      );
    });

    this.events.set(Direction.LEFT, now => left.attempt(now));
    this.events.set(Direction.RIGHT, now => right.attempt(now));
    this.events.set(Direction.UP, now => up.attempt(now));
    this.events.set(Direction.DOWN, now => down.attempt(now));

    directionNumsList
      .filter(
        dir =>
          dir !== Direction.LEFT &&
          dir !== Direction.RIGHT &&
          dir !== Direction.UP &&
          dir !== Direction.DOWN,
      )
      .forEach(dir =>
        this.events.set(dir, () =>
          new FiredDebouncer(() => this.pad.buttons[dir].pressed).attempt(),
        ),
      );
  }