From fb68cfb8344151b935c86cc2dcdbcc10c16dd9e0 Mon Sep 17 00:00:00 2001 From: Hennadii Chernyshchyk Date: Tue, 29 Oct 2024 21:58:43 +0200 Subject: [PATCH] Consume inputs only if the action state is not equal to `ActionState::None` --- CHANGELOG.md | 1 + src/input_context/context_instance.rs | 10 ++++++---- src/input_context/input_action.rs | 4 ++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eb197ae..e53b026 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Rework `ConditionKind` and the logic around it to make the behavior close to UE. +- Consume inputs only if the action state is not equal to `ActionState::None`. - Remove world access from conditions and modifiers. This means that you no longer can write game-specific conditions or modifiers. But it's much nicer (and faster) to just do it in observers instead. - Values from `Input` are now converted to the action-level dimension only after applying all input-level modifiers and conditions. This allows things like mapping the Y-axis of `ActionValue::Axis2D` into an action with `ActionValueDim::Axis1D`. - Rename `ActionBind::with_axis2d` into `ActionBind::with_xy_axis`. diff --git a/src/input_context/context_instance.rs b/src/input_context/context_instance.rs index b9cdfce..3bacab7 100644 --- a/src/input_context/context_instance.rs +++ b/src/input_context/context_instance.rs @@ -279,10 +279,6 @@ impl ActionBind { let mut tracker = TriggerTracker::new(ActionValue::zero(self.dim)); for binding in &mut self.bindings { let value = reader.value(binding.input); - if self.consume_input { - reader.consume(binding.input); - } - if binding.ignored { // Ignore until we read zero for this mapping. if value.as_bool() { @@ -308,6 +304,12 @@ impl ActionBind { let state = tracker.state(); let value = tracker.value().convert(self.dim); + if self.consume_input && state != ActionState::None { + for binding in &self.bindings { + reader.consume(binding.input); + } + } + action.update_time(time); if !tracker.events_blocked() { action.trigger_events(commands, entities, state, value); diff --git a/src/input_context/input_action.rs b/src/input_context/input_action.rs index 45a946f..00f7f69 100644 --- a/src/input_context/input_action.rs +++ b/src/input_context/input_action.rs @@ -433,8 +433,8 @@ pub trait InputAction: Debug + Send + Sync + 'static { /// Specifies whether this action should swallow any [`Input`](crate::input::Input)s /// bound to it or allow them to pass through to affect other actions. /// - /// Inputs are consumed only if their [`Modifiers`](crate::input::Modifiers) - /// are also pressed. + /// Inputs are consumed only if the action state is not equal to [`ActionState::None`]. + /// For details, see [`ContextInstance`](super::context_instance::ContextInstance). /// /// Consuming is global and affect actions in all contexts. const CONSUME_INPUT: bool = true;