2019-06-30 22:01:19 +00:00
|
|
|
|
using System.Xml;
|
2019-02-01 17:19:20 +00:00
|
|
|
|
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;
|
2019-01-30 06:36:56 +00:00
|
|
|
|
|
2021-02-25 20:09:54 +00:00
|
|
|
|
namespace RobloxFiles.Tokens
|
2019-01-30 06:36:56 +00:00
|
|
|
|
{
|
|
|
|
|
public class Color3uint8Token : IXmlPropertyToken
|
|
|
|
|
{
|
2021-02-25 20:09:54 +00:00
|
|
|
|
public string XmlPropertyToken => "Color3uint8";
|
2019-01-30 06:36:56 +00:00
|
|
|
|
|
2019-05-17 12:08:06 +00:00
|
|
|
|
public bool ReadProperty(Property prop, XmlNode token)
|
2019-01-30 06:36:56 +00:00
|
|
|
|
{
|
2020-08-17 05:33:59 +00:00
|
|
|
|
if (XmlPropertyTokens.ReadPropertyGeneric(token, out uint value))
|
2019-01-30 06:36:56 +00:00
|
|
|
|
{
|
|
|
|
|
uint r = (value >> 16) & 0xFF;
|
|
|
|
|
uint g = (value >> 8) & 0xFF;
|
|
|
|
|
uint b = value & 0xFF;
|
|
|
|
|
|
2019-06-30 22:01:19 +00:00
|
|
|
|
Color3uint8 result = Color3.FromRGB(r, g, b);
|
|
|
|
|
prop.Value = result;
|
|
|
|
|
|
|
|
|
|
return true;
|
2019-01-30 06:36:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-06-30 22:01:19 +00:00
|
|
|
|
return false;
|
2019-01-30 06:36:56 +00:00
|
|
|
|
}
|
2019-05-17 12:08:06 +00:00
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
2019-05-17 12:08:06 +00:00
|
|
|
|
|
2019-06-30 22:01:19 +00:00
|
|
|
|
uint r = color.R,
|
|
|
|
|
g = color.G,
|
|
|
|
|
b = color.B;
|
2019-05-17 12:08:06 +00:00
|
|
|
|
|
|
|
|
|
uint rgb = (255u << 24) | (r << 16) | (g << 8) | b;
|
2020-08-17 05:33:59 +00:00
|
|
|
|
node.InnerText = rgb.ToInvariantString();
|
2019-05-17 12:08:06 +00:00
|
|
|
|
}
|
2019-01-30 06:36:56 +00:00
|
|
|
|
}
|
|
|
|
|
}
|