aboutsummaryrefslogtreecommitdiff
path: root/src/world/component.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/world/component.rs')
-rw-r--r--src/world/component.rs23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/world/component.rs b/src/world/component.rs
new file mode 100644
index 0000000..e8a8df9
--- /dev/null
+++ b/src/world/component.rs
@@ -0,0 +1,23 @@
+//! The world is made up of components. Every component must implement this
+//! general trait that makes it possible to argue about certain characteristics
+//! and may make it possible to transform some items.
+
+use crate::math::Rect;
+use crate::transformable::NonRigidTransformable;
+
+/// Anything that can be added to the map or world must implement this trait.
+pub trait Component {
+ /// Get the rectangle that contains the component in its entirety without excess.
+ fn bounding_rect(&self) -> Rect<f64>;
+
+ /// If this component can be transformed in a non-rigid way, a dynamic
+ /// reference is returned, otherwise none.
+ fn as_non_rigid(&self) -> Option<&dyn NonRigidTransformable> {
+ None
+ }
+
+ /// The same as `as_non_rigid`, but mutably.
+ fn as_non_rigid_mut(&mut self) -> Option<&mut dyn NonRigidTransformable> {
+ None
+ }
+}