diff --git a/DataManagerExtensions.cs b/DataManagerExtensions.cs index 2d3a074..01fb7dc 100644 --- a/DataManagerExtensions.cs +++ b/DataManagerExtensions.cs @@ -15,19 +15,19 @@ namespace LLib; public static class DataManagerExtensions { - /* - public static SeString? GetSeDialogueString(this IDataManager dataManager, string key) - where T : struct, IExcelRow + public static ReadOnlySeString? GetSeString(this IDataManager dataManager, string key) + where T : struct, IQuestDialogueText, IExcelRow { ArgumentNullException.ThrowIfNull(dataManager); - return dataManager.GetExcelSheet() - .SingleOrDefault(x => x.Key == key) - .Value; + return dataManager.GetExcelSheet() + .Cast() + .SingleOrDefault(x => x!.Value.Key == key) + ?.Value; } public static string? GetString(this IDataManager dataManager, string key, IPluginLog? pluginLog) - where T : struct, IExcelRow + where T : struct, IQuestDialogueText, IExcelRow { string? text = GetSeString(dataManager, key)?.ToString(); @@ -36,23 +36,22 @@ public static class DataManagerExtensions } public static Regex? GetRegex(this IDataManager dataManager, string key, IPluginLog? pluginLog) - where T : struct, IExcelRow + where T : struct, IQuestDialogueText, IExcelRow { - SeString? text = GetSeString(dataManager, key); + ReadOnlySeString? text = GetSeString(dataManager, key); if (text == null) return null; - string regex = string.Join("", text.Payloads.Select(payload => + string regex = string.Join("", text.Select((ReadOnlySePayload payload) => { - if (payload is TextPayload) - return Regex.Escape(payload.RawString); + if (payload.Type == ReadOnlySePayloadType.Text) + return Regex.Escape(payload.ToString()); else return "(.*)"; })); pluginLog?.Verbose($"{typeof(T).Name}.{key} => /{regex}/"); return new Regex(regex); } - */ public static ReadOnlySeString? GetSeString(this IDataManager dataManager, uint rowId, Func mapper) where T : struct, IExcelRow @@ -117,8 +116,14 @@ public static class DataManagerExtensions } } +public interface IQuestDialogueText +{ + public ReadOnlySeString Key { get; } + public ReadOnlySeString Value { get; } +} + [SuppressMessage("Performance", "CA1815")] -public readonly struct QuestDialogueText(ExcelPage page, uint offset, uint row) : IExcelRow +public readonly struct QuestDialogueText(ExcelPage page, uint offset, uint row) : IQuestDialogueText, IExcelRow { public uint RowId => row;