about summary refs log tree commit diff
path: root/src/entities/entity.rs
diff options
context:
space:
mode:
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)
+    }
+}