50561460ac
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!
49 lines
1.2 KiB
C#
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;
|
|
}
|
|
}
|
|
}
|