Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix axis inputs in a Chord being read a button #381

Merged
merged 4 commits into from
Sep 10, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Prioritize axis over button
  • Loading branch information
100-TomatoJuice committed Sep 10, 2023
commit ec48b5d3cca47365671b9dd5f09e25a272690489
27 changes: 20 additions & 7 deletions src/input_streams.rs
Original file line number Diff line number Diff line change
@@ -332,22 +332,35 @@ impl<'a> InputStreams<'a> {
}
UserInput::Chord(inputs) => {
let mut value = 0.0;
let mut has_axis = false;

inputs.iter().for_each(|input| {
// Prioritize axis over button input values
for input in inputs.iter() {
value += match input {
InputKind::SingleAxis(axis) => {
has_axis = true;
self.input_value(&UserInput::Single(InputKind::SingleAxis(*axis)), true)
}
InputKind::MouseWheel(axis) => {
has_axis = true;
self.input_value(&UserInput::Single(InputKind::MouseWheel(*axis)), true)
}
InputKind::MouseMotion(axis) => self
.input_value(&UserInput::Single(InputKind::MouseMotion(*axis)), true),
_ => use_button_value(),
};
});
InputKind::MouseMotion(axis) => {
has_axis = true;
self.input_value(
&UserInput::Single(InputKind::MouseMotion(*axis)),
true,
)
}
_ => 0.0,
}
}

if has_axis {
return value;
}

value
use_button_value()
}
// This is required because upstream bevy::input still waffles about whether triggers are buttons or axes
UserInput::Single(InputKind::GamepadButton(button_type)) => {