Skip to content

Commit

Permalink
fix deprecated event iter for read
Browse files Browse the repository at this point in the history
  • Loading branch information
aevyrie committed Nov 10, 2023
1 parent a152595 commit 559e5d2
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 29 deletions.
20 changes: 10 additions & 10 deletions crates/bevy_picking_core/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ pub fn pointer_events(
pointer_id,
location,
delta,
} in input_moves.iter().cloned()
} in input_moves.read().cloned()
{
for (hovered_entity, hit) in hover_map
.get(&pointer_id)
Expand All @@ -236,7 +236,7 @@ pub fn pointer_events(
}
}

for press_event in input_presses.iter() {
for press_event in input_presses.read() {
let button = press_event.button;
// We use the previous hover map because we want to consider pointers that just left the
// entity. Without this, touch inputs would never send up events because they are lifted up
Expand Down Expand Up @@ -377,7 +377,7 @@ pub fn send_click_and_drag_events(
pointer_id,
location,
delta: _,
} in input_move.iter().cloned()
} in input_move.read().cloned()
{
for button in PointerButton::iter() {
let Some(down_list) = down_map.get(&(pointer_id, button)) else {
Expand Down Expand Up @@ -430,7 +430,7 @@ pub fn send_click_and_drag_events(
pointer_location,
target,
event: Up { button, hit },
} in pointer_up.iter().cloned()
} in pointer_up.read().cloned()
{
// Can't have a click without the button being pressed down first
if down_map
Expand All @@ -448,14 +448,14 @@ pub fn send_click_and_drag_events(
}

// Triggers when button is pressed over an entity
for event in pointer_down.iter() {
for event in pointer_down.read() {
let button = event.button;
let down_button_entity_map = down_map.entry((event.pointer_id, button)).or_default();
down_button_entity_map.insert(event.target, event.clone());
}

// Triggered for all button presses
for press in input_presses.iter() {
for press in input_presses.read() {
if press.direction != pointer::PressDirection::Up {
continue; // We are only interested in button releases
}
Expand Down Expand Up @@ -507,7 +507,7 @@ pub fn send_drag_over_events(
pointer_location,
target,
event: Over { hit },
} in pointer_over.iter().cloned()
} in pointer_over.read().cloned()
{
for button in PointerButton::iter() {
for drag_target in drag_map
Expand Down Expand Up @@ -541,7 +541,7 @@ pub fn send_drag_over_events(
pointer_location,
target,
event: Move { hit, delta: _ },
} in pointer_move.iter().cloned()
} in pointer_move.read().cloned()
{
for button in PointerButton::iter() {
for drag_target in drag_map
Expand Down Expand Up @@ -575,7 +575,7 @@ pub fn send_drag_over_events(
button,
distance: _,
},
} in pointer_drag_end.iter().cloned()
} in pointer_drag_end.read().cloned()
{
let Some(drag_over_set) = drag_over_map.get_mut(&(pointer_id, button)) else {
continue;
Expand Down Expand Up @@ -610,7 +610,7 @@ pub fn send_drag_over_events(
pointer_location,
target,
event: Out { hit },
} in pointer_out.iter().cloned()
} in pointer_out.read().cloned()
{
for button in PointerButton::iter() {
let Some(dragged_over) = drag_over_map.get_mut(&(pointer_id, button)) else {
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_picking_core/src/focus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ fn build_over_map(
pointer_over_map: &mut Local<OverMap>,
pointer_cancel: &mut EventReader<PointerCancel>,
) {
let cancelled_pointers: Vec<PointerId> = pointer_cancel.iter().map(|p| p.pointer_id).collect();
let cancelled_pointers: Vec<PointerId> = pointer_cancel.read().map(|p| p.pointer_id).collect();

for entities_under_pointer in backend_events
.iter()
.read()
.filter(|e| !cancelled_pointers.contains(&e.pointer))
{
let pointer = entities_under_pointer.pointer;
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_picking_core/src/pointer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ impl InputPress {
mut events: EventReader<InputPress>,
mut pointers: Query<(&PointerId, &mut PointerPress)>,
) {
for input_press_event in events.iter() {
for input_press_event in events.read() {
pointers.for_each_mut(|(pointer_id, mut pointer)| {
if *pointer_id == input_press_event.pointer_id {
let is_down = input_press_event.direction == PressDirection::Down;
Expand Down Expand Up @@ -256,7 +256,7 @@ impl InputMove {
mut events: EventReader<InputMove>,
mut pointers: Query<(&PointerId, &mut PointerLocation)>,
) {
for event_pointer in events.iter() {
for event_pointer in events.read() {
pointers.for_each_mut(|(id, mut pointer)| {
if *id == event_pointer.pointer_id {
pointer.location = Some(event_pointer.location.to_owned());
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_picking_input/src/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ use bevy_picking_core::pointer::{InputMove, InputPress};

/// Listens for input events and prints them.
pub fn print(mut moves: EventReader<InputMove>, mut presses: EventReader<InputPress>) {
for event in moves.iter() {
for event in moves.read() {
info!("Input Move: {:?}", event.pointer_id);
}
for event in presses.iter() {
for event in presses.read() {
info!("Input Press: {:?}, {:?}", event.pointer_id, event.direction);
}
}
4 changes: 2 additions & 2 deletions crates/bevy_picking_input/src/mouse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub fn mouse_pick_events(
mut pointer_move: EventWriter<InputMove>,
mut pointer_presses: EventWriter<InputPress>,
) {
for event in cursor_moves.iter() {
for event in cursor_moves.read() {
pointer_move.send(InputMove::new(
PointerId::Mouse,
Location {
Expand All @@ -45,7 +45,7 @@ pub fn mouse_pick_events(
*cursor_last = event.position;
}

for input in mouse_inputs.iter() {
for input in mouse_inputs.read() {
let button = match input.button {
MouseButton::Left => PointerButton::Primary,
MouseButton::Right => PointerButton::Secondary,
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_picking_input/src/touch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub fn touch_pick_events(
mut input_presses: EventWriter<InputPress>,
mut cancel_events: EventWriter<PointerCancel>,
) {
for touch in touches.iter() {
for touch in touches.read() {
let pointer = PointerId::Touch(touch.id);
let location = Location {
target: RenderTarget::Window(WindowRef::Primary)
Expand Down Expand Up @@ -89,7 +89,7 @@ pub fn deactivate_touch_pointers(
pointers: Query<(Entity, &PointerId)>,
mut touches: EventReader<TouchInput>,
) {
for touch in touches.iter() {
for touch in touches.read() {
match touch.phase {
TouchPhase::Ended | TouchPhase::Canceled => {
for (entity, pointer) in &pointers {
Expand Down
10 changes: 5 additions & 5 deletions crates/bevy_picking_selection/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ pub fn send_selection_events(
target,
event: _,
} in pointer_down
.iter()
.read()
.filter(|pointer| pointer.event.button == PointerButton::Primary)
{
pointer_down_list.insert(pointer_id);
Expand Down Expand Up @@ -164,7 +164,7 @@ pub fn send_selection_events(
// so, and the setting is enabled, deselect everything.
if settings.click_nothing_deselect_all {
for press in presses
.iter()
.read()
.filter(|p| p.is_just_down(PointerButton::Primary))
{
let id = press.pointer_id;
Expand Down Expand Up @@ -194,7 +194,7 @@ pub fn send_selection_events(
target,
event: _,
} in pointer_click
.iter()
.read()
.filter(|pointer| pointer.event.button == PointerButton::Primary)
{
let multiselect = pointers
Expand Down Expand Up @@ -235,12 +235,12 @@ pub fn update_state_from_events(
mut selections: EventReader<Pointer<Select>>,
mut deselections: EventReader<Pointer<Deselect>>,
) {
for selection in selections.iter() {
for selection in selections.read() {
if let Ok(mut select_me) = selectables.get_mut(selection.target) {
select_me.is_selected = true;
}
}
for deselection in deselections.iter() {
for deselection in deselections.read() {
if let Ok(mut deselect_me) = selectables.get_mut(deselection.target) {
deselect_me.is_selected = false;
}
Expand Down
2 changes: 1 addition & 1 deletion examples/event_listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ impl From<ListenerInput<Pointer<Down>>> for DoSomethingComplex {

/// Unlike callback systems, this is a normal system that can be run in parallel with other systems.
fn receive_greetings(mut greetings: EventReader<DoSomethingComplex>) {
for event in greetings.iter() {
for event in greetings.read() {
info!(
"Hello {:?}, you are {:?} depth units away from the pointer",
event.0, event.1
Expand Down
2 changes: 1 addition & 1 deletion examples/split_screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ fn set_camera_viewports(
// We need to dynamically resize the camera's viewports whenever the window size changes so then
// each camera always takes up half the screen. A resize_event is sent when the window is first
// created, allowing us to reuse this system for initial setup.
for resize_event in resize_events.iter() {
for resize_event in resize_events.read() {
let window = windows.get(resize_event.window).unwrap();
let mut left_camera = left_camera.single_mut();
left_camera.viewport = Some(bevy::render::camera::Viewport {
Expand Down
4 changes: 2 additions & 2 deletions src/debug/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,14 @@ impl Plugin for DebugPickingPlugin {

/// Listens for pointer events of type `E` and logs them at "debug" level
pub fn log_debug<E: Debug + Clone + Reflect>(mut pointer_events: EventReader<Pointer<E>>) {
for event in pointer_events.iter() {
for event in pointer_events.read() {
debug!("{event}");
}
}

/// Listens for pointer events of type `E` and logs them at "trace" level
pub fn log_trace<E: Debug + Clone + Reflect>(mut pointer_events: EventReader<Pointer<E>>) {
for event in pointer_events.iter() {
for event in pointer_events.read() {
trace!("{event}");
}
}
Expand Down

0 comments on commit 559e5d2

Please sign in to comment.