mirror of
https://github.com/bevyengine/bevy
synced 2024-11-10 07:04:33 +00:00
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:
parent
a0897428e2
commit
309745c7c6
1 changed files with 8 additions and 5 deletions
|
@ -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(
|
||||||
gamepad: convert_gamepad_id(id),
|
GamepadConnectionEvent {
|
||||||
connection: GamepadConnection::Connected(info),
|
gamepad: convert_gamepad_id(id),
|
||||||
});
|
connection: GamepadConnection::Connected(info),
|
||||||
|
}
|
||||||
|
.into(),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue