Skip to content

Commit

Permalink
Consume inputs only if the action state is not equal to `ActionState:…
Browse files Browse the repository at this point in the history
…:None`
  • Loading branch information
Shatur committed Oct 29, 2024
1 parent b14f85e commit fb68cfb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
10 changes: 6 additions & 4 deletions src/input_context/context_instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/input_context/input_action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit fb68cfb

Please sign in to comment.