add basic italics payload

This commit is contained in:
meli 2020-04-22 09:33:04 -07:00
parent 2d5fdd3c4c
commit 9f884f63f8
3 changed files with 58 additions and 2 deletions

View file

@ -8,12 +8,12 @@ using Serilog;
// TODOs:
// - refactor integer handling now that we have multiple packed types
// - common construction/property design for subclasses
// - wrapper class(es) for handling of composite links in chat (item, map etc) and formatting operations
// - add italics payload
// Maybes:
// - convert parsing to custom structs for each payload? would make some code prettier and easier to work with
// but also wouldn't work out as well for things that are dynamically-sized
// - [SeString] some way to add surrounding formatting information as flags/data to text (or other?) payloads?
// eg, if a text payload is surrounded by italics payloads, strip them out and mark the text payload as italicized
namespace Dalamud.Game.Chat.SeStringHandling
{
@ -98,6 +98,10 @@ namespace Dalamud.Game.Chat.SeStringHandling
switch (chunkType)
{
case SeStringChunkType.EmphasisItalic:
payload = new EmphasisItalicPayload();
break;
case SeStringChunkType.Interactable:
{
var subType = (EmbeddedInfoType)reader.ReadByte();
@ -176,6 +180,7 @@ namespace Dalamud.Game.Chat.SeStringHandling
protected enum SeStringChunkType
{
EmphasisItalic = 0x1A,
Interactable = 0x27,
AutoTranslateKey = 0x2E,
UIForeground = 0x48,

View file

@ -39,6 +39,10 @@ namespace Dalamud.Game.Chat.SeStringHandling
/// </summary>
AutoTranslateText,
/// <summary>
/// An SeString payload representing italic emphasis formatting on text.
/// </summary>
EmphasisItalic,
/// <summary>
/// An SeString payload representing any data we don't handle.
/// </summary>
Unknown

View file

@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using System.IO;
namespace Dalamud.Game.Chat.SeStringHandling.Payloads
{
class EmphasisItalicPayload : Payload
{
public override PayloadType Type => PayloadType.EmphasisItalic;
public bool IsEnabled { get; private set; }
internal EmphasisItalicPayload() { }
public EmphasisItalicPayload(bool enabled)
{
IsEnabled = enabled;
}
public override string ToString()
{
return $"{Type} - Enabled: {IsEnabled}";
}
protected override byte[] EncodeImpl()
{
// realistically this will always be a single byte of value 1 or 2
// but we'll treat it normally anyway
var enabledBytes = MakeInteger(IsEnabled ? (uint)1 : 0);
var chunkLen = enabledBytes.Length + 1;
var bytes = new List<byte>()
{
START_BYTE, (byte)SeStringChunkType.EmphasisItalic, (byte)chunkLen
};
bytes.AddRange(enabledBytes);
bytes.Add(END_BYTE);
return bytes.ToArray();
}
protected override void DecodeImpl(BinaryReader reader, long endOfStream)
{
IsEnabled = (GetInteger(reader) == 1);
}
}
}