Skip to content

Commit

Permalink
Add ActionsData::insert_action
Browse files Browse the repository at this point in the history
  • Loading branch information
Shatur committed Oct 26, 2024
1 parent 9d33571 commit 0d441a4
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Logging for binding.
- `ActionEventKinds` bitmask to store triggered events since the last update. Accessible via `ActionData::event_kinds`.
- `ActionsData::insert_action`.

### Changed

Expand Down
7 changes: 7 additions & 0 deletions src/input_context/input_action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ impl ActionsData {
pub fn action<A: InputAction>(&self) -> Option<&ActionData> {
self.get(&TypeId::of::<A>())
}

/// Inserts a state for action `A`.
///
/// Returns previosly associated state if present.
pub fn insert_action<A: InputAction>(&mut self, action: ActionData) -> Option<ActionData> {
self.insert(TypeId::of::<A>(), action)
}
}

impl From<HashMap<TypeId, ActionData>> for ActionsData {
Expand Down
4 changes: 1 addition & 3 deletions src/input_context/input_condition/block_by.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ impl<A: InputAction> InputCondition for BlockBy<A> {

#[cfg(test)]
mod tests {
use any::TypeId;

use bevy_enhanced_input_macros::InputAction;

use super::*;
Expand All @@ -76,7 +74,7 @@ mod tests {
let time = Time::default();
action.update(&mut world.commands(), &time, &[], ActionState::Fired, true);
let mut actions = ActionsData::default();
actions.insert(TypeId::of::<DummyAction>(), action);
actions.insert_action::<DummyAction>(action);

assert_eq!(
condition.evaluate(&actions, &time, true.into()),
Expand Down
4 changes: 1 addition & 3 deletions src/input_context/input_condition/chord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ impl<A: InputAction> InputCondition for Chord<A> {

#[cfg(test)]
mod tests {
use any::TypeId;

use bevy_enhanced_input_macros::InputAction;

use super::*;
Expand All @@ -77,7 +75,7 @@ mod tests {
let time = Time::default();
action.update(&mut world.commands(), &time, &[], ActionState::Fired, true);
let mut actions = ActionsData::default();
actions.insert(TypeId::of::<DummyAction>(), action);
actions.insert_action::<DummyAction>(action);

assert_eq!(
condition.evaluate(&actions, &time, true.into()),
Expand Down

0 comments on commit 0d441a4

Please sign in to comment.