Overworld Movement #9

Merged
msrd0 merged 9 commits from move_overworld into main 2024-07-07 08:49:20 +00:00
Showing only changes of commit 1eeaf80a93 - Show all commits

View file

@ -430,21 +430,21 @@ impl Overworld {
chunk.get_tile(local_chunk_coords).unwrap()
}
/// 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.
/// Iterate over all generated tiles in all generated chunks and their engine/world
/// cordinates.
pub fn iter_tiles(&self) -> impl Iterator<Item = (IVec2, &Tile)> {
self.iter_tilese_private().map(|(coords, tile)| {
self.iter_tiles_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)> {
/// Iterate over all generated tiles in all generated chunks.
fn iter_tiles_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
// never fail because chunksize fits always into i32
let local_coords: IVec2 = local_coords.try_into().unwrap();
(local_coords + (*chunk_coords * CHUNK_SIZE as i32), tile)
})