fix drawing mirror
All checks were successful
Rust / rustfmt (push) Successful in 25s
Rust / clippy (push) Successful in 1m24s
Rust / build (push) Successful in 3m19s

This commit is contained in:
luckyturtledev 2024-07-06 23:52:01 +02:00
parent e03cd06c78
commit 9c8a399b38

View file

@ -403,9 +403,7 @@ fn world_to_chunk_and_local_coords(world_coords: IVec2) -> (IVec2, UVec2) {
}
impl Overworld {
/// Return a [`Tile`] at the given world coordinates, or `None` if that tile has not
/// been generated yet.
pub fn get_tile(&self, world_coords: IVec2) -> Option<&Tile> {
fn get_tile(&self, world_coords: IVec2) -> Option<&Tile> {
let (chunk_coords, local_chunk_coords) =
world_to_chunk_and_local_coords(world_coords);
@ -413,7 +411,15 @@ impl Overworld {
chunk.get_tile(local_chunk_coords)
}
/// Return a [`Tile`] at the given world coordinates, or `None` if that tile has not
/// been generated yet. use engine/world cordinates.
pub fn get_or_generate_tile(&mut self, world_coords: IVec2) -> &Tile {
let mut coords = world_coords;
coords.y *= -1;
self.get_or_generate_tiles_private(coords)
}
fn get_or_generate_tiles_private(&mut self, world_coords: IVec2) -> &Tile {
let (chunk_coords, local_chunk_coords) =
world_to_chunk_and_local_coords(world_coords);
@ -424,8 +430,18 @@ impl Overworld {
chunk.get_tile(local_chunk_coords).unwrap()
}
/// iterate over all tiles and its global coords
/// Iterate over all generated tiles and its engine/world cordinates. using a [`Tile`] at the given world coordinates, or `None` if that tile has not
/// been generated yet.
pub fn iter_tiles(&self) -> impl Iterator<Item = (IVec2, &Tile)> {
self.iter_tilese_private().map(|(coords, tile)| {
let mut w_coords = coords;
w_coords.y *= -1;
(w_coords, tile)
})
}
/// iterate over all tiles and its global coords
fn iter_tilese_private(&self) -> impl Iterator<Item = (IVec2, &Tile)> {
self.chunks.iter().flat_map(|(chunk_coords, chunk)| {
chunk.iter_tiles().map(|(local_coords, tile)| {
// never fail because chunksize fits alswas into i32