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
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Bugs
- Fixed system order ambiguity between bevy_ui and update_action_state systems
- The input values of axis inputs in a `Chord` are now prioritized over buttons

### Docs

Expand Down
32 changes: 32 additions & 0 deletions src/input_streams.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,38 @@ impl<'a> InputStreams<'a> {
UserInput::VirtualDPad { .. } => {
self.input_axis_pair(input).unwrap_or_default().length()
}
UserInput::Chord(inputs) => {
let mut value = 0.0;
let mut has_axis = false;

// 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) => {
has_axis = true;
self.input_value(
&UserInput::Single(InputKind::MouseMotion(*axis)),
true,
)
}
_ => 0.0,
}
}

if has_axis {
return 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)) => {
if let Some(gamepad) = self.guess_gamepad() {
Expand Down