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 InputMap::len and add InputMap::dual_axislike_mut and missing registrations of chords #608

Merged
merged 1 commit into from
Aug 25, 2024
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
13 changes: 9 additions & 4 deletions src/input_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -680,13 +680,18 @@ impl<A: Actionlike> InputMap<A> {
self.dual_axislike_map.get(action)
}

/// Returns a mutable reference to the [`DualAxislike`] inputs mapped to `action`
#[must_use]
pub fn get_dual_axislike_mut(&mut self, action: &A) -> Option<&mut Vec<Box<dyn DualAxislike>>> {
self.dual_axislike_map.get_mut(action)
}

/// Count the total number of registered input bindings.
#[must_use]
pub fn len(&self) -> usize {
self.buttonlike_map
.values()
.map(|inputs| inputs.len())
.sum()
self.buttonlike_map.values().map(Vec::len).sum::<usize>()
+ self.axislike_map.values().map(Vec::len).sum::<usize>()
+ self.dual_axislike_map.values().map(Vec::len).sum::<usize>()
}

/// Returns `true` if the map contains no action-input bindings.
Expand Down
5 changes: 5 additions & 0 deletions src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,11 @@ impl<A: Actionlike + TypePath + bevy::reflect::GetTypeRegistration> Plugin
.register_user_input::<GamepadVirtualAxis>()
.register_user_input::<GamepadVirtualDPad>();

// Chords
app.register_user_input::<ButtonlikeChord>()
.register_user_input::<AxislikeChord>()
.register_user_input::<DualAxislikeChord>();

// General-purpose reflection
app.register_type::<ActionState<A>>()
.register_type::<InputMap<A>>()
Expand Down