Skip to content
This repository has been archived by the owner on Mar 1, 2024. It is now read-only.

Commit

Permalink
start/stop game pad polling on config enable/disable
Browse files Browse the repository at this point in the history
  • Loading branch information
hmuurine committed Mar 2, 2023
1 parent a60b65d commit e83eaa3
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion Frontend/library/src/Inputs/GamepadController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,19 @@ export class GamePadController {
);
}
this.controllers = [];
for (const gamepad of navigator.getGamepads()) {
if (gamepad) {
this.gamePadConnectHandler(new GamepadEvent('gamepadconnected', { gamepad }));
}
}
}

/**
* Unregisters all event handlers
*/
unregisterGamePadEvents() {
this.gamePadEventListenerTracker.unregisterAll();
this.controllers = [];
}

/**
Expand Down Expand Up @@ -205,7 +211,9 @@ export class GamePadController {
}
this.controllers[controllerIndex].prevState = currentState;
}
this.requestAnimationFrame(() => this.updateStatus());
if (this.controllers.length > 0) {
this.requestAnimationFrame(() => this.updateStatus());
}
}
}

Expand Down

0 comments on commit e83eaa3

Please sign in to comment.