Add UIGlow and UIForeground SeString payloads; refactor some handling of integer markers in payloads, to make encoding a bit simpler

This commit is contained in:
meli 2020-04-01 20:06:19 -07:00
parent 1e00a33577
commit 4c12b1dfb0
6 changed files with 186 additions and 32 deletions

View file

@ -0,0 +1,58 @@
using System;
using System.Collections.Generic;
using System.IO;
namespace Dalamud.Game.Chat.SeStringHandling.Payloads
{
public class UIGlowPayload : Payload
{
public override PayloadType Type => PayloadType.UIGlow;
public ushort RawColor { get; private set; }
//public int Red { get; private set; }
//public int Green { get; private set; }
//public int Blue { get; private set; }
public override byte[] Encode()
{
var colorBytes = MakeInteger(RawColor);
var chunkLen = colorBytes.Length + 1;
var bytes = new List<byte>(new byte[]
{
START_BYTE, (byte)SeStringChunkType.UIGlow, (byte)chunkLen
});
bytes.AddRange(colorBytes);
bytes.Add(END_BYTE);
return bytes.ToArray();
}
public override void Resolve()
{
// TODO: resolve color keys to hex colors via UIColor table
}
public override string ToString()
{
return $"{Type} - RawColor: {RawColor}";
}
protected override void ProcessChunkImpl(BinaryReader reader, long endOfStream)
{
RawColor = (ushort)GetInteger(reader);
}
protected override byte GetMarkerForIntegerBytes(byte[] bytes)
{
return bytes.Length switch
{
// a single byte of 0x01 is used to 'disable' color, and has no marker
1 => (byte)IntegerType.None,
_ => base.GetMarkerForIntegerBytes(bytes)
};
}
}
}