Roblox-File-Format/Tokens/Color3uint8.cs

44 lines
1.2 KiB
C#
Raw Normal View History

using System.Xml;
using RobloxFiles.DataTypes;
2021-02-25 20:09:54 +00:00
using RobloxFiles.XmlFormat;
2020-08-17 05:33:59 +00:00
using System.Diagnostics.Contracts;
2021-02-25 20:09:54 +00:00
namespace RobloxFiles.Tokens
{
public class Color3uint8Token : IXmlPropertyToken
{
2021-02-25 20:09:54 +00:00
public string XmlPropertyToken => "Color3uint8";
public bool ReadProperty(Property prop, XmlNode token)
{
2020-08-17 05:33:59 +00:00
if (XmlPropertyTokens.ReadPropertyGeneric(token, out uint value))
{
uint r = (value >> 16) & 0xFF;
uint g = (value >> 8) & 0xFF;
uint b = value & 0xFF;
Color3uint8 result = Color3.FromRGB(r, g, b);
prop.Value = result;
return true;
}
return false;
}
public void WriteProperty(Property prop, XmlDocument doc, XmlNode node)
{
2020-08-17 05:33:59 +00:00
Color3uint8 color = prop?.CastValue<Color3uint8>();
Contract.Requires(node != null);
uint r = color.R,
g = color.G,
b = color.B;
uint rgb = (255u << 24) | (r << 16) | (g << 8) | b;
2020-08-17 05:33:59 +00:00
node.InnerText = rgb.ToInvariantString();
}
}
}