mirror of
https://github.com/bevyengine/bevy
synced 2024-11-26 06:30:19 +00:00
add Axis::devices
to get all the input devices (#5400)
(github made me type out a message for the commit which looked like it was for the pr, sorry) # Objective - Add a way to get all of the input devices of an `Axis`, primarily useful for looping through them ## Solution - Adds `Axis<T>::devices()` which returns a `FixedSizeIterator<Item = &T>` - Adds a (probably unneeded) `test_axis_devices` test because tests are cool. --- ## Changelog - Added `Axis<T>::devices()` method ## Migration Guide Not a breaking change.
This commit is contained in:
parent
ebc5cb352d
commit
41a5c30fb7
1 changed files with 34 additions and 0 deletions
|
@ -52,6 +52,10 @@ where
|
|||
pub fn remove(&mut self, input_device: T) -> Option<f32> {
|
||||
self.axis_data.remove(&input_device)
|
||||
}
|
||||
/// Returns an iterator of all the input devices that have position data
|
||||
pub fn devices(&self) -> impl ExactSizeIterator<Item = &T> {
|
||||
self.axis_data.keys()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
@ -108,4 +112,34 @@ mod tests {
|
|||
assert_eq!(expected, actual);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_axis_devices() {
|
||||
let mut axis = Axis::<GamepadButton>::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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue