connect method
- int operatorIndex
Connects the given operator to the first available gamepad.
See the discussions at gamepads and osIndexes for context first. This function will loop through all available OS indexes to find the first available index, and then assign it to the operator at the given index.
For example, assume the OS provides gamepads at indexes 0 and 2. There is already an operator connected to gamepad 0. If the next operator (at index 1) wants to connect, this function will assign them the gamepad at index 2.
Implementation
Future<void> connect(int operatorIndex) async {
if (gamepads[operatorIndex].isConnected) {
gamepads[operatorIndex].pulse();
return;
}
gamepads[operatorIndex] = MockGamepad(0);
for (final osIndex in getConnectedGamepads()) {
if (osIndexes.contains(osIndex)) continue;
final gamepad = Gamepad.forPlatform(osIndex);
await gamepad.init();
if (!gamepad.isConnected) {
await gamepad.dispose();
continue;
}
gamepads[operatorIndex] = gamepad;
gamepad.pulse();
return;
}
}