Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions crates/bevy_input/src/axis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,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)]
Expand Down Expand Up @@ -107,4 +111,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);
}
}