Skip to content

Commit

Permalink
Add a missing function of InputMap and fix some internal bugs (#608)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shute052 authored Aug 25, 2024
1 parent 020435d commit e7a6e76
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
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

0 comments on commit e7a6e76

Please sign in to comment.