Skip to content

Commit

Permalink
Add min and max functions
Browse files Browse the repository at this point in the history
  • Loading branch information
desplesda committed Feb 12, 2025
1 parent 634b194 commit 84e17d0
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Added a new method, `Dialogue.GetHeaderValue`, which returns the value of the specified header on a node.
- Language Server: Nodes that are part of a node group now show their condition complexity as a code lens.
- Added a new method, `Dialogue.HasSalientContent(nodegroup)`, which returns a bool if there is any salient content for the requested nodegroup.
- Added `min(a,b)` and `max(a,b)` to the standard library.

### Changed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@ title: ActionDeclarations
{decimal(2.3)}
{int(2.3)}
{format("{0:F2}", 1)}
{min(2,3)}
{max(4,5)}
===
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,48 @@
],
"ReturnType": "number"
},
{
"YarnName": "min",
"DefinitionName": "min",
"Documentation": "Compares a and b, and returns the smaller of the two.",
"Signature": "min(a,b)",
"Parameters": [
{
"Name": "a",
"Type": "number",
"Documentation": "The first number to compare.",
"IsParamsArray": false
},
{
"Name": "b",
"Type": "number",
"Documentation": "The second number to compare.",
"IsParamsArray": false
}
],
"ReturnType": "number"
},
{
"YarnName": "max",
"DefinitionName": "max",
"Documentation": "Compares a and b, and returns the larger of the two.",
"Signature": "max(a,b)",
"Parameters": [
{
"Name": "a",
"Type": "number",
"Documentation": "The first number to compare.",
"IsParamsArray": false
},
{
"Name": "b",
"Type": "number",
"Documentation": "The second number to compare.",
"IsParamsArray": false
}
],
"ReturnType": "number"
},
{
"YarnName": "format",
"DefinitionName": "format",
Expand Down
3 changes: 3 additions & 0 deletions YarnSpinner/Dialogue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1277,6 +1277,9 @@ public StandardLibrary()
});
#pragma warning restore CA5394 // System.Random is cryptographically insecure

this.RegisterFunction("min", (float a, float b) => Math.Min(a, b));
this.RegisterFunction("max", (float a, float b) => Math.Max(a, b));

this.RegisterFunction<float, int>("round", (float num) =>
{
return (int)Math.Round(num);
Expand Down

0 comments on commit 84e17d0

Please sign in to comment.