diff options
| author | Arne Dußin | 2021-01-06 22:56:37 +0100 |
|---|---|---|
| committer | Arne Dußin | 2021-01-06 22:56:37 +0100 |
| commit | fa1afb6be3ba2d521eb0791edc0bb8e631a85327 (patch) | |
| tree | e0a365444784efaaeb1eea6373b34559b6d57fbc /src/map/data.rs | |
| parent | 1c81d7c70fe891e6ded49d49d6a09f04ce74dd6e (diff) | |
| parent | 30b23db9e86fdf72a4e7de72213df274ce19123e (diff) | |
| download | graf_karto-fa1afb6be3ba2d521eb0791edc0bb8e631a85327.tar.gz graf_karto-fa1afb6be3ba2d521eb0791edc0bb8e631a85327.zip | |
Merge branch 'master' into snapping
Diffstat (limited to 'src/map/data.rs')
| -rw-r--r-- | src/map/data.rs | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/src/map/data.rs b/src/map/data.rs index 1031d3c..f7ec484 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, PolygonRoomData, RectRoomData, WallData}; +use super::{IconData, Map, PolygonRoomData, RectRoomData, WallData}; use ron::de::from_reader; use ron::ser::{to_string_pretty, PrettyConfig}; use serde::{Deserialize, Serialize}; @@ -35,8 +35,37 @@ impl MapData { } } + /// Creates a data struct from the Map. It is important to note, that this data element is not + /// bound to the Map in any way after this, so changing anything won't change anything in the map. + /// It is useful however to for instance serialize this map without extra rendering information + /// included. + pub fn extract_data(map: &Map) -> Self { + Self { + rect_rooms: map + .rect_rooms() + .iter() + .map(|r| (r as &RectRoomData).clone()) + .collect(), + polygon_rooms: map + .polygon_rooms() + .iter() + .map(|p| (p as &PolygonRoomData).clone()) + .collect(), + walls: map + .walls() + .iter() + .map(|w| (w as &WallData).clone()) + .collect(), + icons: map + .icons() + .iter() + .map(|i| (i as &IconData).clone()) + .collect(), + } + } + /// Load the map data from a file. Fails if the file does not exist or cannot be correctly parsed. - pub fn load_from_file<P: AsRef<Path>>(&mut self, path: P) -> io::Result<Self> { + pub fn load_from_file<P: AsRef<Path>>(path: P) -> io::Result<Self> { let file = File::open(&path)?; let data: Self = match from_reader(file) { Ok(data) => data, |
