mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-21 16:09:19 +01:00
AutoTranslatePayload: Add public property for group and key (#1814)
This commit is contained in:
parent
9fcb890d20
commit
10b44ba6d0
1 changed files with 33 additions and 33 deletions
|
|
@ -15,11 +15,11 @@ public class AutoTranslatePayload : Payload, ITextProvider
|
||||||
{
|
{
|
||||||
private string text;
|
private string text;
|
||||||
|
|
||||||
[JsonProperty]
|
[JsonProperty("group")]
|
||||||
private uint group;
|
public uint Group { get; private set; }
|
||||||
|
|
||||||
[JsonProperty]
|
[JsonProperty("key")]
|
||||||
private uint key;
|
public uint Key { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="AutoTranslatePayload"/> class.
|
/// Initializes a new instance of the <see cref="AutoTranslatePayload"/> class.
|
||||||
|
|
@ -34,8 +34,8 @@ public class AutoTranslatePayload : Payload, ITextProvider
|
||||||
public AutoTranslatePayload(uint group, uint key)
|
public AutoTranslatePayload(uint group, uint key)
|
||||||
{
|
{
|
||||||
// TODO: friendlier ctor? not sure how to handle that given how weird the tables are
|
// TODO: friendlier ctor? not sure how to handle that given how weird the tables are
|
||||||
this.group = group;
|
this.Group = group;
|
||||||
this.key = key;
|
this.Key = key;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -69,20 +69,20 @@ public class AutoTranslatePayload : Payload, ITextProvider
|
||||||
/// <returns>A string that represents the current object.</returns>
|
/// <returns>A string that represents the current object.</returns>
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return $"{this.Type} - Group: {this.group}, Key: {this.key}, Text: {this.Text}";
|
return $"{this.Type} - Group: {this.Group}, Key: {this.Key}, Text: {this.Text}";
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
protected override byte[] EncodeImpl()
|
protected override byte[] EncodeImpl()
|
||||||
{
|
{
|
||||||
var keyBytes = MakeInteger(this.key);
|
var keyBytes = MakeInteger(this.Key);
|
||||||
|
|
||||||
var chunkLen = keyBytes.Length + 2;
|
var chunkLen = keyBytes.Length + 2;
|
||||||
var bytes = new List<byte>()
|
var bytes = new List<byte>()
|
||||||
{
|
{
|
||||||
START_BYTE,
|
START_BYTE,
|
||||||
(byte)SeStringChunkType.AutoTranslateKey, (byte)chunkLen,
|
(byte)SeStringChunkType.AutoTranslateKey, (byte)chunkLen,
|
||||||
(byte)this.group,
|
(byte)this.Group,
|
||||||
};
|
};
|
||||||
bytes.AddRange(keyBytes);
|
bytes.AddRange(keyBytes);
|
||||||
bytes.Add(END_BYTE);
|
bytes.Add(END_BYTE);
|
||||||
|
|
@ -95,9 +95,9 @@ public class AutoTranslatePayload : Payload, ITextProvider
|
||||||
{
|
{
|
||||||
// this seems to always be a bare byte, and not following normal integer encoding
|
// 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
|
// the values in the table are all <70 so this is presumably ok
|
||||||
this.group = reader.ReadByte();
|
this.Group = reader.ReadByte();
|
||||||
|
|
||||||
this.key = GetInteger(reader);
|
this.Key = GetInteger(reader);
|
||||||
}
|
}
|
||||||
|
|
||||||
private string Resolve()
|
private string Resolve()
|
||||||
|
|
@ -112,13 +112,13 @@ public class AutoTranslatePayload : Payload, ITextProvider
|
||||||
// try to get the row in the Completion table itself, because this is 'easiest'
|
// 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
|
// 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)
|
// (again, if it's meant for another table)
|
||||||
row = sheet.GetRow(this.key);
|
row = sheet.GetRow(this.Key);
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
} // don't care, row will be null
|
} // don't care, row will be null
|
||||||
|
|
||||||
if (row?.Group == this.group)
|
if (row?.Group == this.Group)
|
||||||
{
|
{
|
||||||
// if the row exists in this table and the group matches, this is actually the correct data
|
// if the row exists in this table and the group matches, this is actually the correct data
|
||||||
value = row.Text;
|
value = row.Text;
|
||||||
|
|
@ -129,30 +129,30 @@ public class AutoTranslatePayload : Payload, ITextProvider
|
||||||
{
|
{
|
||||||
// we need to get the linked table and do the lookup there instead
|
// 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
|
// in this case, there will only be one entry for this group id
|
||||||
row = sheet.First(r => r.Group == this.group);
|
row = sheet.First(r => r.Group == this.Group);
|
||||||
// many of the names contain valid id ranges after the table name, but we don't need those
|
// many of the names contain valid id ranges after the table name, but we don't need those
|
||||||
var actualTableName = row.LookupTable.RawString.Split('[')[0];
|
var actualTableName = row.LookupTable.RawString.Split('[')[0];
|
||||||
|
|
||||||
var name = actualTableName switch
|
var name = actualTableName switch
|
||||||
{
|
{
|
||||||
"Action" => this.DataResolver.GetExcelSheet<Lumina.Excel.GeneratedSheets.Action>().GetRow(this.key).Name,
|
"Action" => this.DataResolver.GetExcelSheet<Lumina.Excel.GeneratedSheets.Action>().GetRow(this.Key).Name,
|
||||||
"ActionComboRoute" => this.DataResolver.GetExcelSheet<ActionComboRoute>().GetRow(this.key).Name,
|
"ActionComboRoute" => this.DataResolver.GetExcelSheet<ActionComboRoute>().GetRow(this.Key).Name,
|
||||||
"BuddyAction" => this.DataResolver.GetExcelSheet<BuddyAction>().GetRow(this.key).Name,
|
"BuddyAction" => this.DataResolver.GetExcelSheet<BuddyAction>().GetRow(this.Key).Name,
|
||||||
"ClassJob" => this.DataResolver.GetExcelSheet<ClassJob>().GetRow(this.key).Name,
|
"ClassJob" => this.DataResolver.GetExcelSheet<ClassJob>().GetRow(this.Key).Name,
|
||||||
"Companion" => this.DataResolver.GetExcelSheet<Companion>().GetRow(this.key).Singular,
|
"Companion" => this.DataResolver.GetExcelSheet<Companion>().GetRow(this.Key).Singular,
|
||||||
"CraftAction" => this.DataResolver.GetExcelSheet<CraftAction>().GetRow(this.key).Name,
|
"CraftAction" => this.DataResolver.GetExcelSheet<CraftAction>().GetRow(this.Key).Name,
|
||||||
"GeneralAction" => this.DataResolver.GetExcelSheet<GeneralAction>().GetRow(this.key).Name,
|
"GeneralAction" => this.DataResolver.GetExcelSheet<GeneralAction>().GetRow(this.Key).Name,
|
||||||
"GuardianDeity" => this.DataResolver.GetExcelSheet<GuardianDeity>().GetRow(this.key).Name,
|
"GuardianDeity" => this.DataResolver.GetExcelSheet<GuardianDeity>().GetRow(this.Key).Name,
|
||||||
"MainCommand" => this.DataResolver.GetExcelSheet<MainCommand>().GetRow(this.key).Name,
|
"MainCommand" => this.DataResolver.GetExcelSheet<MainCommand>().GetRow(this.Key).Name,
|
||||||
"Mount" => this.DataResolver.GetExcelSheet<Mount>().GetRow(this.key).Singular,
|
"Mount" => this.DataResolver.GetExcelSheet<Mount>().GetRow(this.Key).Singular,
|
||||||
"Pet" => this.DataResolver.GetExcelSheet<Pet>().GetRow(this.key).Name,
|
"Pet" => this.DataResolver.GetExcelSheet<Pet>().GetRow(this.Key).Name,
|
||||||
"PetAction" => this.DataResolver.GetExcelSheet<PetAction>().GetRow(this.key).Name,
|
"PetAction" => this.DataResolver.GetExcelSheet<PetAction>().GetRow(this.Key).Name,
|
||||||
"PetMirage" => this.DataResolver.GetExcelSheet<PetMirage>().GetRow(this.key).Name,
|
"PetMirage" => this.DataResolver.GetExcelSheet<PetMirage>().GetRow(this.Key).Name,
|
||||||
"PlaceName" => this.DataResolver.GetExcelSheet<PlaceName>().GetRow(this.key).Name,
|
"PlaceName" => this.DataResolver.GetExcelSheet<PlaceName>().GetRow(this.Key).Name,
|
||||||
"Race" => this.DataResolver.GetExcelSheet<Race>().GetRow(this.key).Masculine,
|
"Race" => this.DataResolver.GetExcelSheet<Race>().GetRow(this.Key).Masculine,
|
||||||
"TextCommand" => this.ResolveTextCommand(),
|
"TextCommand" => this.ResolveTextCommand(),
|
||||||
"Tribe" => this.DataResolver.GetExcelSheet<Tribe>().GetRow(this.key).Masculine,
|
"Tribe" => this.DataResolver.GetExcelSheet<Tribe>().GetRow(this.Key).Masculine,
|
||||||
"Weather" => this.DataResolver.GetExcelSheet<Weather>().GetRow(this.key).Name,
|
"Weather" => this.DataResolver.GetExcelSheet<Weather>().GetRow(this.Key).Name,
|
||||||
_ => throw new Exception(actualTableName),
|
_ => throw new Exception(actualTableName),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -160,7 +160,7 @@ public class AutoTranslatePayload : Payload, ITextProvider
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Log.Error(e, $"AutoTranslatePayload - failed to resolve: {this.Type} - Group: {this.group}, Key: {this.key}");
|
Log.Error(e, $"AutoTranslatePayload - failed to resolve: {this.Type} - Group: {this.Group}, Key: {this.Key}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -171,7 +171,7 @@ public class AutoTranslatePayload : Payload, ITextProvider
|
||||||
{
|
{
|
||||||
// TextCommands prioritize the `Alias` field, if it not empty
|
// TextCommands prioritize the `Alias` field, if it not empty
|
||||||
// Example for this is /rangerpose2l which becomes /blackrangerposeb in chat
|
// Example for this is /rangerpose2l which becomes /blackrangerposeb in chat
|
||||||
var result = this.DataResolver.GetExcelSheet<TextCommand>().GetRow(this.key);
|
var result = this.DataResolver.GetExcelSheet<TextCommand>().GetRow(this.Key);
|
||||||
return result.Alias.Payloads.Count > 0 ? result.Alias : result.Command;
|
return result.Alias.Payloads.Count > 0 ? result.Alias : result.Command;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue