refactor: obsolete SeStringManager, move into SeString

This commit is contained in:
goat 2021-08-28 19:02:18 +02:00
parent e5cad2edde
commit ca201e1a14
No known key found for this signature in database
GPG key ID: F18F057873895461
8 changed files with 223 additions and 139 deletions

View file

@ -9,10 +9,9 @@ namespace Dalamud.Test.Game.Text.SeStringHandling
[Fact] [Fact]
public void TestNewLinePayload() public void TestNewLinePayload()
{ {
var manager = new SeStringManager();
var newLinePayloadBytes = new byte[] {0x02, 0x10, 0x01, 0x03}; var newLinePayloadBytes = new byte[] {0x02, 0x10, 0x01, 0x03};
var seString = manager.Parse(newLinePayloadBytes); var seString = SeString.Parse(newLinePayloadBytes);
Assert.True(newLinePayloadBytes.SequenceEqual(seString.Encode())); Assert.True(newLinePayloadBytes.SequenceEqual(seString.Encode()));
} }

View file

@ -196,10 +196,6 @@ namespace Dalamud
Log.Information("[T2] Data OK!"); Log.Information("[T2] Data OK!");
Service<SeStringManager>.Set();
Log.Information("[T2] SeString OK!");
// Initialize managers. Basically handlers for the logic // Initialize managers. Basically handlers for the logic
Service<CommandManager>.Set(); Service<CommandManager>.Set();

View file

@ -356,8 +356,8 @@ namespace Dalamud.Game.Gui
var sender = StdString.ReadFromPointer(pSenderName); var sender = StdString.ReadFromPointer(pSenderName);
var message = StdString.ReadFromPointer(pMessage); var message = StdString.ReadFromPointer(pMessage);
var parsedSender = Service<SeStringManager>.Get().Parse(sender.RawData); var parsedSender = SeString.Parse(sender.RawData);
var parsedMessage = Service<SeStringManager>.Get().Parse(message.RawData); var parsedMessage = SeString.Parse(message.RawData);
Log.Verbose("[CHATGUI][{0}][{1}]", parsedSender.TextValue, parsedMessage.TextValue); Log.Verbose("[CHATGUI][{0}][{1}]", parsedSender.TextValue, parsedMessage.TextValue);
@ -439,7 +439,7 @@ namespace Dalamud.Game.Gui
while (Marshal.ReadByte(payloadPtr, messageSize) != 0) messageSize++; while (Marshal.ReadByte(payloadPtr, messageSize) != 0) messageSize++;
var payloadBytes = new byte[messageSize]; var payloadBytes = new byte[messageSize];
Marshal.Copy(payloadPtr, payloadBytes, 0, messageSize); Marshal.Copy(payloadPtr, payloadBytes, 0, messageSize);
var seStr = Service<SeStringManager>.Get().Parse(payloadBytes); var seStr = SeString.Parse(payloadBytes);
var terminatorIndex = seStr.Payloads.IndexOf(RawPayload.LinkTerminator); var terminatorIndex = seStr.Payloads.IndexOf(RawPayload.LinkTerminator);
var payloads = terminatorIndex >= 0 ? seStr.Payloads.Take(terminatorIndex + 1).ToList() : seStr.Payloads; var payloads = terminatorIndex >= 0 ? seStr.Payloads.Take(terminatorIndex + 1).ToList() : seStr.Payloads;
if (payloads.Count == 0) return; if (payloads.Count == 0) return;

View file

