diff options
| author | Arne Dußin | 2020-12-21 01:22:15 +0100 |
|---|---|---|
| committer | Arne Dußin | 2020-12-21 21:15:55 +0100 |
| commit | d7e9c3cc46d616c2fcd1a6e9f73adbb79c6570b4 (patch) | |
| tree | e5633f4d3b18472922c943d759e9f58722ba4405 /src/map/mod.rs | |
| parent | 48f321a80970ebeb8374072b1d2e0a4d297aa348 (diff) | |
| download | graf_karto-d7e9c3cc46d616c2fcd1a6e9f73adbb79c6570b4.tar.gz graf_karto-d7e9c3cc46d616c2fcd1a6e9f73adbb79c6570b4.zip | |
Add previously missing docs where appropriate
Diffstat (limited to 'src/map/mod.rs')
| -rw-r--r-- | src/map/mod.rs | 29 |
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() |
