about summary refs log tree commit diff
path: root/src/entities/entity.rs
diff options
context:
space:
mode:
authorGriffin Smith <root@gws.fyi>2019-07-29T15·22-0400
committerGriffin Smith <root@gws.fyi>2019-07-29T15·22-0400
commit9db5fad2f900732d59f9714ac4517952d26506d7 (patch)
tree1f8de240a1f7ccecd37282b0f984e1d0a7d38000 /src/entities/entity.rs
parent34b20b7786a8f6753bb449425772958e0285c385 (diff)
Describe what you see when you walk over it
If the character walks over any number of entities, describe those
entities to the character.
Diffstat (limited to 'src/entities/entity.rs')
-rw-r--r--src/entities/entity.rs45
1 files changed, 44 insertions, 1 deletions
diff --git a/src/entities/entity.rs b/src/entities/entity.rs
index 7fedb77b2562..0043a83ecd54 100644
--- a/src/entities/entity.rs
+++ b/src/entities/entity.rs
@@ -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)
+    }
+}