2021-02-25 20:09:54 +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;
|
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
|
|
|
|
{
|
2021-02-25 20:09:54 +00:00
|
|
|
|
public class BrickColorToken : IXmlPropertyToken, IAttributeToken<BrickColor>
|
2019-01-30 06:36:56 +00:00
|
|
|
|
{
|
2021-02-25 20:09:54 +00:00
|
|
|
|
// This is a lie: The token is actually int, but that would cause a name collision.
|
|
|
|
|
// Since BrickColors are written as ints, the IntToken class will try to redirect
|
|
|
|
|
// to this handler if it believes that its representing a BrickColor.
|
|
|
|
|
public string XmlPropertyToken => "BrickColor";
|
|
|
|
|
public AttributeType AttributeType => AttributeType.BrickColor;
|
2019-01-30 06:36:56 +00:00
|
|
|
|
|
2021-06-05 22:21:12 +00:00
|
|
|
|
public BrickColor ReadAttribute(RbxAttribute attr) => attr.ReadInt();
|
|
|
|
|
public void WriteAttribute(RbxAttribute attr, BrickColor value) => attr.WriteInt(value.Number);
|
2021-02-25 20:09:54 +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 int value))
|
2019-01-30 06:36:56 +00:00
|
|
|
|
{
|
2019-06-30 22:01:19 +00:00
|
|
|
|
BrickColor brickColor = BrickColor.FromNumber(value);
|
|
|
|
|
prop.XmlToken = "BrickColor";
|
|
|
|
|
prop.Value = brickColor;
|
2019-05-17 12:08:06 +00:00
|
|
|
|
|
2019-06-30 22:01:19 +00:00
|
|
|
|
return true;
|
2019-01-30 06:36:56 +00:00
|
|
|
|
}
|
2019-05-17 12:08:06 +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)
|
|
|
|
|
{
|
2019-06-30 22:01:19 +00:00
|
|
|
|
BrickColor value = prop.CastValue<BrickColor>();
|
2019-05-17 12:08:06 +00:00
|
|
|
|
|
|
|
|
|
XmlElement brickColor = doc.CreateElement("int");
|
|
|
|
|
brickColor.InnerText = value.Number.ToInvariantString();
|
|
|
|
|
|
|
|
|
|
brickColor.SetAttribute("name", prop.Name);
|
|
|
|
|
brickColor.AppendChild(node);
|
|
|
|
|
}
|
2019-01-30 06:36:56 +00:00
|
|
|
|
}
|
|
|
|
|
}
|