From f024ce7a54cc4ad6cf2d1d34e9acbe71998f3966 Mon Sep 17 00:00:00 2001 From: Xevion Date: Wed, 23 Jul 2025 17:25:28 -0500 Subject: [PATCH] refactor: fix unnecessary qualified imports --- src/edible.rs | 26 +++++++++++--------------- src/game.rs | 25 +++++++++++-------------- src/ghost.rs | 40 +++++++++++++++++++++------------------- src/ghosts/blinky.rs | 25 ++++++++++++------------- 4 files changed, 55 insertions(+), 61 deletions(-) diff --git a/src/edible.rs b/src/edible.rs index 11502f2..a778395 100644 --- a/src/edible.rs +++ b/src/edible.rs @@ -2,7 +2,7 @@ use crate::animation::{AtlasTexture, FrameDrawn}; use crate::constants::{FruitType, MapTile, BOARD_HEIGHT, BOARD_WIDTH}; use crate::direction::Direction; -use crate::entity::{Entity, Renderable}; +use crate::entity::{Entity, Renderable, StaticEntity}; use crate::map::Map; use sdl2::{render::Canvas, video::Window}; use std::cell::RefCell; @@ -16,33 +16,29 @@ pub enum EdibleKind { } pub struct Edible<'a> { - pub base: crate::entity::StaticEntity, + pub base: StaticEntity, pub kind: EdibleKind, - pub sprite: std::rc::Rc>, + pub sprite: Rc>, } impl<'a> Edible<'a> { - pub fn new( - kind: EdibleKind, - cell_position: (u32, u32), - sprite: std::rc::Rc>, - ) -> Self { - let pixel_position = crate::map::Map::cell_to_pixel(cell_position); + pub fn new(kind: EdibleKind, cell_position: (u32, u32), sprite: Rc>) -> Self { + let pixel_position = Map::cell_to_pixel(cell_position); Edible { - base: crate::entity::StaticEntity::new(pixel_position, cell_position), + base: StaticEntity::new(pixel_position, cell_position), kind, sprite, } } /// Checks collision with Pac-Man (or any entity) - pub fn collide(&self, pacman: &dyn crate::entity::Entity) -> bool { + pub fn collide(&self, pacman: &dyn Entity) -> bool { self.base.is_colliding(pacman) } } impl<'a> Entity for Edible<'a> { - fn base(&self) -> &crate::entity::StaticEntity { + fn base(&self) -> &StaticEntity { &self.base } } @@ -57,9 +53,9 @@ impl<'a> Renderable for Edible<'a> { /// Reconstruct all edibles from the original map layout pub fn reconstruct_edibles<'a>( map: Rc>, - pellet_sprite: std::rc::Rc>, - power_pellet_sprite: std::rc::Rc>, - fruit_sprite: std::rc::Rc>, + pellet_sprite: Rc>, + power_pellet_sprite: Rc>, + fruit_sprite: Rc>, ) -> Vec> { let mut edibles = Vec::new(); for x in 0..BOARD_WIDTH { diff --git a/src/game.rs b/src/game.rs index 8876358..a317c35 100644 --- a/src/game.rs +++ b/src/game.rs @@ -13,16 +13,13 @@ use sdl2::{pixels::Color, render::Canvas, video::Window}; use tracing::event; use crate::audio::Audio; -use crate::{ - animation::{AtlasTexture, FrameDrawn}, - constants::{MapTile, BOARD_HEIGHT, BOARD_WIDTH, RAW_BOARD}, - direction::Direction, - entity::{Entity, Renderable}, - ghosts::blinky::Blinky, - map::Map, - pacman::Pacman, -}; - +use crate::animation::{AtlasTexture, FrameDrawn}; +use crate::constants::{MapTile, BOARD_HEIGHT, BOARD_WIDTH, RAW_BOARD}; +use crate::direction::Direction; +use crate::entity::{Entity, Renderable}; +use crate::ghosts::blinky::Blinky; +use crate::map::Map; +use crate::pacman::Pacman; use crate::debug::{DebugMode, DebugRenderer}; use crate::edible::{reconstruct_edibles, Edible, EdibleKind}; @@ -48,10 +45,10 @@ pub struct Game<'a> { power_pellet_texture: Rc>, font: Font<'a, 'static>, pacman: Rc>>, - map: Rc>, + map: Rc>, debug_mode: DebugMode, score: u32, - audio: crate::audio::Audio, + audio: Audio, blinky: Blinky<'a>, edibles: Vec>, } @@ -71,13 +68,13 @@ impl Game<'_> { ttf_context: &'a sdl2::ttf::Sdl2TtfContext, _audio_subsystem: &'a sdl2::AudioSubsystem, ) -> Game<'a> { - let map = Rc::new(std::cell::RefCell::new(Map::new(RAW_BOARD))); + let map = Rc::new(RefCell::new(Map::new(RAW_BOARD))); // Load Pacman texture from embedded data let pacman_atlas = texture_creator .load_texture_bytes(PACMAN_TEXTURE_DATA) .expect("Could not load pacman texture from embedded data"); - let pacman = Rc::new(std::cell::RefCell::new(Pacman::new( + let pacman = Rc::new(RefCell::new(Pacman::new( (1, 1), pacman_atlas, Rc::clone(&map), diff --git a/src/ghost.rs b/src/ghost.rs index d0ea032..036dce1 100644 --- a/src/ghost.rs +++ b/src/ghost.rs @@ -1,15 +1,17 @@ use pathfinding::prelude::dijkstra; use rand::Rng; -use crate::{ - animation::{AnimatedAtlasTexture, FrameDrawn}, - constants::{MapTile, BOARD_WIDTH}, - direction::Direction, - entity::{Entity, MovableEntity, Moving, Renderable, StaticEntity}, - map::Map, - modulation::{SimpleTickModulator, TickModulator}, - pacman::Pacman, -}; +use crate::animation::{AnimatedAtlasTexture, FrameDrawn}; +use crate::constants::{MapTile, BOARD_WIDTH}; +use crate::direction::Direction; +use crate::entity::{Entity, MovableEntity, Moving, Renderable, StaticEntity}; +use crate::map::Map; +use crate::modulation::{SimpleTickModulator, TickModulator}; +use crate::pacman::Pacman; +use sdl2::pixels::Color; +use sdl2::render::Texture; +use std::cell::RefCell; +use std::rc::Rc; /// The different modes a ghost can be in #[derive(Debug, Clone, Copy, PartialEq)] @@ -37,12 +39,12 @@ pub enum GhostType { impl GhostType { /// Returns the color of the ghost. - pub fn color(&self) -> sdl2::pixels::Color { + pub fn color(&self) -> Color { match self { - GhostType::Blinky => sdl2::pixels::Color::RGB(255, 0, 0), - GhostType::Pinky => sdl2::pixels::Color::RGB(255, 184, 255), - GhostType::Inky => sdl2::pixels::Color::RGB(0, 255, 255), - GhostType::Clyde => sdl2::pixels::Color::RGB(255, 184, 82), + GhostType::Blinky => Color::RGB(255, 0, 0), + GhostType::Pinky => Color::RGB(255, 184, 255), + GhostType::Inky => Color::RGB(0, 255, 255), + GhostType::Clyde => Color::RGB(255, 184, 82), } } } @@ -56,7 +58,7 @@ pub struct Ghost<'a> { /// The type/personality of this ghost pub ghost_type: GhostType, /// Reference to Pac-Man for targeting - pub pacman: std::rc::Rc>>, + pub pacman: Rc>>, pub body_sprite: AnimatedAtlasTexture<'a>, pub eyes_sprite: AnimatedAtlasTexture<'a>, } @@ -66,10 +68,10 @@ impl Ghost<'_> { pub fn new<'a>( ghost_type: GhostType, starting_position: (u32, u32), - body_texture: sdl2::render::Texture<'a>, - eyes_texture: sdl2::render::Texture<'a>, - map: std::rc::Rc>, - pacman: std::rc::Rc>>, + body_texture: Texture<'a>, + eyes_texture: Texture<'a>, + map: Rc>, + pacman: Rc>>, ) -> Ghost<'a> { let color = ghost_type.color(); let mut body_sprite = AnimatedAtlasTexture::new(body_texture, 8, 2, 32, 32, Some((-4, -4))); diff --git a/src/ghosts/blinky.rs b/src/ghosts/blinky.rs index 7516fe4..90f6435 100644 --- a/src/ghosts/blinky.rs +++ b/src/ghosts/blinky.rs @@ -4,12 +4,11 @@ use std::rc::Rc; use sdl2::render::{Canvas, Texture}; use sdl2::video::Window; -use crate::{ - entity::{Entity, MovableEntity, Renderable}, - ghost::{Ghost, GhostMode, GhostType}, - map::Map, - pacman::Pacman, -}; +use crate::direction::Direction; +use crate::entity::{Entity, MovableEntity, Moving, Renderable, StaticEntity}; +use crate::ghost::{Ghost, GhostMode, GhostType}; +use crate::map::Map; +use crate::pacman::Pacman; pub struct Blinky<'a> { ghost: Ghost<'a>, @@ -51,29 +50,29 @@ impl<'a> Blinky<'a> { } } -impl<'a> crate::entity::Entity for Blinky<'a> { - fn base(&self) -> &crate::entity::StaticEntity { +impl<'a> Entity for Blinky<'a> { + fn base(&self) -> &StaticEntity { self.ghost.base.base() } } -impl<'a> crate::entity::Renderable for Blinky<'a> { +impl<'a> Renderable for Blinky<'a> { fn render(&self, canvas: &mut Canvas) { self.ghost.render(canvas); } } -impl<'a> crate::entity::Moving for Blinky<'a> { +impl<'a> Moving for Blinky<'a> { fn move_forward(&mut self) { self.ghost.move_forward(); } fn update_cell_position(&mut self) { self.ghost.update_cell_position(); } - fn next_cell(&self, direction: Option) -> (i32, i32) { + fn next_cell(&self, direction: Option) -> (i32, i32) { self.ghost.next_cell(direction) } - fn is_wall_ahead(&self, direction: Option) -> bool { + fn is_wall_ahead(&self, direction: Option) -> bool { self.ghost.is_wall_ahead(direction) } fn handle_tunnel(&mut self) -> bool { @@ -82,7 +81,7 @@ impl<'a> crate::entity::Moving for Blinky<'a> { fn is_grid_aligned(&self) -> bool { self.ghost.is_grid_aligned() } - fn set_direction_if_valid(&mut self, new_direction: crate::direction::Direction) -> bool { + fn set_direction_if_valid(&mut self, new_direction: Direction) -> bool { self.ghost.set_direction_if_valid(new_direction) } }