From f4bec174489afd4eef21ecf9096abbf692fad429 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Mon, 6 Apr 2020 02:20:57 +0200 Subject: [PATCH] made text formatting codes ignore case --- Demos/UiDemo.cs | 3 +-- MLEM/Formatting/TextFormatting.cs | 6 +++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Demos/UiDemo.cs b/Demos/UiDemo.cs index 54f579a..2402299 100644 --- a/Demos/UiDemo.cs +++ b/Demos/UiDemo.cs @@ -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("Textures/Anim"), 4, 4); diff --git a/MLEM/Formatting/TextFormatting.cs b/MLEM/Formatting/TextFormatting.cs index af1080a..151ec49 100644 --- a/MLEM/Formatting/TextFormatting.cs +++ b/MLEM/Formatting/TextFormatting.cs @@ -11,7 +11,7 @@ using MLEM.Textures; namespace MLEM.Formatting { public static class TextFormatting { - public static readonly Dictionary FormattingCodes = new Dictionary(); + public static readonly Dictionary FormattingCodes = new Dictionary(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; }