Skip to content

armgit / godot

Public Imported from GitHub
0

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.cpp
index 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(CSharpScript
StringName 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.cs
index 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 ExportedFields
properties.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.cs
index 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 ExportedProperties
properties.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.cs
index 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.SourceGenerators
return 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.cs
index 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.SourceGenerators
string? 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.cs
index 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.SourceGenerators
var 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.SourceGenerators
if (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.SourceGenerators
propUsage |= 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.SourceGenerators
if (memberNamedType.InheritsFrom("GodotSharp", "Godot.Resource"))
{
hint = PropertyHint.ResourceType;
- hintString = GetTypeName(memberNamedType);
+ hintString = memberNamedType.GetPropertyInfoClassName();
return true;
}
@@ -792,7 +804,7 @@ namespace Godot.SourceGenerators
if (memberNamedType.InheritsFrom("GodotSharp", "Godot.Node"))
{
hint = PropertyHint.NodeType;
- hintString = GetTypeName(memberNamedType);
+ hintString = memberNamedType.GetPropertyInfoClassName();
return true;
}
@@ -830,17 +842,6 @@ namespace Godot.SourceGenerators
return 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.cs
index 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.SourceGenerators
string? 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.cs
index 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.Bridge
public int Type;
public int Hint;
public int Usage;
+ public unsafe godot_string_name* ClassName; // Not owned
public godot_bool Exported;
public void Dispose()
@@ -1221,7 +1222,10 @@ namespace Godot.Bridge
Hint = (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.h
index 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 owned
bool exported;
};