pub(crate) fn update_chunk_hashmap_for_removed_tiles(
    mut commands: Commands,
    mut map_query: Query<&mut Map>,
    mut chunk_query: Query<&mut Chunk>,
    removed_tiles_query: Query<(Entity, &Tile, &MapVec2), With<RemoveTile>>
) {
    // For now only loop over 1 map.
    if let Some(mut map) = map_query.iter_mut().next() {
        for (tile_entity, removed_tile, tile_pos) in removed_tiles_query.iter() {

            // Remove tile from chunk tiles cache.
            if let Ok(mut tile_chunk) = chunk_query.get_mut(removed_tile.chunk) {
                tile_chunk.tiles.remove(&tile_pos);
            }

            let chunk_coords = MapVec2::new(
                tile_pos.x / map.chunk_size.x,
                tile_pos.y / map.chunk_size.y,
            );

            // Remove tile from map tiles cache.
            if let Some(map_chunk) = map.chunks.get_mut(&chunk_coords) {
                map_chunk.1.remove(tile_pos);
            }

            // Remove tile entity
            commands.entity(tile_entity).despawn_recursive();
            commands.entity(removed_tile.chunk).insert(RemeshChunk);
        }
    }
}
// Removes tiles that have been removed from the chunk.
Removes tiles that have been removed from the chunk.
Removes tiles that have been removed from the chunk .
pub(crate) fn update_chunk_hashmap_for_removed_tiles(
    mut commands: Commands,
    mut map_query: Query<&mut Map>,
    mut chunk_query: Query<&mut Chunk>,
    removed_tiles_query: Query<(Entity, &Tile, &MapVec2), With<RemoveTile>>
) {
    // For now only loop over 1 map.
    if let Some(mut map) = map_query.iter_mut().next() {
        for (tile_entity, removed_tile, tile_pos) in removed_tiles_query.iter() {
            // Remove tile from chunk tiles cache.
            if let Ok(mut tile_chunk) = chunk_query.get_mut(removed_tile.chunk) {
                tile_chunk.tiles.remove(&tile_pos);
            }
            let chunk_coords = MapVec2::new(
                tile_pos.x / map.chunk_size.x,
                tile_pos.y / map.chunk_size.y,
            );
            // Remove tile from map tiles cache.
            if let Some(map_chunk) = map.chunks.get_mut(&chunk_coords) {
                map_chunk.1.remove(tile_pos);
            }
            // Remove tile entity
            commands.entity(tile_entity).despawn_recursive();
            commands.entity(removed_tile.chunk).insert(RemeshChunk);
        }
    }
}
pub ( crate ) fn update_chunk_hashmap_for_removed_tiles ( mut commands : Commands , mut map_query : Query < & mut Map > , mut chunk_query : Query < & mut Chunk > , removed_tiles_query : Query < ( Entity , & Tile , & MapVec2 ) , With < RemoveTile > > ) { // For now only loop over 1 map. if let Some ( mut map ) = map_query . iter_mut ( ) . next ( ) { for ( tile_entity , removed_tile , tile_pos ) in removed_tiles_query . iter ( ) { // Remove tile from chunk tiles cache. if let Ok ( mut tile_chunk ) = chunk_query . get_mut ( removed_tile . chunk ) { tile_chunk . tiles . remove ( & tile_pos ) ; } let chunk_coords = MapVec2 :: new ( tile_pos . x / map . chunk_size . x , tile_pos . y / map . chunk_size . y , ) ; // Remove tile from map tiles cache. if let Some ( map_chunk ) = map . chunks . get_mut ( & chunk_coords ) { map_chunk . 1 . remove ( tile_pos ) ; } // Remove tile entity commands . entity ( tile_entity ) . despawn_recursive ( ) ; commands . entity ( removed_tile . chunk ) . insert ( RemeshChunk ) ; } } }
Removes tiles that have been removed from the chunk.
Removes tiles that have been removed from the chunk .
commands
Commands
map_query
Query<&mut Map>
chunk_query
Query<&mut Chunk>
removed_tiles_query
Query<(Entity, &Tile, &MapVec2), With<RemoveTile>>
commands
Commands
map_query
Query<&mut Map>
chunk_query
Query<&mut Chunk>
removed_tiles_query
Query<(Entity, &Tile, &MapVec2), With<RemoveTile>>