pub fn despawn_tile(
        &mut self,
        commands: &mut Commands,
        tile_pos: TilePos,
        map_id: impl MapId,
        layer_id: impl LayerId,
    ) -> Result<(), MapTileError> {
        let map_id = map_id.into();
        let layer_id = layer_id.into();
        if let Some((_, map)) = self
            .map_query_set
            .q1()
            .iter()
            .find(|(_, map)| map.id == map_id)
        {
            if let Some(layer_entity) = map.get_layer_entity(layer_id) {
                if let Ok((_, layer)) = self.layer_query_set.q1().get(*layer_entity) {
                    let chunk_pos = ChunkPos(
                        tile_pos.0 / layer.settings.chunk_size.0,
                        tile_pos.1 / layer.settings.chunk_size.1,
                    );
                    if let Some(chunk_entity) = layer.get_chunk(chunk_pos) {
                        if let Ok((_, mut chunk)) = self.chunk_query_set.q0().get_mut(chunk_entity)
                        {
                            let chunk_tile_pos = chunk.to_chunk_pos(tile_pos);
                            if let Some(tile) = chunk.get_tile_entity(chunk_tile_pos) {
                                commands.entity(tile).despawn_recursive();
                                let morton_tile_index = morton_index(chunk_tile_pos);
                                chunk.tiles[morton_tile_index] = None;
                                return Ok(());
                            } else {
                                return Err(MapTileError::NonExistent);
                            }
                        }
                    }
                }
            }
        }
        Err(MapTileError::OutOfBounds)
    }
/// Despawns the tile entity and removes it from the layer/chunk cache.
Despawns the tile entity and removes it from the layer/chunk cache.
Despawns the tile entity and removes it from the layer / chunk cache .
pub fn despawn_tile(
        &mut self,
        commands: &mut Commands,
        tile_pos: TilePos,
        map_id: impl MapId,
        layer_id: impl LayerId,
    ) -> Result<(), MapTileError> {
        let map_id = map_id.into();
        let layer_id = layer_id.into();
        if let Some((_, map)) = self
            .map_query_set
            .q1()
            .iter()
            .find(|(_, map)| map.id == map_id)
        {
            if let Some(layer_entity) = map.get_layer_entity(layer_id) {
                if let Ok((_, layer)) = self.layer_query_set.q1().get(*layer_entity) {
                    let chunk_pos = ChunkPos(
                        tile_pos.0 / layer.settings.chunk_size.0,
                        tile_pos.1 / layer.settings.chunk_size.1,
                    );
                    if let Some(chunk_entity) = layer.get_chunk(chunk_pos) {
                        if let Ok((_, mut chunk)) = self.chunk_query_set.q0().get_mut(chunk_entity)
                        {
                            let chunk_tile_pos = chunk.to_chunk_pos(tile_pos);
                            if let Some(tile) = chunk.get_tile_entity(chunk_tile_pos) {
                                commands.entity(tile).despawn_recursive();
                                let morton_tile_index = morton_index(chunk_tile_pos);
                                chunk.tiles[morton_tile_index] = None;
                                return Ok(());
                            } else {
                                return Err(MapTileError::NonExistent);
                            }
                        }
                    }
                }
            }
        }
        Err(MapTileError::OutOfBounds)
    }
pub fn despawn_tile ( & mut self , commands : & mut Commands , tile_pos : TilePos , map_id : impl MapId , layer_id : impl LayerId , ) -> Result < ( ) , MapTileError > { let map_id = map_id . into ( ) ; let layer_id = layer_id . into ( ) ; if let Some ( ( _ , map ) ) = self . map_query_set . q1 ( ) . iter ( ) . find ( | ( _ , map ) | map . id == map_id ) { if let Some ( layer_entity ) = map . get_layer_entity ( layer_id ) { if let Ok ( ( _ , layer ) ) = self . layer_query_set . q1 ( ) . get ( * layer_entity ) { let chunk_pos = ChunkPos ( tile_pos . 0 / layer . settings . chunk_size . 0 , tile_pos . 1 / layer . settings . chunk_size . 1 , ) ; if let Some ( chunk_entity ) = layer . get_chunk ( chunk_pos ) { if let Ok ( ( _ , mut chunk ) ) = self . chunk_query_set . q0 ( ) . get_mut ( chunk_entity ) { let chunk_tile_pos = chunk . to_chunk_pos ( tile_pos ) ; if let Some ( tile ) = chunk . get_tile_entity ( chunk_tile_pos ) { commands . entity ( tile ) . despawn_recursive ( ) ; let morton_tile_index = morton_index ( chunk_tile_pos ) ; chunk . tiles [ morton_tile_index ] = None ; return Ok ( ( ) ) ; } else { return Err ( MapTileError :: NonExistent ) ; } } } } } } Err ( MapTileError :: OutOfBounds ) }
Despawns the tile entity and removes it from the layer/chunk cache.
Despawns the tile entity and removes it from the layer / chunk cache .
&mut self
commands
&mut Commands
tile_pos
TilePos
map_id
impl MapId
layer_id
impl LayerId
&mut self
commands
&mut Commands
tile_pos
TilePos
map_id
impl MapId
layer_id
impl LayerId