1
1
//! The gamepad input functionality.
2
2
3
3
use crate :: { Axis , ButtonInput , ButtonState } ;
4
+ use alloc:: string:: String ;
4
5
#[ cfg( feature = "bevy_reflect" ) ]
5
6
use bevy_ecs:: prelude:: ReflectComponent ;
6
7
use bevy_ecs:: {
@@ -12,16 +13,15 @@ use bevy_ecs::{
12
13
prelude:: require,
13
14
system:: { Commands , Query } ,
14
15
} ;
16
+ use bevy_math:: ops;
15
17
use bevy_math:: Vec2 ;
16
18
#[ cfg( feature = "bevy_reflect" ) ]
17
19
use bevy_reflect:: { std_traits:: ReflectDefault , Reflect } ;
18
20
#[ cfg( all( feature = "serialize" , feature = "bevy_reflect" ) ) ]
19
21
use bevy_reflect:: { ReflectDeserialize , ReflectSerialize } ;
20
- use bevy_utils:: {
21
- tracing:: { info, warn} ,
22
- Duration , HashMap ,
23
- } ;
22
+ use bevy_utils:: { Duration , HashMap } ;
24
23
use derive_more:: derive:: From ;
24
+ use log:: { info, warn} ;
25
25
use thiserror:: Error ;
26
26
27
27
/// A gamepad event.
@@ -54,11 +54,11 @@ pub enum GamepadEvent {
54
54
/// the in-frame relative ordering of events is important.
55
55
///
56
56
/// This event type is used by `bevy_input` to feed its components.
57
- #[ derive( Event , Debug , Clone , PartialEq , Reflect , From ) ]
58
- #[ reflect( Debug , PartialEq ) ]
57
+ #[ derive( Event , Debug , Clone , PartialEq , From ) ]
58
+ #[ cfg_attr( feature = "bevy_reflect" , derive( Reflect ) , reflect( Debug , PartialEq ) ) ]
59
+ #[ cfg_attr( feature = "serialize" , derive( serde:: Serialize , serde:: Deserialize ) ) ]
59
60
#[ cfg_attr(
60
- feature = "serialize" ,
61
- derive( serde:: Serialize , serde:: Deserialize ) ,
61
+ all( feature = "serialize" , feature = "bevy_reflect" ) ,
62
62
reflect( Serialize , Deserialize )
63
63
) ]
64
64
pub enum RawGamepadEvent {
@@ -71,11 +71,11 @@ pub enum RawGamepadEvent {
71
71
}
72
72
73
73
/// [`GamepadButton`] changed event unfiltered by [`GamepadSettings`]
74
- #[ derive( Event , Debug , Copy , Clone , PartialEq , Reflect ) ]
75
- #[ reflect( Debug , PartialEq ) ]
74
+ #[ derive( Event , Debug , Copy , Clone , PartialEq ) ]
75
+ #[ cfg_attr( feature = "bevy_reflect" , derive( Reflect ) , reflect( Debug , PartialEq ) ) ]
76
+ #[ cfg_attr( feature = "serialize" , derive( serde:: Serialize , serde:: Deserialize ) ) ]
76
77
#[ cfg_attr(
77
- feature = "serialize" ,
78
- derive( serde:: Serialize , serde:: Deserialize ) ,
78
+ all( feature = "serialize" , feature = "bevy_reflect" ) ,
79
79
reflect( Serialize , Deserialize )
80
80
) ]
81
81
pub struct RawGamepadButtonChangedEvent {
@@ -99,11 +99,11 @@ impl RawGamepadButtonChangedEvent {
99
99
}
100
100
101
101
/// [`GamepadAxis`] changed event unfiltered by [`GamepadSettings`]
102
- #[ derive( Event , Debug , Copy , Clone , PartialEq , Reflect ) ]
103
- #[ reflect( Debug , PartialEq ) ]
102
+ #[ derive( Event , Debug , Copy , Clone , PartialEq ) ]
103
+ #[ cfg_attr( feature = "bevy_reflect" , derive( Reflect ) , reflect( Debug , PartialEq ) ) ]
104
+ #[ cfg_attr( feature = "serialize" , derive( serde:: Serialize , serde:: Deserialize ) ) ]
104
105
#[ cfg_attr(
105
- feature = "serialize" ,
106
- derive( serde:: Serialize , serde:: Deserialize ) ,
106
+ all( feature = "serialize" , feature = "bevy_reflect" ) ,
107
107
reflect( Serialize , Deserialize )
108
108
) ]
109
109
pub struct RawGamepadAxisChangedEvent {
@@ -128,11 +128,11 @@ impl RawGamepadAxisChangedEvent {
128
128
129
129
/// A Gamepad connection event. Created when a connection to a gamepad
130
130
/// is established and when a gamepad is disconnected.
131
- #[ derive( Event , Debug , Clone , PartialEq , Reflect ) ]
132
- #[ reflect( Debug , PartialEq ) ]
131
+ #[ derive( Event , Debug , Clone , PartialEq ) ]
132
+ #[ cfg_attr( feature = "bevy_reflect" , derive( Reflect ) , reflect( Debug , PartialEq ) ) ]
133
+ #[ cfg_attr( feature = "serialize" , derive( serde:: Serialize , serde:: Deserialize ) ) ]
133
134
#[ cfg_attr(
134
- feature = "serialize" ,
135
- derive( serde:: Serialize , serde:: Deserialize ) ,
135
+ all( feature = "serialize" , feature = "bevy_reflect" ) ,
136
136
reflect( Serialize , Deserialize )
137
137
) ]
138
138
pub struct GamepadConnectionEvent {
@@ -163,11 +163,11 @@ impl GamepadConnectionEvent {
163
163
}
164
164
165
165
/// [`GamepadButton`] event triggered by a digital state change
166
- #[ derive( Event , Debug , Clone , Copy , PartialEq , Eq , Reflect ) ]
167
- #[ reflect( Debug , PartialEq ) ]
166
+ #[ derive( Event , Debug , Clone , Copy , PartialEq , Eq ) ]
167
+ #[ cfg_attr( feature = "bevy_reflect" , derive( Reflect ) , reflect( Debug , PartialEq ) ) ]
168
+ #[ cfg_attr( feature = "serialize" , derive( serde:: Serialize , serde:: Deserialize ) ) ]
168
169
#[ cfg_attr(
169
- feature = "serialize" ,
170
- derive( serde:: Serialize , serde:: Deserialize ) ,
170
+ all( feature = "serialize" , feature = "bevy_reflect" ) ,
171
171
reflect( Serialize , Deserialize )
172
172
) ]
173
173
pub struct GamepadButtonStateChangedEvent {
@@ -191,11 +191,11 @@ impl GamepadButtonStateChangedEvent {
191
191
}
192
192
193
193
/// [`GamepadButton`] event triggered by an analog state change
194
- #[ derive( Event , Debug , Clone , Copy , PartialEq , Reflect ) ]
195
- #[ reflect( Debug , PartialEq ) ]
194
+ #[ derive( Event , Debug , Clone , Copy , PartialEq ) ]
195
+ #[ cfg_attr( feature = "bevy_reflect" , derive( Reflect ) , reflect( Debug , PartialEq ) ) ]
196
+ #[ cfg_attr( feature = "serialize" , derive( serde:: Serialize , serde:: Deserialize ) ) ]
196
197
#[ cfg_attr(
197
- feature = "serialize" ,
198
- derive( serde:: Serialize , serde:: Deserialize ) ,
198
+ all( feature = "serialize" , feature = "bevy_reflect" ) ,
199
199
reflect( Serialize , Deserialize )
200
200
) ]
201
201
pub struct GamepadButtonChangedEvent {
@@ -222,11 +222,11 @@ impl GamepadButtonChangedEvent {
222
222
}
223
223
224
224
/// [`GamepadAxis`] event triggered by an analog state change
225
- #[ derive( Event , Debug , Clone , Copy , PartialEq , Reflect ) ]
226
- #[ reflect( Debug , PartialEq ) ]
225
+ #[ derive( Event , Debug , Clone , Copy , PartialEq ) ]
226
+ #[ cfg_attr( feature = "serialize" , derive( serde:: Serialize , serde:: Deserialize ) ) ]
227
+ #[ cfg_attr( feature = "bevy_reflect" , derive( Reflect ) , reflect( Debug , PartialEq ) ) ]
227
228
#[ cfg_attr(
228
- feature = "serialize" ,
229
- derive( serde:: Serialize , serde:: Deserialize ) ,
229
+ all( feature = "bevy_reflect" , feature = "serialize" ) ,
230
230
reflect( Serialize , Deserialize )
231
231
) ]
232
232
pub struct GamepadAxisChangedEvent {
@@ -1232,7 +1232,7 @@ impl AxisSettings {
1232
1232
return true ;
1233
1233
}
1234
1234
1235
- f32 :: abs ( new_value - old_value. unwrap ( ) ) > self . threshold
1235
+ ops :: abs ( new_value - old_value. unwrap ( ) ) > self . threshold
1236
1236
}
1237
1237
1238
1238
/// Filters the `new_value` based on the `old_value`, according to the [`AxisSettings`].
@@ -1307,7 +1307,7 @@ impl ButtonAxisSettings {
1307
1307
return true ;
1308
1308
}
1309
1309
1310
- f32 :: abs ( new_value - old_value. unwrap ( ) ) > self . threshold
1310
+ ops :: abs ( new_value - old_value. unwrap ( ) ) > self . threshold
1311
1311
}
1312
1312
1313
1313
/// Filters the `new_value` based on the `old_value`, according to the [`ButtonAxisSettings`].
0 commit comments