diff --git a/crates/bevy_input/src/input.rs b/crates/bevy_input/src/input.rs index 78a01d8ae5152..86f102dcb5b0b 100644 --- a/crates/bevy_input/src/input.rs +++ b/crates/bevy_input/src/input.rs @@ -129,7 +129,18 @@ where self.just_released.remove(&input); } + /// Clears the `pressed`, `just_pressed`, and `just_released` data for every input. + /// + /// See also [`Input::clear`] for simulating elapsed time steps. + pub fn reset_all(&mut self) { + self.pressed.clear(); + self.just_pressed.clear(); + self.just_released.clear(); + } + /// Clears the `just pressed` and `just released` data for every input. + /// + /// See also [`Input::reset_all`] for a full reset. pub fn clear(&mut self) { self.just_pressed.clear(); self.just_released.clear(); @@ -301,6 +312,22 @@ mod test { assert!(!input.just_released(DummyInput::Input1)); } + #[test] + fn test_reset_all() { + let mut input = Input::default(); + + input.press(DummyInput::Input1); + input.press(DummyInput::Input2); + input.release(DummyInput::Input2); + assert!(input.pressed.contains(&DummyInput::Input1)); + assert!(input.just_pressed.contains(&DummyInput::Input1)); + assert!(input.just_released.contains(&DummyInput::Input2)); + input.reset_all(); + assert!(input.pressed.is_empty()); + assert!(input.just_pressed.is_empty()); + assert!(input.just_released.is_empty()); + } + #[test] fn test_clear() { let mut input = Input::default();