diff --git a/src/pathfinding.rs b/src/pathfinding.rs index fecc5d1..c3b4a47 100644 --- a/src/pathfinding.rs +++ b/src/pathfinding.rs @@ -33,10 +33,7 @@ impl PathState { pub fn enemy_cost_fn(map: &Tilemap) -> impl '_ + Fn(TilePos) -> isize { move |pos| { - let Some(row) = map.tiles.get(pos.x) else { - return -1; - }; - let Some(tile) = row.get(pos.y) else { + let Some(tile) = map.get(pos) else { return -1; }; @@ -50,10 +47,7 @@ pub fn enemy_cost_fn(map: &Tilemap) -> impl '_ + Fn(TilePos) -> isize { pub fn worker_cost_fn(map: &Tilemap) -> impl '_ + Fn(TilePos) -> isize { move |pos| { - let Some(row) = map.tiles.get(pos.x) else { - return -1; - }; - let Some(tile) = row.get(pos.y) else { + let Some(tile) = map.get(pos) else { return -1; }; diff --git a/src/tilemap.rs b/src/tilemap.rs index 5ba494e..5f5e3ca 100644 --- a/src/tilemap.rs +++ b/src/tilemap.rs @@ -246,7 +246,6 @@ pub struct TilePos { pub x: usize, pub y: usize, } -impl TilePos {} impl Into for TilePos { fn into(self) -> Vec2 { Vec2::new(self.x as f32, self.y as f32) @@ -278,6 +277,7 @@ impl Into<(isize, isize)> for TilePos { (self.x as isize, self.y as isize) } } + #[derive(Resource)] pub struct TilemapHandle(pub Handle);