fn screen_to_map(&self, asset: &Asset, screen_pos: (usize, usize)) -> Option<(usize, usize)> {

        let scale = self.scale;

        let map = asset.get_map_of_id(self.tilemap_id);

        let scaled_grid_size = (map.settings.grid_size as f32 * scale) as usize;

        let x_tiles = map.width / map.settings.grid_size;
        let y_tiles = map.height / map.settings.grid_size;

        let total_tiles = (x_tiles * y_tiles) as usize;

        let screen_x = self.rect.2 / scaled_grid_size;

        if screen_pos.0 > self.rect.0 + self.screen_offset.0 && screen_pos.1 > self.rect.1 + self.screen_offset.0 {

            let x = (screen_pos.0 - self.rect.0 - self.screen_offset.0) / scaled_grid_size;
            let y = (screen_pos.1 - self.rect.1 - self.screen_offset.1) / scaled_grid_size + self.line_offset as usize;

            let tile_offset = x + y * screen_x;

            if tile_offset < total_tiles {
                return Some(((tile_offset % x_tiles), (tile_offset / x_tiles)));
            }
        }
        None
    }
/// Converts a screen position to a map grid position
Converts a screen position to a map grid position
Converts a screen position to a map grid position
fn screen_to_map(&self, asset: &Asset, screen_pos: (usize, usize)) -> Option<(usize, usize)> {
        let scale = self.scale;
        let map = asset.get_map_of_id(self.tilemap_id);
        let scaled_grid_size = (map.settings.grid_size as f32 * scale) as usize;
        let x_tiles = map.width / map.settings.grid_size;
        let y_tiles = map.height / map.settings.grid_size;
        let total_tiles = (x_tiles * y_tiles) as usize;
        let screen_x = self.rect.2 / scaled_grid_size;
        if screen_pos.0 > self.rect.0 + self.screen_offset.0 && screen_pos.1 > self.rect.1 + self.screen_offset.0 {
            let x = (screen_pos.0 - self.rect.0 - self.screen_offset.0) / scaled_grid_size;
            let y = (screen_pos.1 - self.rect.1 - self.screen_offset.1) / scaled_grid_size + self.line_offset as usize;
            let tile_offset = x + y * screen_x;
            if tile_offset < total_tiles {
                return Some(((tile_offset % x_tiles), (tile_offset / x_tiles)));
            }
        }
        None
    }
fn screen_to_map ( & self , asset : & Asset , screen_pos : ( usize , usize ) ) -> Option < ( usize , usize ) > { let scale = self . scale ; let map = asset . get_map_of_id ( self . tilemap_id ) ; let scaled_grid_size = ( map . settings . grid_size as f32 * scale ) as usize ; let x_tiles = map . width / map . settings . grid_size ; let y_tiles = map . height / map . settings . grid_size ; let total_tiles = ( x_tiles * y_tiles ) as usize ; let screen_x = self . rect . 2 / scaled_grid_size ; if screen_pos . 0 > self . rect . 0 + self . screen_offset . 0 && screen_pos . 1 > self . rect . 1 + self . screen_offset . 0 { let x = ( screen_pos . 0 - self . rect . 0 - self . screen_offset . 0 ) / scaled_grid_size ; let y = ( screen_pos . 1 - self . rect . 1 - self . screen_offset . 1 ) / scaled_grid_size + self . line_offset as usize ; let tile_offset = x + y * screen_x ; if tile_offset < total_tiles { return Some ( ( ( tile_offset % x_tiles ) , ( tile_offset / x_tiles ) ) ) ; } } None }
Converts a screen position to a map grid position
Converts a screen position to a map grid position
&self
asset
&Asset
screen_pos
(usize, usize)
&self
asset
&Asset
screen_pos
(usize, usize)