Skip to content

Commit

Permalink
Use EventWriter for gilrs_system (#3413)
Browse files Browse the repository at this point in the history
# Objective

- fixes #3397 

## Solution

- Uses EventWriter instead of ResMut<Event> in gilrs_system.rs.

I also renamed the argument from `event` to `events` for consistency. All other instances I could find in the engine of EventWriter use a plural argument name. Happy to undo or modify this change if desired.
  • Loading branch information
PaperCow committed Dec 21, 2021
1 parent c04dfc1 commit 004bbe9
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions crates/bevy_gilrs/src/gilrs_system.rs
Original file line number Diff line number Diff line change
@@ -1,50 +1,44 @@
use crate::converter::{convert_axis, convert_button, convert_gamepad_id};
use bevy_app::Events;
use bevy_ecs::system::{NonSend, NonSendMut, ResMut};
use bevy_app::EventWriter;
use bevy_ecs::system::{NonSend, NonSendMut};
use bevy_input::{gamepad::GamepadEventRaw, prelude::*};
use gilrs::{EventType, Gilrs};

pub fn gilrs_event_startup_system(
gilrs: NonSend<Gilrs>,
mut event: ResMut<Events<GamepadEventRaw>>,
) {
pub fn gilrs_event_startup_system(gilrs: NonSend<Gilrs>, mut events: EventWriter<GamepadEventRaw>) {
for (id, _) in gilrs.gamepads() {
event.send(GamepadEventRaw(
events.send(GamepadEventRaw(
convert_gamepad_id(id),
GamepadEventType::Connected,
));
}
}

pub fn gilrs_event_system(
mut gilrs: NonSendMut<Gilrs>,
mut event: ResMut<Events<GamepadEventRaw>>,
) {
pub fn gilrs_event_system(mut gilrs: NonSendMut<Gilrs>, mut events: EventWriter<GamepadEventRaw>) {
while let Some(gilrs_event) = gilrs.next_event() {
match gilrs_event.event {
EventType::Connected => {
event.send(GamepadEventRaw(
events.send(GamepadEventRaw(
convert_gamepad_id(gilrs_event.id),
GamepadEventType::Connected,
));
}
EventType::Disconnected => {
event.send(GamepadEventRaw(
events.send(GamepadEventRaw(
convert_gamepad_id(gilrs_event.id),
GamepadEventType::Disconnected,
));
}
EventType::ButtonChanged(gilrs_button, value, _) => {
if let Some(button_type) = convert_button(gilrs_button) {
event.send(GamepadEventRaw(
events.send(GamepadEventRaw(
convert_gamepad_id(gilrs_event.id),
GamepadEventType::ButtonChanged(button_type, value),
));
}
}
EventType::AxisChanged(gilrs_axis, value, _) => {
if let Some(axis_type) = convert_axis(gilrs_axis) {
event.send(GamepadEventRaw(
events.send(GamepadEventRaw(
convert_gamepad_id(gilrs_event.id),
GamepadEventType::AxisChanged(axis_type, value),
));
Expand Down

0 comments on commit 004bbe9

Please sign in to comment.