From 35af9eee2595fd9c3269c514550b5e023bc1ca44 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Sun, 28 Mar 2021 06:20:27 +0200 Subject: [PATCH] fixed some number parsing not using invariant culture --- MLEM.Data/DataTextureAtlas.cs | 4 ++-- MLEM.Extended/Tiled/TiledExtensions.cs | 4 ++-- MLEM/Formatting/TextFormatter.cs | 9 +++++++-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/MLEM.Data/DataTextureAtlas.cs b/MLEM.Data/DataTextureAtlas.cs index 1f94587..20fc086 100644 --- a/MLEM.Data/DataTextureAtlas.cs +++ b/MLEM.Data/DataTextureAtlas.cs @@ -78,8 +78,8 @@ namespace MLEM.Data { if (match.Groups[8].Success) { for (var i = 0; i < match.Groups[8].Captures.Count; i++) { region.SetData(match.Groups[8].Captures[i].Value, new Vector2( - float.Parse(match.Groups[9].Captures[i].Value) - (pivotRelative ? 0 : loc.X), - float.Parse(match.Groups[10].Captures[i].Value) - (pivotRelative ? 0 : loc.Y))); + float.Parse(match.Groups[9].Captures[i].Value, CultureInfo.InvariantCulture) - (pivotRelative ? 0 : loc.X), + float.Parse(match.Groups[10].Captures[i].Value, CultureInfo.InvariantCulture) - (pivotRelative ? 0 : loc.Y))); } } atlas.regions.Add(name, region); diff --git a/MLEM.Extended/Tiled/TiledExtensions.cs b/MLEM.Extended/Tiled/TiledExtensions.cs index 8a055d1..51b5830 100644 --- a/MLEM.Extended/Tiled/TiledExtensions.cs +++ b/MLEM.Extended/Tiled/TiledExtensions.cs @@ -55,7 +55,7 @@ namespace MLEM.Extended.Tiled { /// The key by which to get a property /// The float property, or 0 if there is none public static float GetFloat(this TiledMapProperties properties, string key) { - float.TryParse(properties.Get(key), NumberStyles.Number, NumberFormatInfo.InvariantInfo, out var val); + float.TryParse(properties.Get(key), NumberStyles.Number, CultureInfo.InvariantCulture, out var val); return val; } @@ -66,7 +66,7 @@ namespace MLEM.Extended.Tiled { /// The key by which to get a property /// The int property, or 0 if there is none public static int GetInt(this TiledMapProperties properties, string key) { - int.TryParse(properties.Get(key), NumberStyles.Number, NumberFormatInfo.InvariantInfo, out var val); + int.TryParse(properties.Get(key), NumberStyles.Number, CultureInfo.InvariantCulture, out var val); return val; } diff --git a/MLEM/Formatting/TextFormatter.cs b/MLEM/Formatting/TextFormatter.cs index 8bc7c8d..b52bab1 100644 --- a/MLEM/Formatting/TextFormatter.cs +++ b/MLEM/Formatting/TextFormatter.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Globalization; using System.Linq; using System.Text.RegularExpressions; using Microsoft.Xna.Framework; @@ -33,7 +34,9 @@ namespace MLEM.Formatting { // font codes this.Codes.Add(new Regex(""), (f, m, r) => new FontCode(m, r, fnt => fnt.Bold)); this.Codes.Add(new Regex(""), (f, m, r) => new FontCode(m, r, fnt => fnt.Italic)); - this.Codes.Add(new Regex(@""), (f, m, r) => new ShadowCode(m, r, m.Groups[1].Success ? ColorHelper.FromHexString(m.Groups[1].Value) : Color.Black, new Vector2(float.TryParse(m.Groups[2].Value, out var offset) ? offset : 2))); + this.Codes.Add(new Regex(@""), (f, m, r) => new ShadowCode(m, r, + m.Groups[1].Success ? ColorHelper.FromHexString(m.Groups[1].Value) : Color.Black, + new Vector2(float.TryParse(m.Groups[2].Value, NumberStyles.Number, CultureInfo.InvariantCulture, out var offset) ? offset : 2))); this.Codes.Add(new Regex(""), (f, m, r) => new UnderlineCode(m, r, 1 / 16F, 0.85F)); this.Codes.Add(new Regex(""), (f, m, r) => new FontCode(m, r, null)); @@ -48,7 +51,9 @@ namespace MLEM.Formatting { this.Codes.Add(new Regex(""), (f, m, r) => new ColorCode(m, r, null)); // animation codes - this.Codes.Add(new Regex(@""), (f, m, r) => new WobblyCode(m, r, float.TryParse(m.Groups[1].Value, out var mod) ? mod : 5, float.TryParse(m.Groups[2].Value, out var heightMod) ? heightMod : 1 / 8F)); + this.Codes.Add(new Regex(@""), (f, m, r) => new WobblyCode(m, r, + float.TryParse(m.Groups[1].Value, NumberStyles.Number, CultureInfo.InvariantCulture, out var mod) ? mod : 5, + float.TryParse(m.Groups[2].Value, NumberStyles.Number, CultureInfo.InvariantCulture, out var heightMod) ? heightMod : 1 / 8F)); this.Codes.Add(new Regex(""), (f, m, r) => new AnimatedCode(m, r)); // macros