Roblox-File-Format/XmlFormat/PropertyTokens/Vector2.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

49 lines
1.2 KiB
C#

using System.Xml;
using Roblox.DataTypes;
namespace Roblox.XmlFormat.PropertyTokens
{
public class Vector2Token : IXmlPropertyToken
{
public string Token => "Vector2";
private static string[] Coords = new string[2] { "X", "Y" };
public static Vector2? ReadVector2(XmlNode token)
{
float[] xy = new float[2];
for (int i = 0; i < 2; i++)
{
string key = Coords[i];
try
{
var coord = token[key];
string text = coord.InnerText;
xy[i] = XmlPropertyTokens.ParseFloat(text);
}
catch
{
return null;
}
}
return new Vector2(xy);
}
public bool ReadToken(Property property, XmlNode token)
{
Vector2? result = ReadVector2(token);
bool success = (result != null);
if (success)
{
property.Type = PropertyType.Vector2;
property.Value = result;
}
return success;
}
}
}