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

Rename Input to ButtonInput #10859

Merged
merged 2 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
29 changes: 16 additions & 13 deletions crates/bevy_input/src/common_conditions.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::Input;
use crate::ButtonInput;
use bevy_ecs::system::Res;
use std::hash::Hash;

/// Stateful run condition that can be toggled via a input press using [`Input::just_pressed`].
/// Stateful run condition that can be toggled via a input press using [`ButtonInput::just_pressed`].
///
/// ```rust,no_run
/// use bevy::prelude::*;
Expand Down Expand Up @@ -47,26 +47,29 @@ use std::hash::Hash;
/// }
///
/// ```
pub fn input_toggle_active<T>(default: bool, input: T) -> impl FnMut(Res<Input<T>>) -> bool + Clone
pub fn input_toggle_active<T>(
default: bool,
input: T,
) -> impl FnMut(Res<ButtonInput<T>>) -> bool + Clone
where
T: Copy + Eq + Hash + Send + Sync + 'static,
{
let mut active = default;
move |inputs: Res<Input<T>>| {
move |inputs: Res<ButtonInput<T>>| {
active ^= inputs.just_pressed(input);
active
}
}

/// Run condition that is active if [`Input::pressed`] is true for the given input.
pub fn input_pressed<T>(input: T) -> impl FnMut(Res<Input<T>>) -> bool + Clone
/// Run condition that is active if [`ButtonInput::pressed`] is true for the given input.
pub fn input_pressed<T>(input: T) -> impl FnMut(Res<ButtonInput<T>>) -> bool + Clone
where
T: Copy + Eq + Hash + Send + Sync + 'static,
{
move |inputs: Res<Input<T>>| inputs.pressed(input)
move |inputs: Res<ButtonInput<T>>| inputs.pressed(input)
}

/// Run condition that is active if [`Input::just_pressed`] is true for the given input.
/// Run condition that is active if [`ButtonInput::just_pressed`] is true for the given input.
///
/// ```rust,no_run
/// use bevy::prelude::*;
Expand All @@ -80,19 +83,19 @@ where
///
/// # fn jump() {}
/// ```
pub fn input_just_pressed<T>(input: T) -> impl FnMut(Res<Input<T>>) -> bool + Clone
pub fn input_just_pressed<T>(input: T) -> impl FnMut(Res<ButtonInput<T>>) -> bool + Clone
where
T: Copy + Eq + Hash + Send + Sync + 'static,
{
move |inputs: Res<Input<T>>| inputs.just_pressed(input)
move |inputs: Res<ButtonInput<T>>| inputs.just_pressed(input)
}

/// Run condition that is active if [`Input::just_released`] is true for the given input.
pub fn input_just_released<T>(input: T) -> impl FnMut(Res<Input<T>>) -> bool + Clone
/// Run condition that is active if [`ButtonInput::just_released`] is true for the given input.
pub fn input_just_released<T>(input: T) -> impl FnMut(Res<ButtonInput<T>>) -> bool + Clone
where
T: Copy + Eq + Hash + Send + Sync + 'static,
{
move |inputs: Res<Input<T>>| inputs.just_released(input)
move |inputs: Res<ButtonInput<T>>| inputs.just_released(input)
}

#[cfg(test)]
Expand Down
18 changes: 9 additions & 9 deletions crates/bevy_input/src/gamepad.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! The gamepad input functionality.

use crate::{Axis, ButtonState, Input};
use crate::{Axis, ButtonInput, ButtonState};
use bevy_ecs::event::{Event, EventReader, EventWriter};
use bevy_ecs::{
change_detection::DetectChangesMut,
Expand Down Expand Up @@ -165,7 +165,7 @@ impl Gamepads {
///
/// This is used to determine which button has changed its value when receiving a
/// [`GamepadButtonChangedEvent`]. It is also used in the [`GamepadButton`]
/// which in turn is used to create the [`Input<GamepadButton>`] or
/// which in turn is used to create the [`ButtonInput<GamepadButton>`] or
/// [`Axis<GamepadButton>`] `bevy` resources.
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Reflect)]
#[reflect(Debug, Hash, PartialEq)]
Expand Down Expand Up @@ -226,7 +226,7 @@ pub enum GamepadButtonType {
///
/// ## Usage
///
/// It is used as the generic `T` value of an [`Input`] and [`Axis`] to create `bevy` resources. These
/// It is used as the generic `T` value of an [`ButtonInput`] and [`Axis`] to create `bevy` resources. These
/// resources store the data of the buttons of a gamepad and can be accessed inside of a system.
///
/// ## Updating
Expand Down Expand Up @@ -1011,7 +1011,7 @@ impl ButtonAxisSettings {
/// Handles [`GamepadConnectionEvent`]s and updates gamepad resources.
///
/// Updates the [`Gamepads`] resource and resets and/or initializes
/// the [`Axis<GamepadButton>`] and [`Input<GamepadButton>`] resources.
/// the [`Axis<GamepadButton>`] and [`ButtonInput<GamepadButton>`] resources.
///
/// ## Note
///
Expand All @@ -1021,7 +1021,7 @@ pub fn gamepad_connection_system(
mut connection_events: EventReader<GamepadConnectionEvent>,
mut axis: ResMut<Axis<GamepadAxis>>,
mut button_axis: ResMut<Axis<GamepadButton>>,
mut button_input: ResMut<Input<GamepadButton>>,
mut button_input: ResMut<ButtonInput<GamepadButton>>,
) {
for connection_event in connection_events.read() {
let gamepad = connection_event.gamepad;
Expand Down Expand Up @@ -1163,7 +1163,7 @@ impl GamepadButtonChangedEvent {
}
}

/// Uses [`GamepadAxisChangedEvent`]s to update the relevant [`Input`] and [`Axis`] values.
/// Uses [`GamepadAxisChangedEvent`]s to update the relevant [`ButtonInput`] and [`Axis`] values.
pub fn gamepad_axis_event_system(
mut gamepad_axis: ResMut<Axis<GamepadAxis>>,
mut axis_events: EventReader<GamepadAxisChangedEvent>,
Expand All @@ -1174,10 +1174,10 @@ pub fn gamepad_axis_event_system(
}
}

/// Uses [`GamepadButtonChangedEvent`]s to update the relevant [`Input`] and [`Axis`] values.
/// Uses [`GamepadButtonChangedEvent`]s to update the relevant [`ButtonInput`] and [`Axis`] values.
pub fn gamepad_button_event_system(
mut button_changed_events: EventReader<GamepadButtonChangedEvent>,
mut button_input: ResMut<Input<GamepadButton>>,
mut button_input: ResMut<ButtonInput<GamepadButton>>,
mut button_input_events: EventWriter<GamepadButtonInput>,
settings: Res<GamepadSettings>,
) {
Expand Down Expand Up @@ -1255,7 +1255,7 @@ pub fn gamepad_event_system(
mut connection_events: EventWriter<GamepadConnectionEvent>,
mut button_events: EventWriter<GamepadButtonChangedEvent>,
mut axis_events: EventWriter<GamepadAxisChangedEvent>,
mut button_input: ResMut<Input<GamepadButton>>,
mut button_input: ResMut<ButtonInput<GamepadButton>>,
) {
button_input.bypass_change_detection().clear();
for gamepad_event in gamepad_events.read() {
Expand Down
Loading