diff --git a/Cargo.toml b/Cargo.toml index 8958ef3..2b4511e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,6 +12,8 @@ license = "MIT" [dependencies] byteorder = "1" libflate = "0.1" -uuid = "0.7" -chrono = "0.4" -num_enum = "0.2.0" \ No newline at end of file +uuid = { version = "0.7", features = ["v5", "serde"] } +chrono = { version = "0.4", features = ["serde"] } +num_enum = "0.2.0" + +serde = { version = "1.0", features = ["derive"] } \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 04e046f..d386243 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -98,4 +98,4 @@ const MAGIC: [u8; 3] = [b'B', b'R', b'S']; fn ue4_date_time_base() -> DateTime { Utc.ymd(1, 1, 1).and_hms(0, 0, 0) -} +} \ No newline at end of file diff --git a/src/save.rs b/src/save.rs index d0fb2b9..0e76b39 100644 --- a/src/save.rs +++ b/src/save.rs @@ -1,6 +1,7 @@ use num_enum::{IntoPrimitive, TryFromPrimitive}; use std::fmt; use uuid::Uuid; +use serde::{Serialize, Deserialize}; /// A single brick in a save file. /// @@ -10,7 +11,7 @@ use uuid::Uuid; /// /// `size` is used for procedural bricks. For fixed size brick assets, it's /// more efficient to use `(0, 0, 0)` (the file will be smaller). -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct Brick { pub asset_name_index: u32, pub size: (u32, u32, u32), @@ -25,7 +26,9 @@ pub struct Brick { } #[repr(u8)] -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, IntoPrimitive, TryFromPrimitive)] +#[derive( + Debug, Clone, Copy, PartialEq, Eq, Hash, IntoPrimitive, TryFromPrimitive, Serialize, Deserialize +)] pub enum Direction { XPositive, XNegative, @@ -37,7 +40,7 @@ pub enum Direction { #[repr(u8)] #[derive( - Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, IntoPrimitive, TryFromPrimitive, + Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, IntoPrimitive, TryFromPrimitive, Serialize, Deserialize )] pub enum Rotation { Deg0, @@ -46,7 +49,7 @@ pub enum Rotation { Deg270, } -#[derive(Debug, Clone, Copy, PartialEq)] +#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)] pub enum ColorMode { /// A color from the color lookup table. Set(u32), @@ -55,7 +58,7 @@ pub enum ColorMode { } /// Represents a RGBA color. -#[derive(Clone, Copy, PartialEq, Hash)] +#[derive(Clone, Copy, PartialEq, Hash, Serialize, Deserialize)] pub struct Color(u32); impl Color { @@ -101,7 +104,7 @@ impl fmt::Debug for Color { } } -#[derive(Debug, Clone, PartialEq, Hash)] +#[derive(Debug, Clone, PartialEq, Hash, Serialize, Deserialize)] pub struct User { pub id: Uuid, pub name: String, diff --git a/src/write.rs b/src/write.rs index e6e6f1d..3a9291e 100644 --- a/src/write.rs +++ b/src/write.rs @@ -11,10 +11,12 @@ use std::{ io::{self, prelude::*}, }; use uuid::Uuid; +use serde::{Serialize, Deserialize}; const LATEST_VERSION: u16 = 4; /// Data written to save files by [`write_save`](fn.write_save.html). +#[derive(Serialize, Deserialize)] pub struct WriteData { // Header 1 /// The name of the map that the save file was created on.