@@ -208,28 +208,21 @@ fn scale_selected(
208
208
}
209
209
210
210
// FIXME: make this work using `EventWriter<T>` syntax and specialized behavior
211
- // FIXME: all input events are duplicated, due to just_pressed behavior
212
211
/// Dispatches actions to entities based on the input
213
212
/// Note that we can store several events at once!
214
- /// Try pressing both "Enter" and "Space" at the same time to cycle colors twice,
215
- /// Or both "1" and "3" to add 4 all at the same time to the selected display
213
+ /// Try pressing both "1" and "3" to add 4 to the selected display
216
214
fn input_dispatch (
217
215
mut query : Query <
218
216
( & mut Events < CycleColorAction > , & mut Events < AddNumberAction > ) ,
219
217
With < Selectable > ,
220
218
> ,
221
219
selected : Res < Selected > ,
222
- keyboard_input : Res < Input < KeyCode > > ,
220
+ mut keyboard_input : ResMut < Input < KeyCode > > ,
223
221
) {
224
222
let ( mut cycle_actions, mut add_actions) = query. get_mut ( selected. entity ) . unwrap ( ) ;
225
223
226
224
// Inputs for cycling colors
227
- // Normally, you'd probably want to use || on the inputs here,
228
- // but we're demonstrating the ability to process multiple events at once
229
- if keyboard_input. just_pressed ( KeyCode :: Return ) {
230
- cycle_actions. send ( CycleColorAction ) ;
231
- }
232
- if keyboard_input. just_pressed ( KeyCode :: Space ) {
225
+ if keyboard_input. just_pressed ( KeyCode :: Return ) || keyboard_input. just_pressed ( KeyCode :: Space ) {
233
226
cycle_actions. send ( CycleColorAction ) ;
234
227
}
235
228
@@ -281,6 +274,7 @@ fn update_text_color(mut query: Query<(&mut Text, &Rainbow), Changed<Rainbow>>)
281
274
282
275
// Just as when using Events as a resource, you can work with `Events<T>` directly instead
283
276
// EventReader and EventWriter are just convenient wrappers that better communicate intent
277
+ // FIXME: Prevent event duplication by storing a Local resource
284
278
fn add_number ( mut query : Query < ( & mut Text , & Events < AddNumberAction > ) > ) {
285
279
// To add events manually, use events.send(MyEvent::new())
286
280
for ( mut text, action_queue) in query. iter_mut ( ) {
0 commit comments