mirror of
https://github.com/bevyengine/bevy
synced 2024-11-22 12:43:34 +00:00
Add a release_all
function to Input
. (#5011)
Adds a `release_all` function to `Input` that releases all of the currently pressed inputs and marks them as just released.
This commit is contained in:
parent
3217f216aa
commit
2ec5ff9652
1 changed files with 17 additions and 0 deletions
|
@ -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)
|
||||
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue