Skip to content

Commit

Permalink
Send GamepadEvent for gamepads connected at startup
Browse files Browse the repository at this point in the history
  • Loading branch information
uwuPyxl committed Mar 11, 2024
1 parent b3655a3 commit a290bc5
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions crates/bevy_gilrs/src/gilrs_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,20 @@ use gilrs::{ev::filter::axis_dpad_to_button, EventType, Filter};
pub fn gilrs_event_startup_system(
#[cfg(target_arch = "wasm32")] mut gilrs: NonSendMut<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() {
let info = GamepadInfo {
name: gamepad.name().into(),
};

connection_events.send(GamepadConnectionEvent {
gamepad: convert_gamepad_id(id),
connection: GamepadConnection::Connected(info),
});
events.send(
GamepadConnectionEvent {
gamepad: convert_gamepad_id(id),
connection: GamepadConnection::Connected(info),
}
.into(),
);
}
}

Expand Down

0 comments on commit a290bc5

Please sign in to comment.