diff --git a/RELEASES.md b/RELEASES.md index 367fbe3f..36c3eb02 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -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 diff --git a/src/input_map.rs b/src/input_map.rs index 6623cf24..62c39b33 100644 --- a/src/input_map.rs +++ b/src/input_map.rs @@ -373,16 +373,20 @@ impl InputMap { 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()); @@ -402,6 +406,22 @@ impl InputMap { } } +/// 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 InputMap { /// Returns an iterator over actions with their inputs