@ -29,7 +29,6 @@ namespace Dalamud.Game.Gui.PartyFinder.Types
internal PartyFinderListing(PartyFinderPacketListing listing) internal PartyFinderListing(PartyFinderPacketListing listing)
{ {
var dataManager = Service<DataManager>.Get(); var dataManager = Service<DataManager>.Get();
var seStringManager = Service<SeStringManager>.Get();
this.objective = listing.Objective; this.objective = listing.Objective;
this.conditions = listing.Conditions; this.conditions = listing.Conditions;
@ -41,8 +40,8 @@ namespace Dalamud.Game.Gui.PartyFinder.Types
this.Id = listing.Id; this.Id = listing.Id;
this.ContentIdLower = listing.ContentIdLower; this.ContentIdLower = listing.ContentIdLower;
this.Name = seStringManager.Parse(listing.Name.TakeWhile(b => b != 0).ToArray()); this.Name = SeString.Parse(listing.Name.TakeWhile(b => b != 0).ToArray());
this.Description = seStringManager.Parse(listing.Description.TakeWhile(b => b != 0).ToArray()); this.Description = SeString.Parse(listing.Description.TakeWhile(b => b != 0).ToArray());
this.World = new Lazy<World>(() => dataManager.GetExcelSheet<World>().GetRow(listing.World)); this.World = new Lazy<World>(() => dataManager.GetExcelSheet<World>().GetRow(listing.World));
this.HomeWorld = new Lazy<World>(() => dataManager.GetExcelSheet<World>().GetRow(listing.HomeWorld)); this.HomeWorld = new Lazy<World>(() => dataManager.GetExcelSheet<World>().GetRow(listing.HomeWorld));
this.CurrentWorld = new Lazy<World>(() => dataManager.GetExcelSheet<World>().GetRow(listing.CurrentWorld)); this.CurrentWorld = new Lazy<World>(() => dataManager.GetExcelSheet<World>().GetRow(listing.CurrentWorld));

View file

@ -164,7 +164,7 @@ namespace Dalamud.Game.Gui.Toast
} }
// call events // call events
return Service<SeStringManager>.Get().Parse(bytes.ToArray()); return SeString.Parse(bytes.ToArray());
} }
} }

View file

