Skip to content

Commit

Permalink
Properly add the xml version header and imports to the output xml
Browse files Browse the repository at this point in the history
  • Loading branch information
maddymakesgames committed Mar 27, 2024
1 parent 20bfee7 commit c50fe61
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
6 changes: 6 additions & 0 deletions lib/src/saves/def/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ pub type AreaId = u16;
/// The root of a celeste save file
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct SaveData {
#[doc(hidden)]
#[serde(rename(serialize = "@xmlns:xsi", deserialize = "@xmlns:xsi"))]
xsi_url: String,
#[doc(hidden)]
#[serde(rename(serialize = "@xmlns:xsd", deserialize = "@xmlns:xsd"))]
xsd_url: String,
/// The last celeste version that the save file was opened with
#[serde(rename = "Version")]
pub version: String,
Expand Down
9 changes: 7 additions & 2 deletions lib/src/saves/ops/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ pub mod session;
pub mod util;
pub mod vanilla;

const XML_VERSION_HEADER: &str = r#"<?xml version="1.0" encoding="utf-8"?>"#;

fn area_sid_matches(area: &AreaStats, sid: &str) -> bool {
area.def.sid.as_ref().is_some_and(|a_sid| a_sid == sid)
}
Expand All @@ -39,10 +41,13 @@ impl SaveData {
}

pub fn to_string(&self) -> Result<String, DeError> {
quick_xml::se::to_string(&self)
let mut xml = XML_VERSION_HEADER.to_owned();
xml.push_str(&quick_xml::se::to_string(&self)?);
Ok(xml)
}

pub fn to_writer(&self, writer: impl Write) -> Result<(), DeError> {
pub fn to_writer(&self, mut writer: impl Write) -> Result<(), DeError> {
writer.write_str(XML_VERSION_HEADER)?;
quick_xml::se::to_writer(writer, &self)
}

Expand Down

0 comments on commit c50fe61

Please sign in to comment.