add auto-translate/completion payloads; actual resolution logic is known, but waiting on lumina DI in payloads being (re)done

This commit is contained in:
meli 2020-04-02 22:41:44 -07:00
parent 15e8844514
commit 0e30309b2d
3 changed files with 114 additions and 5 deletions

View file

@ -80,6 +80,10 @@ namespace Dalamud.Game.Chat.SeStringHandling
}
break;
case SeStringChunkType.AutoTranslateKey:
payload = new AutoTranslatePayload();
break;
case SeStringChunkType.UIForeground:
payload = new UIForegroundPayload();
break;
@ -119,6 +123,7 @@ namespace Dalamud.Game.Chat.SeStringHandling
protected enum SeStringChunkType
{
Interactable = 0x27,
AutoTranslateKey = 0x2E,
UIForeground = 0x48,
UIGlow = 0x49
}

View file

@ -1,8 +1,3 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Dalamud.Game.Chat.SeStringHandling
{
@ -40,6 +35,10 @@ namespace Dalamud.Game.Chat.SeStringHandling
/// </summary>
MapLink,
/// <summary>
/// An SeString payload representing an auto-translate dictionary entry.
/// </summary>
AutoTranslateText,
/// <summary>
/// An SeString payload representing any data we don't handle.
/// </summary>
Unknown

View file

@ -0,0 +1,105 @@
using System;
using System.Collections.Generic;
using System.IO;
namespace Dalamud.Game.Chat.SeStringHandling.Payloads
{
public class AutoTranslatePayload : Payload
{
public override PayloadType Type => PayloadType.AutoTranslateText;
public uint Group { get; set; }
public uint Key { get; set; }
public string Text { get; set; }
public override void Resolve()
{
// TODO: fixup once lumina DI is in
//if (string.IsNullOrEmpty(Text))
//{
// var sheet = dalamud.Data.GetExcelSheet<Completion>();
// Completion row = null;
// try
// {
// // try to get the row in the Completion table itself, because this is 'easiest'
// // The row may not exist at all (if the Key is for another table), or it could be the wrong row
// // (again, if it's meant for another table)
// row = sheet.GetRow(Key);
// }
// catch {} // don't care, row will be null
// if (row?.Group == Group)
// {
// // if the row exists in this table and the group matches, this is actually the correct data
// Text = $"{{ {row.Text} }} ";
// }
// else
// {
// Log.Verbose("row mismatch");
// try
// {
// // we need to get the linked table and do the lookup there instead
// // in this case, there will only be one entry for this group id
// row = sheet.GetRows().First(r => r.Group == Group);
// // many of the names contain valid id ranges after the table name, but we don't need those
// var actualTableName = row.LookupTable.Split('[')[0];
// var name = actualTableName switch
// {
// // TODO: rest of xref'd tables
// "Action" => dalamud.Data.GetExcelSheet<Data.TransientSheet.Action>().GetRow(Key).Name,
// "ClassJob" => dalamud.Data.GetExcelSheet<ClassJob>().GetRow(Key).Name,
// "CraftAction" => dalamud.Data.GetExcelSheet<CraftAction>().GetRow(Key).Name,
// "Mount" => dalamud.Data.GetExcelSheet<Mount>().GetRow(Key).Singular,
// "PlaceName" => dalamud.Data.GetExcelSheet<PlaceName>().GetRow(Key).Name,
// "Race" => dalamud.Data.GetExcelSheet<Race>().GetRow(Key).Masculine,
// _ => throw new Exception(actualTableName)
// };
// Text = $"{{ {name} }} ";
// }
// catch (Exception e)
// {
// Log.Error(e, $"AutoTranslatePayload - failed to resolve: {this}");
// }
// }
//}
}
public override byte[] Encode()
{
var keyBytes = MakeInteger(Key);
var chunkLen = keyBytes.Length + 2;
var bytes = new List<byte>()
{
START_BYTE,
(byte)SeStringChunkType.AutoTranslateKey, (byte)chunkLen,
(byte)Group
};
bytes.AddRange(keyBytes);
bytes.Add(END_BYTE);
return bytes.ToArray();
}
public override string ToString()
{
return $"{Type} - Group: {Group}, Key: {Key}, Text: {Text}";
}
protected override void ProcessChunkImpl(BinaryReader reader, long endOfStream)
{
// this seems to always be a bare byte, and not following normal integer encoding
// the values in the table are all <70 so this is presumably ok
Group = reader.ReadByte();
Key = GetInteger(reader);
}
}
}