Skip to content

Commit

Permalink
Make Accumulation::Cumulative default
Browse files Browse the repository at this point in the history
  • Loading branch information
Shatur committed Oct 19, 2024
1 parent 8af773c commit 0ad83f5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
14 changes: 7 additions & 7 deletions src/input_context/input_action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,22 +406,22 @@ pub trait InputAction: Debug + Send + Sync + 'static {
const CONSUME_INPUT: bool = true;

/// Associated accumulation behavior.
const ACCUMULATION: Accumulation = Accumulation::MaxAbs;
const ACCUMULATION: Accumulation = Accumulation::Cumulative;
}

/// Defines how [`ActionValue`] is calculated when multiple inputs are evaluated with the same [`ActionState`].
#[derive(Default, Clone, Copy, Debug)]
pub enum Accumulation {
/// Take the value from the mapping with the highest absolute value.
///
/// For example, given values of 0.5 and -1.5, the input action's value would be -1.5.
#[default]
MaxAbs,

/// Cumulatively add the key values for each mapping.
///
/// For example, given values of 0.5 and -0.3, the input action's value would be 0.2.
///
/// Usually used for things like WASD movement, when you want pressing W and S to cancel each other out.
#[default]
Cumulative,

/// Take the value from the mapping with the highest absolute value.
///
/// For example, given values of 0.5 and -1.5, the input action's value would be -1.5.
MaxAbs,
}
6 changes: 3 additions & 3 deletions tests/conditions_and_modifiers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ fn input_level() {
let recorded = app.world().resource::<RecordedActions>();
let events = recorded.get::<InputLevel>(entity).unwrap();
let event = events.last().unwrap();
assert_eq!(event.value, (Vec2::Y * 2.0).into());
assert_eq!(event.value, Vec2::Y.into());

app.world_mut()
.resource_mut::<ButtonInput<KeyCode>>()
Expand Down Expand Up @@ -117,7 +117,7 @@ fn action_level() {
let recorded = app.world().resource::<RecordedActions>();
let events = recorded.get::<ActionLevel>(entity).unwrap();
let event = events.last().unwrap();
assert_eq!(event.value, (Vec2::NEG_Y * 2.0).into());
assert_eq!(event.value, (Vec2::NEG_Y * 4.0).into());

app.world_mut()
.resource_mut::<ButtonInput<KeyCode>>()
Expand Down Expand Up @@ -182,7 +182,7 @@ fn both_levels() {
let recorded = app.world().resource::<RecordedActions>();
let events = recorded.get::<BothLevels>(entity).unwrap();
let event = events.last().unwrap();
assert_eq!(event.value, (Vec2::Y * 2.0).into());
assert_eq!(event.value, Vec2::Y.into());

app.world_mut()
.resource_mut::<ButtonInput<KeyCode>>()
Expand Down

0 comments on commit 0ad83f5

Please sign in to comment.