Skip to content

Commit

Permalink
Fix incorrect axis data in Chord when not all buttons are pressed (#…
Browse files Browse the repository at this point in the history
…432)

* Fix incorrect axis data in `Chord` when not all buttons are pressed

* Update RELEASES.md

* Fix typo

* Fix incorrect related issue
  • Loading branch information
Shute052 authored Dec 29, 2023
1 parent 9d60abb commit d421117
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
1 change: 1 addition & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- Register types in the reflection system.
- added support in `ActionDiff` for value and axis_pair changes
- Added `InputMap::Clear`.
- Fixed [a bug](https://github.com/Leafwing-Studios/leafwing-input-manager/issues/430) related to incorrect axis data in `Chord` when not all buttons are pressed.

## Version 0.11.2

Expand Down
34 changes: 27 additions & 7 deletions src/input_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,16 +373,20 @@ impl<A: Actionlike> InputMap<A> {
for input in input_vec {
let action = &mut action_data[action.index()];

// Merge axis pair into action data
let axis_pair = input_streams.input_axis_pair(input);
if let Some(axis_pair) = axis_pair {
if let Some(current_axis_pair) = &mut action.axis_pair {
*current_axis_pair = current_axis_pair.merged_with(axis_pair);
} else {
action.axis_pair = Some(axis_pair);
// Exclude chord combining both button-like and axis-like inputs unless all buttons are pressed.
if let UserInput::Chord(buttons) = input {
if input_streams.all_buttons_pressed(buttons) {
inputs.push(input.clone());

action.value += input_streams.input_value(input, true);

merge_axis_pair_into_action(action, input_streams, input);
}
continue;
}

merge_axis_pair_into_action(action, input_streams, input);

if input_streams.input_pressed(input) {
inputs.push(input.clone());

Expand All @@ -402,6 +406,22 @@ impl<A: Actionlike> InputMap<A> {
}
}

/// Merges axis pair into action data.
#[inline]
fn merge_axis_pair_into_action(
action: &mut ActionData,
input_streams: &InputStreams,
input: &UserInput,
) {
if let Some(axis_pair) = input_streams.input_axis_pair(input) {
if let Some(current_axis_pair) = &mut action.axis_pair {
*current_axis_pair = current_axis_pair.merged_with(axis_pair);
} else {
action.axis_pair = Some(axis_pair);
}
}
}

// Utilities
impl<A: Actionlike> InputMap<A> {
/// Returns an iterator over actions with their inputs
Expand Down

0 comments on commit d421117

Please sign in to comment.