Roblox-File-Format/XmlFormat/PropertyTokens/NumberRange.cs
CloneTrooper1019 34642f5656 Added support for saving XML files!
Support for binary files will be coming later.
2019-05-17 07:08:06 -05:00

42 lines
1.1 KiB
C#

using System;
using System.Xml;
using RobloxFiles.DataTypes;
namespace RobloxFiles.XmlFormat.PropertyTokens
{
public class NumberRangeToken : IXmlPropertyToken
{
public string Token => "NumberRange";
public bool ReadProperty(Property prop, XmlNode token)
{
string contents = token.InnerText.Trim();
string[] buffer = contents.Split(' ');
bool valid = (buffer.Length == 2);
if (valid)
{
try
{
float min = Formatting.ParseFloat(buffer[0]);
float max = Formatting.ParseFloat(buffer[1]);
prop.Type = PropertyType.NumberRange;
prop.Value = new NumberRange(min, max);
}
catch
{
valid = false;
}
}
return valid;
}
public void WriteProperty(Property prop, XmlDocument doc, XmlNode node)
{
node.InnerText = prop.Value.ToString() + ' ';
}
}
}