From 0eada0bdcb36a9907c6c928aa707ed6bef03c02f Mon Sep 17 00:00:00 2001 From: Arne Dußin Date: Wed, 6 Jan 2021 22:47:34 +0100 Subject: Add loading capabilities back --- src/map/data.rs | 2 +- src/map/mod.rs | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) (limited to 'src/map') diff --git a/src/map/data.rs b/src/map/data.rs index b7719cd..f7ec484 100644 --- a/src/map/data.rs +++ b/src/map/data.rs @@ -65,7 +65,7 @@ impl MapData { } /// Load the map data from a file. Fails if the file does not exist or cannot be correctly parsed. - pub fn load_from_file>(&mut self, path: P) -> io::Result { + pub fn load_from_file>(path: P) -> io::Result { let file = File::open(&path)?; let data: Self = match from_reader(file) { Ok(data) => data, diff --git a/src/map/mod.rs b/src/map/mod.rs index 28025ad..70f65b3 100644 --- a/src/map/mod.rs +++ b/src/map/mod.rs @@ -147,19 +147,52 @@ impl Map { .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 } + /// Get the walls of this map. pub fn walls(&self) -> &Vec { &self.walls } + /// Get the icons of this map. pub fn icons(&self) -> &Vec { &self.icons } + + /// Replace the internal map data with the data provided. (Load and replace) + pub fn set_data(&mut self, data: MapData) { + // Remove all data. + self.icons.clear(); + self.polygon_rooms.clear(); + self.rect_rooms.clear(); + self.walls.clear(); + + // Add all data from the map data. + self.add_data(data); + } + + /// Add the data provided to the current data on the map. All elements will remain, with the + /// additional elements being pushed also. + pub fn add_data(&mut self, data: MapData) { + 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 r in data.rect_rooms { + self.push_rect_room(r); + } + for w in data.walls { + self.push_wall(w); + } + } } -- cgit v1.2.3-70-g09d2