adds viewport_to_px and viewport_to_idx

used for converting a viewport (x, y) value to the correct pixel location on the screen, and to the correct map index
This commit is contained in:
Llywelwyn 2023-10-11 09:47:56 +01:00
parent f862f00f0b
commit 13322eb2a1
2 changed files with 4 additions and 4 deletions

View file

@ -67,10 +67,10 @@ pub fn draw_farlook(
draw: &mut Draw, draw: &mut Draw,
atlas: &HashMap<String, Texture> atlas: &HashMap<String, Texture>
) { ) {
let placement = super::viewport_tile_to_px(x, y); let placement = super::viewport_to_px(x, y);
draw.image(atlas.get("select1").unwrap()) draw.image(atlas.get("select1").unwrap())
.position(placement.x, placement.y) .position(placement.x, placement.y)
.size(TILESIZE.sprite_x, TILESIZE.sprite_y); .size(TILESIZE.sprite_x, TILESIZE.sprite_y);
let _idx = super::viewport_tile_to_map_idx(ecs, x, y); let _idx = super::viewport_to_map_idx(ecs, x, y);
// Get tooltip for idx, etc. // Get tooltip for idx, etc.
} }

View file

@ -1882,7 +1882,7 @@ pub fn with_article(name: &String) -> String {
} }
/// Returns the map index of a tile in the viewport. /// Returns the map index of a tile in the viewport.
pub fn viewport_tile_to_map_idx(ecs: &World, x: i32, y: i32) -> usize { pub fn viewport_to_map_idx(ecs: &World, x: i32, y: i32) -> usize {
let bounds = crate::camera::get_screen_bounds(ecs, false); let bounds = crate::camera::get_screen_bounds(ecs, false);
let x = x + bounds.min_x; let x = x + bounds.min_x;
let y = y + bounds.min_y; let y = y + bounds.min_y;
@ -1902,7 +1902,7 @@ impl Px {
} }
/// Returns the pixel location of a tile in the viewport. /// Returns the pixel location of a tile in the viewport.
pub fn viewport_tile_to_px(x: i32, y: i32) -> Px { pub fn viewport_to_px(x: i32, y: i32) -> Px {
let offsets = crate::camera::get_offset(); let offsets = crate::camera::get_offset();
Px::new( Px::new(
(x as f32) * TILESIZE.sprite_x + (offsets.x as f32) * TILESIZE.x, (x as f32) * TILESIZE.sprite_x + (offsets.x as f32) * TILESIZE.x,