use std::fmt::{Display, Formatter};
use super::super::map_info::MapInfo;
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct MapCoord {
pub x: f32,
pub y: f32,
}
impl MapCoord {
pub fn new(x: f32, y: f32) -> Self {
Self { x, y }
}
}
impl Display for MapCoord {
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
write!(f, "MapCoord{{x: {:.2}m, y: {:.2}m}}", self.x, self.y)
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct MapTerrainCoord {
pub x: usize,
pub y: usize,
}
impl MapTerrainCoord {
pub fn new(x: usize, y: usize) -> Self {
Self { x, y }
}
}
impl From<MapCoord> for MapTerrainCoord {
fn from(map_coord: MapCoord) -> Self {
Self {
x: (map_coord.x + 0.5) as usize,
y: (map_coord.y + 0.5) as usize,
}
}
}
impl From<MapTerrainCoord> for MapCoord {
fn from(terrain_coord: MapTerrainCoord) -> Self {
Self {
x: terrain_coord.x as f32,
y: terrain_coord.y as f32,
}
}
}
impl Display for MapTerrainCoord {
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
write!(f, "MapTerrainCoord{{x: {}mt, y: {}mt}}", self.x, self.y)
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct MapCellCoord {
pub x: usize,
pub y: usize,
}
impl MapCellCoord {
pub fn new(x: usize, y: usize) -> Self {
Self { x, y }
}
}
impl Display for MapCellCoord {
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
write!(f, "MapCellCoord{{x: {}mc, y: {}mc}}", self.x, self.y)
}
}
impl From<MapCoord> for MapCellCoord {
fn from(map_coord: MapCoord) -> Self {
Self {
x: map_coord.x as usize,
y: map_coord.y as usize,
}
}
}
impl From<MapCellCoord> for MapCoord {
fn from(cell_coord: MapCellCoord) -> Self {
Self {
x: cell_coord.x as f32 + 0.5,
y: cell_coord.y as f32 + 0.5,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct PlayableTerrainCoord {
pub x: usize,
pub y: usize,
}
impl PlayableTerrainCoord {
pub fn new(x: usize, y: usize) -> Self {
Self { x, y }
}
pub fn from_map_terrain(map_info: &MapInfo, map_terrain_coord: MapTerrainCoord) -> Self {
Self {
x: map_terrain_coord.x - map_info.cell_left,
y: map_terrain_coord.y - map_info.cell_bottom,
}
}
}
impl Display for PlayableTerrainCoord {
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
write!(
f,
"PlayableTerrainCoord{{x: {}pt, y: {}pt}}",
self.x, self.y
)
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct PlayableCellCoord {
pub x: i32,
pub y: i32,
}
impl PlayableCellCoord {
pub fn new(x: i32, y: i32) -> Self {
Self { x, y }
}
}
impl Display for PlayableCellCoord {
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
write!(f, "PlayableCellCoord{{x: {}pc, y: {}pc}}", self.x, self.y)
}
}