diff --git a/Cargo.toml b/Cargo.toml index f6eaf1f..1275013 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,31 @@ members = [ ] +[lints.clippy] +doc_markdown = "warn" +manual_let_else = "warn" +match_same_arms = "warn" +redundant_closure_for_method_calls = "warn" +redundant_else = "warn" +semicolon_if_nothing_returned = "warn" +type_complexity = "allow" +undocumented_unsafe_blocks = "warn" +unwrap_or_default = "warn" +needless_lifetimes = "allow" + +ptr_as_ptr = "warn" +ptr_cast_constness = "warn" +ref_as_ptr = "warn" + +# see: https://github.com/bevyengine/bevy/pull/15375#issuecomment-2366966219 +too_long_first_doc_paragraph = "allow" + +std_instead_of_core = "warn" +std_instead_of_alloc = "warn" +alloc_instead_of_core = "warn" + + + [dependencies] bevy = { version = "0.15.0-rc.3", features = ["bevy_sprite_picking_backend", "jpeg"] } #bevy = { git = "https://github.com/bevyengine/bevy", features = ["bevy_sprite_picking_backend"] } diff --git a/jigsaw_puzzle_generator/src/lib.rs b/jigsaw_puzzle_generator/src/lib.rs index 1f7d2eb..b888ec8 100644 --- a/jigsaw_puzzle_generator/src/lib.rs +++ b/jigsaw_puzzle_generator/src/lib.rs @@ -681,7 +681,8 @@ impl JigsawGenerator { let (top_index, right_index, bottom_index, left_index) = get_border_indices(i, pieces_in_column); - debug!("starting process piece {i} {top_index} {right_index} {bottom_index} {left_index}"); + // debug!("starting process piece {i} {top_index} {right_index} {bottom_index} {left_index}"); + debug!("starting process piece {i}"); let is_boarder = i < pieces_in_column || i >= (pieces_in_column * (pieces_in_row - 1)) @@ -937,6 +938,7 @@ pub struct JigsawPiece { } impl JigsawPiece { + #[allow(clippy::too_many_arguments)] pub fn new( index: usize, start_point: (f32, f32), diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 0000000..467c453 --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1,12 @@ +use_field_init_shorthand = true +newline_style = "Unix" + +# The following lines may be uncommented on nightly Rust. +# Once these features have stabilized, they should be added to the always-enabled options above. +# unstable_features = true +# imports_granularity = "Crate" +# normalize_comments = true + +# these options seem poorly implemented and cause churn, so, try to avoid them +# wrap_comments = true +# comment_width = 100 diff --git a/src/gameplay.rs b/src/gameplay.rs index 8638a10..70e6630 100644 --- a/src/gameplay.rs +++ b/src/gameplay.rs @@ -10,13 +10,13 @@ use bevy::sprite::Anchor; use bevy::time::Stopwatch; use bevy::utils::HashSet; use bevy::window::WindowMode; +use core::ops::DerefMut; +use core::time::Duration; use flume::{bounded, Receiver}; use jigsaw_puzzle_generator::image::GenericImageView; use jigsaw_puzzle_generator::{JigsawGenerator, JigsawPiece, JigsawTemplate}; use log::debug; use rand::Rng; -use std::ops::DerefMut; -use std::time::Duration; pub(super) fn plugin(app: &mut App) { // app state @@ -127,7 +127,7 @@ fn setup_finish_ui( }, )); p.spawn(( - Text::new(format!("Use time: {}", game_timer.to_string())), + Text::new(format!("Use time: {}", *game_timer)), TextColor(Color::BLACK), Node { margin: UiRect::all(Val::Px(5.0)), @@ -230,17 +230,13 @@ fn exit_app_gameplay(mut game_state: ResMut>) { #[derive(Resource, Deref, DerefMut, Debug)] pub struct GameTimer(pub Stopwatch); -impl std::fmt::Display for GameTimer { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Display for GameTimer { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { let elapsed = self.elapsed(); let seconds = elapsed.as_secs(); let minutes = seconds / 60; let hours = minutes / 60; - write!( - f, - "{}", - format!("{:02}:{:02}:{:02}", hours, minutes % 60, seconds % 60) - ) + write!(f, "{:02}:{:02}:{:02}", hours, minutes % 60, seconds % 60) } } @@ -251,7 +247,7 @@ fn setup_generator( select_piece: Res, ) { let image = images.get(&origin_image.0).unwrap(); - let (columns, rows) = select_piece.to_columns_rows(); + let (columns, rows) = select_piece.get_columns_rows(); let width = image.texture_descriptor.size.width; let height = image.texture_descriptor.size.height; let generator = JigsawGenerator::from_rgba8(width, height, &image.data, columns, rows) @@ -450,7 +446,7 @@ fn count_spawned_piece( let loaded_pieces = q_pieces.iter().count(); text.0 = format!("{}/{}", loaded_pieces, generator.pieces_count()); if loaded_pieces == generator.pieces_count() { - game_state.set(GameState::Play) + game_state.set(GameState::Play); } } @@ -793,14 +789,13 @@ fn shuffle_pieces( match event { Shuffle::Random => { for (piece, mut transform) in &mut query.iter_mut() { - let random_pos = - random_position(&piece, window.resolution.size(), camera.scale); + let random_pos = random_position(piece, window.resolution.size(), camera.scale); transform.translation = random_pos.extend(piece.index as f32); } } Shuffle::Edge => { for (piece, mut transform) in &mut query.iter_mut() { - let edge_pos = edge_position(&piece, window.resolution.size(), camera.scale); + let edge_pos = edge_position(piece, window.resolution.size(), camera.scale); transform.translation = edge_pos.extend(piece.index as f32); } } @@ -1220,7 +1215,7 @@ fn setup_game_ui( .observe( |_trigger: Trigger>, mut game_state: ResMut>| { - game_state.set(GameState::Pause) + game_state.set(GameState::Pause); }, ); // fullscreen button @@ -1370,7 +1365,7 @@ fn handle_toggle_puzzle_hint( if move_together.len() > 0 { continue 'f2; } - if first_piece.beside(&piece) { + if first_piece.beside(piece) { second_entity = Some(entity); break 'f2; } @@ -1425,7 +1420,6 @@ fn handle_puzzle_hint( fn hint_image_click( _trigger: Trigger>, mut commands: Commands, - // top_right: Single>, mut hint_visible: Single< &mut Visibility, ( diff --git a/src/lib.rs b/src/lib.rs index 63a5a09..be9c469 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,8 +1,7 @@ use bevy::prelude::*; use bevy::render::view::RenderLayers; +use core::fmt::Formatter; use jigsaw_puzzle_generator::{GameMode, JigsawPiece}; -use std::fmt; -use std::fmt::Formatter; mod gameplay; mod main_menu; @@ -110,8 +109,8 @@ enum SelectPiece { P500, } -impl fmt::Display for SelectPiece { - fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { +impl core::fmt::Display for SelectPiece { + fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result { write!( f, "{}", @@ -131,7 +130,7 @@ impl fmt::Display for SelectPiece { } impl SelectPiece { - fn to_columns_rows(&self) -> (usize, usize) { + fn get_columns_rows(&self) -> (usize, usize) { match self { SelectPiece::P20 => (5, 4), SelectPiece::P50 => (10, 5), @@ -177,8 +176,8 @@ impl SelectPiece { #[derive(Debug, Resource, Deref, DerefMut, Default)] pub struct SelectGameMode(pub GameMode); -impl fmt::Display for SelectGameMode { - fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { +impl core::fmt::Display for SelectGameMode { + fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result { write!( f, "{}", diff --git a/src/main_menu.rs b/src/main_menu.rs index a0954c9..e05d0bb 100644 --- a/src/main_menu.rs +++ b/src/main_menu.rs @@ -67,6 +67,7 @@ impl AnimatableProperty for TextColorProperty { #[derive(Component)] struct HiddenItem; +#[allow(clippy::too_many_arguments)] fn show_title( _trigger: Trigger, mut commands: Commands, @@ -396,7 +397,7 @@ fn setup_menu( .observe( |_trigger: Trigger>, mut app_state: ResMut>| { - app_state.set(AppState::Gameplay) + app_state.set(AppState::Gameplay); }, ); }); @@ -528,31 +529,20 @@ fn menu_countdown( } fn button_interaction( - mut interaction_query: Query< - ( - &Interaction, - &mut BackgroundColor, - &mut BorderColor, - &Children, - ), - (Changed, With