Roblox-File-Format/XmlFormat/PropertyTokens/Vector2.cs
2019-02-01 12:40:39 -06:00

49 lines
1.2 KiB
C#

using System.Xml;
using RobloxFiles.DataTypes;
namespace RobloxFiles.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;
}
}
}