Skip to content

Commit

Permalink
Remove thiserror from bevy_input (#15770)
Browse files Browse the repository at this point in the history
# Objective

- Contributes to #15460

## Solution

- Removed `thiserror` from `bevy_input`
  • Loading branch information
bushrat011899 authored Oct 9, 2024
1 parent f88c682 commit 5e89aca
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 65 deletions.
6 changes: 5 additions & 1 deletion crates/bevy_input/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ bevy_reflect = { path = "../bevy_reflect", version = "0.15.0-dev", features = [

# other
serde = { version = "1", features = ["derive"], optional = true }
thiserror = "1.0"
derive_more = { version = "1", default-features = false, features = [
"error",
"from",
"display",
] }
smol_str = "0.2"

[lints]
Expand Down
87 changes: 23 additions & 64 deletions crates/bevy_input/src/gamepad.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use bevy_utils::{
tracing::{info, warn},
Duration, HashMap,
};
use thiserror::Error;
use derive_more::derive::{Display, Error, From};

/// A gamepad event.
///
Expand All @@ -26,7 +26,7 @@ use thiserror::Error;
/// the in-frame relative ordering of events is important.
///
/// This event is produced by `bevy_input`
#[derive(Event, Debug, Clone, PartialEq)]
#[derive(Event, Debug, Clone, PartialEq, From)]
#[cfg_attr(feature = "bevy_reflect", derive(Reflect), reflect(Debug, PartialEq))]
#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(
Expand All @@ -42,32 +42,14 @@ pub enum GamepadEvent {
Axis(GamepadAxisChangedEvent),
}

impl From<GamepadConnectionEvent> for GamepadEvent {
fn from(value: GamepadConnectionEvent) -> Self {
Self::Connection(value)
}
}

impl From<GamepadButtonChangedEvent> for GamepadEvent {
fn from(value: GamepadButtonChangedEvent) -> Self {
Self::Button(value)
}
}

impl From<GamepadAxisChangedEvent> for GamepadEvent {
fn from(value: GamepadAxisChangedEvent) -> Self {
Self::Axis(value)
}
}

/// A raw gamepad event.
///
/// This event type is used over the [`GamepadConnectionEvent`],
/// [`RawGamepadButtonChangedEvent`] and [`RawGamepadAxisChangedEvent`] when
/// the in-frame relative ordering of events is important.
///
/// This event type is used by `bevy_input` to feed its components.
#[derive(Event, Debug, Clone, PartialEq, Reflect)]
#[derive(Event, Debug, Clone, PartialEq, Reflect, From)]
#[reflect(Debug, PartialEq)]
#[cfg_attr(
feature = "serialize",
Expand All @@ -83,24 +65,6 @@ pub enum RawGamepadEvent {
Axis(RawGamepadAxisChangedEvent),
}

impl From<GamepadConnectionEvent> for RawGamepadEvent {
fn from(value: GamepadConnectionEvent) -> Self {
Self::Connection(value)
}
}

impl From<RawGamepadButtonChangedEvent> for RawGamepadEvent {
fn from(value: RawGamepadButtonChangedEvent) -> Self {
Self::Button(value)
}
}

impl From<RawGamepadAxisChangedEvent> for RawGamepadEvent {
fn from(value: RawGamepadAxisChangedEvent) -> Self {
Self::Axis(value)
}
}

/// [`GamepadButton`] changed event unfiltered by [`GamepadSettings`]
#[derive(Event, Debug, Copy, Clone, PartialEq, Reflect)]
#[reflect(Debug, PartialEq)]
Expand Down Expand Up @@ -281,52 +245,59 @@ impl GamepadAxisChangedEvent {
}

/// Errors that occur when setting axis settings for gamepad input.
#[derive(Error, Debug, PartialEq)]
#[derive(Error, Display, Debug, PartialEq)]
pub enum AxisSettingsError {
/// The given parameter `livezone_lowerbound` was not in range -1.0..=0.0.
#[error("invalid livezone_lowerbound {0}, expected value [-1.0..=0.0]")]
#[display("invalid livezone_lowerbound {_0}, expected value [-1.0..=0.0]")]
#[error(ignore)]
LiveZoneLowerBoundOutOfRange(f32),
/// The given parameter `deadzone_lowerbound` was not in range -1.0..=0.0.
#[error("invalid deadzone_lowerbound {0}, expected value [-1.0..=0.0]")]
#[display("invalid deadzone_lowerbound {_0}, expected value [-1.0..=0.0]")]
#[error(ignore)]
DeadZoneLowerBoundOutOfRange(f32),
/// The given parameter `deadzone_lowerbound` was not in range -1.0..=0.0.
#[error("invalid deadzone_upperbound {0}, expected value [0.0..=1.0]")]
#[display("invalid deadzone_upperbound {_0}, expected value [0.0..=1.0]")]
#[error(ignore)]
DeadZoneUpperBoundOutOfRange(f32),
/// The given parameter `deadzone_lowerbound` was not in range -1.0..=0.0.
#[error("invalid livezone_upperbound {0}, expected value [0.0..=1.0]")]
#[display("invalid livezone_upperbound {_0}, expected value [0.0..=1.0]")]
#[error(ignore)]
LiveZoneUpperBoundOutOfRange(f32),
/// Parameter `livezone_lowerbound` was not less than or equal to parameter `deadzone_lowerbound`.
#[error("invalid parameter values livezone_lowerbound {} deadzone_lowerbound {}, expected livezone_lowerbound <= deadzone_lowerbound", .livezone_lowerbound, .deadzone_lowerbound)]
#[display("invalid parameter values livezone_lowerbound {} deadzone_lowerbound {}, expected livezone_lowerbound <= deadzone_lowerbound", livezone_lowerbound, deadzone_lowerbound)]
LiveZoneLowerBoundGreaterThanDeadZoneLowerBound {
/// The value of the `livezone_lowerbound` parameter.
livezone_lowerbound: f32,
/// The value of the `deadzone_lowerbound` parameter.
deadzone_lowerbound: f32,
},
/// Parameter `deadzone_upperbound` was not less than or equal to parameter `livezone_upperbound`.
#[error("invalid parameter values livezone_upperbound {} deadzone_upperbound {}, expected deadzone_upperbound <= livezone_upperbound", .livezone_upperbound, .deadzone_upperbound)]
#[display("invalid parameter values livezone_upperbound {} deadzone_upperbound {}, expected deadzone_upperbound <= livezone_upperbound", livezone_upperbound, deadzone_upperbound)]
DeadZoneUpperBoundGreaterThanLiveZoneUpperBound {
/// The value of the `livezone_upperbound` parameter.
livezone_upperbound: f32,
/// The value of the `deadzone_upperbound` parameter.
deadzone_upperbound: f32,
},
/// The given parameter was not in range 0.0..=2.0.
#[error("invalid threshold {0}, expected 0.0 <= threshold <= 2.0")]
#[display("invalid threshold {_0}, expected 0.0 <= threshold <= 2.0")]
#[error(ignore)]
Threshold(f32),
}

/// Errors that occur when setting button settings for gamepad input.
#[derive(Error, Debug, PartialEq)]
#[derive(Error, Display, Debug, PartialEq)]
pub enum ButtonSettingsError {
/// The given parameter was not in range 0.0..=1.0.
#[error("invalid release_threshold {0}, expected value [0.0..=1.0]")]
#[display("invalid release_threshold {_0}, expected value [0.0..=1.0]")]
#[error(ignore)]
ReleaseThresholdOutOfRange(f32),
/// The given parameter was not in range 0.0..=1.0.
#[error("invalid press_threshold {0}, expected [0.0..=1.0]")]
#[display("invalid press_threshold {_0}, expected [0.0..=1.0]")]
#[error(ignore)]
PressThresholdOutOfRange(f32),
/// Parameter `release_threshold` was not less than or equal to `press_threshold`.
#[error("invalid parameter values release_threshold {} press_threshold {}, expected release_threshold <= press_threshold", .release_threshold, .press_threshold)]
#[display("invalid parameter values release_threshold {} press_threshold {}, expected release_threshold <= press_threshold", release_threshold, press_threshold)]
ReleaseThresholdGreaterThanPressThreshold {
/// The value of the `press_threshold` parameter.
press_threshold: f32,
Expand Down Expand Up @@ -716,7 +687,7 @@ impl GamepadAxis {

/// Encapsulation over [`GamepadAxis`] and [`GamepadButton`]
// This is done so Gamepad can share a single Axis<T> and simplifies the API by having only one get/get_unclamped method
#[derive(Debug, Copy, Clone, Eq, Hash, PartialEq)]
#[derive(Debug, Copy, Clone, Eq, Hash, PartialEq, From)]
#[cfg_attr(feature = "bevy_reflect", derive(Reflect), reflect(Debug, PartialEq))]
pub enum GamepadInput {
/// A [`GamepadAxis`]
Expand All @@ -725,18 +696,6 @@ pub enum GamepadInput {
Button(GamepadButton),
}

impl From<GamepadAxis> for GamepadInput {
fn from(value: GamepadAxis) -> Self {
GamepadInput::Axis(value)
}
}

impl From<GamepadButton> for GamepadInput {
fn from(value: GamepadButton) -> Self {
GamepadInput::Button(value)
}
}

/// Gamepad settings component.
///
/// ## Usage
Expand Down

0 comments on commit 5e89aca

Please sign in to comment.