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:
parent
d9aac887b5
commit
1f97717a3d
@ -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
|
/// 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:
|
/// events from the input. For a given input value:
|
||||||
///
|
///
|
||||||
/// * [`Input::pressed`] will return `true` between a press and a release event.
|
/// * [`ButtonInput::pressed`] will return `true` between a press and a release event.
|
||||||
/// * [`Input::just_pressed`] will return `true` for one frame after a press event.
|
/// * [`ButtonInput::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::just_released`] will return `true` for one frame after a release event.
|
||||||
///
|
///
|
||||||
/// ## Multiple systems
|
/// ## 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
|
/// but only one should react, for example in the case of triggering
|
||||||
/// [`State`] change, you should consider clearing the input state, either by:
|
/// [`State`] change, you should consider clearing the input state, either by:
|
||||||
///
|
///
|
||||||
/// * Using [`Input::clear_just_pressed`] or [`Input::clear_just_released`] instead.
|
/// * Using [`ButtonInput::clear_just_pressed`] or [`ButtonInput::clear_just_released`] instead.
|
||||||
/// * Calling [`Input::clear`] or [`Input::reset`] immediately after the state change.
|
/// * Calling [`ButtonInput::clear`] or [`ButtonInput::reset`] immediately after the state change.
|
||||||
///
|
///
|
||||||
/// ## Note
|
/// ## Note
|
||||||
///
|
///
|
||||||
/// When adding this resource for a new input type, you should:
|
/// When adding this resource for a new input type, you should:
|
||||||
///
|
///
|
||||||
/// * Call the [`Input::press`] method for each press event.
|
/// * Call the [`ButtonInput::press`] method for each press event.
|
||||||
/// * Call the [`Input::release`] method for each release event.
|
/// * Call the [`ButtonInput::release`] method for each release event.
|
||||||
/// * Call the [`Input::clear`] method at each frame start, before processing events.
|
/// * Call the [`ButtonInput::clear`] method at each frame start, before processing events.
|
||||||
///
|
///
|
||||||
/// Note: Calling `clear` from a [`ResMut`] will trigger change detection.
|
/// Note: Calling `clear` from a [`ResMut`] will trigger change detection.
|
||||||
/// It may be preferable to use [`DetectChangesMut::bypass_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
|
///[`DetectChangesMut::bypass_change_detection`]: bevy_ecs::change_detection::DetectChangesMut::bypass_change_detection
|
||||||
#[derive(Debug, Clone, Resource, Reflect)]
|
#[derive(Debug, Clone, Resource, Reflect)]
|
||||||
#[reflect(Default)]
|
#[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.
|
/// A collection of every button that is currently being pressed.
|
||||||
pressed: HashSet<T>,
|
pressed: HashSet<T>,
|
||||||
/// A collection of every button that has just been pressed.
|
/// 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>,
|
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 {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
pressed: Default::default(),
|
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
|
where
|
||||||
T: Copy + Eq + Hash + Send + Sync + 'static,
|
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.
|
/// 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 {
|
pub fn clear_just_pressed(&mut self, input: T) -> bool {
|
||||||
self.just_pressed.remove(&input)
|
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.
|
/// 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 {
|
pub fn clear_just_released(&mut self, input: T) -> bool {
|
||||||
self.just_released.remove(&input)
|
self.just_released.remove(&input)
|
||||||
}
|
}
|
||||||
@ -143,7 +143,7 @@ where
|
|||||||
|
|
||||||
/// Clears the `pressed`, `just_pressed`, and `just_released` data for every input.
|
/// 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) {
|
pub fn reset_all(&mut self) {
|
||||||
self.pressed.clear();
|
self.pressed.clear();
|
||||||
self.just_pressed.clear();
|
self.just_pressed.clear();
|
||||||
@ -152,7 +152,7 @@ where
|
|||||||
|
|
||||||
/// Clears the `just pressed` and `just released` data for every input.
|
/// 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) {
|
pub fn clear(&mut self) {
|
||||||
self.just_pressed.clear();
|
self.just_pressed.clear();
|
||||||
self.just_released.clear();
|
self.just_released.clear();
|
||||||
@ -178,9 +178,9 @@ where
|
|||||||
mod test {
|
mod test {
|
||||||
use bevy_reflect::TypePath;
|
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)]
|
#[derive(TypePath, Copy, Clone, Eq, PartialEq, Hash)]
|
||||||
enum DummyInput {
|
enum DummyInput {
|
||||||
Input1,
|
Input1,
|
||||||
@ -189,7 +189,7 @@ mod test {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_press() {
|
fn test_press() {
|
||||||
let mut input = Input::default();
|
let mut input = ButtonInput::default();
|
||||||
assert!(!input.pressed.contains(&DummyInput::Input1));
|
assert!(!input.pressed.contains(&DummyInput::Input1));
|
||||||
assert!(!input.just_pressed.contains(&DummyInput::Input1));
|
assert!(!input.just_pressed.contains(&DummyInput::Input1));
|
||||||
input.press(DummyInput::Input1);
|
input.press(DummyInput::Input1);
|
||||||
@ -199,7 +199,7 @@ mod test {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_pressed() {
|
fn test_pressed() {
|
||||||
let mut input = Input::default();
|
let mut input = ButtonInput::default();
|
||||||
assert!(!input.pressed(DummyInput::Input1));
|
assert!(!input.pressed(DummyInput::Input1));
|
||||||
input.press(DummyInput::Input1);
|
input.press(DummyInput::Input1);
|
||||||
assert!(input.pressed(DummyInput::Input1));
|
assert!(input.pressed(DummyInput::Input1));
|
||||||
@ -207,7 +207,7 @@ mod test {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_any_pressed() {
|
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::Input1]));
|
||||||
assert!(!input.any_pressed([DummyInput::Input2]));
|
assert!(!input.any_pressed([DummyInput::Input2]));
|
||||||
assert!(!input.any_pressed([DummyInput::Input1, DummyInput::Input2]));
|
assert!(!input.any_pressed([DummyInput::Input1, DummyInput::Input2]));
|
||||||
@ -219,7 +219,7 @@ mod test {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_release() {
|
fn test_release() {
|
||||||
let mut input = Input::default();
|
let mut input = ButtonInput::default();
|
||||||
input.press(DummyInput::Input1);
|
input.press(DummyInput::Input1);
|
||||||
assert!(input.pressed.contains(&DummyInput::Input1));
|
assert!(input.pressed.contains(&DummyInput::Input1));
|
||||||
assert!(!input.just_released.contains(&DummyInput::Input1));
|
assert!(!input.just_released.contains(&DummyInput::Input1));
|
||||||
@ -230,7 +230,7 @@ mod test {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_release_all() {
|
fn test_release_all() {
|
||||||
let mut input = Input::default();
|
let mut input = ButtonInput::default();
|
||||||
input.press(DummyInput::Input1);
|
input.press(DummyInput::Input1);
|
||||||
input.press(DummyInput::Input2);
|
input.press(DummyInput::Input2);
|
||||||
input.release_all();
|
input.release_all();
|
||||||
@ -241,7 +241,7 @@ mod test {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_just_pressed() {
|
fn test_just_pressed() {
|
||||||
let mut input = Input::default();
|
let mut input = ButtonInput::default();
|
||||||
assert!(!input.just_pressed(DummyInput::Input1));
|
assert!(!input.just_pressed(DummyInput::Input1));
|
||||||
input.press(DummyInput::Input1);
|
input.press(DummyInput::Input1);
|
||||||
assert!(input.just_pressed(DummyInput::Input1));
|
assert!(input.just_pressed(DummyInput::Input1));
|
||||||
@ -249,7 +249,7 @@ mod test {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_any_just_pressed() {
|
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::Input1]));
|
||||||
assert!(!input.any_just_pressed([DummyInput::Input2]));
|
assert!(!input.any_just_pressed([DummyInput::Input2]));
|
||||||
assert!(!input.any_just_pressed([DummyInput::Input1, DummyInput::Input2]));
|
assert!(!input.any_just_pressed([DummyInput::Input1, DummyInput::Input2]));
|
||||||
@ -261,7 +261,7 @@ mod test {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_clear_just_pressed() {
|
fn test_clear_just_pressed() {
|
||||||
let mut input = Input::default();
|
let mut input = ButtonInput::default();
|
||||||
input.press(DummyInput::Input1);
|
input.press(DummyInput::Input1);
|
||||||
assert!(input.just_pressed(DummyInput::Input1));
|
assert!(input.just_pressed(DummyInput::Input1));
|
||||||
input.clear_just_pressed(DummyInput::Input1);
|
input.clear_just_pressed(DummyInput::Input1);
|
||||||
@ -270,7 +270,7 @@ mod test {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_just_released() {
|
fn test_just_released() {
|
||||||
let mut input = Input::default();
|
let mut input = ButtonInput::default();
|
||||||
input.press(DummyInput::Input1);
|
input.press(DummyInput::Input1);
|
||||||
assert!(!input.just_released(DummyInput::Input1));
|
assert!(!input.just_released(DummyInput::Input1));
|
||||||
input.release(DummyInput::Input1);
|
input.release(DummyInput::Input1);
|
||||||
@ -279,7 +279,7 @@ mod test {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_any_just_released() {
|
fn test_any_just_released() {
|
||||||
let mut input = Input::default();
|
let mut input = ButtonInput::default();
|
||||||
input.press(DummyInput::Input1);
|
input.press(DummyInput::Input1);
|
||||||
assert!(!input.any_just_released([DummyInput::Input1]));
|
assert!(!input.any_just_released([DummyInput::Input1]));
|
||||||
assert!(!input.any_just_released([DummyInput::Input2]));
|
assert!(!input.any_just_released([DummyInput::Input2]));
|
||||||
@ -292,7 +292,7 @@ mod test {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_clear_just_released() {
|
fn test_clear_just_released() {
|
||||||
let mut input = Input::default();
|
let mut input = ButtonInput::default();
|
||||||
input.press(DummyInput::Input1);
|
input.press(DummyInput::Input1);
|
||||||
input.release(DummyInput::Input1);
|
input.release(DummyInput::Input1);
|
||||||
assert!(input.just_released(DummyInput::Input1));
|
assert!(input.just_released(DummyInput::Input1));
|
||||||
@ -302,7 +302,7 @@ mod test {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_reset() {
|
fn test_reset() {
|
||||||
let mut input = Input::default();
|
let mut input = ButtonInput::default();
|
||||||
|
|
||||||
// Pressed
|
// Pressed
|
||||||
input.press(DummyInput::Input1);
|
input.press(DummyInput::Input1);
|
||||||
@ -328,7 +328,7 @@ mod test {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_reset_all() {
|
fn test_reset_all() {
|
||||||
let mut input = Input::default();
|
let mut input = ButtonInput::default();
|
||||||
|
|
||||||
input.press(DummyInput::Input1);
|
input.press(DummyInput::Input1);
|
||||||
input.press(DummyInput::Input2);
|
input.press(DummyInput::Input2);
|
||||||
@ -344,7 +344,7 @@ mod test {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_clear() {
|
fn test_clear() {
|
||||||
let mut input = Input::default();
|
let mut input = ButtonInput::default();
|
||||||
|
|
||||||
// Pressed
|
// Pressed
|
||||||
input.press(DummyInput::Input1);
|
input.press(DummyInput::Input1);
|
||||||
@ -370,7 +370,7 @@ mod test {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_get_pressed() {
|
fn test_get_pressed() {
|
||||||
let mut input = Input::default();
|
let mut input = ButtonInput::default();
|
||||||
input.press(DummyInput::Input1);
|
input.press(DummyInput::Input1);
|
||||||
input.press(DummyInput::Input2);
|
input.press(DummyInput::Input2);
|
||||||
let pressed = input.get_pressed();
|
let pressed = input.get_pressed();
|
||||||
@ -382,7 +382,7 @@ mod test {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_get_just_pressed() {
|
fn test_get_just_pressed() {
|
||||||
let mut input = Input::default();
|
let mut input = ButtonInput::default();
|
||||||
input.press(DummyInput::Input1);
|
input.press(DummyInput::Input1);
|
||||||
input.press(DummyInput::Input2);
|
input.press(DummyInput::Input2);
|
||||||
let just_pressed = input.get_just_pressed();
|
let just_pressed = input.get_just_pressed();
|
||||||
@ -394,7 +394,7 @@ mod test {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_get_just_released() {
|
fn test_get_just_released() {
|
||||||
let mut input = Input::default();
|
let mut input = ButtonInput::default();
|
||||||
input.press(DummyInput::Input1);
|
input.press(DummyInput::Input1);
|
||||||
input.press(DummyInput::Input2);
|
input.press(DummyInput::Input2);
|
||||||
input.release(DummyInput::Input1);
|
input.release(DummyInput::Input1);
|
||||||
@ -408,7 +408,7 @@ mod test {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_general_input_handling() {
|
fn test_general_input_handling() {
|
||||||
let mut input = Input::default();
|
let mut input = ButtonInput::default();
|
||||||
|
|
||||||
// Test pressing
|
// Test pressing
|
||||||
input.press(DummyInput::Input1);
|
input.press(DummyInput::Input1);
|
||||||
@ -453,7 +453,7 @@ mod test {
|
|||||||
assert!(!input.just_released(DummyInput::Input2));
|
assert!(!input.just_released(DummyInput::Input2));
|
||||||
|
|
||||||
// Set up an `Input` to test resetting
|
// Set up an `Input` to test resetting
|
||||||
let mut input = Input::default();
|
let mut input = ButtonInput::default();
|
||||||
|
|
||||||
input.press(DummyInput::Input1);
|
input.press(DummyInput::Input1);
|
||||||
input.release(DummyInput::Input2);
|
input.release(DummyInput::Input2);
|
@ -1,8 +1,8 @@
|
|||||||
use crate::Input;
|
use crate::ButtonInput;
|
||||||
use bevy_ecs::system::Res;
|
use bevy_ecs::system::Res;
|
||||||
use std::hash::Hash;
|
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
|
/// ```rust,no_run
|
||||||
/// use bevy::prelude::*;
|
/// 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
|
where
|
||||||
T: Copy + Eq + Hash + Send + Sync + 'static,
|
T: Copy + Eq + Hash + Send + Sync + 'static,
|
||||||
{
|
{
|
||||||
let mut active = default;
|
let mut active = default;
|
||||||
move |inputs: Res<Input<T>>| {
|
move |inputs: Res<ButtonInput<T>>| {
|
||||||
active ^= inputs.just_pressed(input);
|
active ^= inputs.just_pressed(input);
|
||||||
active
|
active
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Run condition that is active if [`Input::pressed`] is true for the given input.
|
/// Run condition that is active if [`ButtonInput::pressed`] is true for the given input.
|
||||||
pub fn input_pressed<T>(input: T) -> impl FnMut(Res<Input<T>>) -> bool + Clone
|
pub fn input_pressed<T>(input: T) -> impl FnMut(Res<ButtonInput<T>>) -> bool + Clone
|
||||||
where
|
where
|
||||||
T: Copy + Eq + Hash + Send + Sync + 'static,
|
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
|
/// ```rust,no_run
|
||||||
/// use bevy::prelude::*;
|
/// use bevy::prelude::*;
|
||||||
@ -80,19 +83,19 @@ where
|
|||||||
///
|
///
|
||||||
/// # fn jump() {}
|
/// # 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
|
where
|
||||||
T: Copy + Eq + Hash + Send + Sync + 'static,
|
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.
|
/// 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<Input<T>>) -> bool + Clone
|
pub fn input_just_released<T>(input: T) -> impl FnMut(Res<ButtonInput<T>>) -> bool + Clone
|
||||||
where
|
where
|
||||||
T: Copy + Eq + Hash + Send + Sync + 'static,
|
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)]
|
#[cfg(test)]
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
//! The gamepad input functionality.
|
//! The gamepad input functionality.
|
||||||
|
|
||||||
use crate::{Axis, ButtonState, Input};
|
use crate::{Axis, ButtonInput, ButtonState};
|
||||||
use bevy_ecs::event::{Event, EventReader, EventWriter};
|
use bevy_ecs::event::{Event, EventReader, EventWriter};
|
||||||
use bevy_ecs::{
|
use bevy_ecs::{
|
||||||
change_detection::DetectChangesMut,
|
change_detection::DetectChangesMut,
|
||||||
@ -165,7 +165,7 @@ impl Gamepads {
|
|||||||
///
|
///
|
||||||
/// This is used to determine which button has changed its value when receiving a
|
/// This is used to determine which button has changed its value when receiving a
|
||||||
/// [`GamepadButtonChangedEvent`]. It is also used in the [`GamepadButton`]
|
/// [`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.
|
/// [`Axis<GamepadButton>`] `bevy` resources.
|
||||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Reflect)]
|
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Reflect)]
|
||||||
#[reflect(Debug, Hash, PartialEq)]
|
#[reflect(Debug, Hash, PartialEq)]
|
||||||
@ -226,7 +226,7 @@ pub enum GamepadButtonType {
|
|||||||
///
|
///
|
||||||
/// ## Usage
|
/// ## 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.
|
/// resources store the data of the buttons of a gamepad and can be accessed inside of a system.
|
||||||
///
|
///
|
||||||
/// ## Updating
|
/// ## Updating
|
||||||
@ -1011,7 +1011,7 @@ impl ButtonAxisSettings {
|
|||||||
/// Handles [`GamepadConnectionEvent`]s and updates gamepad resources.
|
/// Handles [`GamepadConnectionEvent`]s and updates gamepad resources.
|
||||||
///
|
///
|
||||||
/// Updates the [`Gamepads`] resource and resets and/or initializes
|
/// Updates the [`Gamepads`] resource and resets and/or initializes
|
||||||
/// the [`Axis<GamepadButton>`] and [`Input<GamepadButton>`] resources.
|
/// the [`Axis<GamepadButton>`] and [`ButtonInput<GamepadButton>`] resources.
|
||||||
///
|
///
|
||||||
/// ## Note
|
/// ## Note
|
||||||
///
|
///
|
||||||
@ -1021,7 +1021,7 @@ pub fn gamepad_connection_system(
|
|||||||
mut connection_events: EventReader<GamepadConnectionEvent>,
|
mut connection_events: EventReader<GamepadConnectionEvent>,
|
||||||
mut axis: ResMut<Axis<GamepadAxis>>,
|
mut axis: ResMut<Axis<GamepadAxis>>,
|
||||||
mut button_axis: ResMut<Axis<GamepadButton>>,
|
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() {
|
for connection_event in connection_events.read() {
|
||||||
let gamepad = connection_event.gamepad;
|
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(
|
pub fn gamepad_axis_event_system(
|
||||||
mut gamepad_axis: ResMut<Axis<GamepadAxis>>,
|
mut gamepad_axis: ResMut<Axis<GamepadAxis>>,
|
||||||
mut axis_events: EventReader<GamepadAxisChangedEvent>,
|
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(
|
pub fn gamepad_button_event_system(
|
||||||
mut button_changed_events: EventReader<GamepadButtonChangedEvent>,
|
mut button_changed_events: EventReader<GamepadButtonChangedEvent>,
|
||||||
mut button_input: ResMut<Input<GamepadButton>>,
|
mut button_input: ResMut<ButtonInput<GamepadButton>>,
|
||||||
mut button_input_events: EventWriter<GamepadButtonInput>,
|
mut button_input_events: EventWriter<GamepadButtonInput>,
|
||||||
settings: Res<GamepadSettings>,
|
settings: Res<GamepadSettings>,
|
||||||
) {
|
) {
|
||||||
@ -1255,7 +1255,7 @@ pub fn gamepad_event_system(
|
|||||||
mut connection_events: EventWriter<GamepadConnectionEvent>,
|
mut connection_events: EventWriter<GamepadConnectionEvent>,
|
||||||
mut button_events: EventWriter<GamepadButtonChangedEvent>,
|
mut button_events: EventWriter<GamepadButtonChangedEvent>,
|
||||||
mut axis_events: EventWriter<GamepadAxisChangedEvent>,
|
mut axis_events: EventWriter<GamepadAxisChangedEvent>,
|
||||||
mut button_input: ResMut<Input<GamepadButton>>,
|
mut button_input: ResMut<ButtonInput<GamepadButton>>,
|
||||||
) {
|
) {
|
||||||
button_input.bypass_change_detection().clear();
|
button_input.bypass_change_detection().clear();
|
||||||
for gamepad_event in gamepad_events.read() {
|
for gamepad_event in gamepad_events.read() {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
//! The keyboard input functionality.
|
//! The keyboard input functionality.
|
||||||
|
|
||||||
use crate::{ButtonState, Input};
|
use crate::{ButtonInput, ButtonState};
|
||||||
use bevy_ecs::entity::Entity;
|
use bevy_ecs::entity::Entity;
|
||||||
use bevy_ecs::{
|
use bevy_ecs::{
|
||||||
change_detection::DetectChangesMut,
|
change_detection::DetectChangesMut,
|
||||||
@ -20,7 +20,7 @@ use bevy_reflect::{ReflectDeserialize, ReflectSerialize};
|
|||||||
/// ## Usage
|
/// ## Usage
|
||||||
///
|
///
|
||||||
/// The event is consumed inside of the [`keyboard_input_system`]
|
/// 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)]
|
#[derive(Event, Debug, Clone, Copy, PartialEq, Eq, Reflect)]
|
||||||
#[reflect(Debug, PartialEq)]
|
#[reflect(Debug, PartialEq)]
|
||||||
#[cfg_attr(
|
#[cfg_attr(
|
||||||
@ -39,15 +39,15 @@ pub struct KeyboardInput {
|
|||||||
pub window: Entity,
|
pub window: Entity,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Updates the [`Input<KeyCode>`] resource with the latest [`KeyboardInput`] events.
|
/// Updates the [`ButtonInput<KeyCode>`] resource with the latest [`KeyboardInput`] events.
|
||||||
///
|
///
|
||||||
/// ## Differences
|
/// ## Differences
|
||||||
///
|
///
|
||||||
/// The main difference between the [`KeyboardInput`] event and the [`Input<KeyCode>`] or [`Input<ScanCode>`] resources is that
|
/// The main difference between the [`KeyboardInput`] event and the [`ButtonInput<KeyCode>`] or [`ButtonInput<ScanCode>`] resources is that
|
||||||
/// the latter have convenient functions such as [`Input::pressed`], [`Input::just_pressed`] and [`Input::just_released`].
|
/// the latter have convenient functions such as [`ButtonInput::pressed`], [`ButtonInput::just_pressed`] and [`ButtonInput::just_released`].
|
||||||
pub fn keyboard_input_system(
|
pub fn keyboard_input_system(
|
||||||
mut scan_input: ResMut<Input<ScanCode>>,
|
mut scan_input: ResMut<ButtonInput<ScanCode>>,
|
||||||
mut key_input: ResMut<Input<KeyCode>>,
|
mut key_input: ResMut<ButtonInput<KeyCode>>,
|
||||||
mut keyboard_input_events: EventReader<KeyboardInput>,
|
mut keyboard_input_events: EventReader<KeyboardInput>,
|
||||||
) {
|
) {
|
||||||
// Avoid clearing if it's not empty to ensure change detection is not triggered.
|
// Avoid clearing if it's not empty to ensure change detection is not triggered.
|
||||||
@ -74,7 +74,7 @@ pub fn keyboard_input_system(
|
|||||||
///
|
///
|
||||||
/// ## Usage
|
/// ## 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`].
|
/// The resource values are mapped to the current layout of the keyboard and correlate to an [`ScanCode`].
|
||||||
///
|
///
|
||||||
/// ## Updating
|
/// ## Updating
|
||||||
@ -447,7 +447,7 @@ pub enum KeyCode {
|
|||||||
///
|
///
|
||||||
/// ## Usage
|
/// ## 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`]
|
/// The resource values are mapped to the physical location of a key on the keyboard and correlate to an [`KeyCode`]
|
||||||
///
|
///
|
||||||
/// ## Updating
|
/// ## Updating
|
||||||
|
@ -7,17 +7,17 @@
|
|||||||
//! `bevy` currently supports keyboard, mouse, gamepad, and touch inputs.
|
//! `bevy` currently supports keyboard, mouse, gamepad, and touch inputs.
|
||||||
|
|
||||||
mod axis;
|
mod axis;
|
||||||
|
mod button_input;
|
||||||
/// Common run conditions
|
/// Common run conditions
|
||||||
pub mod common_conditions;
|
pub mod common_conditions;
|
||||||
pub mod gamepad;
|
pub mod gamepad;
|
||||||
mod input;
|
|
||||||
pub mod keyboard;
|
pub mod keyboard;
|
||||||
pub mod mouse;
|
pub mod mouse;
|
||||||
pub mod touch;
|
pub mod touch;
|
||||||
pub mod touchpad;
|
pub mod touchpad;
|
||||||
|
|
||||||
pub use axis::*;
|
pub use axis::*;
|
||||||
pub use input::*;
|
pub use button_input::*;
|
||||||
|
|
||||||
/// Most commonly used re-exported types.
|
/// Most commonly used re-exported types.
|
||||||
pub mod prelude {
|
pub mod prelude {
|
||||||
@ -29,7 +29,7 @@ pub mod prelude {
|
|||||||
keyboard::{KeyCode, ScanCode},
|
keyboard::{KeyCode, ScanCode},
|
||||||
mouse::MouseButton,
|
mouse::MouseButton,
|
||||||
touch::{TouchInput, Touches},
|
touch::{TouchInput, Touches},
|
||||||
Axis, Input,
|
Axis, ButtonInput,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,14 +68,14 @@ impl Plugin for InputPlugin {
|
|||||||
app
|
app
|
||||||
// keyboard
|
// keyboard
|
||||||
.add_event::<KeyboardInput>()
|
.add_event::<KeyboardInput>()
|
||||||
.init_resource::<Input<KeyCode>>()
|
.init_resource::<ButtonInput<KeyCode>>()
|
||||||
.init_resource::<Input<ScanCode>>()
|
.init_resource::<ButtonInput<ScanCode>>()
|
||||||
.add_systems(PreUpdate, keyboard_input_system.in_set(InputSystem))
|
.add_systems(PreUpdate, keyboard_input_system.in_set(InputSystem))
|
||||||
// mouse
|
// mouse
|
||||||
.add_event::<MouseButtonInput>()
|
.add_event::<MouseButtonInput>()
|
||||||
.add_event::<MouseMotion>()
|
.add_event::<MouseMotion>()
|
||||||
.add_event::<MouseWheel>()
|
.add_event::<MouseWheel>()
|
||||||
.init_resource::<Input<MouseButton>>()
|
.init_resource::<ButtonInput<MouseButton>>()
|
||||||
.add_systems(PreUpdate, mouse_button_input_system.in_set(InputSystem))
|
.add_systems(PreUpdate, mouse_button_input_system.in_set(InputSystem))
|
||||||
.add_event::<TouchpadMagnify>()
|
.add_event::<TouchpadMagnify>()
|
||||||
.add_event::<TouchpadRotate>()
|
.add_event::<TouchpadRotate>()
|
||||||
@ -88,7 +88,7 @@ impl Plugin for InputPlugin {
|
|||||||
.add_event::<GamepadRumbleRequest>()
|
.add_event::<GamepadRumbleRequest>()
|
||||||
.init_resource::<GamepadSettings>()
|
.init_resource::<GamepadSettings>()
|
||||||
.init_resource::<Gamepads>()
|
.init_resource::<Gamepads>()
|
||||||
.init_resource::<Input<GamepadButton>>()
|
.init_resource::<ButtonInput<GamepadButton>>()
|
||||||
.init_resource::<Axis<GamepadAxis>>()
|
.init_resource::<Axis<GamepadAxis>>()
|
||||||
.init_resource::<Axis<GamepadButton>>()
|
.init_resource::<Axis<GamepadButton>>()
|
||||||
.add_systems(
|
.add_systems(
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
//! The mouse input functionality.
|
//! The mouse input functionality.
|
||||||
|
|
||||||
use crate::{ButtonState, Input};
|
use crate::{ButtonInput, ButtonState};
|
||||||
use bevy_ecs::entity::Entity;
|
use bevy_ecs::entity::Entity;
|
||||||
use bevy_ecs::{
|
use bevy_ecs::{
|
||||||
change_detection::DetectChangesMut,
|
change_detection::DetectChangesMut,
|
||||||
@ -20,7 +20,7 @@ use bevy_reflect::{ReflectDeserialize, ReflectSerialize};
|
|||||||
/// ## Usage
|
/// ## Usage
|
||||||
///
|
///
|
||||||
/// The event is read inside of the [`mouse_button_input_system`]
|
/// 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)]
|
#[derive(Event, Debug, Clone, Copy, PartialEq, Eq, Reflect)]
|
||||||
#[reflect(Debug, PartialEq)]
|
#[reflect(Debug, PartialEq)]
|
||||||
#[cfg_attr(
|
#[cfg_attr(
|
||||||
@ -41,7 +41,7 @@ pub struct MouseButtonInput {
|
|||||||
///
|
///
|
||||||
/// ## Usage
|
/// ## 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.
|
/// resource.
|
||||||
///
|
///
|
||||||
/// ## Updating
|
/// ## Updating
|
||||||
@ -133,14 +133,14 @@ pub struct MouseWheel {
|
|||||||
pub window: Entity,
|
pub window: Entity,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Updates the [`Input<MouseButton>`] resource with the latest [`MouseButtonInput`] events.
|
/// Updates the [`ButtonInput<MouseButton>`] resource with the latest [`MouseButtonInput`] events.
|
||||||
///
|
///
|
||||||
/// ## Differences
|
/// ## Differences
|
||||||
///
|
///
|
||||||
/// The main difference between the [`MouseButtonInput`] event and the [`Input<MouseButton>`] resource is that
|
/// The main difference between the [`MouseButtonInput`] event and the [`ButtonInput<MouseButton>`] resource is that
|
||||||
/// the latter has convenient functions like [`Input::pressed`], [`Input::just_pressed`] and [`Input::just_released`].
|
/// the latter has convenient functions like [`ButtonInput::pressed`], [`ButtonInput::just_pressed`] and [`ButtonInput::just_released`].
|
||||||
pub fn mouse_button_input_system(
|
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>,
|
mut mouse_button_input_events: EventReader<MouseButtonInput>,
|
||||||
) {
|
) {
|
||||||
mouse_button_input.bypass_change_detection().clear();
|
mouse_button_input.bypass_change_detection().clear();
|
||||||
|
@ -7,7 +7,7 @@ use bevy_ecs::{
|
|||||||
reflect::ReflectComponent,
|
reflect::ReflectComponent,
|
||||||
system::{Local, Query, Res},
|
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_math::{Rect, Vec2};
|
||||||
use bevy_reflect::{Reflect, ReflectDeserialize, ReflectSerialize};
|
use bevy_reflect::{Reflect, ReflectDeserialize, ReflectSerialize};
|
||||||
use bevy_render::{camera::NormalizedRenderTarget, prelude::Camera, view::ViewVisibility};
|
use bevy_render::{camera::NormalizedRenderTarget, prelude::Camera, view::ViewVisibility};
|
||||||
@ -126,7 +126,7 @@ pub fn ui_focus_system(
|
|||||||
mut state: Local<State>,
|
mut state: Local<State>,
|
||||||
camera: Query<(&Camera, Option<&UiCameraConfig>)>,
|
camera: Query<(&Camera, Option<&UiCameraConfig>)>,
|
||||||
windows: Query<&Window>,
|
windows: Query<&Window>,
|
||||||
mouse_button_input: Res<Input<MouseButton>>,
|
mouse_button_input: Res<ButtonInput<MouseButton>>,
|
||||||
touches_input: Res<Touches>,
|
touches_input: Res<Touches>,
|
||||||
ui_scale: Res<UiScale>,
|
ui_scale: Res<UiScale>,
|
||||||
ui_stack: Res<UiStack>,
|
ui_stack: Res<UiStack>,
|
||||||
|
@ -2,7 +2,7 @@ use crate::{PrimaryWindow, Window, WindowCloseRequested};
|
|||||||
|
|
||||||
use bevy_app::AppExit;
|
use bevy_app::AppExit;
|
||||||
use bevy_ecs::prelude::*;
|
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.
|
/// 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(
|
pub fn close_on_esc(
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
focused_windows: Query<(Entity, &Window)>,
|
focused_windows: Query<(Entity, &Window)>,
|
||||||
input: Res<Input<KeyCode>>,
|
input: Res<ButtonInput<KeyCode>>,
|
||||||
) {
|
) {
|
||||||
for (window, focus) in focused_windows.iter() {
|
for (window, focus) in focused_windows.iter() {
|
||||||
if !focus.focused {
|
if !focus.focused {
|
||||||
|
@ -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) {
|
if keyboard.pressed(KeyCode::Right) {
|
||||||
config.line_width += 5. * time.delta_seconds();
|
config.line_width += 5. * time.delta_seconds();
|
||||||
}
|
}
|
||||||
|
@ -91,7 +91,7 @@ fn update_bloom_settings(
|
|||||||
mut camera: Query<(Entity, Option<&mut BloomSettings>), With<Camera>>,
|
mut camera: Query<(Entity, Option<&mut BloomSettings>), With<Camera>>,
|
||||||
mut text: Query<&mut Text>,
|
mut text: Query<&mut Text>,
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
keycode: Res<Input<KeyCode>>,
|
keycode: Res<ButtonInput<KeyCode>>,
|
||||||
time: Res<Time>,
|
time: Res<Time>,
|
||||||
) {
|
) {
|
||||||
let bloom_settings = camera.single_mut();
|
let bloom_settings = camera.single_mut();
|
||||||
|
@ -117,7 +117,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
|||||||
/// Demonstrates applying rotation and movement based on keyboard input.
|
/// Demonstrates applying rotation and movement based on keyboard input.
|
||||||
fn player_movement_system(
|
fn player_movement_system(
|
||||||
time: Res<Time>,
|
time: Res<Time>,
|
||||||
keyboard_input: Res<Input<KeyCode>>,
|
keyboard_input: Res<ButtonInput<KeyCode>>,
|
||||||
mut query: Query<(&Player, &mut Transform)>,
|
mut query: Query<(&Player, &mut Transform)>,
|
||||||
) {
|
) {
|
||||||
let (ship, mut transform) = query.single_mut();
|
let (ship, mut transform) = query.single_mut();
|
||||||
|
@ -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.));
|
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) {
|
if keyboard.just_pressed(KeyCode::D) {
|
||||||
config.depth_bias = if config.depth_bias == 0. { -1. } else { 0. };
|
config.depth_bias = if config.depth_bias == 0. { -1. } else { 0. };
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ fn main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn modify_aa(
|
fn modify_aa(
|
||||||
keys: Res<Input<KeyCode>>,
|
keys: Res<ButtonInput<KeyCode>>,
|
||||||
mut camera: Query<
|
mut camera: Query<
|
||||||
(
|
(
|
||||||
Entity,
|
Entity,
|
||||||
@ -113,7 +113,7 @@ fn modify_aa(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn modify_sharpening(
|
fn modify_sharpening(
|
||||||
keys: Res<Input<KeyCode>>,
|
keys: Res<ButtonInput<KeyCode>>,
|
||||||
mut query: Query<&mut ContrastAdaptiveSharpeningSettings>,
|
mut query: Query<&mut ContrastAdaptiveSharpeningSettings>,
|
||||||
) {
|
) {
|
||||||
for mut cas in &mut query {
|
for mut cas in &mut query {
|
||||||
|
@ -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();
|
let mut fog_settings = fog.single_mut();
|
||||||
|
|
||||||
if keycode.just_pressed(KeyCode::Space) {
|
if keycode.just_pressed(KeyCode::Space) {
|
||||||
|
@ -290,7 +290,7 @@ fn example_control_system(
|
|||||||
labelled: Query<&GlobalTransform>,
|
labelled: Query<&GlobalTransform>,
|
||||||
mut state: Local<ExampleState>,
|
mut state: Local<ExampleState>,
|
||||||
time: Res<Time>,
|
time: Res<Time>,
|
||||||
input: Res<Input<KeyCode>>,
|
input: Res<ButtonInput<KeyCode>>,
|
||||||
) {
|
) {
|
||||||
if input.pressed(KeyCode::Up) {
|
if input.pressed(KeyCode::Up) {
|
||||||
state.alpha = (state.alpha + time.delta_seconds()).min(1.0);
|
state.alpha = (state.alpha + time.delta_seconds()).min(1.0);
|
||||||
|
@ -115,7 +115,7 @@ fn update_bloom_settings(
|
|||||||
mut camera: Query<(Entity, Option<&mut BloomSettings>), With<Camera>>,
|
mut camera: Query<(Entity, Option<&mut BloomSettings>), With<Camera>>,
|
||||||
mut text: Query<&mut Text>,
|
mut text: Query<&mut Text>,
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
keycode: Res<Input<KeyCode>>,
|
keycode: Res<ButtonInput<KeyCode>>,
|
||||||
time: Res<Time>,
|
time: Res<Time>,
|
||||||
) {
|
) {
|
||||||
let bloom_settings = camera.single_mut();
|
let bloom_settings = camera.single_mut();
|
||||||
|
@ -335,7 +335,7 @@ enum DefaultRenderMode {
|
|||||||
fn switch_mode(
|
fn switch_mode(
|
||||||
mut text: Query<&mut Text>,
|
mut text: Query<&mut Text>,
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
keys: Res<Input<KeyCode>>,
|
keys: Res<ButtonInput<KeyCode>>,
|
||||||
mut default_opaque_renderer_method: ResMut<DefaultOpaqueRendererMethod>,
|
mut default_opaque_renderer_method: ResMut<DefaultOpaqueRendererMethod>,
|
||||||
mut materials: ResMut<Assets<StandardMaterial>>,
|
mut materials: ResMut<Assets<StandardMaterial>>,
|
||||||
cameras: Query<Entity, With<Camera>>,
|
cameras: Query<Entity, With<Camera>>,
|
||||||
|
@ -159,7 +159,7 @@ fn update_system(
|
|||||||
mut camera: Query<(&mut FogSettings, &mut Transform)>,
|
mut camera: Query<(&mut FogSettings, &mut Transform)>,
|
||||||
mut text: Query<&mut Text>,
|
mut text: Query<&mut Text>,
|
||||||
time: Res<Time>,
|
time: Res<Time>,
|
||||||
keycode: Res<Input<KeyCode>>,
|
keycode: Res<ButtonInput<KeyCode>>,
|
||||||
) {
|
) {
|
||||||
let now = time.elapsed_seconds();
|
let now = time.elapsed_seconds();
|
||||||
let delta = time.delta_seconds();
|
let delta = time.delta_seconds();
|
||||||
|
@ -85,7 +85,7 @@ fn setup(
|
|||||||
// System to receive input from the user,
|
// System to receive input from the user,
|
||||||
// check out examples/input/ for more examples about user input.
|
// check out examples/input/ for more examples about user input.
|
||||||
fn input_handler(
|
fn input_handler(
|
||||||
keyboard_input: Res<Input<KeyCode>>,
|
keyboard_input: Res<ButtonInput<KeyCode>>,
|
||||||
mesh_query: Query<&Handle<Mesh>, With<CustomUV>>,
|
mesh_query: Query<&Handle<Mesh>, With<CustomUV>>,
|
||||||
mut meshes: ResMut<Assets<Mesh>>,
|
mut meshes: ResMut<Assets<Mesh>>,
|
||||||
mut query: Query<&mut Transform, With<CustomUV>>,
|
mut query: Query<&mut Transform, With<CustomUV>>,
|
||||||
|
@ -261,7 +261,7 @@ fn animate_light_direction(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn movement(
|
fn movement(
|
||||||
input: Res<Input<KeyCode>>,
|
input: Res<ButtonInput<KeyCode>>,
|
||||||
time: Res<Time>,
|
time: Res<Time>,
|
||||||
mut query: Query<&mut Transform, With<Movable>>,
|
mut query: Query<&mut Transform, With<Movable>>,
|
||||||
) {
|
) {
|
||||||
|
@ -79,7 +79,7 @@ impl CurrentMethod {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn update_parallax_depth_scale(
|
fn update_parallax_depth_scale(
|
||||||
input: Res<Input<KeyCode>>,
|
input: Res<ButtonInput<KeyCode>>,
|
||||||
mut materials: ResMut<Assets<StandardMaterial>>,
|
mut materials: ResMut<Assets<StandardMaterial>>,
|
||||||
mut target_depth: Local<TargetDepth>,
|
mut target_depth: Local<TargetDepth>,
|
||||||
mut depth_update: Local<bool>,
|
mut depth_update: Local<bool>,
|
||||||
@ -111,7 +111,7 @@ fn update_parallax_depth_scale(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn switch_method(
|
fn switch_method(
|
||||||
input: Res<Input<KeyCode>>,
|
input: Res<ButtonInput<KeyCode>>,
|
||||||
mut materials: ResMut<Assets<StandardMaterial>>,
|
mut materials: ResMut<Assets<StandardMaterial>>,
|
||||||
mut text: Query<&mut Text>,
|
mut text: Query<&mut Text>,
|
||||||
mut current: Local<CurrentMethod>,
|
mut current: Local<CurrentMethod>,
|
||||||
@ -130,7 +130,7 @@ fn switch_method(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn update_parallax_layers(
|
fn update_parallax_layers(
|
||||||
input: Res<Input<KeyCode>>,
|
input: Res<ButtonInput<KeyCode>>,
|
||||||
mut materials: ResMut<Assets<StandardMaterial>>,
|
mut materials: ResMut<Assets<StandardMaterial>>,
|
||||||
mut target_layers: Local<TargetLayers>,
|
mut target_layers: Local<TargetLayers>,
|
||||||
mut text: Query<&mut Text>,
|
mut text: Query<&mut Text>,
|
||||||
@ -187,7 +187,7 @@ const CAMERA_POSITIONS: &[Transform] = &[
|
|||||||
fn move_camera(
|
fn move_camera(
|
||||||
mut camera: Query<&mut Transform, With<CameraController>>,
|
mut camera: Query<&mut Transform, With<CameraController>>,
|
||||||
mut current_view: Local<usize>,
|
mut current_view: Local<usize>,
|
||||||
button: Res<Input<MouseButton>>,
|
button: Res<ButtonInput<MouseButton>>,
|
||||||
) {
|
) {
|
||||||
let mut camera = camera.single_mut();
|
let mut camera = camera.single_mut();
|
||||||
if button.just_pressed(MouseButton::Left) {
|
if button.just_pressed(MouseButton::Left) {
|
||||||
|
@ -187,7 +187,7 @@ fn setup(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn toggle_light(
|
fn toggle_light(
|
||||||
input: Res<Input<KeyCode>>,
|
input: Res<ButtonInput<KeyCode>>,
|
||||||
mut point_lights: Query<&mut PointLight>,
|
mut point_lights: Query<&mut PointLight>,
|
||||||
mut directional_lights: Query<&mut DirectionalLight>,
|
mut directional_lights: Query<&mut DirectionalLight>,
|
||||||
mut example_text: Query<&mut Text>,
|
mut example_text: Query<&mut Text>,
|
||||||
@ -213,7 +213,7 @@ fn toggle_light(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn adjust_light_position(
|
fn adjust_light_position(
|
||||||
input: Res<Input<KeyCode>>,
|
input: Res<ButtonInput<KeyCode>>,
|
||||||
mut lights: Query<&mut Transform, With<Lights>>,
|
mut lights: Query<&mut Transform, With<Lights>>,
|
||||||
mut example_text: Query<&mut Text>,
|
mut example_text: Query<&mut Text>,
|
||||||
) {
|
) {
|
||||||
@ -249,7 +249,7 @@ fn adjust_light_position(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn cycle_filter_methods(
|
fn cycle_filter_methods(
|
||||||
input: Res<Input<KeyCode>>,
|
input: Res<ButtonInput<KeyCode>>,
|
||||||
mut filter_methods: Query<&mut ShadowFilteringMethod>,
|
mut filter_methods: Query<&mut ShadowFilteringMethod>,
|
||||||
mut example_text: Query<&mut Text>,
|
mut example_text: Query<&mut Text>,
|
||||||
) {
|
) {
|
||||||
@ -276,7 +276,7 @@ fn cycle_filter_methods(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn adjust_point_light_biases(
|
fn adjust_point_light_biases(
|
||||||
input: Res<Input<KeyCode>>,
|
input: Res<ButtonInput<KeyCode>>,
|
||||||
mut query: Query<&mut PointLight>,
|
mut query: Query<&mut PointLight>,
|
||||||
mut example_text: Query<&mut Text>,
|
mut example_text: Query<&mut Text>,
|
||||||
) {
|
) {
|
||||||
@ -310,7 +310,7 @@ fn adjust_point_light_biases(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn adjust_directional_light_biases(
|
fn adjust_directional_light_biases(
|
||||||
input: Res<Input<KeyCode>>,
|
input: Res<ButtonInput<KeyCode>>,
|
||||||
mut query: Query<&mut DirectionalLight>,
|
mut query: Query<&mut DirectionalLight>,
|
||||||
mut example_text: Query<&mut Text>,
|
mut example_text: Query<&mut Text>,
|
||||||
) {
|
) {
|
||||||
@ -387,7 +387,7 @@ impl Default for CameraController {
|
|||||||
fn camera_controller(
|
fn camera_controller(
|
||||||
time: Res<Time>,
|
time: Res<Time>,
|
||||||
mut mouse_events: EventReader<MouseMotion>,
|
mut mouse_events: EventReader<MouseMotion>,
|
||||||
key_input: Res<Input<KeyCode>>,
|
key_input: Res<ButtonInput<KeyCode>>,
|
||||||
mut query: Query<(&mut Transform, &mut CameraController), With<Camera>>,
|
mut query: Query<(&mut Transform, &mut CameraController), With<Camera>>,
|
||||||
) {
|
) {
|
||||||
let dt = time.delta_seconds();
|
let dt = time.delta_seconds();
|
||||||
|
@ -126,7 +126,7 @@ fn setup(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn toggle_light(
|
fn toggle_light(
|
||||||
input: Res<Input<KeyCode>>,
|
input: Res<ButtonInput<KeyCode>>,
|
||||||
mut point_lights: Query<&mut PointLight>,
|
mut point_lights: Query<&mut PointLight>,
|
||||||
mut directional_lights: Query<&mut DirectionalLight>,
|
mut directional_lights: Query<&mut DirectionalLight>,
|
||||||
) {
|
) {
|
||||||
@ -152,7 +152,7 @@ fn toggle_light(
|
|||||||
|
|
||||||
fn toggle_shadows(
|
fn toggle_shadows(
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
input: Res<Input<KeyCode>>,
|
input: Res<ButtonInput<KeyCode>>,
|
||||||
mut queries: ParamSet<(
|
mut queries: ParamSet<(
|
||||||
Query<Entity, (With<Handle<Mesh>>, With<NotShadowCaster>)>,
|
Query<Entity, (With<Handle<Mesh>>, With<NotShadowCaster>)>,
|
||||||
Query<Entity, (With<Handle<Mesh>>, With<NotShadowReceiver>)>,
|
Query<Entity, (With<Handle<Mesh>>, With<NotShadowReceiver>)>,
|
||||||
|
@ -220,8 +220,8 @@ impl Default for CameraController {
|
|||||||
pub fn camera_controller(
|
pub fn camera_controller(
|
||||||
time: Res<Time>,
|
time: Res<Time>,
|
||||||
mut mouse_events: EventReader<MouseMotion>,
|
mut mouse_events: EventReader<MouseMotion>,
|
||||||
mouse_button_input: Res<Input<MouseButton>>,
|
mouse_button_input: Res<ButtonInput<MouseButton>>,
|
||||||
key_input: Res<Input<KeyCode>>,
|
key_input: Res<ButtonInput<KeyCode>>,
|
||||||
mut move_toggled: Local<bool>,
|
mut move_toggled: Local<bool>,
|
||||||
mut query: Query<(&mut Transform, &mut CameraController), With<Camera>>,
|
mut query: Query<(&mut Transform, &mut CameraController), With<Camera>>,
|
||||||
) {
|
) {
|
||||||
|
@ -141,7 +141,7 @@ fn light_sway(time: Res<Time>, mut query: Query<(&mut Transform, &mut SpotLight)
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn movement(
|
fn movement(
|
||||||
input: Res<Input<KeyCode>>,
|
input: Res<ButtonInput<KeyCode>>,
|
||||||
time: Res<Time>,
|
time: Res<Time>,
|
||||||
mut query: Query<&mut Transform, With<Movable>>,
|
mut query: Query<&mut Transform, With<Movable>>,
|
||||||
) {
|
) {
|
||||||
|
@ -127,7 +127,7 @@ fn update(
|
|||||||
mut text: Query<&mut Text>,
|
mut text: Query<&mut Text>,
|
||||||
mut sphere: Query<&mut Transform, With<SphereMarker>>,
|
mut sphere: Query<&mut Transform, With<SphereMarker>>,
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
keycode: Res<Input<KeyCode>>,
|
keycode: Res<ButtonInput<KeyCode>>,
|
||||||
time: Res<Time>,
|
time: Res<Time>,
|
||||||
) {
|
) {
|
||||||
let mut sphere = sphere.single_mut();
|
let mut sphere = sphere.single_mut();
|
||||||
|
@ -347,7 +347,7 @@ fn update_image_viewer(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn toggle_scene(
|
fn toggle_scene(
|
||||||
keys: Res<Input<KeyCode>>,
|
keys: Res<ButtonInput<KeyCode>>,
|
||||||
mut query: Query<(&mut Visibility, &SceneNumber)>,
|
mut query: Query<(&mut Visibility, &SceneNumber)>,
|
||||||
mut current_scene: ResMut<CurrentScene>,
|
mut current_scene: ResMut<CurrentScene>,
|
||||||
) {
|
) {
|
||||||
@ -374,7 +374,7 @@ fn toggle_scene(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn toggle_tonemapping_method(
|
fn toggle_tonemapping_method(
|
||||||
keys: Res<Input<KeyCode>>,
|
keys: Res<ButtonInput<KeyCode>>,
|
||||||
mut tonemapping: Query<&mut Tonemapping>,
|
mut tonemapping: Query<&mut Tonemapping>,
|
||||||
mut color_grading: Query<&mut ColorGrading>,
|
mut color_grading: Query<&mut ColorGrading>,
|
||||||
per_method_settings: Res<PerMethodSettings>,
|
per_method_settings: Res<PerMethodSettings>,
|
||||||
@ -422,7 +422,7 @@ impl SelectedParameter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn update_color_grading_settings(
|
fn update_color_grading_settings(
|
||||||
keys: Res<Input<KeyCode>>,
|
keys: Res<ButtonInput<KeyCode>>,
|
||||||
time: Res<Time>,
|
time: Res<Time>,
|
||||||
mut per_method_settings: ResMut<PerMethodSettings>,
|
mut per_method_settings: ResMut<PerMethodSettings>,
|
||||||
tonemapping: Query<&Tonemapping>,
|
tonemapping: Query<&Tonemapping>,
|
||||||
@ -479,7 +479,7 @@ fn update_ui(
|
|||||||
current_scene: Res<CurrentScene>,
|
current_scene: Res<CurrentScene>,
|
||||||
selected_parameter: Res<SelectedParameter>,
|
selected_parameter: Res<SelectedParameter>,
|
||||||
mut hide_ui: Local<bool>,
|
mut hide_ui: Local<bool>,
|
||||||
keys: Res<Input<KeyCode>>,
|
keys: Res<ButtonInput<KeyCode>>,
|
||||||
) {
|
) {
|
||||||
let (method, color_grading) = settings.single();
|
let (method, color_grading) = settings.single();
|
||||||
let method = *method;
|
let method = *method;
|
||||||
|
@ -438,7 +438,7 @@ fn example_control_system(
|
|||||||
mut display: Query<&mut Text, With<ExampleDisplay>>,
|
mut display: Query<&mut Text, With<ExampleDisplay>>,
|
||||||
mut state: Local<ExampleState>,
|
mut state: Local<ExampleState>,
|
||||||
time: Res<Time>,
|
time: Res<Time>,
|
||||||
input: Res<Input<KeyCode>>,
|
input: Res<ButtonInput<KeyCode>>,
|
||||||
) {
|
) {
|
||||||
if input.pressed(KeyCode::Key2) {
|
if input.pressed(KeyCode::Key2) {
|
||||||
state.diffuse_transmission = (state.diffuse_transmission + time.delta_seconds()).min(1.0);
|
state.diffuse_transmission = (state.diffuse_transmission + time.delta_seconds()).min(1.0);
|
||||||
|
@ -117,7 +117,7 @@ fn setup(
|
|||||||
|
|
||||||
/// This system let's you toggle various wireframe settings
|
/// This system let's you toggle various wireframe settings
|
||||||
fn update_colors(
|
fn update_colors(
|
||||||
keyboard_input: Res<Input<KeyCode>>,
|
keyboard_input: Res<ButtonInput<KeyCode>>,
|
||||||
mut config: ResMut<WireframeConfig>,
|
mut config: ResMut<WireframeConfig>,
|
||||||
mut wireframe_colors: Query<&mut WireframeColor>,
|
mut wireframe_colors: Query<&mut WireframeColor>,
|
||||||
mut text: Query<&mut Text>,
|
mut text: Query<&mut Text>,
|
||||||
|
@ -92,7 +92,7 @@ fn setup_scene_once_loaded(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn keyboard_animation_control(
|
fn keyboard_animation_control(
|
||||||
keyboard_input: Res<Input<KeyCode>>,
|
keyboard_input: Res<ButtonInput<KeyCode>>,
|
||||||
mut animation_players: Query<&mut AnimationPlayer>,
|
mut animation_players: Query<&mut AnimationPlayer>,
|
||||||
animations: Res<Animations>,
|
animations: Res<Animations>,
|
||||||
mut current_animation: Local<usize>,
|
mut current_animation: Local<usize>,
|
||||||
|
@ -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 keyboard_input.just_pressed(KeyCode::Space) {
|
||||||
if let Ok(sink) = music_controller.get_single() {
|
if let Ok(sink) = music_controller.get_single() {
|
||||||
sink.toggle();
|
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 let Ok(sink) = music_controller.get_single() {
|
||||||
if keyboard_input.just_pressed(KeyCode::Plus) {
|
if keyboard_input.just_pressed(KeyCode::Plus) {
|
||||||
sink.set_volume(sink.volume() + 0.1);
|
sink.set_volume(sink.volume() + 0.1);
|
||||||
|
@ -39,7 +39,7 @@ fn play_pitch(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn keyboard_input_system(
|
fn keyboard_input_system(
|
||||||
keyboard_input: Res<Input<KeyCode>>,
|
keyboard_input: Res<ButtonInput<KeyCode>>,
|
||||||
mut frequency: ResMut<PitchFrequency>,
|
mut frequency: ResMut<PitchFrequency>,
|
||||||
mut events: EventWriter<PlayPitch>,
|
mut events: EventWriter<PlayPitch>,
|
||||||
) {
|
) {
|
||||||
|
@ -102,7 +102,7 @@ struct Emitter {
|
|||||||
fn update_emitters(
|
fn update_emitters(
|
||||||
time: Res<Time>,
|
time: Res<Time>,
|
||||||
mut emitters: Query<(&mut Transform, &mut Emitter), With<Emitter>>,
|
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() {
|
for (mut emitter_transform, mut emitter) in emitters.iter_mut() {
|
||||||
if keyboard.just_pressed(KeyCode::Space) {
|
if keyboard.just_pressed(KeyCode::Space) {
|
||||||
@ -116,7 +116,7 @@ fn update_emitters(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn update_listener(
|
fn update_listener(
|
||||||
keyboard: Res<Input<KeyCode>>,
|
keyboard: Res<ButtonInput<KeyCode>>,
|
||||||
time: Res<Time>,
|
time: Res<Time>,
|
||||||
mut listeners: Query<&mut Transform, With<SpatialListener>>,
|
mut listeners: Query<&mut Transform, With<SpatialListener>>,
|
||||||
) {
|
) {
|
||||||
|
@ -101,7 +101,7 @@ struct Emitter {
|
|||||||
fn update_positions(
|
fn update_positions(
|
||||||
time: Res<Time>,
|
time: Res<Time>,
|
||||||
mut emitters: Query<(&mut Transform, &mut Emitter), With<Emitter>>,
|
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() {
|
for (mut emitter_transform, mut emitter) in emitters.iter_mut() {
|
||||||
if keyboard.just_pressed(KeyCode::Space) {
|
if keyboard.just_pressed(KeyCode::Space) {
|
||||||
@ -116,7 +116,7 @@ fn update_positions(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn update_listener(
|
fn update_listener(
|
||||||
keyboard: Res<Input<KeyCode>>,
|
keyboard: Res<ButtonInput<KeyCode>>,
|
||||||
time: Res<Time>,
|
time: Res<Time>,
|
||||||
mut listeners: Query<&mut Transform, With<SpatialListener>>,
|
mut listeners: Query<&mut Transform, With<SpatialListener>>,
|
||||||
) {
|
) {
|
||||||
|
@ -73,7 +73,7 @@ fn print_text_system(time: Res<Time>, mut query: Query<(&mut PrinterTick, &TextT
|
|||||||
|
|
||||||
fn transition_to_in_game_system(
|
fn transition_to_in_game_system(
|
||||||
mut next_state: ResMut<NextState<AppState>>,
|
mut next_state: ResMut<NextState<AppState>>,
|
||||||
keyboard_input: Res<Input<KeyCode>>,
|
keyboard_input: Res<ButtonInput<KeyCode>>,
|
||||||
) {
|
) {
|
||||||
if keyboard_input.pressed(KeyCode::Space) {
|
if keyboard_input.pressed(KeyCode::Space) {
|
||||||
next_state.set(AppState::InGame);
|
next_state.set(AppState::InGame);
|
||||||
|
@ -64,8 +64,8 @@ struct Unused;
|
|||||||
/// they are read only (except for local parameters which can be mutable).
|
/// they are read only (except for local parameters which can be mutable).
|
||||||
/// It returns a bool which determines if the system should run.
|
/// It returns a bool which determines if the system should run.
|
||||||
fn has_user_input(
|
fn has_user_input(
|
||||||
keyboard_input: Res<Input<KeyCode>>,
|
keyboard_input: Res<ButtonInput<KeyCode>>,
|
||||||
mouse_button_input: Res<Input<MouseButton>>,
|
mouse_button_input: Res<ButtonInput<MouseButton>>,
|
||||||
touch_input: Res<Touches>,
|
touch_input: Res<Touches>,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
keyboard_input.just_pressed(KeyCode::Space)
|
keyboard_input.just_pressed(KeyCode::Space)
|
||||||
|
@ -128,7 +128,7 @@ fn setup_game(mut commands: Commands, asset_server: Res<AssetServer>) {
|
|||||||
const SPEED: f32 = 100.0;
|
const SPEED: f32 = 100.0;
|
||||||
fn movement(
|
fn movement(
|
||||||
time: Res<Time>,
|
time: Res<Time>,
|
||||||
input: Res<Input<KeyCode>>,
|
input: Res<ButtonInput<KeyCode>>,
|
||||||
mut query: Query<&mut Transform, With<Sprite>>,
|
mut query: Query<&mut Transform, With<Sprite>>,
|
||||||
) {
|
) {
|
||||||
for mut transform in &mut query {
|
for mut transform in &mut query {
|
||||||
|
@ -192,7 +192,7 @@ fn teardown(mut commands: Commands, entities: Query<Entity, (Without<Camera>, Wi
|
|||||||
// control the game character
|
// control the game character
|
||||||
fn move_player(
|
fn move_player(
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
keyboard_input: Res<Input<KeyCode>>,
|
keyboard_input: Res<ButtonInput<KeyCode>>,
|
||||||
mut game: ResMut<Game>,
|
mut game: ResMut<Game>,
|
||||||
mut transforms: Query<&mut Transform>,
|
mut transforms: Query<&mut Transform>,
|
||||||
time: Res<Time>,
|
time: Res<Time>,
|
||||||
@ -376,7 +376,7 @@ fn scoreboard_system(game: Res<Game>, mut query: Query<&mut Text>) {
|
|||||||
// restart the game when pressing spacebar
|
// restart the game when pressing spacebar
|
||||||
fn gameover_keyboard(
|
fn gameover_keyboard(
|
||||||
mut next_state: ResMut<NextState<GameState>>,
|
mut next_state: ResMut<NextState<GameState>>,
|
||||||
keyboard_input: Res<Input<KeyCode>>,
|
keyboard_input: Res<ButtonInput<KeyCode>>,
|
||||||
) {
|
) {
|
||||||
if keyboard_input.just_pressed(KeyCode::Space) {
|
if keyboard_input.just_pressed(KeyCode::Space) {
|
||||||
next_state.set(GameState::Playing);
|
next_state.set(GameState::Playing);
|
||||||
|
@ -303,7 +303,7 @@ fn setup(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn move_paddle(
|
fn move_paddle(
|
||||||
keyboard_input: Res<Input<KeyCode>>,
|
keyboard_input: Res<ButtonInput<KeyCode>>,
|
||||||
mut query: Query<&mut Transform, With<Paddle>>,
|
mut query: Query<&mut Transform, With<Paddle>>,
|
||||||
time: Res<Time>,
|
time: Res<Time>,
|
||||||
) {
|
) {
|
||||||
|
@ -11,7 +11,7 @@ fn main() {
|
|||||||
|
|
||||||
fn gamepad_system(
|
fn gamepad_system(
|
||||||
gamepads: Res<Gamepads>,
|
gamepads: Res<Gamepads>,
|
||||||
button_inputs: Res<Input<GamepadButton>>,
|
button_inputs: Res<ButtonInput<GamepadButton>>,
|
||||||
button_axes: Res<Axis<GamepadButton>>,
|
button_axes: Res<Axis<GamepadButton>>,
|
||||||
axes: Res<Axis<GamepadAxis>>,
|
axes: Res<Axis<GamepadAxis>>,
|
||||||
) {
|
) {
|
||||||
|
@ -16,7 +16,7 @@ fn main() {
|
|||||||
|
|
||||||
fn gamepad_system(
|
fn gamepad_system(
|
||||||
gamepads: Res<Gamepads>,
|
gamepads: Res<Gamepads>,
|
||||||
button_inputs: Res<Input<GamepadButton>>,
|
button_inputs: Res<ButtonInput<GamepadButton>>,
|
||||||
mut rumble_requests: EventWriter<GamepadRumbleRequest>,
|
mut rumble_requests: EventWriter<GamepadRumbleRequest>,
|
||||||
) {
|
) {
|
||||||
for gamepad in gamepads.iter() {
|
for gamepad in gamepads.iter() {
|
||||||
|
@ -10,7 +10,7 @@ fn main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// This system prints 'A' key state
|
/// 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) {
|
if keyboard_input.pressed(KeyCode::A) {
|
||||||
info!("'A' currently pressed");
|
info!("'A' currently pressed");
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ fn main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// This system prints when `Ctrl + Shift + A` is pressed
|
/// 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 shift = input.any_pressed([KeyCode::ShiftLeft, KeyCode::ShiftRight]);
|
||||||
let ctrl = input.any_pressed([KeyCode::ControlLeft, KeyCode::ControlRight]);
|
let ctrl = input.any_pressed([KeyCode::ControlLeft, KeyCode::ControlRight]);
|
||||||
|
|
||||||
|
@ -13,8 +13,8 @@ fn main() {
|
|||||||
// and releases it when the escape key is pressed
|
// and releases it when the escape key is pressed
|
||||||
fn grab_mouse(
|
fn grab_mouse(
|
||||||
mut windows: Query<&mut Window>,
|
mut windows: Query<&mut Window>,
|
||||||
mouse: Res<Input<MouseButton>>,
|
mouse: Res<ButtonInput<MouseButton>>,
|
||||||
key: Res<Input<KeyCode>>,
|
key: Res<ButtonInput<KeyCode>>,
|
||||||
) {
|
) {
|
||||||
let mut window = windows.single_mut();
|
let mut window = windows.single_mut();
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ fn main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// This system prints messages when you press or release the left mouse button:
|
// 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) {
|
if mouse_button_input.pressed(MouseButton::Left) {
|
||||||
info!("left mouse currently pressed");
|
info!("left mouse currently pressed");
|
||||||
}
|
}
|
||||||
|
@ -101,7 +101,7 @@ fn setup_scene(mut commands: Commands, asset_server: Res<AssetServer>) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn toggle_ime(
|
fn toggle_ime(
|
||||||
input: Res<Input<MouseButton>>,
|
input: Res<ButtonInput<MouseButton>>,
|
||||||
mut windows: Query<&mut Window>,
|
mut windows: Query<&mut Window>,
|
||||||
mut text: Query<&mut Text, With<Node>>,
|
mut text: Query<&mut Text, With<Node>>,
|
||||||
) {
|
) {
|
||||||
|
@ -224,7 +224,7 @@ impl Material for PrepassOutputMaterial {
|
|||||||
/// Every time you press space, it will cycle between transparent, depth and normals view
|
/// Every time you press space, it will cycle between transparent, depth and normals view
|
||||||
fn toggle_prepass_view(
|
fn toggle_prepass_view(
|
||||||
mut prepass_view: Local<u32>,
|
mut prepass_view: Local<u32>,
|
||||||
keycode: Res<Input<KeyCode>>,
|
keycode: Res<ButtonInput<KeyCode>>,
|
||||||
material_handle: Query<&Handle<PrepassOutputMaterial>>,
|
material_handle: Query<&Handle<PrepassOutputMaterial>>,
|
||||||
mut materials: ResMut<Assets<PrepassOutputMaterial>>,
|
mut materials: ResMut<Assets<PrepassOutputMaterial>>,
|
||||||
mut text: Query<&mut Text>,
|
mut text: Query<&mut Text>,
|
||||||
|
@ -285,7 +285,7 @@ fn mouse_handler(
|
|||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
args: Res<Args>,
|
args: Res<Args>,
|
||||||
time: Res<Time>,
|
time: Res<Time>,
|
||||||
mouse_button_input: Res<Input<MouseButton>>,
|
mouse_button_input: Res<ButtonInput<MouseButton>>,
|
||||||
windows: Query<&Window>,
|
windows: Query<&Window>,
|
||||||
bird_resources: ResMut<BirdResources>,
|
bird_resources: ResMut<BirdResources>,
|
||||||
mut counter: ResMut<BevyCounter>,
|
mut counter: ResMut<BevyCounter>,
|
||||||
|
@ -248,7 +248,7 @@ fn update_fox_rings(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn keyboard_animation_control(
|
fn keyboard_animation_control(
|
||||||
keyboard_input: Res<Input<KeyCode>>,
|
keyboard_input: Res<ButtonInput<KeyCode>>,
|
||||||
mut animation_player: Query<&mut AnimationPlayer>,
|
mut animation_player: Query<&mut AnimationPlayer>,
|
||||||
animations: Res<Animations>,
|
animations: Res<Animations>,
|
||||||
mut current_animation: Local<usize>,
|
mut current_animation: Local<usize>,
|
||||||
|
@ -42,7 +42,7 @@ struct Config {
|
|||||||
fancy: bool,
|
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) {
|
if input.just_pressed(KeyCode::Up) {
|
||||||
config.line_count += 10_000;
|
config.line_count += 10_000;
|
||||||
}
|
}
|
||||||
|
@ -446,7 +446,7 @@ fn setup_connected(mut commands: Commands) {
|
|||||||
|
|
||||||
fn update_buttons(
|
fn update_buttons(
|
||||||
gamepads: Res<Gamepads>,
|
gamepads: Res<Gamepads>,
|
||||||
button_inputs: Res<Input<GamepadButton>>,
|
button_inputs: Res<ButtonInput<GamepadButton>>,
|
||||||
materials: Res<ButtonMaterials>,
|
materials: Res<ButtonMaterials>,
|
||||||
mut query: Query<(&mut Handle<ColorMaterial>, &ReactTo)>,
|
mut query: Query<(&mut Handle<ColorMaterial>, &ReactTo)>,
|
||||||
) {
|
) {
|
||||||
|
@ -66,7 +66,7 @@ fn assign_clips(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn handle_inputs(
|
fn handle_inputs(
|
||||||
keyboard_input: Res<Input<KeyCode>>,
|
keyboard_input: Res<ButtonInput<KeyCode>>,
|
||||||
mut animation_player: Query<(&mut AnimationPlayer, &mut Clips, Entity, Option<&Name>)>,
|
mut animation_player: Query<(&mut AnimationPlayer, &mut Clips, Entity, Option<&Name>)>,
|
||||||
) {
|
) {
|
||||||
for (mut player, mut clips, entity, name) in &mut animation_player {
|
for (mut player, mut clips, entity, name) in &mut animation_player {
|
||||||
|
@ -99,8 +99,8 @@ fn camera_controller(
|
|||||||
time: Res<Time>,
|
time: Res<Time>,
|
||||||
mut windows: Query<&mut Window>,
|
mut windows: Query<&mut Window>,
|
||||||
mut mouse_events: EventReader<MouseMotion>,
|
mut mouse_events: EventReader<MouseMotion>,
|
||||||
mouse_button_input: Res<Input<MouseButton>>,
|
mouse_button_input: Res<ButtonInput<MouseButton>>,
|
||||||
key_input: Res<Input<KeyCode>>,
|
key_input: Res<ButtonInput<KeyCode>>,
|
||||||
mut move_toggled: Local<bool>,
|
mut move_toggled: Local<bool>,
|
||||||
mut query: Query<(&mut Transform, &mut CameraController), With<Camera>>,
|
mut query: Query<(&mut Transform, &mut CameraController), With<Camera>>,
|
||||||
) {
|
) {
|
||||||
|
@ -166,7 +166,7 @@ impl MorphKey {
|
|||||||
key,
|
key,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn active(&self, inputs: &Input<KeyCode>) -> bool {
|
fn active(&self, inputs: &ButtonInput<KeyCode>) -> bool {
|
||||||
let mut modifier = self.modifiers.iter();
|
let mut modifier = self.modifiers.iter();
|
||||||
let mut non_modifier = ALL_MODIFIERS.iter().filter(|m| !self.modifiers.contains(m));
|
let mut non_modifier = ALL_MODIFIERS.iter().filter(|m| !self.modifiers.contains(m));
|
||||||
|
|
||||||
@ -202,7 +202,7 @@ fn update_text(
|
|||||||
fn update_morphs(
|
fn update_morphs(
|
||||||
controls: Option<ResMut<WeightsControl>>,
|
controls: Option<ResMut<WeightsControl>>,
|
||||||
mut morphs: Query<&mut MorphWeights>,
|
mut morphs: Query<&mut MorphWeights>,
|
||||||
input: Res<Input<KeyCode>>,
|
input: Res<ButtonInput<KeyCode>>,
|
||||||
time: Res<Time>,
|
time: Res<Time>,
|
||||||
) {
|
) {
|
||||||
let Some(mut controls) = controls else {
|
let Some(mut controls) = controls else {
|
||||||
|
@ -140,7 +140,7 @@ fn scene_load_check(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn update_lights(
|
fn update_lights(
|
||||||
key_input: Res<Input<KeyCode>>,
|
key_input: Res<ButtonInput<KeyCode>>,
|
||||||
time: Res<Time>,
|
time: Res<Time>,
|
||||||
mut query: Query<(&mut Transform, &mut DirectionalLight)>,
|
mut query: Query<(&mut Transform, &mut DirectionalLight)>,
|
||||||
mut animate_directional_light: Local<bool>,
|
mut animate_directional_light: Local<bool>,
|
||||||
@ -197,7 +197,7 @@ impl CameraTracker {
|
|||||||
|
|
||||||
fn camera_tracker(
|
fn camera_tracker(
|
||||||
mut camera_tracker: ResMut<CameraTracker>,
|
mut camera_tracker: ResMut<CameraTracker>,
|
||||||
keyboard_input: Res<Input<KeyCode>>,
|
keyboard_input: Res<ButtonInput<KeyCode>>,
|
||||||
mut queries: ParamSet<(
|
mut queries: ParamSet<(
|
||||||
Query<(Entity, &mut Camera), (Added<Camera>, Without<CameraController>)>,
|
Query<(Entity, &mut Camera), (Added<Camera>, Without<CameraController>)>,
|
||||||
Query<(Entity, &mut Camera), (Added<Camera>, With<CameraController>)>,
|
Query<(Entity, &mut Camera), (Added<Camera>, With<CameraController>)>,
|
||||||
|
@ -239,7 +239,7 @@ fn spawn_container(
|
|||||||
fn update_animation(
|
fn update_animation(
|
||||||
mut animation: ResMut<AnimationState>,
|
mut animation: ResMut<AnimationState>,
|
||||||
time: Res<Time>,
|
time: Res<Time>,
|
||||||
keys: Res<Input<KeyCode>>,
|
keys: Res<ButtonInput<KeyCode>>,
|
||||||
) {
|
) {
|
||||||
let time = time.elapsed_seconds();
|
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) {
|
if keys.just_pressed(KeyCode::O) {
|
||||||
for mut style in &mut containers {
|
for mut style in &mut containers {
|
||||||
style.overflow = match style.overflow {
|
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(
|
fn next_container_size(
|
||||||
keys: Res<Input<KeyCode>>,
|
keys: Res<ButtonInput<KeyCode>>,
|
||||||
mut containers: Query<(&mut Style, &mut Container)>,
|
mut containers: Query<(&mut Style, &mut Container)>,
|
||||||
) {
|
) {
|
||||||
if keys.just_pressed(KeyCode::S) {
|
if keys.just_pressed(KeyCode::S) {
|
||||||
|
@ -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.
|
/// 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) {
|
if input.just_pressed(KeyCode::Up) {
|
||||||
let scale = (ui_scale.target_scale * 2.0).min(8.);
|
let scale = (ui_scale.target_scale * 2.0).min(8.);
|
||||||
ui_scale.set_scale(scale);
|
ui_scale.set_scale(scale);
|
||||||
|
@ -76,7 +76,7 @@ fn setup(
|
|||||||
|
|
||||||
fn increment_atlas_index(
|
fn increment_atlas_index(
|
||||||
mut atlas_images: Query<&mut UiTextureAtlasImage>,
|
mut atlas_images: Query<&mut UiTextureAtlasImage>,
|
||||||
keyboard: Res<Input<KeyCode>>,
|
keyboard: Res<ButtonInput<KeyCode>>,
|
||||||
) {
|
) {
|
||||||
if keyboard.just_pressed(KeyCode::Space) {
|
if keyboard.just_pressed(KeyCode::Space) {
|
||||||
for mut atlas_image in &mut atlas_images {
|
for mut atlas_image in &mut atlas_images {
|
||||||
|
@ -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.
|
// 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) {
|
if keyboard_input.just_pressed(KeyCode::P) {
|
||||||
let mut window = windows.single_mut();
|
let mut window = windows.single_mut();
|
||||||
window.cursor.hit_test = !window.cursor.hit_test;
|
window.cursor.hit_test = !window.cursor.hit_test;
|
||||||
|
@ -17,7 +17,7 @@ fn setup(mut commands: Commands) {
|
|||||||
commands.spawn(Camera2dBundle::default());
|
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) {
|
if input.just_pressed(KeyCode::Space) {
|
||||||
clear_color.0 = Color::PURPLE;
|
clear_color.0 = Color::PURPLE;
|
||||||
}
|
}
|
||||||
|
@ -98,7 +98,7 @@ pub(crate) mod test_setup {
|
|||||||
/// Switch between update modes when the mouse is clicked.
|
/// Switch between update modes when the mouse is clicked.
|
||||||
pub(crate) fn cycle_modes(
|
pub(crate) fn cycle_modes(
|
||||||
mut mode: ResMut<ExampleMode>,
|
mut mode: ResMut<ExampleMode>,
|
||||||
mouse_button_input: Res<Input<KeyCode>>,
|
mouse_button_input: Res<ButtonInput<KeyCode>>,
|
||||||
) {
|
) {
|
||||||
if mouse_button_input.just_pressed(KeyCode::Space) {
|
if mouse_button_input.just_pressed(KeyCode::Space) {
|
||||||
*mode = match *mode {
|
*mode = match *mode {
|
||||||
|
@ -76,7 +76,7 @@ fn display_override(mut windows: Query<&mut Window>) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// This system toggles scale factor overrides when enter is pressed
|
/// 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();
|
let mut window = windows.single_mut();
|
||||||
|
|
||||||
if input.just_pressed(KeyCode::Return) {
|
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
|
/// 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 mut window = windows.single_mut();
|
||||||
let scale_factor_override = window.resolution.scale_factor_override();
|
let scale_factor_override = window.resolution.scale_factor_override();
|
||||||
if input.just_pressed(KeyCode::Up) {
|
if input.just_pressed(KeyCode::Up) {
|
||||||
|
@ -13,7 +13,7 @@ fn main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn screenshot_on_spacebar(
|
fn screenshot_on_spacebar(
|
||||||
input: Res<Input<KeyCode>>,
|
input: Res<ButtonInput<KeyCode>>,
|
||||||
main_window: Query<Entity, With<PrimaryWindow>>,
|
main_window: Query<Entity, With<PrimaryWindow>>,
|
||||||
mut screenshot_manager: ResMut<ScreenshotManager>,
|
mut screenshot_manager: ResMut<ScreenshotManager>,
|
||||||
mut counter: Local<u32>,
|
mut counter: Local<u32>,
|
||||||
|
@ -58,7 +58,7 @@ fn setup_ui(mut cmd: Commands) {
|
|||||||
|
|
||||||
/// This system shows how to request the window to a new resolution
|
/// This system shows how to request the window to a new resolution
|
||||||
fn toggle_resolution(
|
fn toggle_resolution(
|
||||||
keys: Res<Input<KeyCode>>,
|
keys: Res<ButtonInput<KeyCode>>,
|
||||||
mut windows: Query<&mut Window>,
|
mut windows: Query<&mut Window>,
|
||||||
resolution: Res<ResolutionSettings>,
|
resolution: Res<ResolutionSettings>,
|
||||||
) {
|
) {
|
||||||
|
@ -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.
|
/// This system toggles the vsync mode when pressing the button V.
|
||||||
/// You'll see fps increase displayed in the console.
|
/// 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) {
|
if input.just_pressed(KeyCode::V) {
|
||||||
let mut window = windows.single_mut();
|
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
|
/// This feature only works on some platforms. Please check the
|
||||||
/// [documentation](https://docs.rs/bevy/latest/bevy/prelude/struct.Window.html#structfield.window_level)
|
/// [documentation](https://docs.rs/bevy/latest/bevy/prelude/struct.Window.html#structfield.window_level)
|
||||||
/// for more details.
|
/// 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) {
|
if input.just_pressed(KeyCode::T) {
|
||||||
let mut window = windows.single_mut();
|
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
|
/// This feature only works on some platforms. Please check the
|
||||||
/// [documentation](https://docs.rs/bevy/latest/bevy/prelude/struct.Window.html#structfield.enabled_buttons)
|
/// [documentation](https://docs.rs/bevy/latest/bevy/prelude/struct.Window.html#structfield.enabled_buttons)
|
||||||
/// for more details.
|
/// 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_minimize = input.just_pressed(KeyCode::Key1);
|
||||||
let toggle_maximize = input.just_pressed(KeyCode::Key2);
|
let toggle_maximize = input.just_pressed(KeyCode::Key2);
|
||||||
let toggle_close = input.just_pressed(KeyCode::Key3);
|
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) {
|
if input.just_pressed(KeyCode::Space) {
|
||||||
let mut window = windows.single_mut();
|
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
|
// 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) {
|
if input.just_pressed(KeyCode::F) {
|
||||||
let mut window = windows.single_mut();
|
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
|
/// This system cycles the cursor's icon through a small set of icons when clicking
|
||||||
fn cycle_cursor_icon(
|
fn cycle_cursor_icon(
|
||||||
mut windows: Query<&mut Window>,
|
mut windows: Query<&mut Window>,
|
||||||
input: Res<Input<MouseButton>>,
|
input: Res<ButtonInput<MouseButton>>,
|
||||||
mut index: Local<usize>,
|
mut index: Local<usize>,
|
||||||
) {
|
) {
|
||||||
let mut window = windows.single_mut();
|
let mut window = windows.single_mut();
|
||||||
|
@ -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) {
|
if keyboard_input.just_pressed(KeyCode::Space) {
|
||||||
commands.spawn(Enemy {
|
commands.spawn(Enemy {
|
||||||
hit_points: 5,
|
hit_points: 5,
|
||||||
@ -124,7 +124,7 @@ fn spawn_enemy_using_input_resource() {
|
|||||||
app.add_systems(Update, spawn_enemy);
|
app.add_systems(Update, spawn_enemy);
|
||||||
|
|
||||||
// Setup test resource
|
// Setup test resource
|
||||||
let mut input = Input::<KeyCode>::default();
|
let mut input = ButtonInput::<KeyCode>::default();
|
||||||
input.press(KeyCode::Space);
|
input.press(KeyCode::Space);
|
||||||
app.insert_resource(input);
|
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);
|
assert_eq!(app.world.query::<&Enemy>().iter(&app.world).len(), 1);
|
||||||
|
|
||||||
// Clear the `just_pressed` status for all `KeyCode`s
|
// 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
|
// Run systems
|
||||||
app.update();
|
app.update();
|
||||||
|
Loading…
Reference in New Issue
Block a user