1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-06-01 12:53:38 +02:00

made text formatting codes ignore case

This commit is contained in:
Ellpeck 2020-04-06 02:20:57 +02:00
parent 9d3ed95c6d
commit f4bec17448
2 changed files with 4 additions and 5 deletions

View file

@ -95,8 +95,7 @@ namespace Demos {
root.AddChild(new Paragraph(Anchor.AutoLeft, 1, "Paragraphs can also contain [Blue]formatting codes[White], including colors and [Italic]text styles[Regular]. The names of all [Orange]MonoGame Colors[White] can be used, as well as the codes [Italic]Italic[Regular], [Bold]Bold[Regular], [Shadow]Drop Shadow'd[Regular] and [Shadow][Pink]mixed formatting[Regular][White]. \n[Italic]Even [CornflowerBlue]Cornflower Blue[White] works!"));
// adding some custom image formatting codes
// note that all added formatting codes need to be lowercase, while their casing doesn't matter when used
TextFormatting.FormattingCodes["grass"] = new FormattingCode(image.Texture);
TextFormatting.FormattingCodes["Grass"] = new FormattingCode(image.Texture);
TextFormatting.FormattingCodes["tree"] = new FormattingCode(tree);
// formatting codes can also be sprite animations!
var atlas = new UniformTextureAtlas(LoadContent<Texture2D>("Textures/Anim"), 4, 4);

View file

@ -11,7 +11,7 @@ using MLEM.Textures;
namespace MLEM.Formatting {
public static class TextFormatting {
public static readonly Dictionary<string, FormattingCode> FormattingCodes = new Dictionary<string, FormattingCode>();
public static readonly Dictionary<string, FormattingCode> FormattingCodes = new Dictionary<string, FormattingCode>(StringComparer.OrdinalIgnoreCase);
private static Regex formatRegex;
static TextFormatting() {
@ -27,7 +27,7 @@ namespace MLEM.Formatting {
var colors = typeof(Color).GetProperties();
foreach (var color in colors) {
if (color.GetGetMethod().IsStatic)
FormattingCodes[color.Name.ToLowerInvariant()] = new FormattingCode((Color) color.GetValue(null));
FormattingCodes[color.Name] = new FormattingCode((Color) color.GetValue(null));
}
// animations
@ -131,7 +131,7 @@ namespace MLEM.Formatting {
}
private static FormattingCode FromMatch(Capture match) {
var rawCode = match.Value.Substring(1, match.Value.Length - 2).ToLowerInvariant();
var rawCode = match.Value.Substring(1, match.Value.Length - 2);
FormattingCodes.TryGetValue(rawCode, out var val);
return val;
}