Godot Engine – Multi-platform 2D and 3D game engine
[.NET]: Always add `class_name` to properties
Raul Santos27811823c298
diff --git a/modules/mono/csharp_script.cpp b/modules/mono/csharp_script.cppindex 9d795bec33c..e0c4a2bcb5d 100644--- a/modules/mono/csharp_script.cpp+++ b/modules/mono/csharp_script.cpp@@ -2215,7 +2215,13 @@ void GD_CLR_STDCALL CSharpScript::_add_property_info_list_callback(CSharpScriptStringName name = *reinterpret_cast<const StringName *>(&prop.name);String hint_string = *reinterpret_cast<const String *>(&prop.hint_string);- PropertyInfo pinfo(prop.type, name, prop.hint, hint_string, prop.usage);+ StringName class_name;+ const StringName *class_name_ptr = reinterpret_cast<const StringName *>(prop.class_name);+ if (class_name_ptr != nullptr) {+ class_name = *class_name_ptr;+ }++ PropertyInfo pinfo(prop.type, name, prop.hint, hint_string, prop.usage, class_name);p_script->member_info[name] = pinfo;diff --git a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Tests/TestData/GeneratedSources/ExportedFields_ScriptProperties.generated.cs b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Tests/TestData/GeneratedSources/ExportedFields_ScriptProperties.generated.csindex ab9a105d03f..fbab14a2aec 100644--- a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Tests/TestData/GeneratedSources/ExportedFields_ScriptProperties.generated.cs+++ b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Tests/TestData/GeneratedSources/ExportedFields_ScriptProperties.generated.cs@@ -1083,9 +1083,9 @@ partial class ExportedFieldsproperties.Add(new(type: (global::Godot.Variant.Type)30, name: PropertyName.@_fieldEmptyInt32Array, hint: (global::Godot.PropertyHint)0, hintString: "", usage: (global::Godot.PropertyUsageFlags)4102, exported: true));properties.Add(new(type: (global::Godot.Variant.Type)30, name: PropertyName.@_fieldArrayFromList, hint: (global::Godot.PropertyHint)0, hintString: "", usage: (global::Godot.PropertyUsageFlags)4102, exported: true));properties.Add(new(type: (global::Godot.Variant.Type)0, name: PropertyName.@_fieldVariant, hint: (global::Godot.PropertyHint)0, hintString: "", usage: (global::Godot.PropertyUsageFlags)135174, exported: true));- properties.Add(new(type: (global::Godot.Variant.Type)24, name: PropertyName.@_fieldGodotObjectOrDerived, hint: (global::Godot.PropertyHint)0, hintString: "", usage: (global::Godot.PropertyUsageFlags)4102, exported: true));- properties.Add(new(type: (global::Godot.Variant.Type)24, name: PropertyName.@_fieldGodotResourceTexture, hint: (global::Godot.PropertyHint)17, hintString: "Texture", usage: (global::Godot.PropertyUsageFlags)4102, exported: true));- properties.Add(new(type: (global::Godot.Variant.Type)24, name: PropertyName.@_fieldGodotResourceTextureWithInitializer, hint: (global::Godot.PropertyHint)17, hintString: "Texture", usage: (global::Godot.PropertyUsageFlags)4102, exported: true));+ properties.Add(new(type: (global::Godot.Variant.Type)24, name: PropertyName.@_fieldGodotObjectOrDerived, hint: (global::Godot.PropertyHint)0, hintString: "", usage: (global::Godot.PropertyUsageFlags)4102, exported: true, className: new global::Godot.StringName("Object")));+ properties.Add(new(type: (global::Godot.Variant.Type)24, name: PropertyName.@_fieldGodotResourceTexture, hint: (global::Godot.PropertyHint)17, hintString: "Texture", usage: (global::Godot.PropertyUsageFlags)4102, exported: true, className: new global::Godot.StringName("Texture")));+ properties.Add(new(type: (global::Godot.Variant.Type)24, name: PropertyName.@_fieldGodotResourceTextureWithInitializer, hint: (global::Godot.PropertyHint)17, hintString: "Texture", usage: (global::Godot.PropertyUsageFlags)4102, exported: true, className: new global::Godot.StringName("Texture")));properties.Add(new(type: (global::Godot.Variant.Type)21, name: PropertyName.@_fieldStringName, hint: (global::Godot.PropertyHint)0, hintString: "", usage: (global::Godot.PropertyUsageFlags)4102, exported: true));properties.Add(new(type: (global::Godot.Variant.Type)22, name: PropertyName.@_fieldNodePath, hint: (global::Godot.PropertyHint)0, hintString: "", usage: (global::Godot.PropertyUsageFlags)4102, exported: true));properties.Add(new(type: (global::Godot.Variant.Type)23, name: PropertyName.@_fieldRid, hint: (global::Godot.PropertyHint)0, hintString: "", usage: (global::Godot.PropertyUsageFlags)4102, exported: true));diff --git a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Tests/TestData/GeneratedSources/ExportedProperties_ScriptProperties.generated.cs b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Tests/TestData/GeneratedSources/ExportedProperties_ScriptProperties.generated.csindex 19a768200c5..9602de2fcd6 100644--- a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Tests/TestData/GeneratedSources/ExportedProperties_ScriptProperties.generated.cs+++ b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Tests/TestData/GeneratedSources/ExportedProperties_ScriptProperties.generated.cs@@ -1356,9 +1356,9 @@ partial class ExportedPropertiesproperties.Add(new(type: (global::Godot.Variant.Type)28, name: PropertyName.@field_NodePathArray, hint: (global::Godot.PropertyHint)23, hintString: "22/0:", usage: (global::Godot.PropertyUsageFlags)4102, exported: true));properties.Add(new(type: (global::Godot.Variant.Type)28, name: PropertyName.@field_RidArray, hint: (global::Godot.PropertyHint)23, hintString: "23/0:", usage: (global::Godot.PropertyUsageFlags)4102, exported: true));properties.Add(new(type: (global::Godot.Variant.Type)0, name: PropertyName.@PropertyVariant, hint: (global::Godot.PropertyHint)0, hintString: "", usage: (global::Godot.PropertyUsageFlags)135174, exported: true));- properties.Add(new(type: (global::Godot.Variant.Type)24, name: PropertyName.@PropertyGodotObjectOrDerived, hint: (global::Godot.PropertyHint)0, hintString: "", usage: (global::Godot.PropertyUsageFlags)4102, exported: true));- properties.Add(new(type: (global::Godot.Variant.Type)24, name: PropertyName.@PropertyGodotResourceTexture, hint: (global::Godot.PropertyHint)17, hintString: "Texture", usage: (global::Godot.PropertyUsageFlags)4102, exported: true));- properties.Add(new(type: (global::Godot.Variant.Type)24, name: PropertyName.@PropertyGodotResourceTextureWithInitializer, hint: (global::Godot.PropertyHint)17, hintString: "Texture", usage: (global::Godot.PropertyUsageFlags)4102, exported: true));+ properties.Add(new(type: (global::Godot.Variant.Type)24, name: PropertyName.@PropertyGodotObjectOrDerived, hint: (global::Godot.PropertyHint)0, hintString: "", usage: (global::Godot.PropertyUsageFlags)4102, exported: true, className: new global::Godot.StringName("Object")));+ properties.Add(new(type: (global::Godot.Variant.Type)24, name: PropertyName.@PropertyGodotResourceTexture, hint: (global::Godot.PropertyHint)17, hintString: "Texture", usage: (global::Godot.PropertyUsageFlags)4102, exported: true, className: new global::Godot.StringName("Texture")));+ properties.Add(new(type: (global::Godot.Variant.Type)24, name: PropertyName.@PropertyGodotResourceTextureWithInitializer, hint: (global::Godot.PropertyHint)17, hintString: "Texture", usage: (global::Godot.PropertyUsageFlags)4102, exported: true, className: new global::Godot.StringName("Texture")));properties.Add(new(type: (global::Godot.Variant.Type)21, name: PropertyName.@PropertyStringName, hint: (global::Godot.PropertyHint)0, hintString: "", usage: (global::Godot.PropertyUsageFlags)4102, exported: true));properties.Add(new(type: (global::Godot.Variant.Type)22, name: PropertyName.@PropertyNodePath, hint: (global::Godot.PropertyHint)0, hintString: "", usage: (global::Godot.PropertyUsageFlags)4102, exported: true));properties.Add(new(type: (global::Godot.Variant.Type)23, name: PropertyName.@PropertyRid, hint: (global::Godot.PropertyHint)0, hintString: "", usage: (global::Godot.PropertyUsageFlags)4102, exported: true));diff --git a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ExtensionMethods.cs b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ExtensionMethods.csindex c6304c90977..d54e6980ff9 100644--- a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ExtensionMethods.cs+++ b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ExtensionMethods.cs@@ -48,6 +48,17 @@ namespace Godot.SourceGeneratorsreturn false;}+ public static string? GetPropertyInfoClassName(this INamedTypeSymbol memberSymbol)+ {+ if (memberSymbol.GetAttributes()+ .Any(a => a.AttributeClass?.IsGodotGlobalClassAttribute() ?? false))+ {+ return memberSymbol.Name;+ }++ return memberSymbol.GetGodotScriptNativeClassName();+ }+public static INamedTypeSymbol? GetGodotScriptNativeClass(this INamedTypeSymbol classTypeSymbol){var symbol = classTypeSymbol;diff --git a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptMethodsGenerator.cs b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptMethodsGenerator.csindex 488657a7c87..4d6dab5db73 100644--- a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptMethodsGenerator.cs+++ b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptMethodsGenerator.cs@@ -368,7 +368,7 @@ namespace Godot.SourceGeneratorsstring? className = null;if (memberVariantType == VariantType.Object && typeSymbol is INamedTypeSymbol namedTypeSymbol){- className = namedTypeSymbol.GetGodotScriptNativeClassName();+ className = namedTypeSymbol.GetPropertyInfoClassName();}return new PropertyInfo(memberVariantType, name,diff --git a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptPropertiesGenerator.cs b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptPropertiesGenerator.csindex 012774cff6e..dadd9f263ec 100644--- a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptPropertiesGenerator.cs+++ b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptPropertiesGenerator.cs@@ -446,8 +446,14 @@ namespace Godot.SourceGenerators.Append("\", usage: (global::Godot.PropertyUsageFlags)").Append((int)propertyInfo.Usage).Append(", exported: ")- .Append(propertyInfo.Exported ? "true" : "false")- .Append("));\n");+ .Append(propertyInfo.Exported ? "true" : "false");+ if (propertyInfo.ClassName != null)+ {+ source.Append(", className: new global::Godot.StringName(\"")+ .Append(propertyInfo.ClassName)+ .Append("\")");+ }+ source.Append("));\n");}private static IEnumerable<PropertyInfo> DetermineGroupingPropertyInfo(ISymbol memberSymbol)@@ -623,6 +629,12 @@ namespace Godot.SourceGeneratorsvar memberVariantType = MarshalUtils.ConvertMarshalTypeToVariantType(marshalType)!.Value;string memberName = memberSymbol.Name;+ string? className = null;+ if (memberVariantType == VariantType.Object && memberType is INamedTypeSymbol namedTypeSymbol)+ {+ className = namedTypeSymbol.GetPropertyInfoClassName();+ }+string? hintString = null;if (exportToolButtonAttr != null)@@ -653,7 +665,7 @@ namespace Godot.SourceGeneratorsif (exportAttr == null){return new PropertyInfo(memberVariantType, memberName, PropertyHint.None,- hintString: hintString, PropertyUsageFlags.ScriptVariable, exported: false);+ hintString: hintString, PropertyUsageFlags.ScriptVariable, className, exported: false);}if (!TryGetMemberExportHint(typeCache, memberType, exportAttr, memberVariantType,@@ -688,7 +700,7 @@ namespace Godot.SourceGeneratorspropUsage |= PropertyUsageFlags.NilIsVariant;return new PropertyInfo(memberVariantType, memberName,- hint, hintString, propUsage, exported: true);+ hint, hintString, propUsage, className, exported: true);}private static bool TryGetMemberExportHint(@@ -784,7 +796,7 @@ namespace Godot.SourceGeneratorsif (memberNamedType.InheritsFrom("GodotSharp", "Godot.Resource")){hint = PropertyHint.ResourceType;- hintString = GetTypeName(memberNamedType);+ hintString = memberNamedType.GetPropertyInfoClassName();return true;}@@ -792,7 +804,7 @@ namespace Godot.SourceGeneratorsif (memberNamedType.InheritsFrom("GodotSharp", "Godot.Node")){hint = PropertyHint.NodeType;- hintString = GetTypeName(memberNamedType);+ hintString = memberNamedType.GetPropertyInfoClassName();return true;}@@ -830,17 +842,6 @@ namespace Godot.SourceGeneratorsreturn true;}- static string GetTypeName(INamedTypeSymbol memberSymbol)- {- if (memberSymbol.GetAttributes()- .Any(a => a.AttributeClass?.IsGodotGlobalClassAttribute() ?? false))- {- return memberSymbol.Name;- }-- return memberSymbol.GetGodotScriptNativeClassName()!;- }-static bool GetStringArrayEnumHint(VariantType elementVariantType,AttributeData exportAttr, out string? hintString){diff --git a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptSignalsGenerator.cs b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptSignalsGenerator.csindex d1bc86464f1..11937f3d80a 100644--- a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptSignalsGenerator.cs+++ b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptSignalsGenerator.cs@@ -486,7 +486,7 @@ namespace Godot.SourceGeneratorsstring? className = null;if (memberVariantType == VariantType.Object && typeSymbol is INamedTypeSymbol namedTypeSymbol){- className = namedTypeSymbol.GetGodotScriptNativeClassName();+ className = namedTypeSymbol.GetPropertyInfoClassName();}return new PropertyInfo(memberVariantType, name,diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Bridge/ScriptManagerBridge.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Bridge/ScriptManagerBridge.csindex 21d83f1547c..e17e163c170 100644--- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Bridge/ScriptManagerBridge.cs+++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Bridge/ScriptManagerBridge.cs@@ -1143,6 +1143,7 @@ namespace Godot.Bridgepublic int Type;public int Hint;public int Usage;+ public unsafe godot_string_name* ClassName; // Not ownedpublic godot_bool Exported;public void Dispose()@@ -1221,7 +1222,10 @@ namespace Godot.BridgeHint = (int)property.Hint,HintString = Marshaling.ConvertStringToNative(property.HintString),Usage = (int)property.Usage,- Exported = property.Exported.ToGodotBool()+ ClassName = property.ClassName is not null+ ? property.ClassName.NativeValue.DangerousSelfRef.GetUnsafeAddress() // Not owned+ : null,+ Exported = property.Exported.ToGodotBool(),};interopProperties[i] = interopProperty;diff --git a/modules/mono/mono_gd/gd_mono_cache.h b/modules/mono/mono_gd/gd_mono_cache.hindex 9cd5d6cee24..0434b7fc6d4 100644--- a/modules/mono/mono_gd/gd_mono_cache.h+++ b/modules/mono/mono_gd/gd_mono_cache.h@@ -59,6 +59,7 @@ struct godotsharp_property_info {Variant::Type type;PropertyHint hint;PropertyUsageFlags usage;+ godot_string_name *class_name; // Not ownedbool exported;};