From ec071d5bc677101c0168b5fb3065f2d928234ed9 Mon Sep 17 00:00:00 2001 From: Arne Dußin Date: Mon, 11 Jan 2021 12:10:16 +0100 Subject: Rect rooms are now normal polygon rooms in data Before there was an extra data type for rectangular rooms. This is now changed, with the rectangle tool remaining, to create these often required rooms faster, but the data type is just a normal polygon that is generated from a rect to reduce redundancy. --- src/map/data.rs | 10 +------- src/map/mod.rs | 35 ++++----------------------- src/map/rect_room.rs | 68 ---------------------------------------------------- 3 files changed, 5 insertions(+), 108 deletions(-) delete mode 100644 src/map/rect_room.rs (limited to 'src/map') diff --git a/src/map/data.rs b/src/map/data.rs index 0c11d1c..3258512 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, RectRoomData, WallData}; +use super::{IconData, Map, PolygonRoomData, WallData}; use ron::de::from_reader; use ron::ser::{to_string_pretty, PrettyConfig}; use serde::{Deserialize, Serialize}; @@ -13,7 +13,6 @@ use std::path::Path; /// it easily corruptable. #[derive(Serialize, Deserialize)] pub struct MapData { - pub(super) rect_rooms: Vec, pub(super) polygon_rooms: Vec, pub(super) walls: Vec, pub(super) icons: Vec, @@ -22,13 +21,11 @@ pub struct MapData { impl MapData { /// Create a serialisable map data type from the data elements contained in a map. pub fn new( - rect_rooms: Vec, polygon_rooms: Vec, walls: Vec, icons: Vec, ) -> Self { Self { - rect_rooms, polygon_rooms, walls, icons, @@ -41,11 +38,6 @@ impl MapData { /// included. pub fn extract_data(map: &Map) -> Self { Self { - rect_rooms: map - .rect_rooms() - .iter() - .map(|r| *(r as &RectRoomData)) - .collect(), polygon_rooms: map .polygon_rooms() .iter() diff --git a/src/map/mod.rs b/src/map/mod.rs index 70f65b3..2040706 100644 --- a/src/map/mod.rs +++ b/src/map/mod.rs @@ -16,14 +16,12 @@ pub mod icon; pub mod icon_renderer; pub mod mappable; pub mod polygon_room; -pub mod rect_room; pub mod wall; pub use data::MapData; pub use icon::*; pub use mappable::Mappable; pub use polygon_room::*; -pub use rect_room::*; pub use wall::*; use crate::transform::Transform; @@ -34,7 +32,6 @@ use std::rc::Rc; /// The map containing all map elements that are seen on the screen. pub struct Map { - rect_rooms: Vec, polygon_rooms: Vec, walls: Vec, icons: Vec, @@ -45,7 +42,6 @@ impl Map { /// Create a new, empty map/world. pub fn new(rl: &mut RaylibHandle, rlt: &RaylibThread) -> Self { Self { - rect_rooms: Vec::new(), polygon_rooms: Vec::new(), walls: Vec::new(), icons: Vec::new(), @@ -53,13 +49,6 @@ 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) { @@ -115,7 +104,6 @@ impl Map { F: FnMut(&dyn Mappable) -> bool, { // Call retain on all vectors containing the maps actual types. - self.rect_rooms.retain(|r| f(r as &dyn Mappable)); self.polygon_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)); @@ -124,10 +112,9 @@ 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 { - self.rect_rooms + self.polygon_rooms .iter() - .map(|r| r as &dyn Mappable) - .chain(self.polygon_rooms.iter().map(|p| p as &dyn Mappable)) + .map(|p| p as &dyn Mappable) .chain(self.walls.iter().map(|w| w as &dyn Mappable)) .chain(self.icons.iter().map(|i| i as &dyn Mappable)) } @@ -135,23 +122,13 @@ 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 { - self.rect_rooms + self.polygon_rooms .iter_mut() - .map(|r| r as &mut dyn Mappable) - .chain( - self.polygon_rooms - .iter_mut() - .map(|p| p as &mut dyn Mappable), - ) + .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 rectangular rooms of this map. - pub fn rect_rooms(&self) -> &Vec { - &self.rect_rooms - } - /// Get the polygon rooms of this map. pub fn polygon_rooms(&self) -> &Vec { &self.polygon_rooms @@ -172,7 +149,6 @@ impl Map { // Remove all data. self.icons.clear(); self.polygon_rooms.clear(); - self.rect_rooms.clear(); self.walls.clear(); // Add all data from the map data. @@ -188,9 +164,6 @@ impl Map { for p in data.polygon_rooms { self.push_polygon_room(p); } - for r in data.rect_rooms { - self.push_rect_room(r); - } for w in data.walls { self.push_wall(w); } diff --git a/src/map/rect_room.rs b/src/map/rect_room.rs deleted file mode 100644 index ae10327..0000000 --- a/src/map/rect_room.rs +++ /dev/null @@ -1,68 +0,0 @@ -//! Deprecated simple rectangular room type. - -use crate::colours::DEFAULT_COLOURS; -use crate::map::Mappable; -use crate::math::Rect; -use crate::transform::Transform; -use raylib::drawing::{RaylibDraw, RaylibDrawHandle}; -use serde::Serialize; -use std::ops::{Deref, DerefMut}; - -#[allow(missing_docs)] -pub type RectRoomData = Rect; - -#[allow(missing_docs)] -#[derive(Serialize)] -pub struct RectRoom { - data: RectRoomData, - selected: bool, -} - -impl RectRoom { - #[allow(missing_docs)] - pub fn from_data(data: RectRoomData) -> Self { - RectRoom { - data, - selected: false, - } - } -} - -impl Mappable for RectRoom { - fn draw(&self, rld: &mut RaylibDrawHandle, transform: &Transform) { - rld.draw_rectangle_rec( - transform.rect_m_to_px(&self.data), - if self.selected() { - DEFAULT_COLOURS.room_selected - } else { - DEFAULT_COLOURS.room_normal - }, - ); - } - - fn set_selected(&mut self, selected: bool) { - self.selected = selected; - } - - fn selected(&self) -> bool { - self.selected - } - - fn bounding_rect(&self) -> Rect { - self.data - } -} - -impl Deref for RectRoom { - type Target = RectRoomData; - - fn deref(&self) -> &Self::Target { - &self.data - } -} - -impl DerefMut for RectRoom { - fn deref_mut(&mut self) -> &mut Self::Target { - &mut self.data - } -} -- cgit v1.2.3-70-g09d2