diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2024-05-10 09:55:54 +0200 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2024-05-10 09:55:54 +0200 |
commit | 77044574345331aa8406bde958c0c44fd60a0f22 (patch) | |
tree | 012bc18538f46b9d83d73b21c364f947540fe43a | |
parent | 6fcdd2446821c65c36063e00e9555dedddb97763 (diff) | |
parent | 06b716d8b35c9bcaf0efb8da4ee696d0c6d31223 (diff) | |
download | redot-engine-77044574345331aa8406bde958c0c44fd60a0f22.tar.gz |
Merge pull request #91645 from ZerxZ/dotnet/hint-string-fix
Fix C# Hint NodeType and ResourceType HintString
-rw-r--r-- | modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptPropertiesGenerator.cs | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptPropertiesGenerator.cs b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptPropertiesGenerator.cs index 21223654f3..a25a2c2f68 100644 --- a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptPropertiesGenerator.cs +++ b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptPropertiesGenerator.cs @@ -590,6 +590,11 @@ namespace Godot.SourceGenerators if (variantType == VariantType.Object && type is INamedTypeSymbol memberNamedType) { + if (TryGetNodeOrResourceType(exportAttr, out hint, out hintString)) + { + return true; + } + if (memberNamedType.InheritsFrom("GodotSharp", "Godot.Resource")) { hint = PropertyHint.ResourceType; @@ -607,6 +612,37 @@ namespace Godot.SourceGenerators } } + static bool TryGetNodeOrResourceType(AttributeData exportAttr, out PropertyHint hint, out string? hintString) + { + hint = PropertyHint.None; + hintString = null; + + if (exportAttr.ConstructorArguments.Length <= 1) return false; + + var hintValue = exportAttr.ConstructorArguments[0].Value; + + var hintEnum = hintValue switch + { + null => PropertyHint.None, + int intValue => (PropertyHint)intValue, + _ => (PropertyHint)(long)hintValue + }; + + if (!hintEnum.HasFlag(PropertyHint.NodeType) && !hintEnum.HasFlag(PropertyHint.ResourceType)) + return false; + + var hintStringValue = exportAttr.ConstructorArguments[1].Value?.ToString(); + if (string.IsNullOrWhiteSpace(hintStringValue)) + { + return false; + } + + hint = hintEnum; + hintString = hintStringValue; + + return true; + } + static string GetTypeName(INamedTypeSymbol memberSymbol) { if (memberSymbol.GetAttributes() |