Roblox-File-Format/XmlFormat/PropertyTokens/CFrame.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.2 KiB
C#

using System.Xml;
using RobloxFiles.DataTypes;
namespace RobloxFiles.XmlFormat.PropertyTokens
{
public class CFrameToken : IXmlPropertyToken
{
public string Token => "CoordinateFrame; CFrame";
private static string[] Coords = new string[12] { "X", "Y", "Z", "R00", "R01", "R02", "R10", "R11", "R12", "R20", "R21", "R22"};
public static CFrame ReadCFrame(XmlNode token)
{
float[] components = new float[12];
for (int i = 0; i < 12; i++)
{
string key = Coords[i];
try
{
var coord = token[key];
components[i] = float.Parse(coord.InnerText);
}
catch
{
return null;
}
}
return new CFrame(components);
}
public bool ReadToken(Property property, XmlNode token)
{
CFrame result = ReadCFrame(token);
bool success = (result != null);
if (success)
{
property.Type = PropertyType.CFrame;
property.Value = result;
}
return success;
}
}
}