Roblox-File-Format/XmlFormat/PropertyTokens/Vector3.cs
CloneTrooper1019 795018e243 Switch root namespace to "RobloxFiles"
In case there are any future libraries written for Roblox in C#, I want to avoid running into any namespace collisions. Its best to keep everything pertaining to this project nested in its own unique namespace.
2019-02-01 11:19:20 -06:00

48 lines
1.1 KiB
C#

using System.Xml;
using RobloxFiles.DataTypes;
namespace RobloxFiles.XmlFormat.PropertyTokens
{
public class Vector3Token : IXmlPropertyToken
{
public string Token => "Vector3";
private static string[] Coords = new string[3] { "X", "Y", "Z" };
public static Vector3? ReadVector3(XmlNode token)
{
float[] xyz = new float[3];
for (int i = 0; i < 3; i++)
{
string key = Coords[i];
try
{
var coord = token[key];
xyz[i] = XmlPropertyTokens.ParseFloat(coord.InnerText);
}
catch
{
return null;
}
}
return new Vector3(xyz);
}
public bool ReadToken(Property property, XmlNode token)
{
Vector3? result = ReadVector3(token);
bool success = result.HasValue;
if (success)
{
property.Type = PropertyType.Vector3;
property.Value = result.Value;
}
return success;
}
}
}