From 76f99bdd7040790db2c8d14c44e342b9c7c554c9 Mon Sep 17 00:00:00 2001 From: 1e1001 Date: Wed, 20 Jul 2022 10:22:25 -0700 Subject: [PATCH 1/2] add `Axis::devices` to get all the input devices technically a web edit, but i did the changes locally and it worked fine, i'm just too lazy to figure out how to make a pull request from not the web thing the test is probably not needed but this feels like something that wouldn't error if the implementation were to change --- crates/bevy_input/src/axis.rs | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/crates/bevy_input/src/axis.rs b/crates/bevy_input/src/axis.rs index 5ba80f3ee9c92..d9ce7669c0fed 100644 --- a/crates/bevy_input/src/axis.rs +++ b/crates/bevy_input/src/axis.rs @@ -51,6 +51,10 @@ where pub fn remove(&mut self, input_device: T) -> Option { self.axis_data.remove(&input_device) } + /// Returns an iterator of all the input devices that have position data + pub fn devices(&self) -> impl ExactSizeIterator { + self.axis_data.keys() + } } #[cfg(test)] @@ -107,4 +111,34 @@ mod tests { assert_eq!(expected, actual); } } + + #[test] + fn test_axis_devices() { + let mut axis = Axis::::default(); + assert_eq!(axis.devices().count(), 0); + + axis.set( + GamepadButton::new(Gamepad::new(1), GamepadButtonType::RightTrigger), + 0.1, + ); + assert_eq!(axis.devices().count(), 1); + + axis.set( + GamepadButton::new(Gamepad::new(1), GamepadButtonType::LeftTrigger), + 0.5, + ); + assert_eq!(axis.devices().count(), 2); + + axis.set( + GamepadButton::new(Gamepad::new(1), GamepadButtonType::RightTrigger), + -0.1, + ); + assert_eq!(axis.devices().count(), 2); + + axis.remove(GamepadButton::new( + Gamepad::new(1), + GamepadButtonType::RightTrigger, + )); + assert_eq!(axis.devices().count(), 1); + } } From 1ec5cb03209623d031282255f9061436e20f5c36 Mon Sep 17 00:00:00 2001 From: 1e1001 Date: Wed, 20 Jul 2022 10:52:35 -0700 Subject: [PATCH 2/2] remove four spaces so ci doesn't cry --- crates/bevy_input/src/axis.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_input/src/axis.rs b/crates/bevy_input/src/axis.rs index d9ce7669c0fed..20f0bbbc895e9 100644 --- a/crates/bevy_input/src/axis.rs +++ b/crates/bevy_input/src/axis.rs @@ -111,7 +111,7 @@ mod tests { assert_eq!(expected, actual); } } - + #[test] fn test_axis_devices() { let mut axis = Axis::::default();