From 2db23f3213ff1bb2fe0cf005e922536da7ff5cd7 Mon Sep 17 00:00:00 2001 From: Arne Dußin Date: Sun, 1 Nov 2020 17:44:51 +0100 Subject: Refactor a major part of the project In order to be able to save and load the map, a major rework of the code seemed necessary, since Vector2 and Rectangle of raylib do not implement serialize, and it seems cleanest to use the serialize/deserialize traits of serde, to save for instance to RON. ToolShed was renamed to Editor, since it should better show, that it does quite a bit more than harbour tools. The map data is now centrally saved in the editor, instead of decentralised in the tool structs. --- src/map_data.rs | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/map_data.rs (limited to 'src/map_data.rs') diff --git a/src/map_data.rs b/src/map_data.rs new file mode 100644 index 0000000..d958736 --- /dev/null +++ b/src/map_data.rs @@ -0,0 +1,44 @@ +use crate::math::{Rect, Vec2}; +use serde::{Deserialize, Serialize}; +use std::io; +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>, + walls: Vec<(Vec2, Vec2)>, +} + +impl MapData { + pub fn new() -> Self { + Self { + rooms: Vec::new(), + walls: Vec::new(), + } + } + + pub fn load_file>(&mut self, path: P) -> io::Result { + todo!() + } + + pub fn write_file>(&self, path: P) -> io::Result<()> { + todo!() + } + + pub fn rooms(&self) -> &Vec> { + &self.rooms + } + pub fn rooms_mut(&mut self) -> &mut Vec> { + &mut self.rooms + } + + pub fn walls(&self) -> &Vec<(Vec2, Vec2)> { + &self.walls + } + pub fn walls_mut(&mut self) -> &mut Vec<(Vec2, Vec2)> { + &mut self.walls + } +} -- cgit v1.2.3-70-g09d2