@@ -17,7 +17,7 @@ use bevy_utils::{
17
17
tracing:: { info, warn} ,
18
18
Duration , HashMap ,
19
19
} ;
20
- use thiserror :: Error ;
20
+ use derive_more :: derive :: { Display , Error , From } ;
21
21
22
22
/// A gamepad event.
23
23
///
@@ -26,7 +26,7 @@ use thiserror::Error;
26
26
/// the in-frame relative ordering of events is important.
27
27
///
28
28
/// This event is produced by `bevy_input`
29
- #[ derive( Event , Debug , Clone , PartialEq ) ]
29
+ #[ derive( Event , Debug , Clone , PartialEq , From ) ]
30
30
#[ cfg_attr( feature = "bevy_reflect" , derive( Reflect ) , reflect( Debug , PartialEq ) ) ]
31
31
#[ cfg_attr( feature = "serialize" , derive( serde:: Serialize , serde:: Deserialize ) ) ]
32
32
#[ cfg_attr(
@@ -42,32 +42,14 @@ pub enum GamepadEvent {
42
42
Axis ( GamepadAxisChangedEvent ) ,
43
43
}
44
44
45
- impl From < GamepadConnectionEvent > for GamepadEvent {
46
- fn from ( value : GamepadConnectionEvent ) -> Self {
47
- Self :: Connection ( value)
48
- }
49
- }
50
-
51
- impl From < GamepadButtonChangedEvent > for GamepadEvent {
52
- fn from ( value : GamepadButtonChangedEvent ) -> Self {
53
- Self :: Button ( value)
54
- }
55
- }
56
-
57
- impl From < GamepadAxisChangedEvent > for GamepadEvent {
58
- fn from ( value : GamepadAxisChangedEvent ) -> Self {
59
- Self :: Axis ( value)
60
- }
61
- }
62
-
63
45
/// A raw gamepad event.
64
46
///
65
47
/// This event type is used over the [`GamepadConnectionEvent`],
66
48
/// [`RawGamepadButtonChangedEvent`] and [`RawGamepadAxisChangedEvent`] when
67
49
/// the in-frame relative ordering of events is important.
68
50
///
69
51
/// This event type is used by `bevy_input` to feed its components.
70
- #[ derive( Event , Debug , Clone , PartialEq , Reflect ) ]
52
+ #[ derive( Event , Debug , Clone , PartialEq , Reflect , From ) ]
71
53
#[ reflect( Debug , PartialEq ) ]
72
54
#[ cfg_attr(
73
55
feature = "serialize" ,
@@ -83,24 +65,6 @@ pub enum RawGamepadEvent {
83
65
Axis ( RawGamepadAxisChangedEvent ) ,
84
66
}
85
67
86
- impl From < GamepadConnectionEvent > for RawGamepadEvent {
87
- fn from ( value : GamepadConnectionEvent ) -> Self {
88
- Self :: Connection ( value)
89
- }
90
- }
91
-
92
- impl From < RawGamepadButtonChangedEvent > for RawGamepadEvent {
93
- fn from ( value : RawGamepadButtonChangedEvent ) -> Self {
94
- Self :: Button ( value)
95
- }
96
- }
97
-
98
- impl From < RawGamepadAxisChangedEvent > for RawGamepadEvent {
99
- fn from ( value : RawGamepadAxisChangedEvent ) -> Self {
100
- Self :: Axis ( value)
101
- }
102
- }
103
-
104
68
/// [`GamepadButton`] changed event unfiltered by [`GamepadSettings`]
105
69
#[ derive( Event , Debug , Copy , Clone , PartialEq , Reflect ) ]
106
70
#[ reflect( Debug , PartialEq ) ]
@@ -281,52 +245,59 @@ impl GamepadAxisChangedEvent {
281
245
}
282
246
283
247
/// Errors that occur when setting axis settings for gamepad input.
284
- #[ derive( Error , Debug , PartialEq ) ]
248
+ #[ derive( Error , Display , Debug , PartialEq ) ]
285
249
pub enum AxisSettingsError {
286
250
/// The given parameter `livezone_lowerbound` was not in range -1.0..=0.0.
287
- #[ error( "invalid livezone_lowerbound {0}, expected value [-1.0..=0.0]" ) ]
251
+ #[ display( "invalid livezone_lowerbound {_0}, expected value [-1.0..=0.0]" ) ]
252
+ #[ error( ignore) ]
288
253
LiveZoneLowerBoundOutOfRange ( f32 ) ,
289
254
/// The given parameter `deadzone_lowerbound` was not in range -1.0..=0.0.
290
- #[ error( "invalid deadzone_lowerbound {0}, expected value [-1.0..=0.0]" ) ]
255
+ #[ display( "invalid deadzone_lowerbound {_0}, expected value [-1.0..=0.0]" ) ]
256
+ #[ error( ignore) ]
291
257
DeadZoneLowerBoundOutOfRange ( f32 ) ,
292
258
/// The given parameter `deadzone_lowerbound` was not in range -1.0..=0.0.
293
- #[ error( "invalid deadzone_upperbound {0}, expected value [0.0..=1.0]" ) ]
259
+ #[ display( "invalid deadzone_upperbound {_0}, expected value [0.0..=1.0]" ) ]
260
+ #[ error( ignore) ]
294
261
DeadZoneUpperBoundOutOfRange ( f32 ) ,
295
262
/// The given parameter `deadzone_lowerbound` was not in range -1.0..=0.0.
296
- #[ error( "invalid livezone_upperbound {0}, expected value [0.0..=1.0]" ) ]
263
+ #[ display( "invalid livezone_upperbound {_0}, expected value [0.0..=1.0]" ) ]
264
+ #[ error( ignore) ]
297
265
LiveZoneUpperBoundOutOfRange ( f32 ) ,
298
266
/// Parameter `livezone_lowerbound` was not less than or equal to parameter `deadzone_lowerbound`.
299
- #[ error ( "invalid parameter values livezone_lowerbound {} deadzone_lowerbound {}, expected livezone_lowerbound <= deadzone_lowerbound" , . livezone_lowerbound, . deadzone_lowerbound) ]
267
+ #[ display ( "invalid parameter values livezone_lowerbound {} deadzone_lowerbound {}, expected livezone_lowerbound <= deadzone_lowerbound" , livezone_lowerbound, deadzone_lowerbound) ]
300
268
LiveZoneLowerBoundGreaterThanDeadZoneLowerBound {
301
269
/// The value of the `livezone_lowerbound` parameter.
302
270
livezone_lowerbound : f32 ,
303
271
/// The value of the `deadzone_lowerbound` parameter.
304
272
deadzone_lowerbound : f32 ,
305
273
} ,
306
274
/// Parameter `deadzone_upperbound` was not less than or equal to parameter `livezone_upperbound`.
307
- #[ error ( "invalid parameter values livezone_upperbound {} deadzone_upperbound {}, expected deadzone_upperbound <= livezone_upperbound" , . livezone_upperbound, . deadzone_upperbound) ]
275
+ #[ display ( "invalid parameter values livezone_upperbound {} deadzone_upperbound {}, expected deadzone_upperbound <= livezone_upperbound" , livezone_upperbound, deadzone_upperbound) ]
308
276
DeadZoneUpperBoundGreaterThanLiveZoneUpperBound {
309
277
/// The value of the `livezone_upperbound` parameter.
310
278
livezone_upperbound : f32 ,
311
279
/// The value of the `deadzone_upperbound` parameter.
312
280
deadzone_upperbound : f32 ,
313
281
} ,
314
282
/// The given parameter was not in range 0.0..=2.0.
315
- #[ error( "invalid threshold {0}, expected 0.0 <= threshold <= 2.0" ) ]
283
+ #[ display( "invalid threshold {_0}, expected 0.0 <= threshold <= 2.0" ) ]
284
+ #[ error( ignore) ]
316
285
Threshold ( f32 ) ,
317
286
}
318
287
319
288
/// Errors that occur when setting button settings for gamepad input.
320
- #[ derive( Error , Debug , PartialEq ) ]
289
+ #[ derive( Error , Display , Debug , PartialEq ) ]
321
290
pub enum ButtonSettingsError {
322
291
/// The given parameter was not in range 0.0..=1.0.
323
- #[ error( "invalid release_threshold {0}, expected value [0.0..=1.0]" ) ]
292
+ #[ display( "invalid release_threshold {_0}, expected value [0.0..=1.0]" ) ]
293
+ #[ error( ignore) ]
324
294
ReleaseThresholdOutOfRange ( f32 ) ,
325
295
/// The given parameter was not in range 0.0..=1.0.
326
- #[ error( "invalid press_threshold {0}, expected [0.0..=1.0]" ) ]
296
+ #[ display( "invalid press_threshold {_0}, expected [0.0..=1.0]" ) ]
297
+ #[ error( ignore) ]
327
298
PressThresholdOutOfRange ( f32 ) ,
328
299
/// Parameter `release_threshold` was not less than or equal to `press_threshold`.
329
- #[ error ( "invalid parameter values release_threshold {} press_threshold {}, expected release_threshold <= press_threshold" , . release_threshold, . press_threshold) ]
300
+ #[ display ( "invalid parameter values release_threshold {} press_threshold {}, expected release_threshold <= press_threshold" , release_threshold, press_threshold) ]
330
301
ReleaseThresholdGreaterThanPressThreshold {
331
302
/// The value of the `press_threshold` parameter.
332
303
press_threshold : f32 ,
@@ -716,7 +687,7 @@ impl GamepadAxis {
716
687
717
688
/// Encapsulation over [`GamepadAxis`] and [`GamepadButton`]
718
689
// This is done so Gamepad can share a single Axis<T> and simplifies the API by having only one get/get_unclamped method
719
- #[ derive( Debug , Copy , Clone , Eq , Hash , PartialEq ) ]
690
+ #[ derive( Debug , Copy , Clone , Eq , Hash , PartialEq , From ) ]
720
691
#[ cfg_attr( feature = "bevy_reflect" , derive( Reflect ) , reflect( Debug , PartialEq ) ) ]
721
692
pub enum GamepadInput {
722
693
/// A [`GamepadAxis`]
@@ -725,18 +696,6 @@ pub enum GamepadInput {
725
696
Button ( GamepadButton ) ,
726
697
}
727
698
728
- impl From < GamepadAxis > for GamepadInput {
729
- fn from ( value : GamepadAxis ) -> Self {
730
- GamepadInput :: Axis ( value)
731
- }
732
- }
733
-
734
- impl From < GamepadButton > for GamepadInput {
735
- fn from ( value : GamepadButton ) -> Self {
736
- GamepadInput :: Button ( value)
737
- }
738
- }
739
-
740
699
/// Gamepad settings component.
741
700
///
742
701
/// ## Usage
0 commit comments