Send GamepadEvent for gamepads connected at startup (#12424)

# Objective

- Fix GamepadEvent::Connection not being sent for devices connected at
startup.

## Solution

- GamepadConnectionEvent was being sent directly for gamepads connected
at startup, which causes consumers of GamepadEvent to not receive those
events.
- Instead send GamepadEvent. The gamepad_event_system splits
GamepadEvent up, so consumers of GamepadConnectionEvent will still
receive the events.
This commit is contained in:
uwuPyxl 2024-03-11 21:05:10 +01:00 committed by GitHub
parent a0897428e2
commit 309745c7c6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -18,17 +18,20 @@ use gilrs::{ev::filter::axis_dpad_to_button, EventType, Filter};
pub fn gilrs_event_startup_system( pub fn gilrs_event_startup_system(
#[cfg(target_arch = "wasm32")] mut gilrs: NonSendMut<Gilrs>, #[cfg(target_arch = "wasm32")] mut gilrs: NonSendMut<Gilrs>,
#[cfg(not(target_arch = "wasm32"))] mut gilrs: ResMut<Gilrs>, #[cfg(not(target_arch = "wasm32"))] mut gilrs: ResMut<Gilrs>,
mut connection_events: EventWriter<GamepadConnectionEvent>, mut events: EventWriter<GamepadEvent>,
) { ) {
for (id, gamepad) in gilrs.0.get().gamepads() { for (id, gamepad) in gilrs.0.get().gamepads() {
let info = GamepadInfo { let info = GamepadInfo {
name: gamepad.name().into(), name: gamepad.name().into(),
}; };
connection_events.send(GamepadConnectionEvent { events.send(
GamepadConnectionEvent {
gamepad: convert_gamepad_id(id), gamepad: convert_gamepad_id(id),
connection: GamepadConnection::Connected(info), connection: GamepadConnection::Connected(info),
}); }
.into(),
);
} }
} }