pub fn add_tile(&mut self, commands: &mut Commands, tile_pos: MapVec2, tile: Tile) -> Result<(), MapTileError> {
        // First find chunk tile should live in:
        if let Some(chunk_data) = self.get_chunk_mut(MapVec2::new(
            tile_pos.x / self.chunk_size.x,
            tile_pos.y / self.chunk_size.y
        )) {
            if chunk_data.1.contains_key(&tile_pos) {
                return Err(MapTileError::TileAlreadyExists);
            }
            let tile_entity = commands.spawn()
                .insert(Tile {
                    chunk: chunk_data.0,
                    ..tile
                })
                .insert(tile_pos).id();
            chunk_data.1.insert(tile_pos, tile_entity);

            return Ok(());
        }

        Err(MapTileError::UnableToFindChunk)
    }
/// Adds a new tile to the map if the tile already exists this code will do nothing.
Adds a new tile to the map if the tile already exists this code will do nothing.
Adds a new tile to the map if the tile already exists this code will do nothing .
pub fn add_tile(&mut self, commands: &mut Commands, tile_pos: MapVec2, tile: Tile) -> Result<(), MapTileError> {
        // First find chunk tile should live in:
        if let Some(chunk_data) = self.get_chunk_mut(MapVec2::new(
            tile_pos.x / self.chunk_size.x,
            tile_pos.y / self.chunk_size.y
        )) {
            if chunk_data.1.contains_key(&tile_pos) {
                return Err(MapTileError::TileAlreadyExists);
            }
            let tile_entity = commands.spawn()
                .insert(Tile {
                    chunk: chunk_data.0,
                    ..tile
                })
                .insert(tile_pos).id();
            chunk_data.1.insert(tile_pos, tile_entity);
            return Ok(());
        }
        Err(MapTileError::UnableToFindChunk)
    }
pub fn add_tile ( & mut self , commands : & mut Commands , tile_pos : MapVec2 , tile : Tile ) -> Result < ( ) , MapTileError > { // First find chunk tile should live in: if let Some ( chunk_data ) = self . get_chunk_mut ( MapVec2 :: new ( tile_pos . x / self . chunk_size . x , tile_pos . y / self . chunk_size . y ) ) { if chunk_data . 1 . contains_key ( & tile_pos ) { return Err ( MapTileError :: TileAlreadyExists ) ; } let tile_entity = commands . spawn ( ) . insert ( Tile { chunk : chunk_data . 0 , .. tile } ) . insert ( tile_pos ) . id ( ) ; chunk_data . 1 . insert ( tile_pos , tile_entity ) ; return Ok ( ( ) ) ; } Err ( MapTileError :: UnableToFindChunk ) }
Adds a new tile to the map if the tile already exists this code will do nothing.
Adds a new tile to the map if the tile already exists this code will do nothing .
&mut self
commands
&mut Commands
tile_pos
MapVec2
tile
Tile
&mut self
commands
&mut Commands
tile_pos
MapVec2
tile
Tile