@ -1,8 +1,12 @@
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using Dalamud.Data;
using Dalamud.Game.Text.SeStringHandling.Payloads; using Dalamud.Game.Text.SeStringHandling.Payloads;
using Lumina.Excel.GeneratedSheets;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace Dalamud.Game.Text.SeStringHandling namespace Dalamud.Game.Text.SeStringHandling
@ -42,6 +46,20 @@ namespace Dalamud.Game.Text.SeStringHandling
this.Payloads = new List<Payload>(payloads); this.Payloads = new List<Payload>(payloads);
} }
/// <summary>
/// Gets a list of Payloads necessary to display the arrow link marker icon in chat
/// with the appropriate glow and coloring.
/// </summary>
/// <returns>A list of all the payloads required to insert the link marker.</returns>
public static IEnumerable<Payload> TextArrowPayloads => new List<Payload>(new Payload[]
{
new UIForegroundPayload(0x01F4),
new UIGlowPayload(0x01F5),
new TextPayload($"{(char)SeIconChar.LinkMarker}"),
UIGlowPayload.UIGlowOff,
UIForegroundPayload.UIForegroundOff,
});
/// <summary> /// <summary>
/// Gets the ordered list of payloads included in this SeString. /// Gets the ordered list of payloads included in this SeString.
/// </summary> /// </summary>
@ -76,7 +94,179 @@ namespace Dalamud.Game.Text.SeStringHandling
/// </summary> /// </summary>
/// <param name="luminaString">The Lumina SeString.</param> /// <param name="luminaString">The Lumina SeString.</param>
/// <returns>The re-parsed Dalamud SeString.</returns> /// <returns>The re-parsed Dalamud SeString.</returns>
public static implicit operator SeString(Lumina.Text.SeString luminaString) => Service<SeStringManager>.Get().Parse(luminaString.RawData); public static implicit operator SeString(Lumina.Text.SeString luminaString) => Parse(luminaString.RawData);
/// <summary>
/// Parse a binary game message into an SeString.
/// </summary>
/// <param name="ptr">Pointer to the string's data in memory.</param>
/// <param name="len">Length of the string's data in memory.</param>
/// <returns>An SeString containing parsed Payload objects for each payload in the data.</returns>
public static unsafe SeString Parse(byte* ptr, int len)
{
var payloads = new List<Payload>();
using (var stream = new UnmanagedMemoryStream(ptr, len))
using (var reader = new BinaryReader(stream))
{
while (stream.Position < len)
{
var payload = Payload.Decode(reader);
if (payload != null)
payloads.Add(payload);
}
}
return new SeString(payloads);
}
/// <summary>
/// Parse a binary game message into an SeString.
/// </summary>
/// <param name="data">Binary message payload data in SE's internal format.</param>
/// <returns>An SeString containing parsed Payload objects for each payload in the data.</returns>
public static unsafe SeString Parse(ReadOnlySpan<byte> data)
{
fixed (byte* ptr = data)
{
return Parse(ptr, data.Length);
}
}
/// <summary>
/// Parse a binary game message into an SeString.
/// </summary>
/// <param name="bytes">Binary message payload data in SE's internal format.</param>
/// <returns>An SeString containing parsed Payload objects for each payload in the data.</returns>
public static SeString Parse(byte[] bytes) => Parse(new ReadOnlySpan<byte>(bytes));
/// <summary>
/// Creates an SeString representing an entire Payload chain that can be used to link an item in the chat log.
/// </summary>
/// <param name="itemId">The id of the item to link.</param>
/// <param name="isHq">Whether to link the high-quality variant of the item.</param>
/// <param name="displayNameOverride">An optional name override to display, instead of the actual item name.</param>
/// <returns>An SeString containing all the payloads necessary to display an item link in the chat log.</returns>
public static SeString CreateItemLink(uint itemId, bool isHq, string? displayNameOverride = null)
{
var data = Service<DataManager>.Get();
var displayName = displayNameOverride ?? data.GetExcelSheet<Item>()?.GetRow(itemId)?.Name;
if (isHq)
{
displayName += $" {(char)SeIconChar.HighQuality}";
}
// TODO: probably a cleaner way to build these than doing the bulk+insert
var payloads = new List<Payload>(new Payload[]
{
new UIForegroundPayload(0x0225),
new UIGlowPayload(0x0226),
new ItemPayload(itemId, isHq),
// arrow goes here
new TextPayload(displayName),
RawPayload.LinkTerminator,
// sometimes there is another set of uiglow/foreground off payloads here
// might be necessary when including additional text after the item name
});
payloads.InsertRange(3, TextArrowPayloads);
return new SeString(payloads);
}
/// <summary>
/// Creates an SeString representing an entire Payload chain that can be used to link an item in the chat log.
/// </summary>
/// <param name="item">The Lumina Item to link.</param>
/// <param name="isHq">Whether to link the high-quality variant of the item.</param>
/// <param name="displayNameOverride">An optional name override to display, instead of the actual item name.</param>
/// <returns>An SeString containing all the payloads necessary to display an item link in the chat log.</returns>
public static SeString CreateItemLink(Item item, bool isHq, string? displayNameOverride = null)
{
return CreateItemLink(item.RowId, isHq, displayNameOverride ?? item.Name);
}
/// <summary>
/// Creates an SeString representing an entire Payload chain that can be used to link a map position in the chat log.
/// </summary>
/// <param name="territoryId">The id of the TerritoryType for this map link.</param>
/// <param name="mapId">The id of the Map for this map link.</param>
/// <param name="rawX">The raw x-coordinate for this link.</param>
/// <param name="rawY">The raw y-coordinate for this link..</param>
/// <returns>An SeString containing all of the payloads necessary to display a map link in the chat log.</returns>
public static SeString CreateMapLink(uint territoryId, uint mapId, int rawX, int rawY)
{
var mapPayload = new MapLinkPayload(territoryId, mapId, rawX, rawY);
var nameString = $"{mapPayload.PlaceName} {mapPayload.CoordinateString}";
var payloads = new List<Payload>(new Payload[]
{
mapPayload,
// arrow goes here
new TextPayload(nameString),
RawPayload.LinkTerminator,
});
payloads.InsertRange(1, TextArrowPayloads);
return new SeString(payloads);
}
/// <summary>
/// Creates an SeString representing an entire Payload chain that can be used to link a map position in the chat log.
/// </summary>
/// <param name="territoryId">The id of the TerritoryType for this map link.</param>
/// <param name="mapId">The id of the Map for this map link.</param>
/// <param name="xCoord">The human-readable x-coordinate for this link.</param>
/// <param name="yCoord">The human-readable y-coordinate for this link.</param>
/// <param name="fudgeFactor">An optional offset to account for rounding and truncation errors; it is best to leave this untouched in most cases.</param>
/// <returns>An SeString containing all of the payloads necessary to display a map link in the chat log.</returns>
public static SeString CreateMapLink(uint territoryId, uint mapId, float xCoord, float yCoord, float fudgeFactor = 0.05f)
{
var mapPayload = new MapLinkPayload(territoryId, mapId, xCoord, yCoord, fudgeFactor);
var nameString = $"{mapPayload.PlaceName} {mapPayload.CoordinateString}";
var payloads = new List<Payload>(new Payload[]
{
mapPayload,
// arrow goes here
new TextPayload(nameString),
RawPayload.LinkTerminator,
});
payloads.InsertRange(1, TextArrowPayloads);
return new SeString(payloads);
}
/// <summary>
/// Creates an SeString representing an entire Payload chain that can be used to link a map position in the chat log, matching a specified zone name.
/// </summary>
/// <param name="placeName">The name of the location for this link. This should be exactly the name as seen in a displayed map link in-game for the same zone.</param>
/// <param name="xCoord">The human-readable x-coordinate for this link.</param>
/// <param name="yCoord">The human-readable y-coordinate for this link.</param>
/// <param name="fudgeFactor">An optional offset to account for rounding and truncation errors; it is best to leave this untouched in most cases.</param>
/// <returns>An SeString containing all of the payloads necessary to display a map link in the chat log.</returns>
public static SeString? CreateMapLink(string placeName, float xCoord, float yCoord, float fudgeFactor = 0.05f)
{
var data = Service<DataManager>.Get();
var mapSheet = data.GetExcelSheet<Map>();
var matches = data.GetExcelSheet<PlaceName>()
.Where(row => row.Name.ToString().ToLowerInvariant() == placeName.ToLowerInvariant())
.ToArray();
foreach (var place in matches)
{
var map = mapSheet.FirstOrDefault(row => row.PlaceName.Row == place.RowId);
if (map != null)
{
return CreateMapLink(map.TerritoryType.Row, map.RowId, xCoord, yCoord, fudgeFactor);
}
}
// TODO: empty? throw?
return null;
}
/// <summary> /// <summary>
/// Creates a SeString from a json. (For testing - not recommended for production use.) /// Creates a SeString from a json. (For testing - not recommended for production use.)

