Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Serializable WriteData #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ license = "MIT"
[dependencies]
byteorder = "1"
libflate = "0.1"
uuid = "0.7"
chrono = "0.4"
num_enum = "0.2.0"
uuid = { version = "0.7", features = ["v5", "serde"] }
Copy link
Contributor

@qoh qoh Apr 24, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the v5 feature enabled here? It doesn't seem to be used.

chrono = { version = "0.4", features = ["serde"] }
num_enum = "0.2.0"

serde = { version = "1.0", features = ["derive"] }
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,4 @@ const MAGIC: [u8; 3] = [b'B', b'R', b'S'];

fn ue4_date_time_base() -> DateTime<Utc> {
Utc.ymd(1, 1, 1).and_hms(0, 0, 0)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: This diff isn't necessary for this change

15 changes: 9 additions & 6 deletions src/save.rs
Original file line number Diff line number Diff line change
@@ -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.
///
Expand All @@ -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),
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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),
Expand All @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions src/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down