From e8944598cc8ce64a403bb7fc2a9d48d3e968ac4d Mon Sep 17 00:00:00 2001 From: Xevion Date: Fri, 15 Aug 2025 19:48:30 -0500 Subject: [PATCH] chore: fix clippy warnings --- src/game/mod.rs | 154 ++++---------------------------------- src/systems/components.rs | 5 -- src/systems/control.rs | 5 +- src/systems/formatting.rs | 4 +- src/systems/movement.rs | 18 ++--- src/systems/render.rs | 6 +- tests/formatting.rs | 4 +- 7 files changed, 31 insertions(+), 165 deletions(-) diff --git a/src/game/mod.rs b/src/game/mod.rs index 98a3403..dd5e99b 100644 --- a/src/game/mod.rs +++ b/src/game/mod.rs @@ -13,8 +13,8 @@ use crate::systems::{ blinking::blinking_system, collision::collision_system, components::{ - Collider, CollisionLayer, DeltaTime, DirectionalAnimated, EntityType, GlobalState, ItemBundle, ItemCollider, - PacmanCollider, PlayerBundle, PlayerControlled, RenderDirty, Renderable, Score, ScoreResource, + Collider, DeltaTime, DirectionalAnimated, EntityType, GlobalState, ItemBundle, ItemCollider, PacmanCollider, + PlayerBundle, PlayerControlled, RenderDirty, Renderable, ScoreResource, }, control::player_system, debug::{debug_render_system, DebugState, DebugTextureResource}, @@ -174,7 +174,6 @@ impl Game { entity_type: EntityType::Player, collider: Collider { size: constants::CELL_SIZE as f32 * 1.375, - layer: CollisionLayer::PACMAN, }, pacman_collider: PacmanCollider, }; @@ -196,14 +195,10 @@ impl Game { world.insert_resource(DebugState::default()); world.add_observer( - |event: Trigger, mut state: ResMut, _score: ResMut| match *event { - GameEvent::Command(command) => match command { - GameCommand::Exit => { - state.exit = true; - } - _ => {} - }, - GameEvent::Collision(_a, _b) => {} + |event: Trigger, mut state: ResMut, _score: ResMut| { + if matches!(*event, GameEvent::Command(GameCommand::Exit)) { + state.exit = true; + } }, ); schedule.add_systems( @@ -238,6 +233,7 @@ impl Game { ) .chain(), ); + // Spawn player world.spawn(player); @@ -250,14 +246,11 @@ impl Game { let nodes: Vec<_> = world.resource::().iter_nodes().map(|(id, tile)| (*id, *tile)).collect(); for (node_id, tile) in nodes { - let (item_type, score, sprite, size) = match tile { - crate::constants::MapTile::Pellet => (EntityType::Pellet, 10, pellet_sprite, constants::CELL_SIZE as f32 * 0.4), - crate::constants::MapTile::PowerPellet => ( - EntityType::PowerPellet, - 50, - energizer_sprite, - constants::CELL_SIZE as f32 * 0.95, - ), + let (item_type, sprite, size) = match tile { + crate::constants::MapTile::Pellet => (EntityType::Pellet, pellet_sprite, constants::CELL_SIZE as f32 * 0.4), + crate::constants::MapTile::PowerPellet => { + (EntityType::PowerPellet, energizer_sprite, constants::CELL_SIZE as f32 * 0.95) + } _ => continue, }; @@ -272,11 +265,7 @@ impl Game { visible: true, }, entity_type: item_type, - score: Score(score), - collider: Collider { - size, - layer: CollisionLayer::ITEM, - }, + collider: Collider { size }, item_collider: ItemCollider, }); @@ -291,78 +280,6 @@ impl Game { Ok(Game { world, schedule }) } - // fn handle_command(&mut self, command: crate::input::commands::GameCommand) { - // use crate::input::commands::GameCommand; - // match command { - // GameCommand::MovePlayer(direction) => { - // self.state.pacman.set_next_direction(direction); - // } - // GameCommand::ToggleDebug => { - // self.toggle_debug_mode(); - // } - // GameCommand::MuteAudio => { - // let is_muted = self.state.audio.is_muted(); - // self.state.audio.set_mute(!is_muted); - // } - // GameCommand::ResetLevel => { - // if let Err(e) = self.reset_game_state() { - // tracing::error!("Failed to reset game state: {}", e); - // } - // } - // GameCommand::TogglePause => { - // self.state.paused = !self.state.paused; - // } - // GameCommand::Exit => {} - // } - // } - - // fn process_events(&mut self) { - // while let Some(event) = self.state.event_queue.pop_front() { - // match event { - // GameEvent::Command(command) => self.handle_command(command), - // } - // } - - // /// Resets the game state, randomizing ghost positions and resetting Pac-Man - // fn reset_game_state(&mut self) -> GameResult<()> { - // let pacman_start_node = self.state.map.start_positions.pacman; - // self.state.pacman = Pacman::new(&self.state.map.graph, pacman_start_node, &self.state.atlas)?; - - // // Reset items - // self.state.items = self.state.map.generate_items(&self.state.atlas)?; - - // // Randomize ghost positions - // let ghost_types = [GhostType::Blinky, GhostType::Pinky, GhostType::Inky, GhostType::Clyde]; - // let mut rng = SmallRng::from_os_rng(); - - // for (i, ghost) in self.state.ghosts.iter_mut().enumerate() { - // let random_node = rng.random_range(0..self.state.map.graph.node_count()); - // *ghost = Ghost::new(&self.state.map.graph, random_node, ghost_types[i], &self.state.atlas)?; - // } - - // // Reset collision system - // self.state.collision_system = CollisionSystem::default(); - - // // Re-register Pac-Man - // self.state.pacman_id = self.state.collision_system.register_entity(self.state.pacman.position()); - - // // Re-register items - // self.state.item_ids.clear(); - // for item in &self.state.items { - // let item_id = self.state.collision_system.register_entity(item.position()); - // self.state.item_ids.push(item_id); - // } - - // // Re-register ghosts - // self.state.ghost_ids.clear(); - // for ghost in &self.state.ghosts { - // let ghost_id = self.state.collision_system.register_entity(ghost.position()); - // self.state.ghost_ids.push(ghost_id); - // } - - // Ok(()) - // } - /// Ticks the game state. /// /// Returns true if the game should exit. @@ -377,52 +294,9 @@ impl Game { .get_resource::() .expect("GlobalState could not be acquired"); - return state.exit; - - // // Process any events that have been posted (such as unpausing) - // self.process_events(); - - // // If the game is paused, we don't need to do anything beyond returning - // if self.state.paused { - // return false; - // } - - // self.schedule.run(&mut self.world); - - // self.state.pacman.tick(dt, &self.state.map.graph); - - // // Update all ghosts - // for ghost in &mut self.state.ghosts { - // ghost.tick(dt, &self.state.map.graph); - // } - - // // Update collision system positions - // self.update_collision_positions(); - - // // Check for collisions - // self.check_collisions(); + state.exit } - // /// Toggles the debug mode on and off. - // /// - // /// When debug mode is enabled, the game will render additional information - // /// that is useful for debugging, such as the collision grid and entity paths. - // pub fn toggle_debug_mode(&mut self) { - // self.state.debug_mode = !self.state.debug_mode; - // } - - // fn update_collision_positions(&mut self) { - // // Update Pac-Man's position - // self.state - // .collision_system - // .update_position(self.state.pacman_id, self.state.pacman.position()); - - // // Update ghost positions - // for (ghost, &ghost_id) in self.state.ghosts.iter().zip(&self.state.ghost_ids) { - // self.state.collision_system.update_position(ghost_id, ghost.position()); - // } - // } - // fn check_collisions(&mut self) { // // Check Pac-Man vs Items // let potential_collisions = self diff --git a/src/systems/components.rs b/src/systems/components.rs index 2df22a0..e6705fc 100644 --- a/src/systems/components.rs +++ b/src/systems/components.rs @@ -60,7 +60,6 @@ bitflags! { #[derive(Component)] pub struct Collider { pub size: f32, - pub layer: CollisionLayer, } /// Marker components for collision filtering optimization @@ -73,9 +72,6 @@ pub struct GhostCollider; #[derive(Component)] pub struct ItemCollider; -#[derive(Component)] -pub struct Score(pub u32); - #[derive(Bundle)] pub struct PlayerBundle { pub player: PlayerControlled, @@ -94,7 +90,6 @@ pub struct ItemBundle { pub position: Position, pub sprite: Renderable, pub entity_type: EntityType, - pub score: Score, pub collider: Collider, pub item_collider: ItemCollider, } diff --git a/src/systems/control.rs b/src/systems/control.rs index bc4ef1f..7329730 100644 --- a/src/systems/control.rs +++ b/src/systems/control.rs @@ -25,7 +25,10 @@ pub fn player_system( let mut movable = match players.single_mut() { Ok(movable) => movable, Err(e) => { - errors.write(GameError::InvalidState(format!("No/multiple entities queried for player system: {}", e)).into()); + errors.write(GameError::InvalidState(format!( + "No/multiple entities queried for player system: {}", + e + ))); return; } }; diff --git a/src/systems/formatting.rs b/src/systems/formatting.rs index 9f417d2..bc88528 100644 --- a/src/systems/formatting.rs +++ b/src/systems/formatting.rs @@ -1,6 +1,6 @@ use num_width::NumberWidth; use smallvec::SmallVec; -use std::{iter, time::Duration}; +use std::time::Duration; // Helper to split a duration into a integer, decimal, and unit fn get_value(duration: &Duration) -> (u64, u32, &'static str) { @@ -50,7 +50,7 @@ pub fn format_timing_display(timing_data: impl IntoIterator Self { - Position { - node: 0, - edge_progress: None, - } - } -} - #[allow(dead_code)] impl Position { /// Returns `true` if the position is exactly at a node (not traveling). diff --git a/src/systems/render.rs b/src/systems/render.rs index ac2bd6b..4590187 100644 --- a/src/systems/render.rs +++ b/src/systems/render.rs @@ -10,6 +10,7 @@ use bevy_ecs::system::{NonSendMut, Query, Res, ResMut}; use sdl2::render::{Canvas, Texture}; use sdl2::video::Window; +#[allow(clippy::type_complexity)] pub fn dirty_render_system( mut dirty: ResMut, changed_renderables: Query<(), Or<(Changed, Changed)>>, @@ -47,7 +48,7 @@ pub fn directional_render_system( renderable.sprite = new_tile; } } else { - errors.write(TextureError::RenderFailed(format!("Entity has no texture")).into()); + errors.write(TextureError::RenderFailed("Entity has no texture".to_string()).into()); continue; } } @@ -59,6 +60,7 @@ pub struct MapTextureResource(pub Texture<'static>); /// A non-send resource for the backbuffer texture. This just wraps the texture with a type so it can be differentiated when exposed as a resource. pub struct BackbufferResource(pub Texture<'static>); +#[allow(clippy::too_many_arguments)] pub fn render_system( mut canvas: NonSendMut<&mut Canvas>, map_texture: NonSendMut, @@ -105,7 +107,7 @@ pub fn render_system( .map(|e| errors.write(TextureError::RenderFailed(e.to_string()).into())); } Err(e) => { - errors.write(e.into()); + errors.write(e); } } } diff --git a/tests/formatting.rs b/tests/formatting.rs index e0949ad..c008aec 100644 --- a/tests/formatting.rs +++ b/tests/formatting.rs @@ -1,6 +1,4 @@ -use itertools::izip; use pacman::systems::formatting::format_timing_display; -use smallvec::SmallVec; use std::time::Duration; use pretty_assertions::assert_eq; @@ -56,7 +54,7 @@ fn test_formatting_alignment() { // Assert that all positions were found assert_eq!( - vec![ + [ &colon_positions, &first_decimal_positions, &second_decimal_positions,