Roblox-File-Format/Tokens/OptionalCFrame.cs

40 lines
1.1 KiB
C#
Raw Permalink Normal View History

2021-05-01 22:40:09 +00:00
using System.Xml;
using RobloxFiles.DataTypes;
namespace RobloxFiles.Tokens
{
public class OptionalCFrameToken : IXmlPropertyToken
{
public string XmlPropertyToken => "OptionalCoordinateFrame";
public bool ReadProperty(Property prop, XmlNode token)
{
XmlNode first = token.FirstChild;
CFrame value = null;
2021-05-01 22:40:09 +00:00
if (first?.Name == "CFrame")
value = CFrameToken.ReadCFrame(first);
prop.Value = new Optional<CFrame>(value);
prop.Type = PropertyType.OptionalCFrame;
2021-05-01 22:40:09 +00:00
return true;
}
public void WriteProperty(Property prop, XmlDocument doc, XmlNode node)
{
if (prop.Value is Optional<CFrame> optional)
2021-05-01 22:40:09 +00:00
{
if (optional.HasValue)
{
CFrame value = optional.Value;
XmlElement cfNode = doc.CreateElement("CFrame");
CFrameToken.WriteCFrame(value, doc, cfNode);
node.AppendChild(cfNode);
}
2021-05-01 22:40:09 +00:00
}
}
}
}