diff --git a/src/activities/overworld/worldgen.rs b/src/activities/overworld/worldgen.rs index 8b07e31..5af1dcd 100644 --- a/src/activities/overworld/worldgen.rs +++ b/src/activities/overworld/worldgen.rs @@ -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 { + 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 { self.chunks.iter().flat_map(|(chunk_coords, chunk)| { chunk.iter_tiles().map(|(local_coords, tile)| { // never fail because chunksize fits alswas into i32