/// Places a tile if the coordinate is not already occupied, otherwise, if the existing tile matches
/// this one, remove it
///
/// # Arguments
///
/// * `tile_id`: The full ID of the tile to place
/// * `pos`: The tile position
/// * `map_id`: The tile map
/// * `layer_id`: The layer within the tile map
///
/// # Errors
///
/// While this method can return any kind of error from [`TilePlacementError`], the one
/// to look out for is [`TilePlacementError::TileAlreadyExists`] as it denotes that the
/// given coordinate is already occupied by a _non_-matching tile and could not be placed.
///
Places a tile if the coordinate is not already occupied, otherwise, if the existing tile matches
this one, remove it
Places a tile if the coordinate is not already occupied otherwise if the existing tile matches this one remove it
pub fn toggle_matching<Id: Into<TileId>, Pos: Into<TilePos> + Clone, MId: MapId>(
		&mut self,
		tile_id: Id,
		pos: Pos,
		map_id: MId,
		layer_id: u16,
	) -> TilePlacementResult {
		let id = tile_id.into();
		let pos = pos.into();
		if let Some(existing) = self.get_existing(id, pos, map_id, layer_id) {
			// Remove the existing tile if it matches
			if let Some(existing_id) = existing.id {
				if existing_id.eq_tile_group(&id) {
					self.remove(pos, map_id, layer_id)?;
					return Ok(PlacedTile::Removed {
						old_tile: Some((existing.entity, Some(existing_id))),
					});
				}
			}
			// Tile exists but did not match -> don't remove
			return Err(TilePlacementError::TileAlreadyExists {
				new: id,
				existing: existing.id,
				pos,
			});
		}
		self.place_unchecked(id, pos, map_id, layer_id)
	}
pub fn toggle_matching < Id : Into < TileId > , Pos : Into < TilePos > + Clone , MId : MapId > ( & mut self , tile_id : Id , pos : Pos , map_id : MId , layer_id : u16 , ) -> TilePlacementResult { let id = tile_id . into ( ) ; let pos = pos . into ( ) ; if let Some ( existing ) = self . get_existing ( id , pos , map_id , layer_id ) { // Remove the existing tile if it matches if let Some ( existing_id ) = existing . id { if existing_id . eq_tile_group ( & id ) { self . remove ( pos , map_id , layer_id ) ? ; return Ok ( PlacedTile :: Removed { old_tile : Some ( ( existing . entity , Some ( existing_id ) ) ) , } ) ; } } // Tile exists but did not match -> don't remove return Err ( TilePlacementError :: TileAlreadyExists { new : id , existing : existing . id , pos , } ) ; } self . place_unchecked ( id , pos , map_id , layer_id ) }
Places a tile if the coordinate is not already occupied, otherwise, if the existing tile matches
this one, remove it
Places a tile if the coordinate is not already occupied otherwise if the existing tile matches this one remove it
&mut self
tile_id
Id
pos
Pos
map_id
MId
layer_id
u16
errors
While this method can return any kind of error from [`TilePlacementError`], the one
to look out for is [`TilePlacementError::TileAlreadyExists`] as it denotes that the
given coordinate is already occupied by a _non_-matching tile and could not be placed.
While this method can return any kind of error from [ ` TilePlacementError ` ] the one to look out for is [ ` TilePlacementError :: TileAlreadyExists ` ] as it denotes that the given coordinate is already occupied by a _non_ - matching tile and could not be placed .