Describe what you see when you walk over it

If the character walks over any number of entities, describe those
entities to the character.
This commit is contained in:
Griffin Smith 2019-07-29 11:22:39 -04:00
parent 34b20b7786
commit 9db5fad2f9
12 changed files with 168 additions and 48 deletions

View file

@ -1,6 +1,7 @@
use crate::display::DrawWithNeighbors;
use crate::entities::EntityID;
use crate::types::Neighbors;
use crate::types::Position;
use crate::types::{Positioned, PositionedMut};
use downcast_rs::Downcast;
use std::fmt::Debug;
@ -37,8 +38,36 @@ impl<ID, A: Identified<ID>> Identified<ID> for Box<A> {
}
}
pub trait Describe {
fn description(&self) -> String;
}
ref_impl! {
impl<T: Describe> Describe for &T {
fn description(&self) -> String {
(**self).description()
}
}
}
#[macro_export]
macro_rules! static_description {
($name: ident, $description: expr) => {
impl $crate::entities::entity::Describe for $name {
fn description(&self) -> String {
$description.to_string()
}
}
};
}
pub trait Entity:
Positioned + PositionedMut + Identified<EntityID> + DrawWithNeighbors + Downcast
Positioned
+ PositionedMut
+ Identified<EntityID>
+ DrawWithNeighbors
+ Downcast
+ Describe
{
}
@ -80,3 +109,17 @@ impl DrawWithNeighbors for Box<dyn Entity> {
(**self).do_draw_with_neighbors(out, neighbors)
}
}
pub type AnEntity = Box<dyn Entity>;
impl Positioned for AnEntity {
fn position(&self) -> Position {
(**self).position()
}
}
impl PositionedMut for AnEntity {
fn set_position(&mut self, pos: Position) {
(**self).set_position(pos)
}
}