Rename Input to ButtonInput (#10859)

# Objective

- Resolves #10853 

## Solution

- ~~Changed the name of `Input` struct to `PressableInput`.~~
- Changed the name of `Input` struct to `ButtonInput`.

## Migration Guide

- Breaking Change: Users need to rename `Input` to `ButtonInput` in
their projects.
This commit is contained in:
Mateusz Wachowiak 2023-12-06 21:32:34 +01:00 committed by GitHub
parent d9aac887b5
commit 1f97717a3d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
66 changed files with 200 additions and 177 deletions

View file

@ -16,26 +16,26 @@ use bevy_ecs::schedule::State;
/// This type can be used as a resource to keep the current state of an input, by reacting to
/// events from the input. For a given input value:
///
/// * [`Input::pressed`] will return `true` between a press and a release event.
/// * [`Input::just_pressed`] will return `true` for one frame after a press event.
/// * [`Input::just_released`] will return `true` for one frame after a release event.
/// * [`ButtonInput::pressed`] will return `true` between a press and a release event.
/// * [`ButtonInput::just_pressed`] will return `true` for one frame after a press event.
/// * [`ButtonInput::just_released`] will return `true` for one frame after a release event.
///
/// ## Multiple systems
///
/// In case multiple systems are checking for [`Input::just_pressed`] or [`Input::just_released`]
/// In case multiple systems are checking for [`ButtonInput::just_pressed`] or [`ButtonInput::just_released`]
/// but only one should react, for example in the case of triggering
/// [`State`] change, you should consider clearing the input state, either by:
///
/// * Using [`Input::clear_just_pressed`] or [`Input::clear_just_released`] instead.
/// * Calling [`Input::clear`] or [`Input::reset`] immediately after the state change.
/// * Using [`ButtonInput::clear_just_pressed`] or [`ButtonInput::clear_just_released`] instead.
/// * Calling [`ButtonInput::clear`] or [`ButtonInput::reset`] immediately after the state change.
///
/// ## Note
///
/// When adding this resource for a new input type, you should:
///
/// * Call the [`Input::press`] method for each press event.
/// * Call the [`Input::release`] method for each release event.
/// * Call the [`Input::clear`] method at each frame start, before processing events.
/// * Call the [`ButtonInput::press`] method for each press event.
/// * Call the [`ButtonInput::release`] method for each release event.
/// * Call the [`ButtonInput::clear`] method at each frame start, before processing events.
///
/// Note: Calling `clear` from a [`ResMut`] will trigger change detection.
/// It may be preferable to use [`DetectChangesMut::bypass_change_detection`]
@ -45,7 +45,7 @@ use bevy_ecs::schedule::State;
///[`DetectChangesMut::bypass_change_detection`]: bevy_ecs::change_detection::DetectChangesMut::bypass_change_detection
#[derive(Debug, Clone, Resource, Reflect)]
#[reflect(Default)]
pub struct Input<T: Copy + Eq + Hash + Send + Sync + 'static> {
pub struct ButtonInput<T: Copy + Eq + Hash + Send + Sync + 'static> {
/// A collection of every button that is currently being pressed.
pressed: HashSet<T>,
/// A collection of every button that has just been pressed.
@ -54,7 +54,7 @@ pub struct Input<T: Copy + Eq + Hash + Send + Sync + 'static> {
just_released: HashSet<T>,
}
impl<T: Copy + Eq + Hash + Send + Sync + 'static> Default for Input<T> {
impl<T: Copy + Eq + Hash + Send + Sync + 'static> Default for ButtonInput<T> {
fn default() -> Self {
Self {
pressed: Default::default(),
@ -64,7 +64,7 @@ impl<T: Copy + Eq + Hash + Send + Sync + 'static> Default for Input<T> {
}
}
impl<T> Input<T>
impl<T> ButtonInput<T>
where
T: Copy + Eq + Hash + Send + Sync + 'static,
{
@ -112,7 +112,7 @@ where
/// Clears the `just_pressed` state of the `input` and returns `true` if the `input` has just been pressed.
///
/// Future calls to [`Input::just_pressed`] for the given input will return false until a new press event occurs.
/// Future calls to [`ButtonInput::just_pressed`] for the given input will return false until a new press event occurs.
pub fn clear_just_pressed(&mut self, input: T) -> bool {
self.just_pressed.remove(&input)
}
@ -129,7 +129,7 @@ where
/// Clears the `just_released` state of the `input` and returns `true` if the `input` has just been released.
///
/// Future calls to [`Input::just_released`] for the given input will return false until a new release event occurs.
/// Future calls to [`ButtonInput::just_released`] for the given input will return false until a new release event occurs.
pub fn clear_just_released(&mut self, input: T) -> bool {
self.just_released.remove(&input)
}
@ -143,7 +143,7 @@ where
/// Clears the `pressed`, `just_pressed`, and `just_released` data for every input.
///
/// See also [`Input::clear`] for simulating elapsed time steps.
/// See also [`ButtonInput::clear`] for simulating elapsed time steps.
pub fn reset_all(&mut self) {
self.pressed.clear();
self.just_pressed.clear();
@ -152,7 +152,7 @@ where
/// Clears the `just pressed` and `just released` data for every input.
///
/// See also [`Input::reset_all`] for a full reset.
/// See also [`ButtonInput::reset_all`] for a full reset.
pub fn clear(&mut self) {
self.just_pressed.clear();
self.just_released.clear();
@ -178,9 +178,9 @@ where
mod test {
use bevy_reflect::TypePath;
use crate::Input;
use crate::ButtonInput;
/// Used for testing the functionality of [`Input`].
/// Used for testing the functionality of [`ButtonInput`].
#[derive(TypePath, Copy, Clone, Eq, PartialEq, Hash)]
enum DummyInput {
Input1,
@ -189,7 +189,7 @@ mod test {
#[test]
fn test_press() {
let mut input = Input::default();
let mut input = ButtonInput::default();
assert!(!input.pressed.contains(&DummyInput::Input1));
assert!(!input.just_pressed.contains(&DummyInput::Input1));
input.press(DummyInput::Input1);
@ -199,7 +199,7 @@ mod test {
#[test]
fn test_pressed() {
let mut input = Input::default();
let mut input = ButtonInput::default();
assert!(!input.pressed(DummyInput::Input1));
input.press(DummyInput::Input1);
assert!(input.pressed(DummyInput::Input1));
@ -207,7 +207,7 @@ mod test {
#[test]
fn test_any_pressed() {
let mut input = Input::default();
let mut input = ButtonInput::default();
assert!(!input.any_pressed([DummyInput::Input1]));
assert!(!input.any_pressed([DummyInput::Input2]));
assert!(!input.any_pressed([DummyInput::Input1, DummyInput::Input2]));
@ -219,7 +219,7 @@ mod test {
#[test]
fn test_release() {
let mut input = Input::default();
let mut input = ButtonInput::default();
input.press(DummyInput::Input1);
assert!(input.pressed.contains(&DummyInput::Input1));
assert!(!input.just_released.contains(&DummyInput::Input1));
@ -230,7 +230,7 @@ mod test {
#[test]
fn test_release_all() {
let mut input = Input::default();
let mut input = ButtonInput::default();
input.press(DummyInput::Input1);
input.press(DummyInput::Input2);
input.release_all();
@ -241,7 +241,7 @@ mod test {
#[test]
fn test_just_pressed() {
let mut input = Input::default();
let mut input = ButtonInput::default();
assert!(!input.just_pressed(DummyInput::Input1));
input.press(DummyInput::Input1);
assert!(input.just_pressed(DummyInput::Input1));
@ -249,7 +249,7 @@ mod test {
#[test]
fn test_any_just_pressed() {
let mut input = Input::default();
let mut input = ButtonInput::default();
assert!(!input.any_just_pressed([DummyInput::Input1]));
assert!(!input.any_just_pressed([DummyInput::Input2]));
assert!(!input.any_just_pressed([DummyInput::Input1, DummyInput::Input2]));
@ -261,7 +261,7 @@ mod test {
#[test]
fn test_clear_just_pressed() {
let mut input = Input::default();
let mut input = ButtonInput::default();
input.press(DummyInput::Input1);
assert!(input.just_pressed(DummyInput::Input1));
input.clear_just_pressed(DummyInput::Input1);
@ -270,7 +270,7 @@ mod test {
#[test]
fn test_just_released() {
let mut input = Input::default();
let mut input = ButtonInput::default();
input.press(DummyInput::Input1);
assert!(!input.just_released(DummyInput::Input1));
input.release(DummyInput::Input1);
@ -279,7 +279,7 @@ mod test {
#[test]
fn test_any_just_released() {
let mut input = Input::default();
let mut input = ButtonInput::default();
input.press(DummyInput::Input1);
assert!(!input.any_just_released([DummyInput::Input1]));
assert!(!input.any_just_released([DummyInput::Input2]));
@ -292,7 +292,7 @@ mod test {
#[test]
fn test_clear_just_released() {
let mut input = Input::default();
let mut input = ButtonInput::default();
input.press(DummyInput::Input1);
input.release(DummyInput::Input1);
assert!(input.just_released(DummyInput::Input1));
@ -302,7 +302,7 @@ mod test {
#[test]
fn test_reset() {
let mut input = Input::default();
let mut input = ButtonInput::default();
// Pressed
input.press(DummyInput::Input1);
@ -328,7 +328,7 @@ mod test {
#[test]
fn test_reset_all() {
let mut input = Input::default();
let mut input = ButtonInput::default();
input.press(DummyInput::Input1);
input.press(DummyInput::Input2);
@ -344,7 +344,7 @@ mod test {
#[test]
fn test_clear() {
let mut input = Input::default();
let mut input = ButtonInput::default();
// Pressed
input.press(DummyInput::Input1);
@ -370,7 +370,7 @@ mod test {
#[test]
fn test_get_pressed() {
let mut input = Input::default();
let mut input = ButtonInput::default();
input.press(DummyInput::Input1);
input.press(DummyInput::Input2);
let pressed = input.get_pressed();
@ -382,7 +382,7 @@ mod test {
#[test]
fn test_get_just_pressed() {
let mut input = Input::default();
let mut input = ButtonInput::default();
input.press(DummyInput::Input1);
input.press(DummyInput::Input2);
let just_pressed = input.get_just_pressed();
@ -394,7 +394,7 @@ mod test {
#[test]
fn test_get_just_released() {
let mut input = Input::default();
let mut input = ButtonInput::default();
input.press(DummyInput::Input1);
input.press(DummyInput::Input2);
input.release(DummyInput::Input1);
@ -408,7 +408,7 @@ mod test {
#[test]
fn test_general_input_handling() {
let mut input = Input::default();
let mut input = ButtonInput::default();
// Test pressing
input.press(DummyInput::Input1);
@ -453,7 +453,7 @@ mod test {
assert!(!input.just_released(DummyInput::Input2));
// Set up an `Input` to test resetting
let mut input = Input::default();
let mut input = ButtonInput::default();
input.press(DummyInput::Input1);
input.release(DummyInput::Input2);

View file

@ -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::*;
@ -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::*;
@ -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)]

View file

@ -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,
@ -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)]
@ -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
@ -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
///
@ -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;
@ -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>,
@ -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>,
) {
@ -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() {

View file

@ -1,6 +1,6 @@
//! The keyboard input functionality.
use crate::{ButtonState, Input};
use crate::{ButtonInput, ButtonState};
use bevy_ecs::entity::Entity;
use bevy_ecs::{
change_detection::DetectChangesMut,
@ -20,7 +20,7 @@ use bevy_reflect::{ReflectDeserialize, ReflectSerialize};
/// ## Usage
///
/// The event is consumed inside of the [`keyboard_input_system`]
/// to update the [`Input<KeyCode>`](Input<KeyCode>) resource.
/// to update the [`Input<KeyCode>`](ButtonInput<KeyCode>) resource.
#[derive(Event, Debug, Clone, Copy, PartialEq, Eq, Reflect)]
#[reflect(Debug, PartialEq)]
#[cfg_attr(
@ -39,15 +39,15 @@ pub struct KeyboardInput {
pub window: Entity,
}
/// Updates the [`Input<KeyCode>`] resource with the latest [`KeyboardInput`] events.
/// Updates the [`ButtonInput<KeyCode>`] resource with the latest [`KeyboardInput`] events.
///
/// ## Differences
///
/// The main difference between the [`KeyboardInput`] event and the [`Input<KeyCode>`] or [`Input<ScanCode>`] resources is that
/// the latter have convenient functions such as [`Input::pressed`], [`Input::just_pressed`] and [`Input::just_released`].
/// The main difference between the [`KeyboardInput`] event and the [`ButtonInput<KeyCode>`] or [`ButtonInput<ScanCode>`] resources is that
/// the latter have convenient functions such as [`ButtonInput::pressed`], [`ButtonInput::just_pressed`] and [`ButtonInput::just_released`].
pub fn keyboard_input_system(
mut scan_input: ResMut<Input<ScanCode>>,
mut key_input: ResMut<Input<KeyCode>>,
mut scan_input: ResMut<ButtonInput<ScanCode>>,
mut key_input: ResMut<ButtonInput<KeyCode>>,
mut keyboard_input_events: EventReader<KeyboardInput>,
) {
// Avoid clearing if it's not empty to ensure change detection is not triggered.
@ -74,7 +74,7 @@ pub fn keyboard_input_system(
///
/// ## Usage
///
/// It is used as the generic `T` value of an [`Input`] to create a `Res<Input<KeyCode>>`.
/// It is used as the generic `T` value of an [`ButtonInput`] to create a `Res<Input<KeyCode>>`.
/// The resource values are mapped to the current layout of the keyboard and correlate to an [`ScanCode`].
///
/// ## Updating
@ -447,7 +447,7 @@ pub enum KeyCode {
///
/// ## Usage
///
/// It is used as the generic `<T>` value of an [`Input`] to create a `Res<Input<ScanCode>>`.
/// It is used as the generic `<T>` value of an [`ButtonInput`] to create a `Res<Input<ScanCode>>`.
/// The resource values are mapped to the physical location of a key on the keyboard and correlate to an [`KeyCode`]
///
/// ## Updating

View file

@ -7,17 +7,17 @@
//! `bevy` currently supports keyboard, mouse, gamepad, and touch inputs.
mod axis;
mod button_input;
/// Common run conditions
pub mod common_conditions;
pub mod gamepad;
mod input;
pub mod keyboard;
pub mod mouse;
pub mod touch;
pub mod touchpad;
pub use axis::*;
pub use input::*;
pub use button_input::*;
/// Most commonly used re-exported types.
pub mod prelude {
@ -29,7 +29,7 @@ pub mod prelude {
keyboard::{KeyCode, ScanCode},
mouse::MouseButton,
touch::{TouchInput, Touches},
Axis, Input,
Axis, ButtonInput,
};
}
@ -68,14 +68,14 @@ impl Plugin for InputPlugin {
app
// keyboard
.add_event::<KeyboardInput>()
.init_resource::<Input<KeyCode>>()
.init_resource::<Input<ScanCode>>()
.init_resource::<ButtonInput<KeyCode>>()
.init_resource::<ButtonInput<ScanCode>>()
.add_systems(PreUpdate, keyboard_input_system.in_set(InputSystem))
// mouse
.add_event::<MouseButtonInput>()
.add_event::<MouseMotion>()
.add_event::<MouseWheel>()
.init_resource::<Input<MouseButton>>()
.init_resource::<ButtonInput<MouseButton>>()
.add_systems(PreUpdate, mouse_button_input_system.in_set(InputSystem))
.add_event::<TouchpadMagnify>()
.add_event::<TouchpadRotate>()
@ -88,7 +88,7 @@ impl Plugin for InputPlugin {
.add_event::<GamepadRumbleRequest>()
.init_resource::<GamepadSettings>()
.init_resource::<Gamepads>()
.init_resource::<Input<GamepadButton>>()
.init_resource::<ButtonInput<GamepadButton>>()
.init_resource::<Axis<GamepadAxis>>()
.init_resource::<Axis<GamepadButton>>()
.add_systems(

View file

@ -1,6 +1,6 @@
//! The mouse input functionality.
use crate::{ButtonState, Input};
use crate::{ButtonInput, ButtonState};
use bevy_ecs::entity::Entity;
use bevy_ecs::{
change_detection::DetectChangesMut,
@ -20,7 +20,7 @@ use bevy_reflect::{ReflectDeserialize, ReflectSerialize};
/// ## Usage
///
/// The event is read inside of the [`mouse_button_input_system`]
/// to update the [`Input<MouseButton>`](Input<MouseButton>) resource.
/// to update the [`Input<MouseButton>`](ButtonInput<MouseButton>) resource.
#[derive(Event, Debug, Clone, Copy, PartialEq, Eq, Reflect)]
#[reflect(Debug, PartialEq)]
#[cfg_attr(
@ -41,7 +41,7 @@ pub struct MouseButtonInput {
///
/// ## Usage
///
/// It is used as the generic `T` value of an [`Input`] to create a `bevy`
/// It is used as the generic `T` value of an [`ButtonInput`] to create a `bevy`
/// resource.
///
/// ## Updating
@ -133,14 +133,14 @@ pub struct MouseWheel {
pub window: Entity,
}
/// Updates the [`Input<MouseButton>`] resource with the latest [`MouseButtonInput`] events.
/// Updates the [`ButtonInput<MouseButton>`] resource with the latest [`MouseButtonInput`] events.
///
/// ## Differences
///
/// The main difference between the [`MouseButtonInput`] event and the [`Input<MouseButton>`] resource is that
/// the latter has convenient functions like [`Input::pressed`], [`Input::just_pressed`] and [`Input::just_released`].
/// The main difference between the [`MouseButtonInput`] event and the [`ButtonInput<MouseButton>`] resource is that
/// the latter has convenient functions like [`ButtonInput::pressed`], [`ButtonInput::just_pressed`] and [`ButtonInput::just_released`].
pub fn mouse_button_input_system(
mut mouse_button_input: ResMut<Input<MouseButton>>,
mut mouse_button_input: ResMut<ButtonInput<MouseButton>>,
mut mouse_button_input_events: EventReader<MouseButtonInput>,
) {
mouse_button_input.bypass_change_detection().clear();

View file

@ -7,7 +7,7 @@ use bevy_ecs::{
reflect::ReflectComponent,
system::{Local, Query, Res},
};
use bevy_input::{mouse::MouseButton, touch::Touches, Input};
use bevy_input::{mouse::MouseButton, touch::Touches, ButtonInput};
use bevy_math::{Rect, Vec2};
use bevy_reflect::{Reflect, ReflectDeserialize, ReflectSerialize};
use bevy_render::{camera::NormalizedRenderTarget, prelude::Camera, view::ViewVisibility};
@ -126,7 +126,7 @@ pub fn ui_focus_system(
mut state: Local<State>,
camera: Query<(&Camera, Option<&UiCameraConfig>)>,
windows: Query<&Window>,
mouse_button_input: Res<Input<MouseButton>>,
mouse_button_input: Res<ButtonInput<MouseButton>>,
touches_input: Res<Touches>,
ui_scale: Res<UiScale>,
ui_stack: Res<UiStack>,

View file

@ -2,7 +2,7 @@ use crate::{PrimaryWindow, Window, WindowCloseRequested};
use bevy_app::AppExit;
use bevy_ecs::prelude::*;
use bevy_input::{keyboard::KeyCode, Input};
use bevy_input::{keyboard::KeyCode, ButtonInput};
/// Exit the application when there are no open windows.
///
@ -52,7 +52,7 @@ pub fn close_when_requested(mut commands: Commands, mut closed: EventReader<Wind
pub fn close_on_esc(
mut commands: Commands,
focused_windows: Query<(Entity, &Window)>,
input: Res<Input<KeyCode>>,
input: Res<ButtonInput<KeyCode>>,
) {
for (window, focus) in focused_windows.iter() {
if !focus.focused {

View file

@ -61,7 +61,11 @@ fn system(mut gizmos: Gizmos, time: Res<Time>) {
);
}
fn update_config(mut config: ResMut<GizmoConfig>, keyboard: Res<Input<KeyCode>>, time: Res<Time>) {
fn update_config(
mut config: ResMut<GizmoConfig>,
keyboard: Res<ButtonInput<KeyCode>>,
time: Res<Time>,
) {
if keyboard.pressed(KeyCode::Right) {
config.line_width += 5. * time.delta_seconds();
}

View file

@ -91,7 +91,7 @@ fn update_bloom_settings(
mut camera: Query<(Entity, Option<&mut BloomSettings>), With<Camera>>,
mut text: Query<&mut Text>,
mut commands: Commands,
keycode: Res<Input<KeyCode>>,
keycode: Res<ButtonInput<KeyCode>>,
time: Res<Time>,
) {
let bloom_settings = camera.single_mut();

View file

@ -117,7 +117,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
/// Demonstrates applying rotation and movement based on keyboard input.
fn player_movement_system(
time: Res<Time>,
keyboard_input: Res<Input<KeyCode>>,
keyboard_input: Res<ButtonInput<KeyCode>>,
mut query: Query<(&Player, &mut Transform)>,
) {
let (ship, mut transform) = query.single_mut();

View file

@ -106,7 +106,11 @@ fn rotate_camera(mut query: Query<&mut Transform, With<Camera>>, time: Res<Time>
transform.rotate_around(Vec3::ZERO, Quat::from_rotation_y(time.delta_seconds() / 2.));
}
fn update_config(mut config: ResMut<GizmoConfig>, keyboard: Res<Input<KeyCode>>, time: Res<Time>) {
fn update_config(
mut config: ResMut<GizmoConfig>,
keyboard: Res<ButtonInput<KeyCode>>,
time: Res<Time>,
) {
if keyboard.just_pressed(KeyCode::D) {
config.depth_bias = if config.depth_bias == 0. { -1. } else { 0. };
}

View file

@ -28,7 +28,7 @@ fn main() {
}
fn modify_aa(
keys: Res<Input<KeyCode>>,
keys: Res<ButtonInput<KeyCode>>,
mut camera: Query<
(
Entity,
@ -113,7 +113,7 @@ fn modify_aa(
}
fn modify_sharpening(
keys: Res<Input<KeyCode>>,
keys: Res<ButtonInput<KeyCode>>,
mut query: Query<&mut ContrastAdaptiveSharpeningSettings>,
) {
for mut cas in &mut query {

View file

@ -111,7 +111,7 @@ fn setup_instructions(mut commands: Commands) {
);
}
fn toggle_system(keycode: Res<Input<KeyCode>>, mut fog: Query<&mut FogSettings>) {
fn toggle_system(keycode: Res<ButtonInput<KeyCode>>, mut fog: Query<&mut FogSettings>) {
let mut fog_settings = fog.single_mut();
if keycode.just_pressed(KeyCode::Space) {

View file

@ -290,7 +290,7 @@ fn example_control_system(
labelled: Query<&GlobalTransform>,
mut state: Local<ExampleState>,
time: Res<Time>,
input: Res<Input<KeyCode>>,
input: Res<ButtonInput<KeyCode>>,
) {
if input.pressed(KeyCode::Up) {
state.alpha = (state.alpha + time.delta_seconds()).min(1.0);

View file

@ -115,7 +115,7 @@ fn update_bloom_settings(
mut camera: Query<(Entity, Option<&mut BloomSettings>), With<Camera>>,
mut text: Query<&mut Text>,
mut commands: Commands,
keycode: Res<Input<KeyCode>>,
keycode: Res<ButtonInput<KeyCode>>,
time: Res<Time>,
) {
let bloom_settings = camera.single_mut();

View file

@ -335,7 +335,7 @@ enum DefaultRenderMode {
fn switch_mode(
mut text: Query<&mut Text>,
mut commands: Commands,
keys: Res<Input<KeyCode>>,
keys: Res<ButtonInput<KeyCode>>,
mut default_opaque_renderer_method: ResMut<DefaultOpaqueRendererMethod>,
mut materials: ResMut<Assets<StandardMaterial>>,
cameras: Query<Entity, With<Camera>>,

View file

@ -159,7 +159,7 @@ fn update_system(
mut camera: Query<(&mut FogSettings, &mut Transform)>,
mut text: Query<&mut Text>,
time: Res<Time>,
keycode: Res<Input<KeyCode>>,
keycode: Res<ButtonInput<KeyCode>>,
) {
let now = time.elapsed_seconds();
let delta = time.delta_seconds();

View file

@ -85,7 +85,7 @@ fn setup(
// System to receive input from the user,
// check out examples/input/ for more examples about user input.
fn input_handler(
keyboard_input: Res<Input<KeyCode>>,
keyboard_input: Res<ButtonInput<KeyCode>>,
mesh_query: Query<&Handle<Mesh>, With<CustomUV>>,
mut meshes: ResMut<Assets<Mesh>>,
mut query: Query<&mut Transform, With<CustomUV>>,

View file

@ -261,7 +261,7 @@ fn animate_light_direction(
}
fn movement(
input: Res<Input<KeyCode>>,
input: Res<ButtonInput<KeyCode>>,
time: Res<Time>,
mut query: Query<&mut Transform, With<Movable>>,
) {

View file

@ -79,7 +79,7 @@ impl CurrentMethod {
}
fn update_parallax_depth_scale(
input: Res<Input<KeyCode>>,
input: Res<ButtonInput<KeyCode>>,
mut materials: ResMut<Assets<StandardMaterial>>,
mut target_depth: Local<TargetDepth>,
mut depth_update: Local<bool>,
@ -111,7 +111,7 @@ fn update_parallax_depth_scale(
}
fn switch_method(
input: Res<Input<KeyCode>>,
input: Res<ButtonInput<KeyCode>>,
mut materials: ResMut<Assets<StandardMaterial>>,
mut text: Query<&mut Text>,
mut current: Local<CurrentMethod>,
@ -130,7 +130,7 @@ fn switch_method(
}
fn update_parallax_layers(
input: Res<Input<KeyCode>>,
input: Res<ButtonInput<KeyCode>>,
mut materials: ResMut<Assets<StandardMaterial>>,
mut target_layers: Local<TargetLayers>,
mut text: Query<&mut Text>,
@ -187,7 +187,7 @@ const CAMERA_POSITIONS: &[Transform] = &[
fn move_camera(
mut camera: Query<&mut Transform, With<CameraController>>,
mut current_view: Local<usize>,
button: Res<Input<MouseButton>>,
button: Res<ButtonInput<MouseButton>>,
) {
let mut camera = camera.single_mut();
if button.just_pressed(MouseButton::Left) {

View file

@ -187,7 +187,7 @@ fn setup(
}
fn toggle_light(
input: Res<Input<KeyCode>>,
input: Res<ButtonInput<KeyCode>>,
mut point_lights: Query<&mut PointLight>,
mut directional_lights: Query<&mut DirectionalLight>,
mut example_text: Query<&mut Text>,
@ -213,7 +213,7 @@ fn toggle_light(
}
fn adjust_light_position(
input: Res<Input<KeyCode>>,
input: Res<ButtonInput<KeyCode>>,
mut lights: Query<&mut Transform, With<Lights>>,
mut example_text: Query<&mut Text>,
) {
@ -249,7 +249,7 @@ fn adjust_light_position(
}
fn cycle_filter_methods(
input: Res<Input<KeyCode>>,
input: Res<ButtonInput<KeyCode>>,
mut filter_methods: Query<&mut ShadowFilteringMethod>,
mut example_text: Query<&mut Text>,
) {
@ -276,7 +276,7 @@ fn cycle_filter_methods(
}
fn adjust_point_light_biases(
input: Res<Input<KeyCode>>,
input: Res<ButtonInput<KeyCode>>,
mut query: Query<&mut PointLight>,
mut example_text: Query<&mut Text>,
) {
@ -310,7 +310,7 @@ fn adjust_point_light_biases(
}
fn adjust_directional_light_biases(
input: Res<Input<KeyCode>>,
input: Res<ButtonInput<KeyCode>>,
mut query: Query<&mut DirectionalLight>,
mut example_text: Query<&mut Text>,
) {
@ -387,7 +387,7 @@ impl Default for CameraController {
fn camera_controller(
time: Res<Time>,
mut mouse_events: EventReader<MouseMotion>,
key_input: Res<Input<KeyCode>>,
key_input: Res<ButtonInput<KeyCode>>,
mut query: Query<(&mut Transform, &mut CameraController), With<Camera>>,
) {
let dt = time.delta_seconds();

View file

@ -126,7 +126,7 @@ fn setup(
}
fn toggle_light(
input: Res<Input<KeyCode>>,
input: Res<ButtonInput<KeyCode>>,
mut point_lights: Query<&mut PointLight>,
mut directional_lights: Query<&mut DirectionalLight>,
) {
@ -152,7 +152,7 @@ fn toggle_light(
fn toggle_shadows(
mut commands: Commands,
input: Res<Input<KeyCode>>,
input: Res<ButtonInput<KeyCode>>,
mut queries: ParamSet<(
Query<Entity, (With<Handle<Mesh>>, With<NotShadowCaster>)>,
Query<Entity, (With<Handle<Mesh>>, With<NotShadowReceiver>)>,

View file

@ -220,8 +220,8 @@ impl Default for CameraController {
pub fn camera_controller(
time: Res<Time>,
mut mouse_events: EventReader<MouseMotion>,
mouse_button_input: Res<Input<MouseButton>>,
key_input: Res<Input<KeyCode>>,
mouse_button_input: Res<ButtonInput<MouseButton>>,
key_input: Res<ButtonInput<KeyCode>>,
mut move_toggled: Local<bool>,
mut query: Query<(&mut Transform, &mut CameraController), With<Camera>>,
) {

View file

@ -141,7 +141,7 @@ fn light_sway(time: Res<Time>, mut query: Query<(&mut Transform, &mut SpotLight)
}
fn movement(
input: Res<Input<KeyCode>>,
input: Res<ButtonInput<KeyCode>>,
time: Res<Time>,
mut query: Query<&mut Transform, With<Movable>>,
) {

View file

@ -127,7 +127,7 @@ fn update(
mut text: Query<&mut Text>,
mut sphere: Query<&mut Transform, With<SphereMarker>>,
mut commands: Commands,
keycode: Res<Input<KeyCode>>,
keycode: Res<ButtonInput<KeyCode>>,
time: Res<Time>,
) {
let mut sphere = sphere.single_mut();

View file

@ -347,7 +347,7 @@ fn update_image_viewer(
}
fn toggle_scene(
keys: Res<Input<KeyCode>>,
keys: Res<ButtonInput<KeyCode>>,
mut query: Query<(&mut Visibility, &SceneNumber)>,
mut current_scene: ResMut<CurrentScene>,
) {
@ -374,7 +374,7 @@ fn toggle_scene(
}
fn toggle_tonemapping_method(
keys: Res<Input<KeyCode>>,
keys: Res<ButtonInput<KeyCode>>,
mut tonemapping: Query<&mut Tonemapping>,
mut color_grading: Query<&mut ColorGrading>,
per_method_settings: Res<PerMethodSettings>,
@ -422,7 +422,7 @@ impl SelectedParameter {
}
fn update_color_grading_settings(
keys: Res<Input<KeyCode>>,
keys: Res<ButtonInput<KeyCode>>,
time: Res<Time>,
mut per_method_settings: ResMut<PerMethodSettings>,
tonemapping: Query<&Tonemapping>,
@ -479,7 +479,7 @@ fn update_ui(
current_scene: Res<CurrentScene>,
selected_parameter: Res<SelectedParameter>,
mut hide_ui: Local<bool>,
keys: Res<Input<KeyCode>>,
keys: Res<ButtonInput<KeyCode>>,
) {
let (method, color_grading) = settings.single();
let method = *method;

View file

@ -438,7 +438,7 @@ fn example_control_system(
mut display: Query<&mut Text, With<ExampleDisplay>>,
mut state: Local<ExampleState>,
time: Res<Time>,
input: Res<Input<KeyCode>>,
input: Res<ButtonInput<KeyCode>>,
) {
if input.pressed(KeyCode::Key2) {
state.diffuse_transmission = (state.diffuse_transmission + time.delta_seconds()).min(1.0);

View file

@ -117,7 +117,7 @@ fn setup(
/// This system let's you toggle various wireframe settings
fn update_colors(
keyboard_input: Res<Input<KeyCode>>,
keyboard_input: Res<ButtonInput<KeyCode>>,
mut config: ResMut<WireframeConfig>,
mut wireframe_colors: Query<&mut WireframeColor>,
mut text: Query<&mut Text>,

View file

@ -92,7 +92,7 @@ fn setup_scene_once_loaded(
}
fn keyboard_animation_control(
keyboard_input: Res<Input<KeyCode>>,
keyboard_input: Res<ButtonInput<KeyCode>>,
mut animation_players: Query<&mut AnimationPlayer>,
animations: Res<Animations>,
mut current_animation: Local<usize>,

View file

@ -29,7 +29,10 @@ fn update_speed(music_controller: Query<&AudioSink, With<MyMusic>>, time: Res<Ti
}
}
fn pause(keyboard_input: Res<Input<KeyCode>>, music_controller: Query<&AudioSink, With<MyMusic>>) {
fn pause(
keyboard_input: Res<ButtonInput<KeyCode>>,
music_controller: Query<&AudioSink, With<MyMusic>>,
) {
if keyboard_input.just_pressed(KeyCode::Space) {
if let Ok(sink) = music_controller.get_single() {
sink.toggle();
@ -37,7 +40,10 @@ fn pause(keyboard_input: Res<Input<KeyCode>>, music_controller: Query<&AudioSink
}
}
fn volume(keyboard_input: Res<Input<KeyCode>>, music_controller: Query<&AudioSink, With<MyMusic>>) {
fn volume(
keyboard_input: Res<ButtonInput<KeyCode>>,
music_controller: Query<&AudioSink, With<MyMusic>>,
) {
if let Ok(sink) = music_controller.get_single() {
if keyboard_input.just_pressed(KeyCode::Plus) {
sink.set_volume(sink.volume() + 0.1);

View file

@ -39,7 +39,7 @@ fn play_pitch(
}
fn keyboard_input_system(
keyboard_input: Res<Input<KeyCode>>,
keyboard_input: Res<ButtonInput<KeyCode>>,
mut frequency: ResMut<PitchFrequency>,
mut events: EventWriter<PlayPitch>,
) {

View file

@ -102,7 +102,7 @@ struct Emitter {
fn update_emitters(
time: Res<Time>,
mut emitters: Query<(&mut Transform, &mut Emitter), With<Emitter>>,
keyboard: Res<Input<KeyCode>>,
keyboard: Res<ButtonInput<KeyCode>>,
) {
for (mut emitter_transform, mut emitter) in emitters.iter_mut() {
if keyboard.just_pressed(KeyCode::Space) {
@ -116,7 +116,7 @@ fn update_emitters(
}
fn update_listener(
keyboard: Res<Input<KeyCode>>,
keyboard: Res<ButtonInput<KeyCode>>,
time: Res<Time>,
mut listeners: Query<&mut Transform, With<SpatialListener>>,
) {

View file

@ -101,7 +101,7 @@ struct Emitter {
fn update_positions(
time: Res<Time>,
mut emitters: Query<(&mut Transform, &mut Emitter), With<Emitter>>,
keyboard: Res<Input<KeyCode>>,
keyboard: Res<ButtonInput<KeyCode>>,
) {
for (mut emitter_transform, mut emitter) in emitters.iter_mut() {
if keyboard.just_pressed(KeyCode::Space) {
@ -116,7 +116,7 @@ fn update_positions(
}
fn update_listener(
keyboard: Res<Input<KeyCode>>,
keyboard: Res<ButtonInput<KeyCode>>,
time: Res<Time>,
mut listeners: Query<&mut Transform, With<SpatialListener>>,
) {

View file

@ -73,7 +73,7 @@ fn print_text_system(time: Res<Time>, mut query: Query<(&mut PrinterTick, &TextT
fn transition_to_in_game_system(
mut next_state: ResMut<NextState<AppState>>,
keyboard_input: Res<Input<KeyCode>>,
keyboard_input: Res<ButtonInput<KeyCode>>,
) {
if keyboard_input.pressed(KeyCode::Space) {
next_state.set(AppState::InGame);

View file

@ -64,8 +64,8 @@ struct Unused;
/// they are read only (except for local parameters which can be mutable).
/// It returns a bool which determines if the system should run.
fn has_user_input(
keyboard_input: Res<Input<KeyCode>>,
mouse_button_input: Res<Input<MouseButton>>,
keyboard_input: Res<ButtonInput<KeyCode>>,
mouse_button_input: Res<ButtonInput<MouseButton>>,
touch_input: Res<Touches>,
) -> bool {
keyboard_input.just_pressed(KeyCode::Space)

View file

@ -128,7 +128,7 @@ fn setup_game(mut commands: Commands, asset_server: Res<AssetServer>) {
const SPEED: f32 = 100.0;
fn movement(
time: Res<Time>,
input: Res<Input<KeyCode>>,
input: Res<ButtonInput<KeyCode>>,
mut query: Query<&mut Transform, With<Sprite>>,
) {
for mut transform in &mut query {

View file

@ -192,7 +192,7 @@ fn teardown(mut commands: Commands, entities: Query<Entity, (Without<Camera>, Wi
// control the game character
fn move_player(
mut commands: Commands,
keyboard_input: Res<Input<KeyCode>>,
keyboard_input: Res<ButtonInput<KeyCode>>,
mut game: ResMut<Game>,
mut transforms: Query<&mut Transform>,
time: Res<Time>,
@ -376,7 +376,7 @@ fn scoreboard_system(game: Res<Game>, mut query: Query<&mut Text>) {
// restart the game when pressing spacebar
fn gameover_keyboard(
mut next_state: ResMut<NextState<GameState>>,
keyboard_input: Res<Input<KeyCode>>,
keyboard_input: Res<ButtonInput<KeyCode>>,
) {
if keyboard_input.just_pressed(KeyCode::Space) {
next_state.set(GameState::Playing);

View file

@ -303,7 +303,7 @@ fn setup(
}
fn move_paddle(
keyboard_input: Res<Input<KeyCode>>,
keyboard_input: Res<ButtonInput<KeyCode>>,
mut query: Query<&mut Transform, With<Paddle>>,
time: Res<Time>,
) {

View file

@ -11,7 +11,7 @@ fn main() {
fn gamepad_system(
gamepads: Res<Gamepads>,
button_inputs: Res<Input<GamepadButton>>,
button_inputs: Res<ButtonInput<GamepadButton>>,
button_axes: Res<Axis<GamepadButton>>,
axes: Res<Axis<GamepadAxis>>,
) {

View file

@ -16,7 +16,7 @@ fn main() {
fn gamepad_system(
gamepads: Res<Gamepads>,
button_inputs: Res<Input<GamepadButton>>,
button_inputs: Res<ButtonInput<GamepadButton>>,
mut rumble_requests: EventWriter<GamepadRumbleRequest>,
) {
for gamepad in gamepads.iter() {

View file

@ -10,7 +10,7 @@ fn main() {
}
/// This system prints 'A' key state
fn keyboard_input_system(keyboard_input: Res<Input<KeyCode>>) {
fn keyboard_input_system(keyboard_input: Res<ButtonInput<KeyCode>>) {
if keyboard_input.pressed(KeyCode::A) {
info!("'A' currently pressed");
}

View file

@ -10,7 +10,7 @@ fn main() {
}
/// This system prints when `Ctrl + Shift + A` is pressed
fn keyboard_input_system(input: Res<Input<KeyCode>>) {
fn keyboard_input_system(input: Res<ButtonInput<KeyCode>>) {
let shift = input.any_pressed([KeyCode::ShiftLeft, KeyCode::ShiftRight]);
let ctrl = input.any_pressed([KeyCode::ControlLeft, KeyCode::ControlRight]);

View file

@ -13,8 +13,8 @@ fn main() {
// and releases it when the escape key is pressed
fn grab_mouse(
mut windows: Query<&mut Window>,
mouse: Res<Input<MouseButton>>,
key: Res<Input<KeyCode>>,
mouse: Res<ButtonInput<MouseButton>>,
key: Res<ButtonInput<KeyCode>>,
) {
let mut window = windows.single_mut();

View file

@ -10,7 +10,7 @@ fn main() {
}
// This system prints messages when you press or release the left mouse button:
fn mouse_click_system(mouse_button_input: Res<Input<MouseButton>>) {
fn mouse_click_system(mouse_button_input: Res<ButtonInput<MouseButton>>) {
if mouse_button_input.pressed(MouseButton::Left) {
info!("left mouse currently pressed");
}

View file

@ -101,7 +101,7 @@ fn setup_scene(mut commands: Commands, asset_server: Res<AssetServer>) {
}
fn toggle_ime(
input: Res<Input<MouseButton>>,
input: Res<ButtonInput<MouseButton>>,
mut windows: Query<&mut Window>,
mut text: Query<&mut Text, With<Node>>,
) {

View file

@ -224,7 +224,7 @@ impl Material for PrepassOutputMaterial {
/// Every time you press space, it will cycle between transparent, depth and normals view
fn toggle_prepass_view(
mut prepass_view: Local<u32>,
keycode: Res<Input<KeyCode>>,
keycode: Res<ButtonInput<KeyCode>>,
material_handle: Query<&Handle<PrepassOutputMaterial>>,
mut materials: ResMut<Assets<PrepassOutputMaterial>>,
mut text: Query<&mut Text>,

View file

@ -285,7 +285,7 @@ fn mouse_handler(
mut commands: Commands,
args: Res<Args>,
time: Res<Time>,
mouse_button_input: Res<Input<MouseButton>>,
mouse_button_input: Res<ButtonInput<MouseButton>>,
windows: Query<&Window>,
bird_resources: ResMut<BirdResources>,
mut counter: ResMut<BevyCounter>,

View file

@ -248,7 +248,7 @@ fn update_fox_rings(
}
fn keyboard_animation_control(
keyboard_input: Res<Input<KeyCode>>,
keyboard_input: Res<ButtonInput<KeyCode>>,
mut animation_player: Query<&mut AnimationPlayer>,
animations: Res<Animations>,
mut current_animation: Local<usize>,

View file

@ -42,7 +42,7 @@ struct Config {
fancy: bool,
}
fn input(mut config: ResMut<Config>, input: Res<Input<KeyCode>>) {
fn input(mut config: ResMut<Config>, input: Res<ButtonInput<KeyCode>>) {
if input.just_pressed(KeyCode::Up) {
config.line_count += 10_000;
}

View file

@ -446,7 +446,7 @@ fn setup_connected(mut commands: Commands) {
fn update_buttons(
gamepads: Res<Gamepads>,
button_inputs: Res<Input<GamepadButton>>,
button_inputs: Res<ButtonInput<GamepadButton>>,
materials: Res<ButtonMaterials>,
mut query: Query<(&mut Handle<ColorMaterial>, &ReactTo)>,
) {

View file

@ -66,7 +66,7 @@ fn assign_clips(
}
fn handle_inputs(
keyboard_input: Res<Input<KeyCode>>,
keyboard_input: Res<ButtonInput<KeyCode>>,
mut animation_player: Query<(&mut AnimationPlayer, &mut Clips, Entity, Option<&Name>)>,
) {
for (mut player, mut clips, entity, name) in &mut animation_player {

View file

@ -99,8 +99,8 @@ fn camera_controller(
time: Res<Time>,
mut windows: Query<&mut Window>,
mut mouse_events: EventReader<MouseMotion>,
mouse_button_input: Res<Input<MouseButton>>,
key_input: Res<Input<KeyCode>>,
mouse_button_input: Res<ButtonInput<MouseButton>>,
key_input: Res<ButtonInput<KeyCode>>,
mut move_toggled: Local<bool>,
mut query: Query<(&mut Transform, &mut CameraController), With<Camera>>,
) {

View file

@ -166,7 +166,7 @@ impl MorphKey {
key,
}
}
fn active(&self, inputs: &Input<KeyCode>) -> bool {
fn active(&self, inputs: &ButtonInput<KeyCode>) -> bool {
let mut modifier = self.modifiers.iter();
let mut non_modifier = ALL_MODIFIERS.iter().filter(|m| !self.modifiers.contains(m));
@ -202,7 +202,7 @@ fn update_text(
fn update_morphs(
controls: Option<ResMut<WeightsControl>>,
mut morphs: Query<&mut MorphWeights>,
input: Res<Input<KeyCode>>,
input: Res<ButtonInput<KeyCode>>,
time: Res<Time>,
) {
let Some(mut controls) = controls else {

View file

@ -140,7 +140,7 @@ fn scene_load_check(
}
}
fn update_lights(
key_input: Res<Input<KeyCode>>,
key_input: Res<ButtonInput<KeyCode>>,
time: Res<Time>,
mut query: Query<(&mut Transform, &mut DirectionalLight)>,
mut animate_directional_light: Local<bool>,
@ -197,7 +197,7 @@ impl CameraTracker {
fn camera_tracker(
mut camera_tracker: ResMut<CameraTracker>,
keyboard_input: Res<Input<KeyCode>>,
keyboard_input: Res<ButtonInput<KeyCode>>,
mut queries: ParamSet<(
Query<(Entity, &mut Camera), (Added<Camera>, Without<CameraController>)>,
Query<(Entity, &mut Camera), (Added<Camera>, With<CameraController>)>,

View file

@ -239,7 +239,7 @@ fn spawn_container(
fn update_animation(
mut animation: ResMut<AnimationState>,
time: Res<Time>,
keys: Res<Input<KeyCode>>,
keys: Res<ButtonInput<KeyCode>>,
) {
let time = time.elapsed_seconds();
@ -270,7 +270,10 @@ fn update_transform<T: UpdateTransform + Component>(
}
}
fn toggle_overflow(keys: Res<Input<KeyCode>>, mut containers: Query<&mut Style, With<Container>>) {
fn toggle_overflow(
keys: Res<ButtonInput<KeyCode>>,
mut containers: Query<&mut Style, With<Container>>,
) {
if keys.just_pressed(KeyCode::O) {
for mut style in &mut containers {
style.overflow = match style.overflow {
@ -293,7 +296,7 @@ fn toggle_overflow(keys: Res<Input<KeyCode>>, mut containers: Query<&mut Style,
}
fn next_container_size(
keys: Res<Input<KeyCode>>,
keys: Res<ButtonInput<KeyCode>>,
mut containers: Query<(&mut Style, &mut Container)>,
) {
if keys.just_pressed(KeyCode::S) {

View file

@ -84,7 +84,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
}
/// System that changes the scale of the ui when pressing up or down on the keyboard.
fn change_scaling(input: Res<Input<KeyCode>>, mut ui_scale: ResMut<TargetScale>) {
fn change_scaling(input: Res<ButtonInput<KeyCode>>, mut ui_scale: ResMut<TargetScale>) {
if input.just_pressed(KeyCode::Up) {
let scale = (ui_scale.target_scale * 2.0).min(8.);
ui_scale.set_scale(scale);

View file

@ -76,7 +76,7 @@ fn setup(
fn increment_atlas_index(
mut atlas_images: Query<&mut UiTextureAtlasImage>,
keyboard: Res<Input<KeyCode>>,
keyboard: Res<ButtonInput<KeyCode>>,
) {
if keyboard.just_pressed(KeyCode::Space) {
for mut atlas_image in &mut atlas_images {

View file

@ -47,7 +47,10 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
));
}
// A simple system to handle some keyboard input and toggle on/off the hittest.
fn toggle_mouse_passthrough(keyboard_input: Res<Input<KeyCode>>, mut windows: Query<&mut Window>) {
fn toggle_mouse_passthrough(
keyboard_input: Res<ButtonInput<KeyCode>>,
mut windows: Query<&mut Window>,
) {
if keyboard_input.just_pressed(KeyCode::P) {
let mut window = windows.single_mut();
window.cursor.hit_test = !window.cursor.hit_test;

View file

@ -17,7 +17,7 @@ fn setup(mut commands: Commands) {
commands.spawn(Camera2dBundle::default());
}
fn change_clear_color(input: Res<Input<KeyCode>>, mut clear_color: ResMut<ClearColor>) {
fn change_clear_color(input: Res<ButtonInput<KeyCode>>, mut clear_color: ResMut<ClearColor>) {
if input.just_pressed(KeyCode::Space) {
clear_color.0 = Color::PURPLE;
}

View file

@ -98,7 +98,7 @@ pub(crate) mod test_setup {
/// Switch between update modes when the mouse is clicked.
pub(crate) fn cycle_modes(
mut mode: ResMut<ExampleMode>,
mouse_button_input: Res<Input<KeyCode>>,
mouse_button_input: Res<ButtonInput<KeyCode>>,
) {
if mouse_button_input.just_pressed(KeyCode::Space) {
*mode = match *mode {

View file

@ -76,7 +76,7 @@ fn display_override(mut windows: Query<&mut Window>) {
}
/// This system toggles scale factor overrides when enter is pressed
fn toggle_override(input: Res<Input<KeyCode>>, mut windows: Query<&mut Window>) {
fn toggle_override(input: Res<ButtonInput<KeyCode>>, mut windows: Query<&mut Window>) {
let mut window = windows.single_mut();
if input.just_pressed(KeyCode::Return) {
@ -88,7 +88,7 @@ fn toggle_override(input: Res<Input<KeyCode>>, mut windows: Query<&mut Window>)
}
/// This system changes the scale factor override when up or down is pressed
fn change_scale_factor(input: Res<Input<KeyCode>>, mut windows: Query<&mut Window>) {
fn change_scale_factor(input: Res<ButtonInput<KeyCode>>, mut windows: Query<&mut Window>) {
let mut window = windows.single_mut();
let scale_factor_override = window.resolution.scale_factor_override();
if input.just_pressed(KeyCode::Up) {

View file

@ -13,7 +13,7 @@ fn main() {
}
fn screenshot_on_spacebar(
input: Res<Input<KeyCode>>,
input: Res<ButtonInput<KeyCode>>,
main_window: Query<Entity, With<PrimaryWindow>>,
mut screenshot_manager: ResMut<ScreenshotManager>,
mut counter: Local<u32>,

View file

@ -58,7 +58,7 @@ fn setup_ui(mut cmd: Commands) {
/// This system shows how to request the window to a new resolution
fn toggle_resolution(
keys: Res<Input<KeyCode>>,
keys: Res<ButtonInput<KeyCode>>,
mut windows: Query<&mut Window>,
resolution: Res<ResolutionSettings>,
) {

View file

@ -64,7 +64,7 @@ fn make_visible(mut window: Query<&mut Window>, frames: Res<FrameCount>) {
/// This system toggles the vsync mode when pressing the button V.
/// You'll see fps increase displayed in the console.
fn toggle_vsync(input: Res<Input<KeyCode>>, mut windows: Query<&mut Window>) {
fn toggle_vsync(input: Res<ButtonInput<KeyCode>>, mut windows: Query<&mut Window>) {
if input.just_pressed(KeyCode::V) {
let mut window = windows.single_mut();
@ -84,7 +84,7 @@ fn toggle_vsync(input: Res<Input<KeyCode>>, mut windows: Query<&mut Window>) {
/// This feature only works on some platforms. Please check the
/// [documentation](https://docs.rs/bevy/latest/bevy/prelude/struct.Window.html#structfield.window_level)
/// for more details.
fn switch_level(input: Res<Input<KeyCode>>, mut windows: Query<&mut Window>) {
fn switch_level(input: Res<ButtonInput<KeyCode>>, mut windows: Query<&mut Window>) {
if input.just_pressed(KeyCode::T) {
let mut window = windows.single_mut();
@ -102,7 +102,7 @@ fn switch_level(input: Res<Input<KeyCode>>, mut windows: Query<&mut Window>) {
/// This feature only works on some platforms. Please check the
/// [documentation](https://docs.rs/bevy/latest/bevy/prelude/struct.Window.html#structfield.enabled_buttons)
/// for more details.
fn toggle_window_controls(input: Res<Input<KeyCode>>, mut windows: Query<&mut Window>) {
fn toggle_window_controls(input: Res<ButtonInput<KeyCode>>, mut windows: Query<&mut Window>) {
let toggle_minimize = input.just_pressed(KeyCode::Key1);
let toggle_maximize = input.just_pressed(KeyCode::Key2);
let toggle_close = input.just_pressed(KeyCode::Key3);
@ -131,7 +131,7 @@ fn change_title(mut windows: Query<&mut Window>, time: Res<Time>) {
);
}
fn toggle_cursor(mut windows: Query<&mut Window>, input: Res<Input<KeyCode>>) {
fn toggle_cursor(mut windows: Query<&mut Window>, input: Res<ButtonInput<KeyCode>>) {
if input.just_pressed(KeyCode::Space) {
let mut window = windows.single_mut();
@ -144,7 +144,7 @@ fn toggle_cursor(mut windows: Query<&mut Window>, input: Res<Input<KeyCode>>) {
}
// This system will toggle the color theme used by the window
fn toggle_theme(mut windows: Query<&mut Window>, input: Res<Input<KeyCode>>) {
fn toggle_theme(mut windows: Query<&mut Window>, input: Res<ButtonInput<KeyCode>>) {
if input.just_pressed(KeyCode::F) {
let mut window = windows.single_mut();
@ -160,7 +160,7 @@ fn toggle_theme(mut windows: Query<&mut Window>, input: Res<Input<KeyCode>>) {
/// This system cycles the cursor's icon through a small set of icons when clicking
fn cycle_cursor_icon(
mut windows: Query<&mut Window>,
input: Res<Input<MouseButton>>,
input: Res<ButtonInput<MouseButton>>,
mut index: Local<usize>,
) {
let mut window = windows.single_mut();

View file

@ -37,7 +37,7 @@ fn hurt_enemies(mut enemies: Query<&mut Enemy>) {
}
}
fn spawn_enemy(mut commands: Commands, keyboard_input: Res<Input<KeyCode>>) {
fn spawn_enemy(mut commands: Commands, keyboard_input: Res<ButtonInput<KeyCode>>) {
if keyboard_input.just_pressed(KeyCode::Space) {
commands.spawn(Enemy {
hit_points: 5,
@ -124,7 +124,7 @@ fn spawn_enemy_using_input_resource() {
app.add_systems(Update, spawn_enemy);
// Setup test resource
let mut input = Input::<KeyCode>::default();
let mut input = ButtonInput::<KeyCode>::default();
input.press(KeyCode::Space);
app.insert_resource(input);
@ -135,7 +135,7 @@ fn spawn_enemy_using_input_resource() {
assert_eq!(app.world.query::<&Enemy>().iter(&app.world).len(), 1);
// Clear the `just_pressed` status for all `KeyCode`s
app.world.resource_mut::<Input<KeyCode>>().clear();
app.world.resource_mut::<ButtonInput<KeyCode>>().clear();
// Run systems
app.update();