Skip to content

Commit

Permalink
Rename Input to PressableInput
Browse files Browse the repository at this point in the history
  • Loading branch information
matiqo15 committed Dec 3, 2023
1 parent 4d42713 commit 7d43744
Show file tree
Hide file tree
Showing 66 changed files with 198 additions and 175 deletions.
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::PressableInput;
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 [`PressableInput::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<PressableInput<T>>) -> bool + Clone
where
T: Copy + Eq + Hash + Send + Sync + 'static,
{
let mut active = default;
move |inputs: Res<Input<T>>| {
move |inputs: Res<PressableInput<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 [`PressableInput::pressed`] is true for the given input.
pub fn input_pressed<T>(input: T) -> impl FnMut(Res<PressableInput<T>>) -> bool + Clone
where
T: Copy + Eq + Hash + Send + Sync + 'static,
{
move |inputs: Res<Input<T>>| inputs.pressed(input)
move |inputs: Res<PressableInput<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 [`PressableInput::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<PressableInput<T>>) -> bool + Clone
where
T: Copy + Eq + Hash + Send + Sync + 'static,
{
move |inputs: Res<Input<T>>| inputs.just_pressed(input)
move |inputs: Res<PressableInput<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 [`PressableInput::just_released`] is true for the given input.
pub fn input_just_released<T>(input: T) -> impl FnMut(Res<PressableInput<T>>) -> bool + Clone
where
T: Copy + Eq + Hash + Send + Sync + 'static,
{
move |inputs: Res<Input<T>>| inputs.just_released(input)
move |inputs: Res<PressableInput<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, ButtonState, PressableInput};
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 [`PressableInput<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 [`PressableInput`] 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 [`PressableInput<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<PressableInput<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 [`PressableInput`] 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 [`PressableInput`] 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<PressableInput<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<PressableInput<GamepadButton>>,
) {
button_input.bypass_change_detection().clear();
for gamepad_event in gamepad_events.read() {
Expand Down
Loading

0 comments on commit 7d43744

Please sign in to comment.