From b966d38e945ce7f87431c322f1d266fad9b1efdc Mon Sep 17 00:00:00 2001 From: Kristofers Solo Date: Mon, 23 Dec 2024 13:53:53 +0200 Subject: [PATCH] fix: clippy warnings --- Cargo.toml | 2 ++ src/asset_tracking.rs | 7 ++++--- src/dev_tools/ui/maze_controls.rs | 2 +- src/dev_tools/ui/mod.rs | 2 +- src/floor/components.rs | 2 +- src/floor/systems/despawn.rs | 2 +- src/lib.rs | 6 +++--- src/maze/assets.rs | 24 ++++++++++++------------ src/maze/errors.rs | 2 +- src/maze/systems/setup.rs | 2 +- src/maze/triggers/common.rs | 2 +- src/maze/triggers/spawn.rs | 17 +++++++---------- src/player/systems/setup.rs | 2 +- src/screens/loading.rs | 2 +- src/screens/splash.rs | 2 +- 15 files changed, 38 insertions(+), 38 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 44b271b..bb788cf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -60,6 +60,8 @@ dev_native = [ too_many_arguments = "allow" # Queries that access many components may trigger this lint. type_complexity = "allow" +nursery = { level = "warn", priority = -1 } +unwrap_used = "warn" # Compile with Performance Optimizations: diff --git a/src/asset_tracking.rs b/src/asset_tracking.rs index f61992a..396ab1f 100644 --- a/src/asset_tracking.rs +++ b/src/asset_tracking.rs @@ -1,8 +1,7 @@ //! A high-level way to load collections of asset handles as resources. -use std::collections::VecDeque; - use bevy::prelude::*; +use std::collections::VecDeque; pub(super) fn plugin(app: &mut App) { app.init_resource::(); @@ -51,7 +50,9 @@ fn load_resource_assets(world: &mut World) { world.resource_scope(|world, mut resource_handles: Mut| { world.resource_scope(|world, assets: Mut| { for _ in 0..resource_handles.waiting.len() { - let (handle, insert_fn) = resource_handles.waiting.pop_front().unwrap(); + let Some((handle, insert_fn)) = resource_handles.waiting.pop_front() else { + continue; + }; if assets.is_loaded_with_dependencies(&handle) { insert_fn(world, &handle); resource_handles.finished.push(handle); diff --git a/src/dev_tools/ui/maze_controls.rs b/src/dev_tools/ui/maze_controls.rs index 95002cb..6c94755 100644 --- a/src/dev_tools/ui/maze_controls.rs +++ b/src/dev_tools/ui/maze_controls.rs @@ -12,7 +12,7 @@ use hexx::{Hex, HexOrientation}; use rand::{thread_rng, Rng}; use std::ops::RangeInclusive; -pub(crate) fn maze_controls_ui(world: &mut World) { +pub fn maze_controls_ui(world: &mut World) { if world.get_resource::().is_none() { return; } diff --git a/src/dev_tools/ui/mod.rs b/src/dev_tools/ui/mod.rs index 63c404f..4923190 100644 --- a/src/dev_tools/ui/mod.rs +++ b/src/dev_tools/ui/mod.rs @@ -1,3 +1,3 @@ mod maze_controls; -pub(crate) use maze_controls::maze_controls_ui; +pub use maze_controls::maze_controls_ui; diff --git a/src/floor/components.rs b/src/floor/components.rs index b3e8adf..9a8e924 100644 --- a/src/floor/components.rs +++ b/src/floor/components.rs @@ -19,7 +19,7 @@ impl Default for Floor { } impl Floor { - pub fn increased(&self) -> Self { + pub const fn increased(&self) -> Self { Self(self.0.saturating_add(1)) } diff --git a/src/floor/systems/despawn.rs b/src/floor/systems/despawn.rs index 2c77d52..3567c3b 100644 --- a/src/floor/systems/despawn.rs +++ b/src/floor/systems/despawn.rs @@ -1,3 +1,3 @@ use bevy::prelude::*; -pub(super) fn despawn_floor(mut commands: Commands) {} +pub const fn despawn_floor(mut _commands: Commands) {} diff --git a/src/lib.rs b/src/lib.rs index 3dcce5c..94bbcf7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,11 +1,11 @@ -mod asset_tracking; +pub mod asset_tracking; pub mod audio; #[cfg(feature = "dev")] -mod dev_tools; +pub mod dev_tools; pub mod floor; pub mod maze; pub mod player; -mod screens; +pub mod screens; pub mod theme; use bevy::{ diff --git a/src/maze/assets.rs b/src/maze/assets.rs index 12d9872..f80519b 100644 --- a/src/maze/assets.rs +++ b/src/maze/assets.rs @@ -8,26 +8,26 @@ const WALL_OVERLAP_MODIFIER: f32 = 1.25; const HEX_SIDES: u32 = 6; const WHITE_EMISSION_INTENSITY: f32 = 10.; -pub(crate) struct MazeAssets { - pub(crate) hex_mesh: Handle, - pub(crate) wall_mesh: Handle, - pub(crate) hex_material: Handle, - pub(crate) wall_material: Handle, - pub(crate) custom_materials: HashMap>, +pub struct MazeAssets { + pub hex_mesh: Handle, + pub wall_mesh: Handle, + pub hex_material: Handle, + pub wall_material: Handle, + pub custom_materials: HashMap>, } impl MazeAssets { - pub(crate) fn new( + pub fn new( meshes: &mut ResMut>, materials: &mut ResMut>, global_config: &GlobalMazeConfig, - ) -> MazeAssets { + ) -> Self { let mut custom_materials = HashMap::new(); custom_materials.extend(vec![ ("LOVE".to_string(), materials.add(red_material())), ("PINE".to_string(), materials.add(blue_material())), ]); - MazeAssets { + Self { hex_mesh: meshes.add(generate_hex_mesh( global_config.hex_size, global_config.height, @@ -62,7 +62,7 @@ fn generate_square_mesh(depth: f32, wall_size: f32) -> Mesh { Mesh::from(rectangular_prism).rotated_by(rotation) } -pub(crate) fn white_material() -> StandardMaterial { +pub fn white_material() -> StandardMaterial { StandardMaterial { emissive: LinearRgba::new( WHITE_EMISSION_INTENSITY, @@ -74,14 +74,14 @@ pub(crate) fn white_material() -> StandardMaterial { } } -pub(crate) fn red_material() -> StandardMaterial { +pub fn red_material() -> StandardMaterial { StandardMaterial { emissive: LOVE.to_linear(), ..default() } } -pub(crate) fn blue_material() -> StandardMaterial { +pub fn blue_material() -> StandardMaterial { StandardMaterial { emissive: PINE.to_linear(), ..default() diff --git a/src/maze/errors.rs b/src/maze/errors.rs index 005ff83..87e36a6 100644 --- a/src/maze/errors.rs +++ b/src/maze/errors.rs @@ -32,7 +32,7 @@ impl MazeError { Self::ConfigurationError(msg.into()) } - pub fn generation_failed(radius: u32, seed: u64) -> Self { + pub const fn generation_failed(radius: u32, seed: u64) -> Self { Self::GenerationFailed { radius, seed } } } diff --git a/src/maze/systems/setup.rs b/src/maze/systems/setup.rs index b26c975..42fe9fe 100644 --- a/src/maze/systems/setup.rs +++ b/src/maze/systems/setup.rs @@ -1,6 +1,6 @@ use crate::maze::events::SpawnMaze; use bevy::prelude::*; -pub(crate) fn setup(mut commands: Commands) { +pub fn setup(mut commands: Commands) { commands.trigger(SpawnMaze::default()); } diff --git a/src/maze/triggers/common.rs b/src/maze/triggers/common.rs index 6716a09..c39b539 100644 --- a/src/maze/triggers/common.rs +++ b/src/maze/triggers/common.rs @@ -4,7 +4,7 @@ use crate::maze::{ }; use hexlab::{GeneratorType, HexMaze, MazeBuilder}; -pub(crate) fn generate_maze(config: &MazeConfig) -> MazeResult { +pub fn generate_maze(config: &MazeConfig) -> MazeResult { MazeBuilder::new() .with_radius(config.radius) .with_seed(config.seed) diff --git a/src/maze/triggers/spawn.rs b/src/maze/triggers/spawn.rs index c92c50f..493fefe 100644 --- a/src/maze/triggers/spawn.rs +++ b/src/maze/triggers/spawn.rs @@ -1,3 +1,4 @@ +use super::common::generate_maze; use crate::{ floor::components::{CurrentFloor, Floor, NextFloor}, maze::{ @@ -12,9 +13,7 @@ use hexlab::prelude::*; use hexx::HexOrientation; use std::f32::consts::{FRAC_PI_2, FRAC_PI_3, FRAC_PI_6}; -use super::common::generate_maze; - -pub(crate) const FLOOR_Y_OFFSET: u8 = 100; +pub const FLOOR_Y_OFFSET: u8 = 100; pub(super) fn spawn_maze( trigger: Trigger, @@ -31,7 +30,7 @@ pub(super) fn spawn_maze( return; } - let maze = match generate_maze(&config) { + let maze = match generate_maze(config) { Ok(m) => m, Err(e) => { error!("Failed to generate maze for floor {floor}: {:?}", e); @@ -60,12 +59,12 @@ pub(super) fn spawn_maze( entity, &maze, &assets, - &config, + config, &global_config, ); } -pub(crate) fn spawn_maze_tiles( +pub fn spawn_maze_tiles( commands: &mut Commands, parent_entity: Entity, maze: &HexMaze, @@ -98,14 +97,12 @@ pub(super) fn spawn_single_hex_tile( .custom_materials .get("PINE") .cloned() - .to_owned() - .unwrap(), + .unwrap_or_default(), pos if pos == maze_config.end_pos => assets .custom_materials .get("LOVE") .cloned() - .to_owned() - .unwrap(), + .unwrap_or_default(), _ => assets.hex_material.clone(), }; diff --git a/src/player/systems/setup.rs b/src/player/systems/setup.rs index 84d879c..12157dd 100644 --- a/src/player/systems/setup.rs +++ b/src/player/systems/setup.rs @@ -1,6 +1,6 @@ use crate::player::events::SpawnPlayer; use bevy::prelude::*; -pub(crate) fn setup(mut commands: Commands) { +pub fn setup(mut commands: Commands) { commands.trigger(SpawnPlayer); } diff --git a/src/screens/loading.rs b/src/screens/loading.rs index a1cbccf..556c9a4 100644 --- a/src/screens/loading.rs +++ b/src/screens/loading.rs @@ -33,7 +33,7 @@ fn continue_to_title_screen(mut next_screen: ResMut>) { next_screen.set(Screen::Title); } -fn all_assets_loaded( +const fn all_assets_loaded( interaction_assets: Option>, credits_music: Option>, gameplay_music: Option>, diff --git a/src/screens/splash.rs b/src/screens/splash.rs index 4c60199..3171d0f 100644 --- a/src/screens/splash.rs +++ b/src/screens/splash.rs @@ -101,7 +101,7 @@ impl UiImageFadeInOut { let fade = self.fade_duration / self.total_duration; // Regular trapezoid-shaped graph, flat at the top with alpha = 1.0. - ((1.0 - (2.0 * t - 1.0).abs()) / fade).min(1.0) + ((1.0 - 2.0f32.mul_add(t, -1.0).abs()) / fade).min(1.0) } }