1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-11-26 14:38:34 +01:00

added some more information to formatted text

This commit is contained in:
Ellpeck 2020-03-20 20:58:15 +01:00
parent ce50c6d569
commit a3f39f170a
2 changed files with 21 additions and 4 deletions

View file

@ -1,7 +1,22 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Text.RegularExpressions;
namespace MLEM.Formatting { namespace MLEM.Formatting {
public class FormattingCodeCollection : Dictionary<int, List<FormattingCode>> { public class FormattingCodeCollection : Dictionary<int, List<FormattingCodeData>> {
}
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;
}
} }
} }

View file

@ -70,10 +70,11 @@ namespace MLEM.Formatting {
if (code == null) if (code == null)
continue; continue;
var index = match.Index - codeLengths; var index = match.Index - codeLengths;
var data = new FormattingCodeData(code, match, index);
if (codes.TryGetValue(index, out var curr)) { if (codes.TryGetValue(index, out var curr)) {
curr.Add(code); curr.Add(data);
} else { } else {
codes.Add(index, new List<FormattingCode> {code}); codes.Add(index, new List<FormattingCodeData> {data});
} }
codeLengths += match.Length - code.GetReplacementString(font).Length; codeLengths += match.Length - code.GetReplacementString(font).Length;
} }
@ -93,7 +94,8 @@ namespace MLEM.Formatting {
foreach (var c in unformattedText) { foreach (var c in unformattedText) {
// check if the current character's index has a formatting code // check if the current character's index has a formatting code
if (formatting.TryGetValue(formatIndex, out var codes)) { 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 // if so, apply it
switch (code.CodeType) { switch (code.CodeType) {
case FormattingCode.Type.Color: case FormattingCode.Type.Color: