diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e95b71a9..8e1c9451c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/YarnSpinner.LanguageServer.Tests/TestData/ActionDeclarationTests/ActionDeclarations.yarn b/YarnSpinner.LanguageServer.Tests/TestData/ActionDeclarationTests/ActionDeclarations.yarn index 93c43a2b2..1ec141bc0 100644 --- a/YarnSpinner.LanguageServer.Tests/TestData/ActionDeclarationTests/ActionDeclarations.yarn +++ b/YarnSpinner.LanguageServer.Tests/TestData/ActionDeclarationTests/ActionDeclarations.yarn @@ -19,4 +19,6 @@ title: ActionDeclarations {decimal(2.3)} {int(2.3)} {format("{0:F2}", 1)} +{min(2,3)} +{max(4,5)} === \ No newline at end of file diff --git a/YarnSpinner.LanguageServer/src/Server/Documentation/BuiltInFunctionsAndCommands.ysls.json b/YarnSpinner.LanguageServer/src/Server/Documentation/BuiltInFunctionsAndCommands.ysls.json index af6950bfd..0693737a0 100644 --- a/YarnSpinner.LanguageServer/src/Server/Documentation/BuiltInFunctionsAndCommands.ysls.json +++ b/YarnSpinner.LanguageServer/src/Server/Documentation/BuiltInFunctionsAndCommands.ysls.json @@ -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", diff --git a/YarnSpinner/Dialogue.cs b/YarnSpinner/Dialogue.cs index 8a5b054e1..61e68b089 100644 --- a/YarnSpinner/Dialogue.cs +++ b/YarnSpinner/Dialogue.cs @@ -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("round", (float num) => { return (int)Math.Round(num);