Skip to content

Commit f76e61d

Browse files
Code quality cleanup
1 parent 1f7f601 commit f76e61d

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

examples/ecs/per_entity_events.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -208,28 +208,21 @@ fn scale_selected(
208208
}
209209

210210
// FIXME: make this work using `EventWriter<T>` syntax and specialized behavior
211-
// FIXME: all input events are duplicated, due to just_pressed behavior
212211
/// Dispatches actions to entities based on the input
213212
/// 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
216214
fn input_dispatch(
217215
mut query: Query<
218216
(&mut Events<CycleColorAction>, &mut Events<AddNumberAction>),
219217
With<Selectable>,
220218
>,
221219
selected: Res<Selected>,
222-
keyboard_input: Res<Input<KeyCode>>,
220+
mut keyboard_input: ResMut<Input<KeyCode>>,
223221
) {
224222
let (mut cycle_actions, mut add_actions) = query.get_mut(selected.entity).unwrap();
225223

226224
// 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) {
233226
cycle_actions.send(CycleColorAction);
234227
}
235228

@@ -281,6 +274,7 @@ fn update_text_color(mut query: Query<(&mut Text, &Rainbow), Changed<Rainbow>>)
281274

282275
// Just as when using Events as a resource, you can work with `Events<T>` directly instead
283276
// EventReader and EventWriter are just convenient wrappers that better communicate intent
277+
// FIXME: Prevent event duplication by storing a Local resource
284278
fn add_number(mut query: Query<(&mut Text, &Events<AddNumberAction>)>) {
285279
// To add events manually, use events.send(MyEvent::new())
286280
for (mut text, action_queue) in query.iter_mut() {

0 commit comments

Comments
 (0)