tavern_keeper/src/entity.rs

46 lines
809 B
Rust
Raw Normal View History

2023-01-05 20:01:11 +00:00
use std::fmt;
2023-01-04 13:37:25 +00:00
2023-01-07 09:08:42 +00:00
pub type EntityId = (EntityType, u32);
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
pub enum EntityType {
Creature,
Site,
Item,
}
2023-01-04 13:37:25 +00:00
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
pub struct Location {
pub x: i32,
pub y: i32,
2022-12-31 14:22:44 +00:00
}
2023-01-04 13:37:25 +00:00
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
pub struct Entity {
pub id: EntityId,
2023-01-05 20:01:11 +00:00
}
2023-01-07 09:08:42 +00:00
impl Entity {
pub fn new_creature() -> Entity {
Entity { id: (EntityType::Creature, 0) }
}
pub fn new_site() -> Entity {
Entity { id: (EntityType::Site, 0) }
}
pub fn new_item() -> Entity {
Entity { id: (EntityType::Item, 0) }
}
}
2023-01-05 20:01:11 +00:00
impl fmt::Display for Location {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "({}, {})", self.x, self.y)
}
2023-01-07 09:08:42 +00:00
}