From c0578011e01a5e264c0a2936bdd8877a7eccbe21 Mon Sep 17 00:00:00 2001 From: Jamiras <32680403+Jamiras@users.noreply.github.com> Date: Wed, 30 Aug 2023 18:34:59 -0600 Subject: [PATCH] fix Centiseconds macro; support for CENTISECS value format (#412) --- Source/Data/Leaderboard.cs | 27 ++++++++++++++++--- .../Functions/RichPresenceMacroFunction.cs | 5 +++- .../RichPresenceMacroFunctionTests.cs | 3 ++- .../RichPresenceValueFunctionTests.cs | 24 ++++++++++++++--- 4 files changed, 50 insertions(+), 9 deletions(-) diff --git a/Source/Data/Leaderboard.cs b/Source/Data/Leaderboard.cs index 16b52f07..8329e9aa 100644 --- a/Source/Data/Leaderboard.cs +++ b/Source/Data/Leaderboard.cs @@ -49,17 +49,18 @@ public static ValueFormat ParseFormat(string format) return ValueFormat.Value; case "SECS": - case "TIMESECS": + case "TIMESECS": // valid in runtime - maps to SECS return ValueFormat.TimeSecs; case "FRAMES": - case "TIME": + case "TIME": // valid in runtime - maps to FRAMES return ValueFormat.TimeFrames; - case "POINTS": + case "POINTS": // valid in runtime - maps to SCORE case "SCORE": return ValueFormat.Score; + case "CENTISECS": // not valid in runtime. converted to MILLISECS when serialized case "MILLISECS": return ValueFormat.TimeMillisecs; @@ -69,7 +70,7 @@ public static ValueFormat ParseFormat(string format) case "SECS_AS_MINS": return ValueFormat.TimeSecsAsMins; - case "OTHER": + case "OTHER": // valid in runtime - maps to SCORE return ValueFormat.Other; case "FLOAT1": @@ -123,6 +124,24 @@ public static string GetFormatString(ValueFormat format) case ValueFormat.Other: return "OTHER"; + case ValueFormat.Float1: + return "FLOAT1"; + + case ValueFormat.Float2: + return "FLOAT2"; + + case ValueFormat.Float3: + return "FLOAT3"; + + case ValueFormat.Float4: + return "FLOAT4"; + + case ValueFormat.Float5: + return "FLOAT5"; + + case ValueFormat.Float6: + return "FLOAT6"; + default: return "UNKNOWN"; } diff --git a/Source/Parser/Functions/RichPresenceMacroFunction.cs b/Source/Parser/Functions/RichPresenceMacroFunction.cs index c2de8cb4..6d3c5649 100644 --- a/Source/Parser/Functions/RichPresenceMacroFunction.cs +++ b/Source/Parser/Functions/RichPresenceMacroFunction.cs @@ -24,12 +24,15 @@ public static ValueFormat GetValueFormat(string macro) case "Score": return ValueFormat.Score; - case "Centisecs": + case "Centiseconds": return ValueFormat.TimeMillisecs; case "Seconds": return ValueFormat.TimeSecs; + case "SecondsAsMinutes": + return ValueFormat.TimeSecsAsMins; + case "Minutes": return ValueFormat.TimeMinutes; diff --git a/Tests/Parser/Functions/RichPresenceMacroFunctionTests.cs b/Tests/Parser/Functions/RichPresenceMacroFunctionTests.cs index 49523d24..c15b20c1 100644 --- a/Tests/Parser/Functions/RichPresenceMacroFunctionTests.cs +++ b/Tests/Parser/Functions/RichPresenceMacroFunctionTests.cs @@ -55,8 +55,9 @@ private RichPresenceBuilder Evaluate(string input, string expectedError = null) [Test] [TestCase("Number")] [TestCase("Score")] - [TestCase("Centisecs")] + [TestCase("Centiseconds")] [TestCase("Seconds")] + [TestCase("SecondsAsMinutes")] [TestCase("Minutes")] [TestCase("Float1")] [TestCase("Float2")] diff --git a/Tests/Parser/Functions/RichPresenceValueFunctionTests.cs b/Tests/Parser/Functions/RichPresenceValueFunctionTests.cs index 51ac9b4f..c928510d 100644 --- a/Tests/Parser/Functions/RichPresenceValueFunctionTests.cs +++ b/Tests/Parser/Functions/RichPresenceValueFunctionTests.cs @@ -116,10 +116,28 @@ public void TestValueConstant() } [Test] - public void TestFormat() + [TestCase("VALUE", "VALUE")] + [TestCase("SECS", "SECS")] + [TestCase("TIMESECS", "SECS")] + [TestCase("FRAMES", "FRAMES")] + [TestCase("TIME", "FRAMES")] + [TestCase("POINTS", "SCORE")] + [TestCase("SCORE", "SCORE")] + [TestCase("CENTISECS", "MILLISECS")] + [TestCase("MILLISECS", "MILLISECS")] + [TestCase("MINUTES", "MINUTES")] + [TestCase("SECS_AS_MINS", "SECS_AS_MINS")] + [TestCase("OTHER", "OTHER")] + [TestCase("FLOAT1", "FLOAT1")] + [TestCase("FLOAT2", "FLOAT2")] + [TestCase("FLOAT3", "FLOAT3")] + [TestCase("FLOAT4", "FLOAT4")] + [TestCase("FLOAT5", "FLOAT5")] + [TestCase("FLOAT6", "FLOAT6")] + public void TestFormat(string format, string expectedFormat) { - var rp = Evaluate("rich_presence_value(\"Name\", byte(0x1234), format=\"FRAMES\")"); - Assert.That(rp.ToString(), Is.EqualTo("Format:Name\r\nFormatType=FRAMES\r\n\r\nDisplay:\r\n@Name(0xH001234)\r\n")); + var rp = Evaluate("rich_presence_value(\"Name\", byte(0x1234), format=\"" + format + "\")"); + Assert.That(rp.ToString(), Is.EqualTo("Format:Name\r\nFormatType=" + expectedFormat + "\r\n\r\nDisplay:\r\n@Name(0xH001234)\r\n")); } [Test]