Roblox-File-Format/XmlFormat/PropertyTokens/UDim.cs
CloneTrooper1019 50561460ac Add support for XML files.
XML support is now implemented and should generally be working!
This library should be useable now, but I still need to set it up to
work as a NuGet package.
If there are any bugs, let me know!
2019-01-30 00:36:56 -06:00

43 lines
1.0 KiB
C#

using System.Xml;
using Roblox.DataTypes;
namespace Roblox.XmlFormat.PropertyTokens
{
public class UDimToken : IXmlPropertyToken
{
public string Token => "UDim";
public static UDim? ReadUDim(XmlNode token, string prefix = "")
{
try
{
XmlElement scaleToken = token[prefix + 'S'];
float scale = XmlPropertyTokens.ParseFloat(scaleToken.InnerText);
XmlElement offsetToken = token[prefix + 'O'];
int offset = int.Parse(offsetToken.InnerText);
return new UDim(scale, offset);
}
catch
{
return null;
}
}
public bool ReadToken(Property property, XmlNode token)
{
UDim? result = ReadUDim(token);
bool success = (result != null);
if (success)
{
property.Type = PropertyType.UDim;
property.Value = result;
}
return success;
}
}
}