diff --git a/crates/behaviour/src/chase.rs b/crates/behaviour/src/chase.rs index a6a911cfe..f404a29ea 100644 --- a/crates/behaviour/src/chase.rs +++ b/crates/behaviour/src/chase.rs @@ -114,7 +114,7 @@ impl ChaseTarget { } fn handle_chase_events(mut commands: Commands, mut events: EventReader) { - for event in events.iter() { + for event in events.read() { let mut entity_commands = commands.entity(event.entity()); match event.target() { Some(target) => entity_commands.insert(ChaseTargetComponent::new(target.clone())), diff --git a/crates/camera/src/camera.rs b/crates/camera/src/camera.rs index 086d344a6..832624788 100644 --- a/crates/camera/src/camera.rs +++ b/crates/camera/src/camera.rs @@ -391,7 +391,7 @@ fn process_move_focus_events( terrain: TerrainCollider, mut out_events: EventWriter, ) { - let event = match in_events.iter().last() { + let event = match in_events.read().last() { Some(event) => event, None => return, }; @@ -516,7 +516,7 @@ fn handle_horizontal_events( mut movement: ResMut, mut events: EventReader, ) { - if let Some(event) = events.iter().last() { + if let Some(event) = events.read().last() { movement.set(event.direction()); } } @@ -526,7 +526,7 @@ fn handle_zoom_events( mut events: EventReader, mut desired: ResMut, ) { - for event in events.iter() { + for event in events.read() { desired.zoom_clamped(conf.camera(), event.factor()); } } @@ -535,7 +535,7 @@ fn handle_tilt_events( mut events: EventReader, mut desired: ResMut, ) { - for event in events.iter() { + for event in events.read() { desired.tilt_clamped(Radian::ONE * event.delta()); } } @@ -544,7 +544,7 @@ fn handle_rotate_events( mut events: EventReader, mut desired: ResMut, ) { - for event in events.iter() { + for event in events.read() { desired.rotate(Radian::ONE * event.delta()); } } diff --git a/crates/combat/src/attack.rs b/crates/combat/src/attack.rs index 0ca6a8bb4..cca10aa98 100644 --- a/crates/combat/src/attack.rs +++ b/crates/combat/src/attack.rs @@ -105,7 +105,7 @@ fn attack( cannons: Query<&LaserCannon>, mut chase_events: EventWriter, ) { - for event in attack_events.iter() { + for event in attack_events.read() { if let Ok(cannon) = cannons.get(event.attacker()) { commands .entity(event.attacker()) diff --git a/crates/combat/src/health.rs b/crates/combat/src/health.rs index 3d9cc51c4..16a2df9fa 100644 --- a/crates/combat/src/health.rs +++ b/crates/combat/src/health.rs @@ -81,7 +81,7 @@ fn update_local_health( mut out_events: EventWriter, mut net_events: EventWriter, ) { - for event in in_events.iter() { + for event in in_events.read() { out_events.send(UpdateHealthEvent::new(event.entity, event.delta)); if config.multiplayer() { @@ -97,7 +97,7 @@ fn update_remote_health( mut in_events: EventReader, mut out_events: EventWriter, ) { - for event in in_events.iter() { + for event in in_events.read() { out_events.send(UpdateHealthEvent::new(event.entity(), event.delta())); } } @@ -107,7 +107,7 @@ fn update_health( mut health_events: EventReader, mut bar_events: EventWriter, ) { - for event in health_events.iter() { + for event in health_events.read() { let Ok(mut health) = healths.get_mut(event.entity) else { continue; }; diff --git a/crates/combat/src/laser.rs b/crates/combat/src/laser.rs index 7fb86bcef..64b3fbf9c 100644 --- a/crates/combat/src/laser.rs +++ b/crates/combat/src/laser.rs @@ -81,7 +81,7 @@ fn fire( mut health: EventWriter, mut trail: EventWriter, ) { - for fire in fires.iter() { + for fire in fires.read() { let observation = sightline.sight(fire.ray(), fire.max_toi(), fire.attacker()); trail.send(LocalLaserTrailEvent::new(Ray::new( diff --git a/crates/combat/src/trail.rs b/crates/combat/src/trail.rs index 5d3af1f82..5b773babf 100644 --- a/crates/combat/src/trail.rs +++ b/crates/combat/src/trail.rs @@ -129,7 +129,7 @@ fn local_laser_trail( mut out_events: EventWriter, mut net_events: EventWriter, ) { - for event in in_events.iter() { + for event in in_events.read() { out_events.send(LaserTrailEvent(event.0)); if config.multiplayer() { @@ -147,7 +147,7 @@ fn remote_laser_trail( mut in_events: EventReader, mut out_events: EventWriter, ) { - for event in in_events.iter() { + for event in in_events.read() { match **event { NetProjectile::Laser { origin, direction } => { out_events.send(LaserTrailEvent(Ray::new(origin.into(), direction.into()))); @@ -163,7 +163,7 @@ fn laser_trail( mesh: Res, mut events: EventReader, ) { - for event in events.iter() { + for event in events.read() { let material = materials.add(TrailMaterial::new(time.elapsed_seconds_wrapped())); commands.spawn(( @@ -189,7 +189,7 @@ fn laser_sound( mut events: EventReader, mut sound_events: EventWriter, ) { - for event in events.iter() { + for event in events.read() { sound_events.send(PlaySpatialAudioEvent::new( Sound::LaserFire, event.0.origin.into(), diff --git a/crates/construction/src/manufacturing.rs b/crates/construction/src/manufacturing.rs index 5404e14bd..7a2d2c26f 100644 --- a/crates/construction/src/manufacturing.rs +++ b/crates/construction/src/manufacturing.rs @@ -321,7 +321,7 @@ fn change_locations( mut pole_events: EventWriter, mut line_events: EventWriter, ) { - for event in events.iter() { + for event in events.read() { if let Ok(mut location) = locations.get_mut(event.factory()) { let owner = event.factory(); location.0 = event.position(); @@ -337,7 +337,7 @@ fn enqueue( mut events: EventReader, mut lines: Query<&mut AssemblyLine>, ) { - for event in events.iter() { + for event in events.read() { let Ok(mut line) = lines.get_mut(event.factory()) else { continue; }; @@ -415,7 +415,7 @@ fn deliver( &DeliveryLocation, )>, ) { - for delivery in deliver_events.iter() { + for delivery in deliver_events.read() { info!( "Manufacturing of {} in {:?} just finished.", delivery.unit(), diff --git a/crates/controller/src/commands/executor.rs b/crates/controller/src/commands/executor.rs index 0223a42c1..27303675d 100644 --- a/crates/controller/src/commands/executor.rs +++ b/crates/controller/src/commands/executor.rs @@ -86,7 +86,7 @@ fn send_selected_system( mut path_events: EventWriter, mut chase_events: EventWriter, ) { - if let Some(send) = send_events.iter().last() { + if let Some(send) = send_events.read().last() { for entity in selected.iter() { chase_events.send(ChaseTargetEvent::new(entity, None)); path_events.send(UpdateEntityPathEvent::new( @@ -104,7 +104,7 @@ fn delivery_location_system( selected: Query, mut out_events: EventWriter, ) { - if let Some(event) = in_events.iter().last() { + if let Some(event) = in_events.read().last() { for entity in selected.iter() { out_events.send(ChangeDeliveryLocationEvent::new(entity, event.target())); } @@ -116,7 +116,7 @@ fn attack_system( selected: Query, mut individual_events: EventWriter, ) { - if let Some(group_event) = group_events.iter().last() { + if let Some(group_event) = group_events.read().last() { for attacker in selected.iter() { individual_events.send(AttackEvent::new(attacker, group_event.target())); } diff --git a/crates/controller/src/commands/handlers.rs b/crates/controller/src/commands/handlers.rs index 1026a4b96..541f789e3 100644 --- a/crates/controller/src/commands/handlers.rs +++ b/crates/controller/src/commands/handlers.rs @@ -138,7 +138,7 @@ fn on_click(button: MouseButton) -> impl Fn(EventReader) -> b move |mut events: EventReader| { // It is desirable to exhaust the iterator, thus .filter().count() is // used instead of .any() - events.iter().filter(|e| e.button() == button).count() > 0 + events.read().filter(|e| e.button() == button).count() > 0 } } @@ -146,7 +146,7 @@ fn on_double_click(button: MouseButton) -> impl Fn(EventReader| { // It is desirable to exhaust the iterator, thus .filter().count() is // used instead of .any() - events.iter().filter(|e| e.button() == button).count() > 0 + events.read().filter(|e| e.button() == button).count() > 0 } } @@ -210,7 +210,7 @@ fn move_camera_arrows_system( mut key_events: EventReader, mut move_events: EventWriter, ) { - for key_event in key_events.iter() { + for key_event in key_events.read() { let Some(key_code) = key_event.key_code else { continue; }; @@ -277,7 +277,7 @@ fn zoom_camera( ) { let conf = conf.camera(); let factor = wheel_events - .iter() + .read() .fold(1.0, |factor, event| match event.unit { MouseScrollUnit::Line => factor * conf.wheel_zoom_sensitivity().powf(event.y), MouseScrollUnit::Pixel => factor * conf.touchpad_zoom_sensitivity().powf(event.y), @@ -297,7 +297,7 @@ fn pivot_camera( return; } - let delta = mouse_event.iter().fold(Vec2::ZERO, |sum, e| sum + e.delta); + let delta = mouse_event.read().fold(Vec2::ZERO, |sum, e| sum + e.delta); let sensitivity = conf.camera().rotation_sensitivity(); if delta.x != 0. { rotate_event.send(RotateCameraEvent::new(sensitivity * delta.x)); @@ -390,7 +390,7 @@ fn update_drags( mut ui_events: EventWriter, mut select_events: EventWriter, ) { - for drag_event in drag_events.iter() { + for drag_event in drag_events.read() { if drag_event.button() != MouseButton::Left { continue; } diff --git a/crates/controller/src/commands/keyboard.rs b/crates/controller/src/commands/keyboard.rs index 2c67be9c3..1b5d4b524 100644 --- a/crates/controller/src/commands/keyboard.rs +++ b/crates/controller/src/commands/keyboard.rs @@ -36,7 +36,7 @@ impl KeyCondition { pub(super) fn build(self) -> impl Fn(Res>, EventReader) -> bool { move |keys: Res>, mut events: EventReader| { let proper_key = events - .iter() + .read() .filter(|k| { k.state == ButtonState::Pressed && k.key_code.map_or(false, |c| c == self.key) }) diff --git a/crates/controller/src/draft.rs b/crates/controller/src/draft.rs index 671d721a5..36aa2f5da 100644 --- a/crates/controller/src/draft.rs +++ b/crates/controller/src/draft.rs @@ -99,7 +99,7 @@ fn new_drafts( mut events: EventReader, drafts: Query>, ) { - let event = match events.iter().last() { + let event = match events.read().last() { Some(event) => event, None => return, }; diff --git a/crates/controller/src/hud/menu.rs b/crates/controller/src/hud/menu.rs index a901566c5..a9bc27ab1 100644 --- a/crates/controller/src/hud/menu.rs +++ b/crates/controller/src/hud/menu.rs @@ -116,7 +116,7 @@ fn toggle_system( mut events: EventReader, mut query: Query<&mut Visibility, With>, ) { - if events.iter().count() % 2 == 0 { + if events.read().count() % 2 == 0 { return; } diff --git a/crates/controller/src/hud/minimap/interaction.rs b/crates/controller/src/hud/minimap/interaction.rs index 441f838ed..2967d0d1b 100644 --- a/crates/controller/src/hud/minimap/interaction.rs +++ b/crates/controller/src/hud/minimap/interaction.rs @@ -119,7 +119,7 @@ fn press_handler( ) { let cursor = window_query.single().cursor_position(); - for event in input_events.iter() { + for event in input_events.read() { match event.state { ButtonState::Released => { dragging.retain(|b| *b != event.button); @@ -173,7 +173,7 @@ fn move_camera_system( mut drag_events: EventReader, mut camera_events: EventWriter, ) { - for press in press_events.iter() { + for press in press_events.read() { if press.button() != MouseButton::Left { continue; } @@ -182,7 +182,7 @@ fn move_camera_system( camera_events.send(event); } - for drag in drag_events.iter() { + for drag in drag_events.read() { if drag.button() != MouseButton::Left { continue; } @@ -196,7 +196,7 @@ fn send_units_system( mut press_events: EventReader, mut send_events: EventWriter, ) { - for press in press_events.iter() { + for press in press_events.read() { if press.button() != MouseButton::Right { continue; } @@ -208,7 +208,7 @@ fn delivery_location_system( mut press_events: EventReader, mut location_events: EventWriter, ) { - for press in press_events.iter() { + for press in press_events.read() { if press.button() != MouseButton::Right { continue; } diff --git a/crates/controller/src/hud/selection.rs b/crates/controller/src/hud/selection.rs index f9780970c..32611c423 100644 --- a/crates/controller/src/hud/selection.rs +++ b/crates/controller/src/hud/selection.rs @@ -35,7 +35,7 @@ fn process_events( mut boxes: Query<(Entity, &mut Style), With>, mut events: EventReader, ) { - if let Some(event) = events.iter().last() { + if let Some(event) = events.read().last() { match event.0 { Some(rect) => { let size = rect.size(); diff --git a/crates/controller/src/mouse/input.rs b/crates/controller/src/mouse/input.rs index 9bdab4dca..0ac9d63f5 100644 --- a/crates/controller/src/mouse/input.rs +++ b/crates/controller/src/mouse/input.rs @@ -273,7 +273,7 @@ fn update_buttons( mut clicks: EventWriter, mut drags: EventWriter, ) { - for event in input_events.iter() { + for event in input_events.read() { match event.state { ButtonState::Released => { if let Some(drag_resolution) = mouse_state.resolve(event.button) { @@ -305,7 +305,7 @@ fn check_double_click( mut last_click_time: Local, time: Res