Skip to content

Commit

Permalink
fix clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
foxzool committed Nov 25, 2024
1 parent abe4d02 commit 70f05f3
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 40 deletions.
25 changes: 25 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
4 changes: 3 additions & 1 deletion jigsaw_puzzle_generator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -937,6 +938,7 @@ pub struct JigsawPiece {
}

impl JigsawPiece {
#[allow(clippy::too_many_arguments)]
pub fn new(
index: usize,
start_point: (f32, f32),
Expand Down
12 changes: 12 additions & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -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
30 changes: 12 additions & 18 deletions src/gameplay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)),
Expand Down Expand Up @@ -230,17 +230,13 @@ fn exit_app_gameplay(mut game_state: ResMut<NextState<GameState>>) {
#[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)
}
}

Expand All @@ -251,7 +247,7 @@ fn setup_generator(
select_piece: Res<SelectPiece>,
) {
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)
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -1220,7 +1215,7 @@ fn setup_game_ui(
.observe(
|_trigger: Trigger<Pointer<Click>>,
mut game_state: ResMut<NextState<GameState>>| {
game_state.set(GameState::Pause)
game_state.set(GameState::Pause);
},
);
// fullscreen button
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -1425,7 +1420,6 @@ fn handle_puzzle_hint(
fn hint_image_click(
_trigger: Trigger<Pointer<Click>>,
mut commands: Commands,
// top_right: Single<Entity, With<TopRightNode>>,
mut hint_visible: Single<
&mut Visibility,
(
Expand Down
13 changes: 6 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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,
"{}",
Expand All @@ -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),
Expand Down Expand Up @@ -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,
"{}",
Expand Down
18 changes: 4 additions & 14 deletions src/main_menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ impl AnimatableProperty for TextColorProperty {
#[derive(Component)]
struct HiddenItem;

#[allow(clippy::too_many_arguments)]
fn show_title(
_trigger: Trigger<ShowTitleAnime>,
mut commands: Commands,
Expand Down Expand Up @@ -396,7 +397,7 @@ fn setup_menu(
.observe(
|_trigger: Trigger<Pointer<Click>>,
mut app_state: ResMut<NextState<AppState>>| {
app_state.set(AppState::Gameplay)
app_state.set(AppState::Gameplay);
},
);
});
Expand Down Expand Up @@ -528,31 +529,20 @@ fn menu_countdown(
}

fn button_interaction(
mut interaction_query: Query<
(
&Interaction,
&mut BackgroundColor,
&mut BorderColor,
&Children,
),
(Changed<Interaction>, With<Button>),
>,
interaction_query: Query<(&Interaction, &Children), (Changed<Interaction>, With<Button>)>,
mut text_query: Query<&mut TextColor>,
) {
for (interaction, _color, _border_color, children) in &mut interaction_query {
for (interaction, children) in interaction_query.iter() {
let mut text_color = text_query.get_mut(children[0]).unwrap();
match *interaction {
Interaction::Pressed => {
text_color.0 = PRESSED_BUTTON;
}
Interaction::Hovered => {
// *color = Color::srgb(0.8, 0.8, 0.8).into();
text_color.0 = HOVERED_BUTTON;
}
Interaction::None => {
text_color.0 = NORMAL_BUTTON;
// *color = Color::srgba(0.0, 0.0, 0.0, 0.0).into();
// border_color.0 = Color::BLACK;
}
}
}
Expand Down

0 comments on commit 70f05f3

Please sign in to comment.