Skip to content

Commit

Permalink
Changed parameter of get and remove of Axis<T> from &T to T
Browse files Browse the repository at this point in the history
This makes Axis<T> more analogous to Input<T>
  • Loading branch information
simpuid committed Oct 18, 2020
1 parent 842b4bc commit 96b0aa5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
8 changes: 4 additions & 4 deletions crates/bevy_input/src/axis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ where
self.axis_data.insert(axis, value)
}

pub fn get(&self, axis: &T) -> Option<f32> {
self.axis_data.get(axis).copied()
pub fn get(&self, axis: T) -> Option<f32> {
self.axis_data.get(&axis).copied()
}

pub fn remove(&mut self, axis: &T) -> Option<f32> {
self.axis_data.remove(axis)
pub fn remove(&mut self, axis: T) -> Option<f32> {
self.axis_data.remove(&axis)
}
}
8 changes: 4 additions & 4 deletions crates/bevy_input/src/gamepad.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,24 +226,24 @@ pub fn gamepad_event_system(
for button_type in ALL_BUTTON_TYPES.iter() {
let gamepad_button = GamepadButton(*gamepad, *button_type);
button.reset(gamepad_button);
button_axis.remove(&gamepad_button);
button_axis.remove(gamepad_button);
}
for axis_type in ALL_AXIS_TYPES.iter() {
axis.remove(&GamepadAxis(*gamepad, *axis_type));
axis.remove(GamepadAxis(*gamepad, *axis_type));
}
}
GamepadEventType::AxisChanged(axis_type, value) => {
let gamepad_axis = GamepadAxis(*gamepad, *axis_type);
let value = properties
.get_axis_properties(gamepad_axis)
.filter(*value, axis.get(&gamepad_axis));
.filter(*value, axis.get(gamepad_axis));
axis.set(gamepad_axis, value);
}
GamepadEventType::ButtonChanged(button_type, value) => {
let gamepad_button = GamepadButton(*gamepad, *button_type);
let filtered_value = properties
.get_button_axis_properties(gamepad_button)
.filter(*value, button_axis.get(&gamepad_button));
.filter(*value, button_axis.get(gamepad_button));
button_axis.set(gamepad_button, filtered_value);

let button_property = properties.get_button_properties(gamepad_button);
Expand Down
4 changes: 2 additions & 2 deletions examples/input/gamepad_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ fn button_system(
} else if inputs.just_released(GamepadButton(*gamepad, *button_type)) {
println!("{:?} Released", gamepad_button);
}
if let Some(value) = button_axes.get(&gamepad_button) {
if let Some(value) = button_axes.get(gamepad_button) {
if data.button.get(&gamepad_button).copied().unwrap_or(0.0) != value {
data.button.insert(gamepad_button, value);
println!("{:?} is {}", gamepad_button, value);
Expand All @@ -101,7 +101,7 @@ fn axis_system(lobby: Res<Lobby>, axes: Res<Axis<GamepadAxis>>, mut data: ResMut
for gamepad in lobby.gamepad.iter() {
for axis_type in axis_types.iter() {
let gamepad_axis = GamepadAxis(*gamepad, *axis_type);
if let Some(value) = axes.get(&gamepad_axis) {
if let Some(value) = axes.get(gamepad_axis) {
if data.axis.get(&gamepad_axis).copied().unwrap_or(0.0) != value {
data.axis.insert(gamepad_axis, value);
println!("{:?} is {}", gamepad_axis, value);
Expand Down

0 comments on commit 96b0aa5

Please sign in to comment.