fix: resolve clippy warnings, inline format vars, use tracing to log warnings

This commit is contained in:
2025-08-11 22:09:08 -05:00
parent 27079e127d
commit 1f8e7c6d71
4 changed files with 16 additions and 13 deletions

View File

@@ -7,6 +7,7 @@
use pathfinding::prelude::dijkstra;
use rand::prelude::*;
use smallvec::SmallVec;
use tracing::error;
use crate::entity::direction::Direction;
use crate::entity::graph::{Edge, EdgePermissions, Graph, NodeId};
@@ -104,7 +105,7 @@ impl Entity for Ghost {
}
if let Err(e) = self.traverser.advance(graph, dt * 60.0 * self.speed, &can_ghost_traverse) {
eprintln!("Ghost movement error: {}", e);
error!("Ghost movement error: {}", e);
}
self.texture.tick(dt);
}

View File

@@ -12,6 +12,7 @@ use crate::texture::animated::AnimatedTexture;
use crate::texture::directional::DirectionalAnimatedTexture;
use crate::texture::sprite::SpriteAtlas;
use sdl2::keyboard::Keycode;
use tracing::error;
use crate::error::{GameError, GameResult, TextureError};
@@ -60,7 +61,7 @@ impl Entity for Pacman {
fn tick(&mut self, dt: f32, graph: &Graph) {
if let Err(e) = self.traverser.advance(graph, dt * 60.0 * 1.125, &can_pacman_traverse) {
eprintln!("Pac-Man movement error: {}", e);
error!("Pac-Man movement error: {}", e);
}
self.texture.tick(dt);
}

View File

@@ -68,7 +68,7 @@ impl Game {
let atlas_texture = unsafe {
let texture = texture_creator.load_texture_bytes(&atlas_bytes).map_err(|e| {
if e.to_string().contains("format") || e.to_string().contains("unsupported") {
GameError::Texture(TextureError::InvalidFormat(format!("Unsupported texture format: {}", e)))
GameError::Texture(TextureError::InvalidFormat(format!("Unsupported texture format: {e}")))
} else {
GameError::Texture(TextureError::LoadFailed(e.to_string()))
}
@@ -94,6 +94,7 @@ impl Game {
if map.graph.node_count() == 0 {
return Err(GameError::Config("Game map has no nodes - invalid configuration".to_string()));
// TODO: This is a bug, we should handle this better
}
for &ghost_type in &ghost_types {

View File

@@ -117,7 +117,7 @@ impl Map {
// Connect the new node to the source node
graph
.connect(*source_node_id, new_node_id, false, None, dir)
.map_err(|e| MapError::InvalidConfig(format!("Failed to add edge: {}", e)))?;
.map_err(|e| MapError::InvalidConfig(format!("Failed to add edge: {e}")))?;
}
}
}
@@ -132,7 +132,7 @@ impl Map {
if let Some(&neighbor_id) = grid_to_node.get(&neighbor) {
graph
.connect(node_id, neighbor_id, false, None, dir)
.map_err(|e| MapError::InvalidConfig(format!("Failed to add edge: {}", e)))?;
.map_err(|e| MapError::InvalidConfig(format!("Failed to add edge: {e}")))?;
}
}
}
@@ -241,10 +241,10 @@ impl Map {
// Connect the house door to the left and right nodes
graph
.connect(node_id, *left_node, true, None, Direction::Left)
.map_err(|e| MapError::InvalidConfig(format!("Failed to connect house door to left node: {}", e)))?;
.map_err(|e| MapError::InvalidConfig(format!("Failed to connect house door to left node: {e}")))?;
graph
.connect(node_id, *right_node, true, None, Direction::Right)
.map_err(|e| MapError::InvalidConfig(format!("Failed to connect house door to right node: {}", e)))?;
.map_err(|e| MapError::InvalidConfig(format!("Failed to connect house door to right node: {e}")))?;
(node_id, node_position)
};
@@ -263,10 +263,10 @@ impl Map {
// Connect the center node to the top and bottom nodes
graph
.connect(center_node_id, top_node_id, false, None, Direction::Up)
.map_err(|e| MapError::InvalidConfig(format!("Failed to connect house line to top node: {}", e)))?;
.map_err(|e| MapError::InvalidConfig(format!("Failed to connect house line to top node: {e}")))?;
graph
.connect(center_node_id, bottom_node_id, false, None, Direction::Down)
.map_err(|e| MapError::InvalidConfig(format!("Failed to connect house line to bottom node: {}", e)))?;
.map_err(|e| MapError::InvalidConfig(format!("Failed to connect house line to bottom node: {e}")))?;
Ok((center_node_id, top_node_id))
};
@@ -289,7 +289,7 @@ impl Map {
Direction::Down,
EdgePermissions::GhostsOnly,
)
.map_err(|e| MapError::InvalidConfig(format!("Failed to create ghost-only entrance to house: {}", e)))?;
.map_err(|e| MapError::InvalidConfig(format!("Failed to create ghost-only entrance to house: {e}")))?;
graph
.add_edge(
@@ -300,7 +300,7 @@ impl Map {
Direction::Up,
EdgePermissions::GhostsOnly,
)
.map_err(|e| MapError::InvalidConfig(format!("Failed to create ghost-only exit from house: {}", e)))?;
.map_err(|e| MapError::InvalidConfig(format!("Failed to create ghost-only exit from house: {e}")))?;
// Create the left line
let (left_center_node_id, _) = create_house_line(
@@ -319,11 +319,11 @@ impl Map {
// Connect the center line to the left and right lines
graph
.connect(center_center_node_id, left_center_node_id, false, None, Direction::Left)
.map_err(|e| MapError::InvalidConfig(format!("Failed to connect house entrance to left top line: {}", e)))?;
.map_err(|e| MapError::InvalidConfig(format!("Failed to connect house entrance to left top line: {e}")))?;
graph
.connect(center_center_node_id, right_center_node_id, false, None, Direction::Right)
.map_err(|e| MapError::InvalidConfig(format!("Failed to connect house entrance to right top line: {}", e)))?;
.map_err(|e| MapError::InvalidConfig(format!("Failed to connect house entrance to right top line: {e}")))?;
debug!("House entrance node id: {house_entrance_node_id}");