From 145008a52dbb1c13654aea2a36e5233e1c1d0675 Mon Sep 17 00:00:00 2001 From: Elijah Voigt Date: Tue, 22 Jul 2025 15:21:28 -0700 Subject: [PATCH] Make clippy happy --- src/bin/trees/main.rs | 32 ++++++------ src/bin/trees/mono.rs | 6 +-- src/debug.rs | 113 +++++++++++++++++++++--------------------- src/ui.rs | 21 +++----- 4 files changed, 83 insertions(+), 89 deletions(-) diff --git a/src/bin/trees/main.rs b/src/bin/trees/main.rs index 0c8c38b..60a25ff 100644 --- a/src/bin/trees/main.rs +++ b/src/bin/trees/main.rs @@ -774,26 +774,26 @@ fn drag_tree( camera: Single<(&Camera, &GlobalTransform), With>, window: Single<&Window>, ) { - if *state.get() == DebuggingState::On { - if let Ok(mut t) = query.get_mut(trigger.target()) { - let world_position = window - .cursor_position() - .and_then(|cursor| camera.0.viewport_to_world(camera.1, cursor).ok()) - .map(|ray| { - // Compute ray's distance to entity - let distance = ray - .intersect_plane(t.translation, InfinitePlane3d::new(t.up())) - .unwrap(); - ray.get_point(distance) - }); - t.translation = world_position.unwrap(); - } + if *state.get() == DebuggingState::On + && let Ok(mut t) = query.get_mut(trigger.target()) + { + let world_position = window + .cursor_position() + .and_then(|cursor| camera.0.viewport_to_world(camera.1, cursor).ok()) + .map(|ray| { + // Compute ray's distance to entity + let distance = ray + .intersect_plane(t.translation, InfinitePlane3d::new(t.up())) + .unwrap(); + ray.get_point(distance) + }); + t.translation = world_position.unwrap(); } } // When you pointer over the '+' make the entire menu visible -fn hide_menu(mut nodes: Query<(Entity, &mut Visibility, &NavState), Changed>) { - nodes.iter_mut().for_each(|(e, mut v, n)| { +fn hide_menu(mut nodes: Query<(&mut Visibility, &NavState), Changed>) { + nodes.iter_mut().for_each(|(mut v, n)| { *v = match n { NavState::Open => Visibility::Inherited, NavState::Closed => Visibility::Hidden, diff --git a/src/bin/trees/mono.rs b/src/bin/trees/mono.rs index 8154c48..bc23836 100644 --- a/src/bin/trees/mono.rs +++ b/src/bin/trees/mono.rs @@ -46,9 +46,9 @@ impl From for MonologueLine { } } -impl Into for MonologueLine { - fn into(self) -> String { - self.value +impl From for String { + fn from(val: MonologueLine) -> Self { + val.value } } diff --git a/src/debug.rs b/src/debug.rs index bcebfc6..399b05a 100644 --- a/src/debug.rs +++ b/src/debug.rs @@ -72,9 +72,7 @@ fn init_debug_ui(mut commands: Commands) { DebuggingState::On, Name::new("Debug Indicator"), GlobalZIndex(i32::MAX - 1), - children![ - Text(" Debug: ON ".into()), - ], + children![Text(" Debug: ON ".into()),], Node { align_self: AlignSelf::Center, justify_self: JustifySelf::End, @@ -86,9 +84,7 @@ fn init_debug_ui(mut commands: Commands) { commands.spawn(( DebuggingState::On, Name::new("Version #"), - children![ - Text::new(VERSION), - ], + children![Text::new(VERSION),], GlobalZIndex(i32::MAX - 1), Node { width: Val::Auto, @@ -99,62 +95,65 @@ fn init_debug_ui(mut commands: Commands) { )); // Version string for troubleshooting - commands.spawn(( - DebuggingState::On, - Name::new("FPS"), - GlobalZIndex(i32::MAX - 1), - Node { - width: Val::Auto, - align_self: AlignSelf::Start, - justify_self: JustifySelf::End, - ..default() - }, - )).with_children(|parent| { - parent.spawn(( - Text::new("FPS: ##.#"), - SyncResource::::default(), - )); - }); + commands + .spawn(( + DebuggingState::On, + Name::new("FPS"), + GlobalZIndex(i32::MAX - 1), + Node { + width: Val::Auto, + align_self: AlignSelf::Start, + justify_self: JustifySelf::End, + ..default() + }, + )) + .with_children(|parent| { + parent.spawn((Text::new("FPS: ##.#"), SyncResource::::default())); + }); - commands.spawn(( - DebuggingState::On, - Name::new("Entity Count"), - GlobalZIndex(i32::MAX - 1), - Node { - width: Val::Auto, - align_self: AlignSelf::Start, - justify_self: JustifySelf::Center, - ..default() - }, - )).with_children(|parent| { - parent.spawn(( - Text::new("Entities: ###"), - SyncResource::::default(), - )); - }); + commands + .spawn(( + DebuggingState::On, + Name::new("Entity Count"), + GlobalZIndex(i32::MAX - 1), + Node { + width: Val::Auto, + align_self: AlignSelf::Start, + justify_self: JustifySelf::Center, + ..default() + }, + )) + .with_children(|parent| { + parent.spawn(( + Text::new("Entities: ###"), + SyncResource::::default(), + )); + }); // Tooltip - commands.spawn(( - DebuggingState::On, - SyncResource::::default(), - Pickable::IGNORE, - GlobalZIndex(i32::MAX), - Node { - position_type: PositionType::Absolute, - margin: UiRect { - left: Val::Px(20.0), + commands + .spawn(( + DebuggingState::On, + SyncResource::::default(), + Pickable::IGNORE, + GlobalZIndex(i32::MAX), + Node { + position_type: PositionType::Absolute, + margin: UiRect { + left: Val::Px(20.0), + ..default() + }, + align_content: AlignContent::Center, + justify_content: JustifyContent::Center, ..default() }, - align_content: AlignContent::Center, - justify_content: JustifyContent::Center, - ..default() - }, - )).with_children(|parent| { - parent.spawn(( - Text("Tooltip Placeholder".into()), - SyncResource::::default(), - )); - }); + )) + .with_children(|parent| { + parent.spawn(( + Text("Tooltip Placeholder".into()), + SyncResource::::default(), + )); + }); } /// Toggles the debug state from off -> on // off -> on when triggered diff --git a/src/ui.rs b/src/ui.rs index 92ecaa2..22d67a1 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -14,7 +14,7 @@ impl Plugin for BaseUiPlugin { add_ui_text .run_if(any_component_added::) .after(add_ui_node), - navs_on_top.run_if(any_component_changed::) + navs_on_top.run_if(any_component_changed::), ), ); } @@ -208,18 +208,13 @@ pub enum NavState { Closed, } -fn navs_on_top( - changed: Query<(Entity, &NavState), Changed>, - mut commands: Commands, -) { - changed.iter().for_each(|(e, ns)| { - match ns { - NavState::Open => { - commands.entity(e).insert(GlobalZIndex(i32::MAX/ 2)); - } - NavState::Closed => { - commands.entity(e).remove::(); - } +fn navs_on_top(changed: Query<(Entity, &NavState), Changed>, mut commands: Commands) { + changed.iter().for_each(|(e, ns)| match ns { + NavState::Open => { + commands.entity(e).insert(GlobalZIndex(i32::MAX / 2)); + } + NavState::Closed => { + commands.entity(e).remove::(); } }) }