Skip to content

Commit 7d8c02e

Browse files
committed
can now add the YarnEnumParameter attribute onto functions and commands.
Provides hints to the editor that when writing these commands and functions to offer suggestions of enums. This is a temporary solution to giving the editor more information until generation and declaration of Yarn enums works seamlessly between Yarn and C#
1 parent 2562288 commit 7d8c02e

File tree

5 files changed

+44
-2
lines changed

5 files changed

+44
-2
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
1616
- Generated YSLS file now includes subtype information for instance commands
1717
- This means a command like `<<move gary left>>` now knows that the `"gary"` is the name of a game object and the specific game object subclass
1818
- Only works at a single level of monobehaviour depth, subclasses of a monobehaviour subclass will not be recognised
19+
- `YarnNodeParameterAttribute` can now be added to string parameters in function and command methods
20+
- Intended to allow you to hint to the VSCode extension that when writing this parameter in commands and functions to limit suggestions to nodes
21+
- `YarnEnumParameterAttribute` can now be added to parameters in functions and command methods
22+
- has one field which is the name the enum as declared in your Yarn
23+
- Intended to allow you to hint to the VSCode extension to offer enum based suggestions
24+
- this is temporary until forward declaration of Yarn enums into C# works
1925

2026
### Changed
2127

Editor/Analysis/Action.cs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,12 +290,31 @@ public string ToJSON()
290290
}
291291
else
292292
{
293-
// there is one special case of the regular types which is if you are a string and attributed as a node parameter
293+
// there are two special case of the regular types:
294+
// if you are a string and attributed as a node parameter you get declared as being a node type
295+
// if you have an enum attribute it gets declared as an enum and it has the subtype as defined in the enum attribute
296+
294297
var isANodeType = p.Attributes?.Count(a => a.AttributeClass?.Name == "YarnNodeParameterAttribute") > 0;
298+
var isAnEnum = p.Attributes?.Count(a => a.AttributeClass?.Name == "YarnEnumParameterAttribute") > 0;
299+
295300
if (isANodeType && p.Type.SpecialType == SpecialType.System_String)
296301
{
297302
paramObject["type"] = "node";
298303
}
304+
else if (isAnEnum)
305+
{
306+
paramObject["type"] = "enum";
307+
308+
var attribute = p.Attributes?.Where(a => a.AttributeClass?.Name == "YarnEnumParameterAttribute").First();
309+
if (attribute != null && attribute.ConstructorArguments.Count() > 0)
310+
{
311+
var enumType = attribute.ConstructorArguments[0];
312+
if (enumType.Type?.SpecialType == SpecialType.System_String)
313+
{
314+
paramObject["subtype"] = enumType.Value as string ?? p.YarnTypeString;
315+
}
316+
}
317+
}
299318
else
300319
{
301320
paramObject["type"] = p.YarnTypeString;
@@ -312,7 +331,7 @@ public string ToJSON()
312331

313332
if (!string.IsNullOrWhiteSpace(this.ReturnDescription))
314333
{
315-
retvrn["description"] = this.ReturnDescription;
334+
retvrn["description"] = this.ReturnDescription!;
316335
}
317336
result["return"] = retvrn;
318337
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
Yarn Spinner is licensed to you under the terms found in the file LICENSE.md.
3+
*/
4+
5+
#nullable enable
6+
7+
namespace Yarn.Unity.Attributes
8+
{
9+
public class YarnEnumParameterAttribute: YarnParameterAttribute
10+
{
11+
public string Name { get; set; }
12+
13+
public YarnEnumParameterAttribute(string name) => Name = name;
14+
}
15+
}

Runtime/Commands/YarnEnumParameterAttribute.cs.meta

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
512 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)