Handle OptionalCFrame encoding in XML explicitly.

This commit is contained in:
Max 2021-05-05 13:39:01 -05:00
parent fb443cdf42
commit 71cd85513e
3 changed files with 18 additions and 12 deletions

Binary file not shown.

View File

@ -30,9 +30,8 @@ namespace RobloxFiles.Tokens
return new CFrame(components); return new CFrame(components);
} }
public static void WriteCFrame(Property prop, XmlDocument doc, XmlNode node) public static void WriteCFrame(CFrame cf, XmlDocument doc, XmlNode node)
{ {
CFrame cf = prop.CastValue<CFrame>();
float[] components = cf.GetComponents(); float[] components = cf.GetComponents();
for (int i = 0; i < 12; i++) for (int i = 0; i < 12; i++)
@ -63,7 +62,8 @@ namespace RobloxFiles.Tokens
public void WriteProperty(Property prop, XmlDocument doc, XmlNode node) public void WriteProperty(Property prop, XmlDocument doc, XmlNode node)
{ {
WriteCFrame(prop, doc, node); CFrame value = prop.Value as CFrame;
WriteCFrame(value, doc, node);
} }
} }
} }

View File

@ -10,23 +10,29 @@ namespace RobloxFiles.Tokens
public bool ReadProperty(Property prop, XmlNode token) public bool ReadProperty(Property prop, XmlNode token)
{ {
XmlNode first = token.FirstChild; XmlNode first = token.FirstChild;
prop.Type = PropertyType.OptionalCFrame; CFrame value = null;
if (first?.Name == "CFrame") if (first?.Name == "CFrame")
prop.Value = CFrameToken.ReadCFrame(first); value = CFrameToken.ReadCFrame(first);
prop.Value = new Optional<CFrame>(value);
prop.Type = PropertyType.OptionalCFrame;
return true; return true;
} }
public void WriteProperty(Property prop, XmlDocument doc, XmlNode node) public void WriteProperty(Property prop, XmlDocument doc, XmlNode node)
{ {
CFrame value = prop.CastValue<CFrame>(); if (prop.Value is Optional<CFrame> optional)
if (value != null)
{ {
XmlElement cfNode = doc.CreateElement("CFrame"); if (optional.HasValue)
CFrameToken.WriteCFrame(prop, doc, cfNode); {
node.AppendChild(cfNode); CFrame value = optional.Value;
XmlElement cfNode = doc.CreateElement("CFrame");
CFrameToken.WriteCFrame(value, doc, cfNode);
node.AppendChild(cfNode);
}
} }
} }
} }