1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-11-26 06:28:35 +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.Text.RegularExpressions;
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)
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<FormattingCode> {code});
codes.Add(index, new List<FormattingCodeData> {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: