aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArne Dußin2021-01-11 14:21:03 +0100
committerArne Dußin2021-01-11 16:02:03 +0100
commitb1179849c28e50c39ac3c94af9dda86ee24beca0 (patch)
tree6fc845d3547bdeb87de75e0f049132de3e05a81d
parentec071d5bc677101c0168b5fb3065f2d928234ed9 (diff)
downloadgraf_karto-b1179849c28e50c39ac3c94af9dda86ee24beca0.tar.gz
graf_karto-b1179849c28e50c39ac3c94af9dda86ee24beca0.zip
Rename PolygonRoom to just Room
-rw-r--r--src/map/data.rs18
-rw-r--r--src/map/mod.rs30
-rw-r--r--src/map/room.rs (renamed from src/map/polygon_room.rs)23
-rw-r--r--src/tool/polygon_room_tool.rs2
-rw-r--r--src/tool/rect_room_tool.rs4
5 files changed, 37 insertions, 40 deletions
diff --git a/src/map/data.rs b/src/map/data.rs
index 3258512..20f193d 100644
--- a/src/map/data.rs
+++ b/src/map/data.rs
@@ -1,6 +1,6 @@
//! Module containing the raw map data version of the map.
-use super::{IconData, Map, PolygonRoomData, WallData};
+use super::{IconData, Map, RoomData, WallData};
use ron::de::from_reader;
use ron::ser::{to_string_pretty, PrettyConfig};
use serde::{Deserialize, Serialize};
@@ -13,20 +13,16 @@ use std::path::Path;
/// it easily corruptable.
#[derive(Serialize, Deserialize)]
pub struct MapData {
- pub(super) polygon_rooms: Vec<PolygonRoomData>,
+ pub(super) rooms: Vec<RoomData>,
pub(super) walls: Vec<WallData>,
pub(super) icons: Vec<IconData>,
}
impl MapData {
/// Create a serialisable map data type from the data elements contained in a map.
- pub fn new(
- polygon_rooms: Vec<PolygonRoomData>,
- walls: Vec<WallData>,
- icons: Vec<IconData>,
- ) -> Self {
+ pub fn new(rooms: Vec<RoomData>, walls: Vec<WallData>, icons: Vec<IconData>) -> Self {
Self {
- polygon_rooms,
+ rooms,
walls,
icons,
}
@@ -38,10 +34,10 @@ impl MapData {
/// included.
pub fn extract_data(map: &Map) -> Self {
Self {
- polygon_rooms: map
- .polygon_rooms()
+ rooms: map
+ .rooms()
.iter()
- .map(|p| (p as &PolygonRoomData).clone())
+ .map(|p| (p as &RoomData).clone())
.collect(),
walls: map
.walls()
diff --git a/src/map/mod.rs b/src/map/mod.rs
index 2040706..e1def09 100644
--- a/src/map/mod.rs
+++ b/src/map/mod.rs
@@ -15,13 +15,13 @@ pub mod data;
pub mod icon;
pub mod icon_renderer;
pub mod mappable;
-pub mod polygon_room;
+pub mod room;
pub mod wall;
pub use data::MapData;
pub use icon::*;
pub use mappable::Mappable;
-pub use polygon_room::*;
+pub use room::*;
pub use wall::*;
use crate::transform::Transform;
@@ -32,7 +32,7 @@ use std::rc::Rc;
/// The map containing all map elements that are seen on the screen.
pub struct Map {
- polygon_rooms: Vec<PolygonRoom>,
+ rooms: Vec<Room>,
walls: Vec<Wall>,
icons: Vec<Icon>,
icon_renderer: Rc<IconRenderer>,
@@ -42,7 +42,7 @@ impl Map {
/// Create a new, empty map/world.
pub fn new(rl: &mut RaylibHandle, rlt: &RaylibThread) -> Self {
Self {
- polygon_rooms: Vec::new(),
+ rooms: Vec::new(),
walls: Vec::new(),
icons: Vec::new(),
icon_renderer: Rc::new(IconRenderer::new(rl, rlt)),
@@ -51,8 +51,8 @@ impl Map {
/// 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));
+ pub fn push_room(&mut self, room_data: RoomData) {
+ self.rooms.push(Room::from_data(room_data));
}
/// Add a wall to the world.
@@ -104,7 +104,7 @@ impl Map {
F: FnMut(&dyn Mappable) -> bool,
{
// Call retain on all vectors containing the maps actual types.
- self.polygon_rooms.retain(|p| f(p as &dyn Mappable));
+ self.rooms.retain(|p| f(p as &dyn Mappable));
self.walls.retain(|w| f(w as &dyn Mappable));
self.icons.retain(|i| f(i as &dyn Mappable));
}
@@ -112,7 +112,7 @@ impl Map {
/// Iterator over all elements as objects when an operation needs to go over all elements of the
/// map.
pub fn elements(&self) -> impl Iterator<Item = &dyn Mappable> {
- self.polygon_rooms
+ self.rooms
.iter()
.map(|p| p as &dyn Mappable)
.chain(self.walls.iter().map(|w| w as &dyn Mappable))
@@ -122,16 +122,16 @@ impl Map {
/// 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.polygon_rooms
+ self.rooms
.iter_mut()
.map(|p| p as &mut dyn Mappable)
.chain(self.walls.iter_mut().map(|w| w as &mut dyn Mappable))
.chain(self.icons.iter_mut().map(|i| i as &mut dyn Mappable))
}
- /// Get the polygon rooms of this map.
- pub fn polygon_rooms(&self) -> &Vec<PolygonRoom> {
- &self.polygon_rooms
+ /// Get the rooms of this map.
+ pub fn rooms(&self) -> &Vec<Room> {
+ &self.rooms
}
/// Get the walls of this map.
@@ -148,7 +148,7 @@ impl Map {
pub fn set_data(&mut self, data: MapData) {
// Remove all data.
self.icons.clear();
- self.polygon_rooms.clear();
+ self.rooms.clear();
self.walls.clear();
// Add all data from the map data.
@@ -161,8 +161,8 @@ impl Map {
for i in data.icons {
self.push_icon(Icon::from_data(i, self.icon_renderer.clone()))
}
- for p in data.polygon_rooms {
- self.push_polygon_room(p);
+ for p in data.rooms {
+ self.push_room(p);
}
for w in data.walls {
self.push_wall(w);
diff --git a/src/map/polygon_room.rs b/src/map/room.rs
index 2a29436..3050763 100644
--- a/src/map/polygon_room.rs
+++ b/src/map/room.rs
@@ -12,19 +12,19 @@ use raylib::drawing::{RaylibDraw, RaylibDrawHandle};
use std::ops::Deref;
/// Data type for the Polygon room.
-pub type PolygonRoomData = Polygon<f64>;
+pub type RoomData = Polygon<f64>;
/// A polygon room, which can be placed and modified in the world.
-pub struct PolygonRoom {
- data: PolygonRoomData,
+pub struct Room {
+ data: RoomData,
// The polygon shape, but in triangles, so the polygon does not have to be triangulated every frame.
triangulated: Vec<Triangle<f64>>,
selected: bool,
}
-impl PolygonRoom {
+impl Room {
/// Create a room from the given polygon data.
- pub fn from_data(data: PolygonRoomData) -> Self {
+ pub fn from_data(data: RoomData) -> Self {
Self {
data: data.clone(),
triangulated: math::triangulate(data, FLOAT_MARGIN),
@@ -32,14 +32,15 @@ impl PolygonRoom {
}
}
- // When the internal polygon changes, it must be retriangulated to be drawn on the screen
- // properly, so this function must be called any time that happens.
+ /* When the internal polygon changes, it must be retriangulated to be drawn on the screen
+ * properly, so this function must be called any time that happens.
+ */
fn retriangulate(&mut self) {
self.triangulated = math::triangulate(self.data.clone(), FLOAT_MARGIN);
}
}
-impl Mappable for PolygonRoom {
+impl Mappable for Room {
fn draw(&self, rld: &mut RaylibDrawHandle, transform: &Transform) {
for triangle in &self.triangulated {
rld.draw_triangle(
@@ -76,7 +77,7 @@ impl Mappable for PolygonRoom {
}
}
-impl NonRigidTransformable for PolygonRoom {
+impl NonRigidTransformable for Room {
fn apply_matrix(&mut self, matrix: &Matrix3<f64>) {
for corner in self.data.corners_mut() {
*corner = matrix
@@ -88,8 +89,8 @@ impl NonRigidTransformable for PolygonRoom {
}
}
-impl Deref for PolygonRoom {
- type Target = PolygonRoomData;
+impl Deref for Room {
+ type Target = RoomData;
fn deref(&self) -> &Self::Target {
&self.data
diff --git a/src/tool/polygon_room_tool.rs b/src/tool/polygon_room_tool.rs
index d181669..d7c188f 100644
--- a/src/tool/polygon_room_tool.rs
+++ b/src/tool/polygon_room_tool.rs
@@ -43,7 +43,7 @@ impl PolygonRoomTool {
.bounding_polygon(FLOAT_MARGIN)
{
Some(polygon) => {
- map.push_polygon_room(polygon);
+ map.push_room(polygon);
self.unfinished_room = None;
true
}
diff --git a/src/tool/rect_room_tool.rs b/src/tool/rect_room_tool.rs
index da23fd7..ec0f0ec 100644
--- a/src/tool/rect_room_tool.rs
+++ b/src/tool/rect_room_tool.rs
@@ -55,7 +55,7 @@ impl Tool for RectRoomTool {
return;
}
- map.push_polygon_room(Rect::bounding_rect(pos1, pos2).into());
+ map.push_room(Rect::bounding_rect(pos1, pos2).into());
self.unfinished_rect = None;
} else {
self.unfinished_rect = Some((*mouse_pos_m, *mouse_pos_m));
@@ -69,7 +69,7 @@ impl Tool for RectRoomTool {
return;
}
- map.push_polygon_room(Rect::bounding_rect(pos1, pos2).into());
+ map.push_room(Rect::bounding_rect(pos1, pos2).into());
self.unfinished_rect = None;
}
}