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!
This commit is contained in:
CloneTrooper1019
2019-01-30 00:36:56 -06:00
parent 5319ae72f9
commit 50561460ac
44 changed files with 1292 additions and 99 deletions

@ -0,0 +1,50 @@
using System;
using System.Xml;
using Roblox.DataTypes;
namespace Roblox.XmlFormat.PropertyTokens
{
public class PhysicalPropertiesToken : IXmlPropertyToken
{
public string Token => "PhysicalProperties";
private Func<string, T> createReader<T>(Func<string, T> parse, XmlNode token) where T : struct
{
return new Func<string, T>(key =>
{
XmlElement node = token[key];
return parse(node.InnerText);
});
}
public bool ReadToken(Property prop, XmlNode token)
{
var readBool = createReader(bool.Parse, token);
var readFloat = createReader(XmlPropertyTokens.ParseFloat, token);
try
{
bool custom = readBool("CustomPhysics");
if (custom)
{
prop.Value = new PhysicalProperties
(
readFloat("Density"),
readFloat("Friction"),
readFloat("Elasticity"),
readFloat("FrictionWeight"),
readFloat("ElasticityWeight")
);
prop.Type = PropertyType.PhysicalProperties;
}
return true;
}
catch
{
return false;
}
}
}
}