Skip to content

Commit 04dbc47

Browse files
committed
added in support for YarnNodeParameter attribute.
This allows for tagging a string as part of a yarn action as being a node. This doesn't do anything at run time but as part of editing the LSP now knows to offer autocomplete and warnings if the values of the parameter aren't a node in the project.
1 parent 67bacd9 commit 04dbc47

File tree

7 files changed

+61
-1
lines changed

7 files changed

+61
-1
lines changed

Editor/Analysis/Action.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ public struct Parameter
138138
public string? DefaultValueString;
139139
public bool IsParamsArray;
140140

141+
public AttributeData[]? Attributes;
142+
141143
public readonly string? YarnTypeString => Type.GetYarnTypeString();
142144
}
143145

@@ -287,7 +289,17 @@ public string ToJSON()
287289
}
288290
else
289291
{
290-
paramObject["Type"] = p.YarnTypeString;
292+
// there is one special case of the regular types
293+
// if the parameter has the YarnNodeParameterAttribute on it then we want to say it's a node and not a string
294+
var isANodeType = p.Attributes?.Count(a => a.AttributeClass?.Name == "YarnNodeParameterAttribute") > 0;
295+
if (isANodeType && p.Type.SpecialType == SpecialType.System_String)
296+
{
297+
paramObject["Type"] = "node";
298+
}
299+
else
300+
{
301+
paramObject["Type"] = p.YarnTypeString;
302+
}
291303
}
292304

293305
return paramObject;

Editor/Analysis/Analyser.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -865,6 +865,16 @@ private static List<Parameter> GetParams(IMethodSymbol symbol, XElement? documen
865865
{
866866
logger?.WriteLine($"\t{param.Name} is a {param.Type.ToDisplayString()}");
867867

868+
List<AttributeData> attributes = new List<AttributeData>();
869+
foreach (var attribute in param.GetAttributes())
870+
{
871+
if (attribute.AttributeClass?.BaseType?.Name == "YarnParameterAttribute")
872+
{
873+
logger?.WriteLine($"\t\tattribute: {attribute.AttributeClass?.Name}");
874+
attributes.Add(attribute);
875+
}
876+
}
877+
868878
parameterDocumentation.TryGetValue(param.Name, out var paramDoc);
869879
var p = new Parameter
870880
{
@@ -873,6 +883,7 @@ private static List<Parameter> GetParams(IMethodSymbol symbol, XElement? documen
873883
Type = param.Type,
874884
Description = paramDoc,
875885
IsParamsArray = param.IsParams,
886+
Attributes = attributes.Count() == 0 ? null : attributes.ToArray(),
876887
DefaultValueString = param.HasExplicitDefaultValue ? param.ExplicitDefaultValue?.ToString() : null,
877888
};
878889
parameters.Add(p);
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+
using System;
6+
using System.Collections;
7+
using System.Collections.Generic;
8+
using UnityEngine;
9+
10+
#nullable enable
11+
12+
namespace Yarn.Unity.Attributes
13+
{
14+
public class YarnNodeParameterAttribute: YarnParameterAttribute {}
15+
}

Runtime/Commands/YarnNodeParameterAttribute.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.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
Yarn Spinner is licensed to you under the terms found in the file LICENSE.md.
3+
*/
4+
5+
using System;
6+
using System.Collections;
7+
using System.Collections.Generic;
8+
using UnityEngine;
9+
10+
#nullable enable
11+
12+
namespace Yarn.Unity.Attributes
13+
{
14+
[AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
15+
public abstract class YarnParameterAttribute : Attribute
16+
{
17+
}
18+
}

Runtime/Commands/YarnParameterAttribute.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)