summaryrefslogtreecommitdiffstats
path: root/modules/mono/editor
diff options
context:
space:
mode:
authorRaul Santos <raulsntos@gmail.com>2024-02-05 02:49:57 +0100
committerRaul Santos <raulsntos@gmail.com>2024-02-08 18:31:13 +0100
commit5815d1c8c821bab204caf46caf650a3cd009efa4 (patch)
tree5f7c073cfa7399511413b8abac9acb3072591c63 /modules/mono/editor
parent41564aaf7708b0bf594f745dd2448a54dd687cc5 (diff)
downloadredot-engine-5815d1c8c821bab204caf46caf650a3cd009efa4.tar.gz
Improve handling of generic C# types
- Create CSharpScript for generic C# types. - `ScriptPathAttributeGenerator` registers the path for the generic type definition. - `ScriptManagerBridge` lookup uses the generic type definition that was registered by the generator. - Constructed generic types use a virtual `csharp://` path so they can be registered in the map and loaded as if there was a different file for each constructed type, even though they all share the same real path. - This allows getting the base type for a C# type that derives from a generic type. - Shows base scripts in the _Add Node_ and _Create Resource_ dialogs even when they are generic types. - `get_global_class_name` implementation was moved to C# and now always returns the base type even if the script is not a global class (this behavior matches GDScript). - Create `CSharpScript::TypeInfo` struct to hold all the type information about the C# type that corresponds to the `CSharpScript`, and use it as the parameter in `UpdateScriptClassInfo` to avoid adding more parameters.
Diffstat (limited to 'modules/mono/editor')
-rw-r--r--modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptPathAttributeGenerator.cs6
-rw-r--r--modules/mono/editor/GodotTools/GodotTools/Inspector/InspectorPlugin.cs15
2 files changed, 16 insertions, 5 deletions
diff --git a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptPathAttributeGenerator.cs b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptPathAttributeGenerator.cs
index 01aafe9c74..d6d8a93e03 100644
--- a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptPathAttributeGenerator.cs
+++ b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptPathAttributeGenerator.cs
@@ -54,9 +54,7 @@ namespace Godot.SourceGenerators
)
.Where(x =>
// Ignore classes whose name is not the same as the file name
- Path.GetFileNameWithoutExtension(x.cds.SyntaxTree.FilePath) == x.symbol.Name &&
- // Ignore generic classes
- !x.symbol.IsGenericType)
+ Path.GetFileNameWithoutExtension(x.cds.SyntaxTree.FilePath) == x.symbol.Name)
.GroupBy(x => x.symbol)
.ToDictionary(g => g.Key, g => g.Select(x => x.cds));
@@ -160,6 +158,8 @@ namespace Godot.SourceGenerators
first = false;
sourceBuilder.Append("typeof(");
sourceBuilder.Append(qualifiedName);
+ if (godotClass.Key.IsGenericType)
+ sourceBuilder.Append($"<{new string(',', godotClass.Key.TypeParameters.Count() - 1)}>");
sourceBuilder.Append(")");
}
diff --git a/modules/mono/editor/GodotTools/GodotTools/Inspector/InspectorPlugin.cs b/modules/mono/editor/GodotTools/GodotTools/Inspector/InspectorPlugin.cs
index 323a0fb380..b86a2b8b24 100644
--- a/modules/mono/editor/GodotTools/GodotTools/Inspector/InspectorPlugin.cs
+++ b/modules/mono/editor/GodotTools/GodotTools/Inspector/InspectorPlugin.cs
@@ -1,3 +1,4 @@
+using System;
using System.Collections.Generic;
using Godot;
using GodotTools.Build;
@@ -23,9 +24,19 @@ namespace GodotTools.Inspector
{
foreach (var script in EnumerateScripts(godotObject))
{
- if (script is not CSharpScript) continue;
+ if (script is not CSharpScript)
+ continue;
- if (File.GetLastWriteTime(script.ResourcePath) > BuildManager.LastValidBuildDateTime)
+ string scriptPath = script.ResourcePath;
+ if (scriptPath.StartsWith("csharp://"))
+ {
+ // This is a virtual path used by generic types, extract the real path.
+ var scriptPathSpan = scriptPath.AsSpan("csharp://".Length);
+ scriptPathSpan = scriptPathSpan[..scriptPathSpan.IndexOf(':')];
+ scriptPath = $"res://{scriptPathSpan}";
+ }
+
+ if (File.GetLastWriteTime(scriptPath) > BuildManager.LastValidBuildDateTime)
{
AddCustomControl(new InspectorOutOfSyncWarning());
break;