From a3f39f170a203a2e533016fba2592a45199c038a Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Fri, 20 Mar 2020 20:58:15 +0100 Subject: [PATCH] added some more information to formatted text --- MLEM/Formatting/FormattingCodeCollection.cs | 17 ++++++++++++++++- MLEM/Formatting/TextFormatting.cs | 8 +++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/MLEM/Formatting/FormattingCodeCollection.cs b/MLEM/Formatting/FormattingCodeCollection.cs index f3ee385..af3380b 100644 --- a/MLEM/Formatting/FormattingCodeCollection.cs +++ b/MLEM/Formatting/FormattingCodeCollection.cs @@ -1,7 +1,22 @@ using System.Collections.Generic; +using System.Text.RegularExpressions; namespace MLEM.Formatting { - public class FormattingCodeCollection : Dictionary> { + public class FormattingCodeCollection : Dictionary> { + + } + + public class FormattingCodeData { + + public readonly FormattingCode Code; + public readonly Match Match; + public readonly int UnformattedIndex; + + public FormattingCodeData(FormattingCode code, Match match, int unformattedIndex) { + this.Code = code; + this.Match = match; + this.UnformattedIndex = unformattedIndex; + } } } \ No newline at end of file diff --git a/MLEM/Formatting/TextFormatting.cs b/MLEM/Formatting/TextFormatting.cs index 49b7e85..6947741 100644 --- a/MLEM/Formatting/TextFormatting.cs +++ b/MLEM/Formatting/TextFormatting.cs @@ -70,10 +70,11 @@ namespace MLEM.Formatting { if (code == null) continue; var index = match.Index - codeLengths; + var data = new FormattingCodeData(code, match, index); if (codes.TryGetValue(index, out var curr)) { - curr.Add(code); + curr.Add(data); } else { - codes.Add(index, new List {code}); + codes.Add(index, new List {data}); } codeLengths += match.Length - code.GetReplacementString(font).Length; } @@ -93,7 +94,8 @@ namespace MLEM.Formatting { foreach (var c in unformattedText) { // check if the current character's index has a formatting code if (formatting.TryGetValue(formatIndex, out var codes)) { - foreach (var code in codes) { + foreach (var data in codes) { + var code = data.Code; // if so, apply it switch (code.CodeType) { case FormattingCode.Type.Color: