aboutsummaryrefslogtreecommitdiff
path: root/src/map_data.rs
diff options
context:
space:
mode:
authorArne Dußin2020-12-21 21:12:01 +0100
committerGitHub2020-12-21 21:12:01 +0100
commitc435f278eddcada279fdc424120e4a1448843c20 (patch)
treebe9a5601e99608966d4ccd146c3bfb3a70c7fc02 /src/map_data.rs
parent3bc690803fb59493ea8180fd630d65b3e26642d0 (diff)
parent82d11b7d3e15d8175accf7579db1fbe528fc6583 (diff)
downloadgraf_karto-c435f278eddcada279fdc424120e4a1448843c20.tar.gz
graf_karto-c435f278eddcada279fdc424120e4a1448843c20.zip
Merge pull request #24 from LordSentox/refactor
Refactor to make interaction between tools easier
Diffstat (limited to 'src/map_data.rs')
-rw-r--r--src/map_data.rs97
1 files changed, 0 insertions, 97 deletions
diff --git a/src/map_data.rs b/src/map_data.rs
deleted file mode 100644
index a6ce5a0..0000000
--- a/src/map_data.rs
+++ /dev/null
@@ -1,97 +0,0 @@
-use crate::math::{Polygon, Rect, Vec2};
-use crate::tool::icon_tool::IconInfo;
-use ron::de::from_reader;
-use ron::ser::{to_string_pretty, PrettyConfig};
-use serde::{Deserialize, Serialize};
-use std::fs::File;
-use std::io::{self, Write};
-use std::path::Path;
-
-/// All the data of the currently opened map. This does not include things that are currently being
-/// drawn, but not finished. It also does not contain Metadata, like the current position of the
-/// transform, or the zoom-level
-#[derive(Serialize, Deserialize)]
-pub struct MapData {
- rooms: Vec<Rect<f64>>,
- polygons: Vec<Polygon<f64>>,
- walls: Vec<(Vec2<f64>, Vec2<f64>)>,
- icons: Vec<IconInfo>,
-}
-
-impl MapData {
- #[allow(clippy::new_without_default)]
- pub fn new() -> Self {
- Self {
- rooms: Vec::new(),
- polygons: Vec::new(),
- walls: Vec::new(),
- icons: Vec::new(),
- }
- }
-
- pub fn load_file<P: AsRef<Path>>(&mut self, path: P) -> io::Result<()> {
- let file = File::open(&path)?;
- let mut data: Self = match from_reader(file) {
- Ok(data) => data,
- Err(err) => {
- return Err(io::Error::new(io::ErrorKind::InvalidData, err));
- }
- };
-
- /* Append map data to the currently loaded map. (Default behaviour might change in the
- * future)
- */
- self.rooms.append(&mut data.rooms);
- self.polygons.append(&mut data.polygons);
- self.walls.append(&mut data.walls);
- self.icons.append(&mut data.icons);
-
- Ok(())
- }
-
- pub fn write_file<P: AsRef<Path>>(&self, path: P) -> io::Result<()> {
- let mut file = File::create(&path)?;
-
- let pretty_conf = PrettyConfig::new()
- .with_depth_limit(4)
- .with_decimal_floats(true)
- .with_separate_tuple_members(true)
- .with_indentor("\t".to_owned());
- let string = match to_string_pretty(&self, pretty_conf) {
- Ok(string) => string,
- Err(err) => {
- return Err(io::Error::new(io::ErrorKind::InvalidInput, err));
- }
- };
-
- file.write_all(&string.as_bytes())
- }
-
- pub fn rooms(&self) -> &Vec<Rect<f64>> {
- &self.rooms
- }
- pub fn rooms_mut(&mut self) -> &mut Vec<Rect<f64>> {
- &mut self.rooms
- }
-
- pub fn polygons(&self) -> &Vec<Polygon<f64>> {
- &self.polygons
- }
- pub fn polygons_mut(&mut self) -> &mut Vec<Polygon<f64>> {
- &mut self.polygons
- }
-
- pub fn walls(&self) -> &Vec<(Vec2<f64>, Vec2<f64>)> {
- &self.walls
- }
- pub fn walls_mut(&mut self) -> &mut Vec<(Vec2<f64>, Vec2<f64>)> {
- &mut self.walls
- }
-
- pub fn icons(&self) -> &Vec<IconInfo> {
- &self.icons
- }
- pub fn icons_mut(&mut self) -> &mut Vec<IconInfo> {
- &mut self.icons
- }
-}