pub use wows_replays::types::WorldPos;
pub const NATIVE_MINIMAP_SIZE: u32 = 760;
#[derive(Debug, Clone)]
pub struct MapInfo {
pub space_size: i32,
}
#[derive(Debug, Clone, Copy)]
pub struct MinimapPos {
pub x: i32,
pub y: i32,
}
impl MapInfo {
pub fn world_to_minimap(&self, pos: WorldPos, output_size: u32) -> MinimapPos {
let native = NATIVE_MINIMAP_SIZE as f64;
let scale = native / self.space_size as f64;
let half = native / 2.0;
let rescale = output_size as f64 / native;
MinimapPos {
x: ((pos.x as f64 * scale + half) * rescale) as i32,
y: ((-pos.z as f64 * scale + half) * rescale) as i32,
}
}
pub fn normalized_to_minimap(
&self,
pos: &wows_replays::types::NormalizedPos,
output_size: u32,
) -> MinimapPos {
let raw_x = (pos.x + 1.5) * 512.0;
let raw_y = (pos.y + 1.5) * 512.0;
let world_x = raw_x as f64 / 2047.0 * 5000.0 - 2500.0;
let world_z = raw_y as f64 / 2047.0 * 5000.0 - 2500.0;
self.world_to_minimap(
WorldPos {
x: world_x as f32,
y: 0.0,
z: world_z as f32,
},
output_size,
)
}
}