aboutsummaryrefslogtreecommitdiff
path: root/src/map/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/map/mod.rs')
-rw-r--r--src/map/mod.rs29
1 files changed, 28 insertions, 1 deletions
diff --git a/src/map/mod.rs b/src/map/mod.rs
index ff03474..88a7e6c 100644
--- a/src/map/mod.rs
+++ b/src/map/mod.rs
@@ -1,3 +1,16 @@
+//! The map contains all the items that make up the world.
+//!
+//! There are two main structs to look out for, the first being [Map]. This is the interaction point
+//! for most parts of the program. It contains the actual elements that are drawn on the screen. and
+//! can be changed by the user.
+//! The second is [MapData] and it contains the data that can be saved/loaded and distributed. Every
+//! map item has an internal item that it can be dereferenced to and can be used to construct this
+//! exact item in the same world elsewhere or at a different time. This is often different from the
+//! item that is being drawn. An example would be the [PolygonRoom], which contains a triangulated
+//! version of itself, so it can be drawn without always having to compute the triangles every frame.
+//! It's data type however [PolygonRoomData] contains only the raw polygon data, not the triangulated
+//! version, since that is enough to create the same [PolygonRoom] again.
+
pub mod data;
pub mod icon;
pub mod icon_renderer;
@@ -19,6 +32,7 @@ use raylib::drawing::RaylibDrawHandle;
use raylib::{RaylibHandle, RaylibThread};
use std::rc::Rc;
+/// The map containing all map elements that are seen on the screen.
pub struct Map {
rect_rooms: Vec<RectRoom>,
polygon_rooms: Vec<PolygonRoom>,
@@ -28,6 +42,7 @@ pub struct Map {
}
impl Map {
+ /// Create a new, empty map/world.
pub fn new(rl: &mut RaylibHandle, rlt: &RaylibThread) -> Self {
Self {
rect_rooms: Vec::new(),
@@ -38,14 +53,20 @@ impl Map {
}
}
+ /// Add a rectangularly shaped room to the world. Since the polygon room tool was added, and
+ /// afaik rects are polygon rooms, this will be phased out in favour of only having polygon
+ /// rooms, which will then become just normal rooms.
pub fn push_rect_room(&mut self, room_data: RectRoomData) {
self.rect_rooms.push(RectRoom::from_data(room_data));
}
+ /// Add a room to the map. Currently, holes are not supported in the polygon, but this might
+ /// change later.
pub fn push_polygon_room(&mut self, room_data: PolygonRoomData) {
self.polygon_rooms.push(PolygonRoom::from_data(room_data));
}
+ /// Add a wall to the world.
pub fn push_wall(&mut self, wall_data: WallData) {
/* Check for intersections with any wall that was arleady created so the wall ends can be
* rendered properly.
@@ -70,21 +91,25 @@ impl Map {
.push(Wall::from_data(wall_data, start_intersects, end_intersects));
}
+ /// Add an icon to the world.
pub fn push_icon(&mut self, icon: Icon) {
self.icons.push(icon);
}
+ /// Draw all elements of the map to the screen. This should be called after the background of the
+ /// map has already been drawn.
pub fn draw(&self, rld: &mut RaylibDrawHandle, transform: &Transform) {
for element in self.elements() {
element.draw(rld, transform);
}
}
+ /// Get the icon-renderer that is currently used to render the icons.
pub fn icon_renderer(&self) -> Rc<IconRenderer> {
self.icon_renderer.clone()
}
- /// Retain all map elements that fulfill the given predicate.
+ /// Retain all map elements that fulfill the given predicate, removing everything else.
pub fn retain<F>(&mut self, mut f: F)
where
F: FnMut(&dyn Mappable) -> bool,
@@ -107,6 +132,8 @@ impl Map {
.chain(self.icons.iter().map(|i| i as &dyn Mappable))
}
+ /// Iterator over all elements, but the individual elements can be mutated. It is however
+ /// impossible to add or remove elements in this way. For that, use the dedicated functions.
pub fn elements_mut(&mut self) -> impl Iterator<Item = &mut dyn Mappable> {
self.rect_rooms
.iter_mut()