Skip to content

Commit

Permalink
added logical key from winit ; removed ScanCode ; removed copy from I…
Browse files Browse the repository at this point in the history
…nput
  • Loading branch information
Vrixyz committed Jun 4, 2023
1 parent a93bf05 commit 54483f9
Show file tree
Hide file tree
Showing 6 changed files with 1,132 additions and 52 deletions.
4 changes: 3 additions & 1 deletion crates/bevy_input/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ bevy_app = { path = "../bevy_app", version = "0.11.0-dev" }
bevy_ecs = { path = "../bevy_ecs", version = "0.11.0-dev" }
bevy_math = { path = "../bevy_math", version = "0.11.0-dev" }
bevy_utils = { path = "../bevy_utils", version = "0.11.0-dev" }
bevy_reflect = { path = "../bevy_reflect", version = "0.11.0-dev", features = ["glam"] }
bevy_reflect = { path = "../bevy_reflect", version = "0.11.0-dev", features = [
"glam",
] }

# other
serde = { version = "1", features = ["derive"], optional = true }
Expand Down
12 changes: 6 additions & 6 deletions crates/bevy_input/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,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 Input<T: Clone + 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.
Expand All @@ -52,7 +52,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: Clone + Eq + Hash + Send + Sync + 'static> Default for Input<T> {
fn default() -> Self {
Self {
pressed: Default::default(),
Expand All @@ -64,13 +64,13 @@ impl<T: Copy + Eq + Hash + Send + Sync + 'static> Default for Input<T> {

impl<T> Input<T>
where
T: Copy + Eq + Hash + Send + Sync + 'static,
T: Clone + Eq + Hash + Send + Sync + 'static,
{
/// Registers a press for the given `input`.
pub fn press(&mut self, input: T) {
// Returns `true` if the `input` wasn't pressed.
if self.pressed.insert(input) {
self.just_pressed.insert(input);
if self.pressed.insert(input.clone()) {
self.just_pressed.insert(input.clone());
}
}

Expand Down Expand Up @@ -177,7 +177,7 @@ mod test {
use crate::Input;

/// Used for testing the functionality of [`Input`].
#[derive(Copy, Clone, Eq, PartialEq, Hash)]
#[derive(Clone, Eq, PartialEq, Hash)]
enum DummyInput {
Input1,
Input2,
Expand Down
Loading

0 comments on commit 54483f9

Please sign in to comment.