From ecf759121f05e72ce29bf53cda03d642f5d01c8c Mon Sep 17 00:00:00 2001 From: Liza Carvelli Date: Sat, 23 Nov 2024 14:17:29 +0100 Subject: [PATCH] Replace new lines with "" in localized `GetString` calls --- DataManagerExtensions.cs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/DataManagerExtensions.cs b/DataManagerExtensions.cs index cc2d952..eea0a87 100644 --- a/DataManagerExtensions.cs +++ b/DataManagerExtensions.cs @@ -9,6 +9,7 @@ using Dalamud.Utility; using Lumina.Excel; using Lumina.Excel.Sheets; using Lumina.Text; +using Lumina.Text.Payloads; using Lumina.Text.ReadOnly; namespace LLib; @@ -29,7 +30,7 @@ public static class DataManagerExtensions public static string? GetString(this IDataManager dataManager, string key, IPluginLog? pluginLog) where T : struct, IQuestDialogueText, IExcelRow { - string? text = GetSeString(dataManager, key)?.ToString(); + string? text = GetSeString(dataManager, key)?.WithCertainMacroCodeReplacements(); pluginLog?.Verbose($"{typeof(T).Name}.{key} => {text}"); return text; @@ -70,7 +71,7 @@ public static class DataManagerExtensions IPluginLog? pluginLog = null) where T : struct, IExcelRow { - string? text = GetSeString(dataManager, rowId, mapper)?.ToString(); + string? text = GetSeString(dataManager, rowId, mapper)?.WithCertainMacroCodeReplacements(); pluginLog?.Verbose($"{typeof(T).Name}.{rowId} => {text}"); return text; @@ -114,6 +115,19 @@ public static class DataManagerExtensions return "(.*)"; }))); } + + public static string WithCertainMacroCodeReplacements(this ReadOnlySeString text) + { + return string.Join("", text.Select(payload => + { + if (payload.Type == ReadOnlySePayloadType.Text) + return Regex.Escape(payload.ToString()); + else if (payload is { Type: ReadOnlySePayloadType.Macro, MacroCode: MacroCode.NewLine }) + return ""; + else + return payload.ToString(); + })); + } } public interface IQuestDialogueText