From bb576585d4993438d2131f9af15789296da6ba05 Mon Sep 17 00:00:00 2001 From: cooolbros Date: Tue, 4 Jun 2024 12:58:53 +1000 Subject: [PATCH] Print floats with CultureInfo.InvariantCulture --- src/HUDAnimations/Models/Animations/Animate.cs | 3 ++- src/HUDAnimations/Models/Animations/FireCommand.cs | 2 +- src/HUDAnimations/Models/Animations/PlaySound.cs | 2 +- src/HUDAnimations/Models/Animations/RunEvent.cs | 2 +- src/HUDAnimations/Models/Animations/RunEventChild.cs | 2 +- src/HUDAnimations/Models/Animations/SetInputEnabled.cs | 2 +- src/HUDAnimations/Models/Animations/SetVisible.cs | 2 +- src/HUDAnimations/Models/Animations/StopAnimation.cs | 2 +- src/HUDAnimations/Models/Animations/StopEvent.cs | 2 +- src/HUDAnimations/Models/Animations/StopPanelAnimations.cs | 2 +- src/HUDAnimations/Models/HUDAnimationBase.cs | 6 ++++++ src/HUDAnimations/Models/InterpolatorBase.cs | 6 ++++++ src/HUDAnimations/Models/Interpolators/BiasInterpolator.cs | 2 +- .../Models/Interpolators/FlickerInterpolator.cs | 2 +- src/HUDAnimations/Models/Interpolators/GainInterpolator.cs | 2 +- src/HUDAnimations/Models/Interpolators/PulseInterpolator.cs | 2 +- 16 files changed, 27 insertions(+), 14 deletions(-) diff --git a/src/HUDAnimations/Models/Animations/Animate.cs b/src/HUDAnimations/Models/Animations/Animate.cs index a4cf15a..3031f29 100644 --- a/src/HUDAnimations/Models/Animations/Animate.cs +++ b/src/HUDAnimations/Models/Animations/Animate.cs @@ -1,4 +1,5 @@ using System; +using System.Globalization; namespace HUDAnimations.Models.Animations; @@ -14,6 +15,6 @@ public class Animate : HUDAnimationBase public override string ToString() { - return $"{Type} {Print(Element)} {Print(Property)} {Print(Value)} {Interpolator} {Delay} {Duration}" + PrintConditional(); + return $"{Type} {Print(Element)} {Print(Property)} {Print(Value)} {Interpolator} {Print(Delay)} {Print(Duration)}" + PrintConditional(); } } diff --git a/src/HUDAnimations/Models/Animations/FireCommand.cs b/src/HUDAnimations/Models/Animations/FireCommand.cs index 430c8e1..cbc25f2 100644 --- a/src/HUDAnimations/Models/Animations/FireCommand.cs +++ b/src/HUDAnimations/Models/Animations/FireCommand.cs @@ -10,6 +10,6 @@ public class FireCommand : HUDAnimationBase public override string ToString() { - return $"{Type} {Delay} {Print(Command)}" + PrintConditional(); + return $"{Type} {Print(Delay)} {Print(Command)}" + PrintConditional(); } } diff --git a/src/HUDAnimations/Models/Animations/PlaySound.cs b/src/HUDAnimations/Models/Animations/PlaySound.cs index ec10636..35d22f4 100644 --- a/src/HUDAnimations/Models/Animations/PlaySound.cs +++ b/src/HUDAnimations/Models/Animations/PlaySound.cs @@ -10,6 +10,6 @@ public class PlaySound : HUDAnimationBase public override string ToString() { - return $"{Type} {Delay} {Print(Sound)}" + PrintConditional(); + return $"{Type} {Print(Delay)} {Print(Sound)}" + PrintConditional(); } } diff --git a/src/HUDAnimations/Models/Animations/RunEvent.cs b/src/HUDAnimations/Models/Animations/RunEvent.cs index e7b720f..7310e5b 100644 --- a/src/HUDAnimations/Models/Animations/RunEvent.cs +++ b/src/HUDAnimations/Models/Animations/RunEvent.cs @@ -10,6 +10,6 @@ public class RunEvent : HUDAnimationBase public override string ToString() { - return $"{Type} {Print(Event)} {Delay}" + PrintConditional(); + return $"{Type} {Print(Event)} {Print(Delay)}" + PrintConditional(); } } diff --git a/src/HUDAnimations/Models/Animations/RunEventChild.cs b/src/HUDAnimations/Models/Animations/RunEventChild.cs index 76edd55..d26877f 100644 --- a/src/HUDAnimations/Models/Animations/RunEventChild.cs +++ b/src/HUDAnimations/Models/Animations/RunEventChild.cs @@ -11,6 +11,6 @@ public class RunEventChild : HUDAnimationBase public override string ToString() { - return $"{Type} {Print(Element)} {Print(Event)} {Delay}" + PrintConditional(); + return $"{Type} {Print(Element)} {Print(Event)} {Print(Delay)}" + PrintConditional(); } } diff --git a/src/HUDAnimations/Models/Animations/SetInputEnabled.cs b/src/HUDAnimations/Models/Animations/SetInputEnabled.cs index 13824c3..41e99cb 100644 --- a/src/HUDAnimations/Models/Animations/SetInputEnabled.cs +++ b/src/HUDAnimations/Models/Animations/SetInputEnabled.cs @@ -11,6 +11,6 @@ public class SetInputEnabled : HUDAnimationBase public override string ToString() { - return $"{Type} {Print(Element)} {Convert.ToByte(Enabled)} {Delay}" + PrintConditional(); + return $"{Type} {Print(Element)} {Convert.ToByte(Enabled)} {Print(Delay)}" + PrintConditional(); } } diff --git a/src/HUDAnimations/Models/Animations/SetVisible.cs b/src/HUDAnimations/Models/Animations/SetVisible.cs index f1bede7..756a43c 100644 --- a/src/HUDAnimations/Models/Animations/SetVisible.cs +++ b/src/HUDAnimations/Models/Animations/SetVisible.cs @@ -11,6 +11,6 @@ public class SetVisible : HUDAnimationBase public override string ToString() { - return $"{Type} {Print(Element)} {Convert.ToByte(Visible)} {Delay}" + PrintConditional(); + return $"{Type} {Print(Element)} {Convert.ToByte(Visible)} {Print(Delay)}" + PrintConditional(); } } diff --git a/src/HUDAnimations/Models/Animations/StopAnimation.cs b/src/HUDAnimations/Models/Animations/StopAnimation.cs index 9ac8c4f..1afb3d4 100644 --- a/src/HUDAnimations/Models/Animations/StopAnimation.cs +++ b/src/HUDAnimations/Models/Animations/StopAnimation.cs @@ -11,6 +11,6 @@ public class StopAnimation : HUDAnimationBase public override string ToString() { - return $"{Type} {Print(Element)} {Print(Property)} {Delay}" + PrintConditional(); + return $"{Type} {Print(Element)} {Print(Property)} {Print(Delay)}" + PrintConditional(); } } diff --git a/src/HUDAnimations/Models/Animations/StopEvent.cs b/src/HUDAnimations/Models/Animations/StopEvent.cs index b17a329..ec4693d 100644 --- a/src/HUDAnimations/Models/Animations/StopEvent.cs +++ b/src/HUDAnimations/Models/Animations/StopEvent.cs @@ -10,6 +10,6 @@ public class StopEvent : HUDAnimationBase public override string ToString() { - return $"{Type} {Print(Event)} {Delay}" + PrintConditional(); + return $"{Type} {Print(Event)} {Print(Delay)}" + PrintConditional(); } } diff --git a/src/HUDAnimations/Models/Animations/StopPanelAnimations.cs b/src/HUDAnimations/Models/Animations/StopPanelAnimations.cs index 03e9135..f26b37c 100644 --- a/src/HUDAnimations/Models/Animations/StopPanelAnimations.cs +++ b/src/HUDAnimations/Models/Animations/StopPanelAnimations.cs @@ -10,6 +10,6 @@ public class StopPanelAnimations : HUDAnimationBase public override string ToString() { - return $"{Type} {Print(Element)} {Delay}" + PrintConditional(); + return $"{Type} {Print(Element)} {Print(Delay)}" + PrintConditional(); } } diff --git a/src/HUDAnimations/Models/HUDAnimationBase.cs b/src/HUDAnimations/Models/HUDAnimationBase.cs index 3de0d5d..6a4c67a 100644 --- a/src/HUDAnimations/Models/HUDAnimationBase.cs +++ b/src/HUDAnimations/Models/HUDAnimationBase.cs @@ -1,4 +1,5 @@ using System; +using System.Globalization; using System.Text.RegularExpressions; namespace HUDAnimations.Models; @@ -16,6 +17,11 @@ protected static string Print(string str) return WhitespaceRegex().IsMatch(str) ? $"\"{str}\"" : str; } + protected static string Print(float num) + { + return num.ToString(CultureInfo.InvariantCulture); + } + protected string PrintConditional() { return Conditional != null ? $" {Conditional}" : ""; diff --git a/src/HUDAnimations/Models/InterpolatorBase.cs b/src/HUDAnimations/Models/InterpolatorBase.cs index 22eb41e..7bafb2b 100644 --- a/src/HUDAnimations/Models/InterpolatorBase.cs +++ b/src/HUDAnimations/Models/InterpolatorBase.cs @@ -1,8 +1,14 @@ using System; +using System.Globalization; namespace HUDAnimations.Models; public abstract class InterpolatorBase { public abstract override string ToString(); + + protected static string Print(float num) + { + return num.ToString(CultureInfo.InvariantCulture); + } } diff --git a/src/HUDAnimations/Models/Interpolators/BiasInterpolator.cs b/src/HUDAnimations/Models/Interpolators/BiasInterpolator.cs index d820e3d..9d88b90 100644 --- a/src/HUDAnimations/Models/Interpolators/BiasInterpolator.cs +++ b/src/HUDAnimations/Models/Interpolators/BiasInterpolator.cs @@ -6,5 +6,5 @@ public class BiasInterpolator : InterpolatorBase { public required float Bias { get; init; } - public override string ToString() => $"Bias {Bias}"; + public override string ToString() => $"Bias {Print(Bias)}"; } diff --git a/src/HUDAnimations/Models/Interpolators/FlickerInterpolator.cs b/src/HUDAnimations/Models/Interpolators/FlickerInterpolator.cs index f6fb0e2..921f84b 100644 --- a/src/HUDAnimations/Models/Interpolators/FlickerInterpolator.cs +++ b/src/HUDAnimations/Models/Interpolators/FlickerInterpolator.cs @@ -6,5 +6,5 @@ public class FlickerInterpolator : InterpolatorBase { public required float Randomness { get; init; } - public override string ToString() => $"Flicker {Randomness}"; + public override string ToString() => $"Flicker {Print(Randomness)}"; } diff --git a/src/HUDAnimations/Models/Interpolators/GainInterpolator.cs b/src/HUDAnimations/Models/Interpolators/GainInterpolator.cs index cb10175..60a485b 100644 --- a/src/HUDAnimations/Models/Interpolators/GainInterpolator.cs +++ b/src/HUDAnimations/Models/Interpolators/GainInterpolator.cs @@ -6,5 +6,5 @@ public class GainInterpolator : InterpolatorBase { public required float Bias { get; init; } - public override string ToString() => $"Gain {Bias}"; + public override string ToString() => $"Gain {Print(Bias)}"; } diff --git a/src/HUDAnimations/Models/Interpolators/PulseInterpolator.cs b/src/HUDAnimations/Models/Interpolators/PulseInterpolator.cs index 750cd51..4e89d47 100644 --- a/src/HUDAnimations/Models/Interpolators/PulseInterpolator.cs +++ b/src/HUDAnimations/Models/Interpolators/PulseInterpolator.cs @@ -6,5 +6,5 @@ public class PulseInterpolator : InterpolatorBase { public required float Frequency { get; init; } - public override string ToString() => $"Pulse {Frequency}"; + public override string ToString() => $"Pulse {Print(Frequency)}"; }