View file

@ -16,6 +16,7 @@ namespace Dalamud.Game.Text.SeStringHandling
/// </summary> /// </summary>
[PluginInterface] [PluginInterface]
[InterfaceVersion("1.0")] [InterfaceVersion("1.0")]
[Obsolete("This class is obsolete. Please use the static methods on SeString instead.", true)]
public sealed class SeStringManager public sealed class SeStringManager
{ {
/// <summary> /// <summary>
@ -31,43 +32,24 @@ namespace Dalamud.Game.Text.SeStringHandling
/// <param name="ptr">Pointer to the string's data in memory.</param> /// <param name="ptr">Pointer to the string's data in memory.</param>
/// <param name="len">Length of the string's data in memory.</param> /// <param name="len">Length of the string's data in memory.</param>
/// <returns>An SeString containing parsed Payload objects for each payload in the data.</returns> /// <returns>An SeString containing parsed Payload objects for each payload in the data.</returns>
public unsafe SeString Parse(byte* ptr, int len) [Obsolete("This method is obsolete. Please use the static methods on SeString instead.", true)]
{ public unsafe SeString Parse(byte* ptr, int len) => SeString.Parse(ptr, len);
var payloads = new List<Payload>();
using (var stream = new UnmanagedMemoryStream(ptr, len))
using (var reader = new BinaryReader(stream))
{
while (stream.Position < len)
{
var payload = Payload.Decode(reader);
if (payload != null)
payloads.Add(payload);
}
}
return new SeString(payloads);
}
/// <summary> /// <summary>
/// Parse a binary game message into an SeString. /// Parse a binary game message into an SeString.
/// </summary> /// </summary>
/// <param name="data">Binary message payload data in SE's internal format.</param> /// <param name="data">Binary message payload data in SE's internal format.</param>
/// <returns>An SeString containing parsed Payload objects for each payload in the data.</returns> /// <returns>An SeString containing parsed Payload objects for each payload in the data.</returns>
public unsafe SeString Parse(ReadOnlySpan<byte> data) [Obsolete("This method is obsolete. Please use the static methods on SeString instead.", true)]
{ public unsafe SeString Parse(ReadOnlySpan<byte> data) => SeString.Parse(data);
fixed (byte* ptr = data)
{
return this.Parse(ptr, data.Length);
}
}
/// <summary> /// <summary>
/// Parse a binary game message into an SeString. /// Parse a binary game message into an SeString.
/// </summary> /// </summary>
/// <param name="bytes">Binary message payload data in SE's internal format.</param> /// <param name="bytes">Binary message payload data in SE's internal format.</param>
/// <returns>An SeString containing parsed Payload objects for each payload in the data.</returns> /// <returns>An SeString containing parsed Payload objects for each payload in the data.</returns>
public SeString Parse(byte[] bytes) => this.Parse(new ReadOnlySpan<byte>(bytes)); [Obsolete("This method is obsolete. Please use the static methods on SeString instead.", true)]
public SeString Parse(byte[] bytes) => SeString.Parse(new ReadOnlySpan<byte>(bytes));
/// <summary> /// <summary>
/// Creates an SeString representing an entire Payload chain that can be used to link an item in the chat log. /// Creates an SeString representing an entire Payload chain that can be used to link an item in the chat log.
@ -76,32 +58,8 @@ namespace Dalamud.Game.Text.SeStringHandling
/// <param name="isHQ">Whether to link the high-quality variant of the item.</param> /// <param name="isHQ">Whether to link the high-quality variant of the item.</param>
/// <param name="displayNameOverride">An optional name override to display, instead of the actual item name.</param> /// <param name="displayNameOverride">An optional name override to display, instead of the actual item name.</param>
/// <returns>An SeString containing all the payloads necessary to display an item link in the chat log.</returns> /// <returns>An SeString containing all the payloads necessary to display an item link in the chat log.</returns>
public SeString CreateItemLink(uint itemId, bool isHQ, string displayNameOverride = null) [Obsolete("This method is obsolete. Please use the static methods on SeString instead.", true)]
{ public SeString CreateItemLink(uint itemId, bool isHQ, string displayNameOverride = null) => SeString.CreateItemLink(itemId, isHQ, displayNameOverride);
var data = Service<DataManager>.Get();
var displayName = displayNameOverride ?? data.GetExcelSheet<Item>().GetRow(itemId).Name;
if (isHQ)
{
displayName += $" {(char)SeIconChar.HighQuality}";
}
// TODO: probably a cleaner way to build these than doing the bulk+insert
var payloads = new List<Payload>(new Payload[]
{
new UIForegroundPayload(0x0225),
new UIGlowPayload(0x0226),
new ItemPayload(itemId, isHQ),
// arrow goes here
new TextPayload(displayName),
RawPayload.LinkTerminator,
// sometimes there is another set of uiglow/foreground off payloads here
// might be necessary when including additional text after the item name
});
payloads.InsertRange(3, this.TextArrowPayloads());
return new SeString(payloads);
}
/// <summary> /// <summary>
/// Creates an SeString representing an entire Payload chain that can be used to link an item in the chat log. /// Creates an SeString representing an entire Payload chain that can be used to link an item in the chat log.
@ -110,10 +68,8 @@ namespace Dalamud.Game.Text.SeStringHandling
/// <param name="isHQ">Whether to link the high-quality variant of the item.</param> /// <param name="isHQ">Whether to link the high-quality variant of the item.</param>
/// <param name="displayNameOverride">An optional name override to display, instead of the actual item name.</param> /// <param name="displayNameOverride">An optional name override to display, instead of the actual item name.</param>
/// <returns>An SeString containing all the payloads necessary to display an item link in the chat log.</returns> /// <returns>An SeString containing all the payloads necessary to display an item link in the chat log.</returns>
public SeString CreateItemLink(Item item, bool isHQ, string displayNameOverride = null) [Obsolete("This method is obsolete. Please use the static methods on SeString instead.", true)]
{ public SeString CreateItemLink(Item item, bool isHQ, string displayNameOverride = null) => SeString.CreateItemLink(item, isHQ, displayNameOverride);
return this.CreateItemLink(item.RowId, isHQ, displayNameOverride ?? item.Name);
}
/// <summary> /// <summary>
/// Creates an SeString representing an entire Payload chain that can be used to link a map position in the chat log. /// Creates an SeString representing an entire Payload chain that can be used to link a map position in the chat log.
@ -123,22 +79,9 @@ namespace Dalamud.Game.Text.SeStringHandling
/// <param name="rawX">The raw x-coordinate for this link.</param> /// <param name="rawX">The raw x-coordinate for this link.</param>
/// <param name="rawY">The raw y-coordinate for this link..</param> /// <param name="rawY">The raw y-coordinate for this link..</param>
/// <returns>An SeString containing all of the payloads necessary to display a map link in the chat log.</returns> /// <returns>An SeString containing all of the payloads necessary to display a map link in the chat log.</returns>
public SeString CreateMapLink(uint territoryId, uint mapId, int rawX, int rawY) [Obsolete("This method is obsolete. Please use the static methods on SeString instead.", true)]
{ public SeString CreateMapLink(uint territoryId, uint mapId, int rawX, int rawY) =>
var mapPayload = new MapLinkPayload(territoryId, mapId, rawX, rawY); SeString.CreateMapLink(territoryId, mapId, rawX, rawY);
var nameString = $"{mapPayload.PlaceName} {mapPayload.CoordinateString}";
var payloads = new List<Payload>(new Payload[]
{
mapPayload,
// arrow goes here
new TextPayload(nameString),
RawPayload.LinkTerminator,
});
payloads.InsertRange(1, this.TextArrowPayloads());
return new SeString(payloads);
}
/// <summary> /// <summary>
/// Creates an SeString representing an entire Payload chain that can be used to link a map position in the chat log. /// Creates an SeString representing an entire Payload chain that can be used to link a map position in the chat log.
@ -149,22 +92,8 @@ namespace Dalamud.Game.Text.SeStringHandling
/// <param name="yCoord">The human-readable y-coordinate for this link.</param> /// <param name="yCoord">The human-readable y-coordinate for this link.</param>
/// <param name="fudgeFactor">An optional offset to account for rounding and truncation errors; it is best to leave this untouched in most cases.</param> /// <param name="fudgeFactor">An optional offset to account for rounding and truncation errors; it is best to leave this untouched in most cases.</param>
/// <returns>An SeString containing all of the payloads necessary to display a map link in the chat log.</returns> /// <returns>An SeString containing all of the payloads necessary to display a map link in the chat log.</returns>
public SeString CreateMapLink(uint territoryId, uint mapId, float xCoord, float yCoord, float fudgeFactor = 0.05f) [Obsolete("This method is obsolete. Please use the static methods on SeString instead.", true)]
{ public SeString CreateMapLink(uint territoryId, uint mapId, float xCoord, float yCoord, float fudgeFactor = 0.05f) => SeString.CreateMapLink(territoryId, mapId, xCoord, yCoord, fudgeFactor);
var mapPayload = new MapLinkPayload(territoryId, mapId, xCoord, yCoord, fudgeFactor);
var nameString = $"{mapPayload.PlaceName} {mapPayload.CoordinateString}";
var payloads = new List<Payload>(new Payload[]
{
mapPayload,
// arrow goes here
new TextPayload(nameString),
RawPayload.LinkTerminator,
});
payloads.InsertRange(1, this.TextArrowPayloads());
return new SeString(payloads);
}
/// <summary> /// <summary>
/// Creates an SeString representing an entire Payload chain that can be used to link a map position in the chat log, matching a specified zone name. /// Creates an SeString representing an entire Payload chain that can be used to link a map position in the chat log, matching a specified zone name.
@ -174,44 +103,15 @@ namespace Dalamud.Game.Text.SeStringHandling
/// <param name="yCoord">The human-readable y-coordinate for this link.</param> /// <param name="yCoord">The human-readable y-coordinate for this link.</param>
/// <param name="fudgeFactor">An optional offset to account for rounding and truncation errors; it is best to leave this untouched in most cases.</param> /// <param name="fudgeFactor">An optional offset to account for rounding and truncation errors; it is best to leave this untouched in most cases.</param>
/// <returns>An SeString containing all of the payloads necessary to display a map link in the chat log.</returns> /// <returns>An SeString containing all of the payloads necessary to display a map link in the chat log.</returns>
public SeString CreateMapLink(string placeName, float xCoord, float yCoord, float fudgeFactor = 0.05f) [Obsolete("This method is obsolete. Please use the static methods on SeString instead.", true)]
{ public SeString CreateMapLink(string placeName, float xCoord, float yCoord, float fudgeFactor = 0.05f) => SeString.CreateMapLink(placeName, xCoord, yCoord, fudgeFactor);
var data = Service<DataManager>.Get();
var mapSheet = data.GetExcelSheet<Map>();
var matches = data.GetExcelSheet<PlaceName>()
.Where(row => row.Name.ToString().ToLowerInvariant() == placeName.ToLowerInvariant())
.ToArray();
foreach (var place in matches)
{
var map = mapSheet.FirstOrDefault(row => row.PlaceName.Row == place.RowId);
if (map != null)
{
return this.CreateMapLink(map.TerritoryType.Row, map.RowId, xCoord, yCoord, fudgeFactor);
}
}
// TODO: empty? throw?
return null;
}
/// <summary> /// <summary>
/// Creates a list of Payloads necessary to display the arrow link marker icon in chat /// Creates a list of Payloads necessary to display the arrow link marker icon in chat
/// with the appropriate glow and coloring. /// with the appropriate glow and coloring.
/// </summary> /// </summary>
/// <returns>A list of all the payloads required to insert the link marker.</returns> /// <returns>A list of all the payloads required to insert the link marker.</returns>
public List<Payload> TextArrowPayloads() [Obsolete("This data is obsolete. Please use the static version on SeString instead.", true)]
{ public List<Payload> TextArrowPayloads() => new(SeString.TextArrowPayloads);
return new List<Payload>(new Payload[]
{
new UIForegroundPayload(0x01F4),
new UIGlowPayload(0x01F5),
new TextPayload($"{(char)SeIconChar.LinkMarker}"),
UIGlowPayload.UIGlowOff,
UIForegroundPayload.UIForegroundOff,
});
}
} }
} }

View file

@ -230,7 +230,7 @@ namespace Dalamud.Memory
public static SeString ReadSeStringNullTerminated(IntPtr memoryAddress) public static SeString ReadSeStringNullTerminated(IntPtr memoryAddress)
{ {
var buffer = ReadRawNullTerminated(memoryAddress); var buffer = ReadRawNullTerminated(memoryAddress);
return Service<SeStringManager>.Get().Parse(buffer); return SeString.Parse(buffer);
} }
/// <summary> /// <summary>
@ -246,13 +246,13 @@ namespace Dalamud.Memory
var eos = Array.IndexOf(buffer, (byte)0); var eos = Array.IndexOf(buffer, (byte)0);
if (eos < 0) if (eos < 0)
{ {
return Service<SeStringManager>.Get().Parse(buffer); return SeString.Parse(buffer);
} }
else else
{ {
var newBuffer = new byte[eos]; var newBuffer = new byte[eos];
Buffer.BlockCopy(buffer, 0, newBuffer, 0, eos); Buffer.BlockCopy(buffer, 0, newBuffer, 0, eos);
return Service<SeStringManager>.Get().Parse(newBuffer); return SeString.Parse(newBuffer);
} }
} }