+ // Requests gamepad access and binds to the events
+
+ _initializeGamepad() {
+
+ window.addEventListener('gamepadconnected', (event) => {
+
+ internals.gamepadState[event.gamepad.index] = event.gamepad;
+ window.gamepad = event.gamepad;
+ });
+
+ window.addEventListener('gamepaddisconnected', (event) => {
+
+ delete internals.gamepadState[event.gamepad.index];
+ });
+ }
+
+ // Update Gamepad
+
+ _updateGamepads() {
+
+ const gamepads = navigator.getGamepads();
+ for (const index of Object.keys(internals.gamepadState)) {
+ internals.gamepadState[index] = gamepads[index];
+ }
+ }
+