From dbfbcfc26d2cbbae3b424a19b33ab6091a4b259f Mon Sep 17 00:00:00 2001 From: Alice Cecile Date: Mon, 11 Jul 2022 22:30:27 -0400 Subject: [PATCH] Remove reasons_pressed API. (#167) --- RELEASES.md | 10 ++++++---- src/action_state.rs | 46 -------------------------------------------- src/input_map.rs | 1 - tests/integration.rs | 2 -- 4 files changed, 6 insertions(+), 53 deletions(-) diff --git a/RELEASES.md b/RELEASES.md index 2156e33c..716f3441 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -2,10 +2,6 @@ ## Version 0.5 -### Changes - -- Renamed `InputButton` to `InputKind` to reflect it's ability to represent non-button inputs such as axes. - ### Enhancements - Added `SingleGamepadAxis` and `DualGamepadAxis` structs that can be supplied to an `InputMap` to trigger on axis inputs. @@ -13,6 +9,12 @@ - Added `ActionState::action_axis_pair()` which can return an `AxisPair` to containing the analog values of a `SingleGamepadAxis`, `DualGamepadAxis`, or `VirtualDPad`. - Added `ActionState::action_value()` which represents the floating point value of any action: `1.0` or `0.0` for pressed or unpressed buttons, a value in the range `-1.0..=1.0` for a single axis representing its analog input, or a value in the range `0.0..=1.0` for a dual axis representing the magnitude (length) of its vector. +### Usability + +- Removed the `ActionState::reasons_pressed` API. + - This API was quite complex and not terribly useful. + - This was not needed for axislike inputs in the end. + ## Version 0.4.1 ### Bug fixes diff --git a/src/action_state.rs b/src/action_state.rs index 58db5e61..39cb18be 100644 --- a/src/action_state.rs +++ b/src/action_state.rs @@ -1,6 +1,5 @@ //! This module contains [`ActionState`] and its supporting methods and impls. -use crate::user_input::UserInput; use crate::Actionlike; use crate::{axislike::AxisPair, buttonlike::ButtonState}; @@ -24,8 +23,6 @@ pub struct ActionData { /// /// See [`ActionState::action_axis_pair()`] for more details. pub axis_pair: Option, - /// What inputs were responsible for causing this action to be pressed? - pub reasons_pressed: Vec, /// When was the button pressed / released, and how long has it been held for? pub timing: Timing, /// Was this action consumed by [`ActionState::consume`]? @@ -106,7 +103,6 @@ impl ActionState { self.action_data[i].axis_pair = action_data[i].axis_pair; self.action_data[i].value = action_data[i].value; - self.action_data[i].reasons_pressed = action_data[i].reasons_pressed.clone(); } } @@ -297,7 +293,6 @@ impl ActionState { if self.pressed(action) { self.action_data[index].timing.flip(); - self.action_data[index].reasons_pressed = Vec::new(); } self.action_data[index].state.release(); @@ -347,7 +342,6 @@ impl ActionState { // This is the only difference from action_state.release(action) self.action_data[index].consumed = true; self.action_data[index].state.release(); - self.action_data[index].reasons_pressed = Vec::new(); self.action_data[index].timing.flip(); } @@ -416,46 +410,6 @@ impl ActionState { .collect() } - /// The reasons (in terms of [`UserInput`]) that the button was pressed - /// - /// If the button is currently released, the `Vec returned will be empty - /// - /// # Example - /// - /// ```rust - /// use leafwing_input_manager::prelude::*; - /// use leafwing_input_manager::buttonlike::ButtonState; - /// use leafwing_input_manager::action_state::ActionData; - /// use bevy_input::keyboard::KeyCode; - /// - /// #[derive(Actionlike, Clone)] - /// enum PlatformerAction{ - /// Move, - /// Jump, - /// } - /// - /// let mut action_state = ActionState::::default(); - /// - /// // Usually this will be done automatically for you, via [`ActionState::update`] - /// action_state.set_action_data(PlatformerAction::Jump, - /// ActionData { - /// state: ButtonState::JustPressed, - /// // Manually setting the reason why this action was pressed - /// reasons_pressed: vec![KeyCode::Space.into()], - /// // For the sake of this example, we don't care about any other fields - /// ..Default::default() - /// } - /// ); - /// - /// let reasons_jumped = action_state.reasons_pressed(PlatformerAction::Jump); - /// assert_eq!(reasons_jumped[0], KeyCode::Space.into()); - /// ``` - #[inline] - #[must_use] - pub fn reasons_pressed(&self, action: A) -> Vec { - self.action_data[action.index()].reasons_pressed.clone() - } - /// The [`Instant`] that the action was last pressed or released /// /// If the action was pressed or released since the last time [`ActionState::tick`] was called diff --git a/src/input_map.rs b/src/input_map.rs index f03ccdb7..32383a9c 100644 --- a/src/input_map.rs +++ b/src/input_map.rs @@ -317,7 +317,6 @@ impl InputMap { if input_streams.input_pressed(input) { inputs.push(input.clone()); let action = &mut action_data[action.index()]; - action.reasons_pressed.push(input.clone()); action.value += value; action.value = action.value.clamp(-1.0, 1.0); diff --git a/tests/integration.rs b/tests/integration.rs index 4ed451d8..838968b6 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -77,8 +77,6 @@ fn do_nothing() { assert!(action_state.released(Action::PayRespects)); assert!(!action_state.just_released(Action::PayRespects)); - assert_eq!(action_state.reasons_pressed(Action::PayRespects).len(), 0); - assert_eq!(action_state.instant_started(Action::PayRespects), t0); assert_eq!( action_state.previous_duration(Action::PayRespects),