Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - Add a release_all function to Input. #5011

Closed
wants to merge 1 commit into from
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
17 changes: 17 additions & 0 deletions crates/bevy_input/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ where
}
}

/// Registers a release for all currently pressed inputs.
pub fn release_all(&mut self) {
// Move all items from pressed into just_released
self.just_released.extend(self.pressed.drain());
}

/// Returns `true` if the `input` has just been pressed.
pub fn just_pressed(&self, input: T) -> bool {
self.just_pressed.contains(&input)
Expand Down Expand Up @@ -197,6 +203,17 @@ mod test {
assert!(input.just_released.contains(&DummyInput::Input1));
}

#[test]
fn test_release_all() {
let mut input = Input::default();
input.press(DummyInput::Input1);
input.press(DummyInput::Input2);
input.release_all();
assert!(input.pressed.is_empty());
assert!(input.just_released.contains(&DummyInput::Input1));
assert!(input.just_released.contains(&DummyInput::Input2));
}

#[test]
fn test_just_pressed() {
let mut input = Input::default();
Expand Down