Resolve comments

This commit is contained in:
Carter Anderson 2024-11-18 14:07:30 -08:00
parent 0ed7917f4f
commit 9126b38363
3 changed files with 25 additions and 27 deletions

View file

@ -210,7 +210,17 @@ where
/// Returns `true` if any item in `inputs` has just been released. /// Returns `true` if any item in `inputs` has just been released.
pub fn any_just_released(&self, inputs: impl IntoIterator<Item = T>) -> bool { pub fn any_just_released(&self, inputs: impl IntoIterator<Item = T>) -> bool {
inputs.into_iter().any(|it| self.just_released(it)) inputs.into_iter().any(|input| self.just_released(input))
}
/// Returns `true` if all items in `inputs` have just been released.
pub fn all_just_released(&self, inputs: impl IntoIterator<Item = T>) -> bool {
inputs.into_iter().all(|input| self.just_released(input))
}
/// Returns `true` if all items in `inputs` have been just pressed.
pub fn all_just_pressed(&self, inputs: impl IntoIterator<Item = T>) -> bool {
inputs.into_iter().all(|input| self.just_pressed(input))
} }
/// Clears the `just_released` state of the `input` and returns `true` if the `input` has just been released. /// Clears the `just_released` state of the `input` and returns `true` if the `input` has just been released.

View file

@ -414,16 +414,12 @@ impl Gamepad {
/// Returns `true` if any item in the [`GamepadButton`] iterator has been pressed. /// Returns `true` if any item in the [`GamepadButton`] iterator has been pressed.
pub fn any_pressed(&self, button_inputs: impl IntoIterator<Item = GamepadButton>) -> bool { pub fn any_pressed(&self, button_inputs: impl IntoIterator<Item = GamepadButton>) -> bool {
button_inputs self.digital.any_pressed(button_inputs)
.into_iter()
.any(|button_type| self.pressed(button_type))
} }
/// Returns `true` if all items in [`GamepadButton`] have been pressed. /// Returns `true` if all items in the [`GamepadButton`] iterator have been pressed.
pub fn all_pressed(&self, button_inputs: impl IntoIterator<Item = GamepadButton>) -> bool { pub fn all_pressed(&self, button_inputs: impl IntoIterator<Item = GamepadButton>) -> bool {
button_inputs self.digital.all_pressed(button_inputs)
.into_iter()
.all(|button_type| self.pressed(button_type))
} }
/// Returns `true` if the [`GamepadButton`] has been pressed during the current frame. /// Returns `true` if the [`GamepadButton`] has been pressed during the current frame.
@ -433,18 +429,14 @@ impl Gamepad {
self.digital.just_pressed(button_type) self.digital.just_pressed(button_type)
} }
/// Returns `true` if any item in [`GamepadButton`] has been pressed during the current frame. /// Returns `true` if any item in the [`GamepadButton`] iterator has been pressed during the current frame.
pub fn any_just_pressed(&self, button_inputs: impl IntoIterator<Item = GamepadButton>) -> bool { pub fn any_just_pressed(&self, button_inputs: impl IntoIterator<Item = GamepadButton>) -> bool {
button_inputs self.digital.any_just_pressed(button_inputs)
.into_iter()
.any(|button_type| self.just_pressed(button_type))
} }
/// Returns `true` if all items in [`GamepadButton`] have been just pressed. /// Returns `true` if all items in the [`GamepadButton`] iterator have been just pressed.
pub fn all_just_pressed(&self, button_inputs: impl IntoIterator<Item = GamepadButton>) -> bool { pub fn all_just_pressed(&self, button_inputs: impl IntoIterator<Item = GamepadButton>) -> bool {
button_inputs self.digital.all_just_pressed(button_inputs)
.into_iter()
.all(|button_type| self.just_pressed(button_type))
} }
/// Returns `true` if the [`GamepadButton`] has been released during the current frame. /// Returns `true` if the [`GamepadButton`] has been released during the current frame.
@ -454,24 +446,20 @@ impl Gamepad {
self.digital.just_released(button_type) self.digital.just_released(button_type)
} }
/// Returns `true` if any item in [`GamepadButton`] has just been released. /// Returns `true` if any item in the [`GamepadButton`] iterator has just been released.
pub fn any_just_released( pub fn any_just_released(
&self, &self,
button_inputs: impl IntoIterator<Item = GamepadButton>, button_inputs: impl IntoIterator<Item = GamepadButton>,
) -> bool { ) -> bool {
button_inputs self.digital.any_just_released(button_inputs)
.into_iter()
.any(|button_type| self.just_released(button_type))
} }
/// Returns `true` if all items in [`GamepadButton`] have just been released. /// Returns `true` if all items in the [`GamepadButton`] iterator have just been released.
pub fn all_just_released( pub fn all_just_released(
&self, &self,
button_inputs: impl IntoIterator<Item = GamepadButton>, button_inputs: impl IntoIterator<Item = GamepadButton>,
) -> bool { ) -> bool {
button_inputs self.digital.all_just_released(button_inputs)
.into_iter()
.all(|button_type| self.just_released(button_type))
} }
/// Returns an iterator over all digital [button]s that are pressed. /// Returns an iterator over all digital [button]s that are pressed.

View file

@ -393,12 +393,12 @@ fn update_buttons(
materials: Res<ButtonMaterials>, materials: Res<ButtonMaterials>,
mut query: Query<(&mut MeshMaterial2d<ColorMaterial>, &ReactTo)>, mut query: Query<(&mut MeshMaterial2d<ColorMaterial>, &ReactTo)>,
) { ) {
for buttons in &gamepads { for gamepad in &gamepads {
for (mut handle, react_to) in query.iter_mut() { for (mut handle, react_to) in query.iter_mut() {
if buttons.just_pressed(**react_to) { if gamepad.just_pressed(**react_to) {
*handle = materials.active.clone(); *handle = materials.active.clone();
} }
if buttons.just_released(**react_to) { if gamepad.just_released(**react_to) {
*handle = materials.normal.clone(); *handle = materials.normal.clone();
} }
} }