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:
BinaryFormat
Core
DataTypes
RobloxFileFormat.csprojXmlFormat
PropertyTokens
Axes.csBinaryString.csBoolean.csBrickColor.csCFrame.csColor3.csColor3uint8.csColorSequence.csContent.csDouble.csEnum.csFaces.csFloat.csInt.csInt64.csNumberRange.csNumberSequence.csPhysicalProperties.csRay.csRect.csRef.csString.csUDim.csUDim2.csVector2.csVector3.cs
XmlDataReader.csXmlFile.csXmlPropertyTokens.csXmlRobloxFile.cs
50
XmlFormat/PropertyTokens/PhysicalProperties.cs
Normal file
50
XmlFormat/PropertyTokens/PhysicalProperties.cs
Normal file
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user