mirror of
https://github.com/Xevion/Pac-Man.git
synced 2025-12-08 10:07:51 -06:00
fix: resolve clippy warnings, inline format vars, use tracing to log warnings
This commit is contained in:
@@ -7,6 +7,7 @@
|
|||||||
use pathfinding::prelude::dijkstra;
|
use pathfinding::prelude::dijkstra;
|
||||||
use rand::prelude::*;
|
use rand::prelude::*;
|
||||||
use smallvec::SmallVec;
|
use smallvec::SmallVec;
|
||||||
|
use tracing::error;
|
||||||
|
|
||||||
use crate::entity::direction::Direction;
|
use crate::entity::direction::Direction;
|
||||||
use crate::entity::graph::{Edge, EdgePermissions, Graph, NodeId};
|
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) {
|
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);
|
self.texture.tick(dt);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ use crate::texture::animated::AnimatedTexture;
|
|||||||
use crate::texture::directional::DirectionalAnimatedTexture;
|
use crate::texture::directional::DirectionalAnimatedTexture;
|
||||||
use crate::texture::sprite::SpriteAtlas;
|
use crate::texture::sprite::SpriteAtlas;
|
||||||
use sdl2::keyboard::Keycode;
|
use sdl2::keyboard::Keycode;
|
||||||
|
use tracing::error;
|
||||||
|
|
||||||
use crate::error::{GameError, GameResult, TextureError};
|
use crate::error::{GameError, GameResult, TextureError};
|
||||||
|
|
||||||
@@ -60,7 +61,7 @@ impl Entity for Pacman {
|
|||||||
|
|
||||||
fn tick(&mut self, dt: f32, graph: &Graph) {
|
fn tick(&mut self, dt: f32, graph: &Graph) {
|
||||||
if let Err(e) = self.traverser.advance(graph, dt * 60.0 * 1.125, &can_pacman_traverse) {
|
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);
|
self.texture.tick(dt);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ impl Game {
|
|||||||
let atlas_texture = unsafe {
|
let atlas_texture = unsafe {
|
||||||
let texture = texture_creator.load_texture_bytes(&atlas_bytes).map_err(|e| {
|
let texture = texture_creator.load_texture_bytes(&atlas_bytes).map_err(|e| {
|
||||||
if e.to_string().contains("format") || e.to_string().contains("unsupported") {
|
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 {
|
} else {
|
||||||
GameError::Texture(TextureError::LoadFailed(e.to_string()))
|
GameError::Texture(TextureError::LoadFailed(e.to_string()))
|
||||||
}
|
}
|
||||||
@@ -94,6 +94,7 @@ impl Game {
|
|||||||
|
|
||||||
if map.graph.node_count() == 0 {
|
if map.graph.node_count() == 0 {
|
||||||
return Err(GameError::Config("Game map has no nodes - invalid configuration".to_string()));
|
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 {
|
for &ghost_type in &ghost_types {
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ impl Map {
|
|||||||
// Connect the new node to the source node
|
// Connect the new node to the source node
|
||||||
graph
|
graph
|
||||||
.connect(*source_node_id, new_node_id, false, None, dir)
|
.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) {
|
if let Some(&neighbor_id) = grid_to_node.get(&neighbor) {
|
||||||
graph
|
graph
|
||||||
.connect(node_id, neighbor_id, false, None, dir)
|
.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
|
// Connect the house door to the left and right nodes
|
||||||
graph
|
graph
|
||||||
.connect(node_id, *left_node, true, None, Direction::Left)
|
.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
|
graph
|
||||||
.connect(node_id, *right_node, true, None, Direction::Right)
|
.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)
|
(node_id, node_position)
|
||||||
};
|
};
|
||||||
@@ -263,10 +263,10 @@ impl Map {
|
|||||||
// Connect the center node to the top and bottom nodes
|
// Connect the center node to the top and bottom nodes
|
||||||
graph
|
graph
|
||||||
.connect(center_node_id, top_node_id, false, None, Direction::Up)
|
.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
|
graph
|
||||||
.connect(center_node_id, bottom_node_id, false, None, Direction::Down)
|
.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))
|
Ok((center_node_id, top_node_id))
|
||||||
};
|
};
|
||||||
@@ -289,7 +289,7 @@ impl Map {
|
|||||||
Direction::Down,
|
Direction::Down,
|
||||||
EdgePermissions::GhostsOnly,
|
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
|
graph
|
||||||
.add_edge(
|
.add_edge(
|
||||||
@@ -300,7 +300,7 @@ impl Map {
|
|||||||
Direction::Up,
|
Direction::Up,
|
||||||
EdgePermissions::GhostsOnly,
|
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
|
// Create the left line
|
||||||
let (left_center_node_id, _) = create_house_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
|
// Connect the center line to the left and right lines
|
||||||
graph
|
graph
|
||||||
.connect(center_center_node_id, left_center_node_id, false, None, Direction::Left)
|
.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
|
graph
|
||||||
.connect(center_center_node_id, right_center_node_id, false, None, Direction::Right)
|
.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}");
|
debug!("House entrance node id: {house_entrance_node_id}");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user