diff --git a/src/entity/ghost.rs b/src/entity/ghost.rs index d0c1ad6..bd11a74 100644 --- a/src/entity/ghost.rs +++ b/src/entity/ghost.rs @@ -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); } diff --git a/src/entity/pacman.rs b/src/entity/pacman.rs index e4d05dc..ee0dda4 100644 --- a/src/entity/pacman.rs +++ b/src/entity/pacman.rs @@ -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); } diff --git a/src/game.rs b/src/game.rs index cdd0619..c7307b6 100644 --- a/src/game.rs +++ b/src/game.rs @@ -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 { diff --git a/src/map/builder.rs b/src/map/builder.rs index e1a2c7e..50ea117 100644 --- a/src/map/builder.rs +++ b/src/map/builder.rs @@ -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}");