Skip to content

Commit

Permalink
Skip seralizing Options when they are None
Browse files Browse the repository at this point in the history
  • Loading branch information
maddymakesgames committed Mar 28, 2024
1 parent 3094a39 commit f5f2f21
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/src/saves/def/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ pub struct SaveData {
/// Is `None` if the save has never loaded 7a
// TODO: idk if the option documentation is correct
#[serde(rename = "SummitGems")]
#[serde(skip_serializing_if = "Option::is_none")]
pub summit_gems: Option<SummitGems>,
/// Whether farewell has been revealed
#[serde(rename = "RevealedChapter9")]
Expand All @@ -111,6 +112,7 @@ pub struct SaveData {
///
/// This is only used by vanilla celeste, everest uses [current_session_safe](SaveData::current_session_safe)
#[serde(rename = "CurrentSession")]
#[serde(skip_serializing_if = "Option::is_none")]
pub current_session: Option<SavedSession>,
/// Data about each vanilla area
///
Expand All @@ -134,11 +136,13 @@ pub struct SaveData {
pub has_modded_save_data: bool,
/// A reference to the last area played, including modded levels
#[serde(rename = "LastArea_Safe")]
#[serde(skip_serializing_if = "Option::is_none")]
pub last_area_safe: Option<LastAreaRef>,
/// The current session saved on the file
///
/// This is what is saved when you use "save & exit" while in a level
#[serde(rename = "CurrentSession_Safe")]
#[serde(skip_serializing_if = "Option::is_none")]
pub current_session_safe: Option<SavedSession>,
}

Expand Down
4 changes: 4 additions & 0 deletions lib/src/saves/def/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub struct SessionAreaRef {
/// This is `None` in a Vanilla session, and is always Some in a modded session.<br>
/// Modded sessions will always be stored in [CurrentSession_Safe](crate::saves::def::SaveData::current_session_safe) and any vanilla sessions will always be stored in [CurrentSession](crate::saves::def::SaveData::current_session)
#[serde(rename = "@SID")]
#[serde(skip_serializing_if = "Option::is_none")]
pub sid: Option<String>,
}

Expand Down Expand Up @@ -114,11 +115,13 @@ pub struct SavedSession {
///
/// Don't currently know what causes this to be `None` but I just know it can be
#[serde(rename = "FurthestSeenLevel")]
#[serde(skip_serializing_if = "Option::is_none")]
pub furthest_seen_level: Option<String>,
#[serde(rename = "BeatBestTime")]
pub beat_best_time: bool,
#[serde(rename = "RestartedFromGolden")]
// Seems to be None in vanilla saves
#[serde(skip_serializing_if = "Option::is_none")]
pub restarted_from_golden: Option<bool>,
}

Expand Down Expand Up @@ -171,6 +174,7 @@ pub struct Audio {
#[serde(rename = "Ambience")]
pub ambience: Music,
#[serde(rename = "AmbienceVolume")]
#[serde(skip_serializing_if = "Option::is_none")]
pub ambience_volume: Option<AmbienceVolume>,
}

Expand Down
4 changes: 4 additions & 0 deletions lib/src/saves/def/vanilla.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ pub struct LastAreaRef {
pub mode: String,
#[serde(rename = "@SID")]
/// Is `None` in a non-modded save
#[serde(skip_serializing_if = "Option::is_none")]
pub sid: Option<String>,
}

Expand All @@ -50,6 +52,8 @@ pub struct AreaDef {
pub cassette: bool,
#[serde(rename = "@SID")]
/// Is `None` in a non-modded save
#[serde(skip_serializing_if = "Option::is_none")]
pub sid: Option<String>,
}

Expand Down

0 comments on commit f5f2f21

Please sign in to comment.