From 39c38e6eb84803fa93b1f1281ccc3b66472b57cd Mon Sep 17 00:00:00 2001 From: Peter Hayman Date: Sat, 9 Nov 2024 15:51:47 +1100 Subject: [PATCH] refactor: populated, single --- .../src/components/camera_distance.rs | 9 ++--- .../src/components/collectable.rs | 2 +- .../src/components/follow_cursor.rs | 35 ++++++------------- .../src/components/randomize_position.rs | 2 +- .../src/components/wrap_around.rs | 4 +-- crates/beet_flow/examples/derive_action.rs | 2 +- .../examples/derive_action_generic.rs | 6 ++-- .../examples/derive_action_systems.rs | 5 ++- crates/beet_flow/examples/observer_test.rs | 2 +- crates/beet_flow/examples/observers.rs | 8 ++--- 10 files changed, 29 insertions(+), 46 deletions(-) diff --git a/crates/beet_examples/src/components/camera_distance.rs b/crates/beet_examples/src/components/camera_distance.rs index 63cdec01..c86775ca 100644 --- a/crates/beet_examples/src/components/camera_distance.rs +++ b/crates/beet_examples/src/components/camera_distance.rs @@ -26,7 +26,7 @@ impl CameraDistance { pub fn camera_distance( mut resize: EventReader, - main_window: Query<&Window, With>, + main_window: Single<&Window, With>, camera_added: Query< (), ( @@ -34,16 +34,13 @@ pub fn camera_distance( Or<(Added, Added)>, ), >, - mut query: Query<(&mut Transform, &Projection, &CameraDistance)>, + mut query: Populated<(&mut Transform, &Projection, &CameraDistance)>, ) { if camera_added.iter().count() == 0 && resize.read().count() == 0 { return; } - let Ok(window) = main_window.get_single() else { - return; - }; - let aspect_ratio = window.width() as f32 / window.height() as f32; + let aspect_ratio = main_window.width() as f32 / main_window.height() as f32; for (mut transform, projection, camera_distance) in query.iter_mut() { let Projection::Perspective(perspective) = projection else { diff --git a/crates/beet_examples/src/components/collectable.rs b/crates/beet_examples/src/components/collectable.rs index bad0436a..253ac6bc 100644 --- a/crates/beet_examples/src/components/collectable.rs +++ b/crates/beet_examples/src/components/collectable.rs @@ -12,7 +12,7 @@ const TURNS_PER_SECOND: f32 = 0.5; pub fn rotate_collectables( time: Res