Skip to content

Commit

Permalink
Add Input::reset_all (bevyengine#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 bevyengine#3383
  • Loading branch information
Hoidigan authored and inodentry committed Aug 8, 2022
1 parent 699e1af commit 69f34f3
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 69f34f3

Please sign in to comment.