refactor: remove dead code, tune lints, remove useless tests

This commit is contained in:
Ryan Walters
2025-09-09 14:20:32 -05:00
parent 139afb2d40
commit ca006b5073
24 changed files with 148 additions and 518 deletions
-5
View File
@@ -14,11 +14,6 @@ impl TileSequence {
Self { tiles: tiles.to_vec() }
}
/// Creates a tile sequence with a single tile.
pub fn single(tile: AtlasTile) -> Self {
Self { tiles: vec![tile] }
}
/// Returns the tile at the given frame index, wrapping if necessary
pub fn get_tile(&self, frame: usize) -> AtlasTile {
if self.tiles.is_empty() {
-41
View File
@@ -58,19 +58,6 @@ impl AtlasTile {
canvas.copy(&atlas.texture, src, dest).map_err(TextureError::RenderFailed)?;
Ok(())
}
/// Creates a new atlas tile.
#[allow(dead_code)]
pub fn new(pos: U16Vec2, size: U16Vec2, color: Option<Color>) -> Self {
Self { pos, size, color }
}
/// Sets the color of the tile.
#[allow(dead_code)]
pub fn with_color(mut self, color: Color) -> Self {
self.color = Some(color);
self
}
}
/// High-performance sprite atlas providing fast texture region lookups and rendering.
@@ -120,32 +107,4 @@ impl SpriteAtlas {
color: self.default_color,
})
}
#[allow(dead_code)]
pub fn set_color(&mut self, color: Color) {
self.default_color = Some(color);
}
#[allow(dead_code)]
pub fn texture(&self) -> &Texture {
&self.texture
}
/// Returns the number of tiles in the atlas.
#[allow(dead_code)]
pub fn tiles_count(&self) -> usize {
self.tiles.len()
}
/// Returns true if the atlas has a tile with the given name.
#[allow(dead_code)]
pub fn has_tile(&self, name: &str) -> bool {
self.tiles.contains_key(name)
}
/// Returns the default color of the atlas.
#[allow(dead_code)]
pub fn default_color(&self) -> Option<Color> {
self.default_color
}
}
+19 -37
View File
@@ -5,7 +5,10 @@
//! The `GameSprite` enum is the main entry point, and its `to_path` method
//! generates the correct path for a given sprite in the texture atlas.
use crate::{map::direction::Direction, systems::Ghost};
use crate::{
map::direction::Direction,
systems::{FruitType, Ghost},
};
/// Represents the different sprites for Pac-Man.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
@@ -47,34 +50,10 @@ pub enum MazeSprite {
Energizer,
}
/// Represents the different fruit sprites that can appear as bonus items.
/// Represents the different effect sprites that can appear as bonus items.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[allow(dead_code)]
pub enum FruitSprite {
Cherry,
Strawberry,
Orange,
Apple,
Melon,
Galaxian,
Bell,
Key,
}
impl FruitSprite {
/// Returns the score value for this fruit type.
pub fn score_value(self) -> u32 {
match self {
FruitSprite::Cherry => 100,
FruitSprite::Strawberry => 300,
FruitSprite::Orange => 500,
FruitSprite::Apple => 700,
FruitSprite::Melon => 1000,
FruitSprite::Galaxian => 2000,
FruitSprite::Bell => 3000,
FruitSprite::Key => 5000,
}
}
pub enum EffectSprite {
Bonus(u32),
}
/// A top-level enum that encompasses all game sprites.
@@ -83,7 +62,8 @@ pub enum GameSprite {
Pacman(PacmanSprite),
Ghost(GhostSprite),
Maze(MazeSprite),
Fruit(FruitSprite),
Fruit(FruitType),
Effect(EffectSprite),
}
impl GameSprite {
@@ -138,14 +118,16 @@ impl GameSprite {
GameSprite::Maze(MazeSprite::Energizer) => "maze/energizer.png".to_string(),
// Fruit sprites
GameSprite::Fruit(FruitSprite::Cherry) => "edible/cherry.png".to_string(),
GameSprite::Fruit(FruitSprite::Strawberry) => "edible/strawberry.png".to_string(),
GameSprite::Fruit(FruitSprite::Orange) => "edible/orange.png".to_string(),
GameSprite::Fruit(FruitSprite::Apple) => "edible/apple.png".to_string(),
GameSprite::Fruit(FruitSprite::Melon) => "edible/melon.png".to_string(),
GameSprite::Fruit(FruitSprite::Galaxian) => "edible/galaxian.png".to_string(),
GameSprite::Fruit(FruitSprite::Bell) => "edible/bell.png".to_string(),
GameSprite::Fruit(FruitSprite::Key) => "edible/key.png".to_string(),
GameSprite::Fruit(fruit) => format!("edible/{}.png", Into::<&'static str>::into(fruit)),
// Effect sprites
GameSprite::Effect(EffectSprite::Bonus(value)) => match value {
100 | 200 | 300 | 400 | 700 | 800 | 1000 | 2000 | 3000 | 5000 => format!("effects/{}.png", value),
_ => {
tracing::warn!("Invalid bonus value: {}", value);
"effects/100.png".to_string()
}
},
}
}
}
+1 -22
View File
@@ -1,5 +1,3 @@
#![allow(dead_code)]
//! This module provides text rendering using the texture atlas.
//!
//! The TextTexture system renders text from the atlas using character mapping.
@@ -109,6 +107,7 @@ impl TextTexture {
}
}
#[allow(dead_code)]
pub fn get_char_map(&self) -> &HashMap<char, AtlasTile> {
&self.char_map
}
@@ -167,26 +166,6 @@ impl TextTexture {
Ok(())
}
/// Sets the default color for text rendering.
pub fn set_color(&mut self, color: Color) {
self.default_color = Some(color);
}
/// Gets the current default color.
pub fn color(&self) -> Option<Color> {
self.default_color
}
/// Sets the scale for text rendering.
pub fn set_scale(&mut self, scale: f32) {
self.scale = scale;
}
/// Gets the current scale.
pub fn scale(&self) -> f32 {
self.scale
}
/// Calculates the width of a string in pixels at the current scale.
pub fn text_width(&self, text: &str) -> u32 {
let char_width = (8.0 * self.scale) as u32;