Skip to content

Commit

Permalink
fix Centiseconds macro; support for CENTISECS value format (#412)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamiras authored Aug 31, 2023
1 parent e0ed085 commit c057801
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 9 deletions.
27 changes: 23 additions & 4 deletions Source/Data/Leaderboard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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":
Expand Down Expand Up @@ -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";
}
Expand Down
5 changes: 4 additions & 1 deletion Source/Parser/Functions/RichPresenceMacroFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
3 changes: 2 additions & 1 deletion Tests/Parser/Functions/RichPresenceMacroFunctionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
24 changes: 21 additions & 3 deletions Tests/Parser/Functions/RichPresenceValueFunctionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit c057801

Please sign in to comment.