Skip to content

Commit

Permalink
Add Input::reset_all (#5015)
Browse files Browse the repository at this point in the history
Adds a `reset_all` method to reset `pressed`, `just_pressed`, and `just_released` on the `Input`.

Fixes #3383
  • Loading branch information
Hoidigan committed Jun 20, 2022
1 parent 9089c8b commit 984ce3f
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions crates/bevy_input/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 984ce3f

Please sign in to comment.