diff --git a/Godot 3 Tests/TestScenes/Feature93.AutoloadExtensions/AutoloadExtensionTests.cs b/Godot 3 Tests/TestScenes/Feature93.AutoloadExtensions/AutoloadExtensionTests.cs index bffb7b0..46bbd65 100644 --- a/Godot 3 Tests/TestScenes/Feature93.AutoloadExtensions/AutoloadExtensionTests.cs +++ b/Godot 3 Tests/TestScenes/Feature93.AutoloadExtensions/AutoloadExtensionTests.cs @@ -1,5 +1,3 @@ -#define RENAME_TEST - using System; using FluentAssertions; using FluentAssertions.Execution; @@ -8,6 +6,14 @@ namespace GodotTests.TestScenes; +[Autoload] +public static partial class MyAutoloads; + +[Autoload] +[AutoloadRename("NamedAutoLoad1", "namedAutoLoad1")] +[AutoloadRename("NamedAutoLoad2", "namedAutoLoad2")] +public static partial class MyAutoloadsWithRenames; + [SceneTree] public partial class AutoloadExtensionTests : Node, ITest { @@ -36,62 +42,98 @@ static void TypeTest() { static Type TypeOf(T _) => typeof(T); - TypeOf(Autoload.AutoloadScene).Should().Be(); - TypeOf(Autoload.AutoloadSceneCS).Should().Be(); - TypeOf(Autoload.AutoloadSceneGD).Should().Be(); + TypeOf(MyAutoloads.AutoloadScene).Should().Be(); + TypeOf(MyAutoloads.AutoloadSceneCS).Should().Be(); + TypeOf(MyAutoloads.AutoloadSceneGD).Should().Be(); + + TypeOf(MyAutoloads.InheritedScene).Should().Be(); + TypeOf(MyAutoloads.InheritedSceneCS).Should().Be(); + TypeOf(MyAutoloads.InheritedSceneGD).Should().Be(); + + TypeOf(MyAutoloads.AutoloadScriptCS).Should().Be(); + TypeOf(MyAutoloads.InheritedScriptCS).Should().Be(); - TypeOf(Autoload.InheritedScene).Should().Be(); - TypeOf(Autoload.InheritedSceneCS).Should().Be(); - TypeOf(Autoload.InheritedSceneGD).Should().Be(); + TypeOf(MyAutoloads.AutoloadScriptGD1).Should().Be(); + TypeOf(MyAutoloads.AutoloadScriptGD2).Should().Be(); + TypeOf(MyAutoloads.AutoloadScriptGD3).Should().Be(); - TypeOf(Autoload.AutoloadScriptCS).Should().Be(); - TypeOf(Autoload.InheritedScriptCS).Should().Be(); + TypeOf(MyAutoloads.InheritedScriptGD1).Should().Be(); // Can't currently resolve if extending by class name + TypeOf(MyAutoloads.InheritedScriptGD2).Should().Be(); + TypeOf(MyAutoloads.InheritedScriptGD3).Should().Be(); - TypeOf(Autoload.AutoloadScriptGD1).Should().Be(); - TypeOf(Autoload.AutoloadScriptGD2).Should().Be(); - TypeOf(Autoload.AutoloadScriptGD3).Should().Be(); + TypeOf(MyAutoloads.namedAutoLoad1).Should().Be(); + TypeOf(MyAutoloads.namedAutoLoad2).Should().Be(); - TypeOf(Autoload.InheritedScriptGD1).Should().Be(); // Can't currently resolve if extending by class name - TypeOf(Autoload.InheritedScriptGD2).Should().Be(); - TypeOf(Autoload.InheritedScriptGD3).Should().Be(); + // As above, so below (except those so marked) + TypeOf(MyAutoloadsWithRenames.AutoloadScene).Should().Be(); + TypeOf(MyAutoloadsWithRenames.AutoloadSceneCS).Should().Be(); + TypeOf(MyAutoloadsWithRenames.AutoloadSceneGD).Should().Be(); -#if RENAME_TEST - TypeOf(Autoload.NamedAutoLoad1).Should().Be(); - TypeOf(Autoload.NamedAutoLoad2).Should().Be(); -#else - TypeOf(Autoload.namedAutoLoad1).Should().Be(); - TypeOf(Autoload.namedAutoLoad2).Should().Be(); -#endif + TypeOf(MyAutoloadsWithRenames.InheritedScene).Should().Be(); + TypeOf(MyAutoloadsWithRenames.InheritedSceneCS).Should().Be(); + TypeOf(MyAutoloadsWithRenames.InheritedSceneGD).Should().Be(); + + TypeOf(MyAutoloadsWithRenames.AutoloadScriptCS).Should().Be(); + TypeOf(MyAutoloadsWithRenames.InheritedScriptCS).Should().Be(); + + TypeOf(MyAutoloadsWithRenames.AutoloadScriptGD1).Should().Be(); + TypeOf(MyAutoloadsWithRenames.AutoloadScriptGD2).Should().Be(); + TypeOf(MyAutoloadsWithRenames.AutoloadScriptGD3).Should().Be(); + + TypeOf(MyAutoloadsWithRenames.InheritedScriptGD1).Should().Be(); // Can't currently resolve if extending by class name + TypeOf(MyAutoloadsWithRenames.InheritedScriptGD2).Should().Be(); + TypeOf(MyAutoloadsWithRenames.InheritedScriptGD3).Should().Be(); + + TypeOf(MyAutoloadsWithRenames.NamedAutoLoad1).Should().Be(); // Renamed! + TypeOf(MyAutoloadsWithRenames.NamedAutoLoad2).Should().Be(); // Renamed! } static void ValueTest() { - Autoload.AutoloadScene.Should().NotBeNull().And.BeOfType(); - Autoload.AutoloadSceneCS.Should().NotBeNull().And.BeOfType(); - Autoload.AutoloadSceneGD.Should().NotBeNull().And.BeOfType(); - - Autoload.InheritedScene.Should().NotBeNull().And.BeOfType(); - Autoload.InheritedSceneCS.Should().NotBeNull().And.BeOfType(); - Autoload.InheritedSceneGD.Should().NotBeNull().And.BeOfType(); - - Autoload.AutoloadScriptCS.Should().NotBeNull().And.BeOfType(); - Autoload.InheritedScriptCS.Should().NotBeNull().And.BeOfType(); - - Autoload.AutoloadScriptGD1.Should().NotBeNull().And.BeOfType(); - Autoload.AutoloadScriptGD2.Should().NotBeNull().And.BeOfType(); - Autoload.AutoloadScriptGD3.Should().NotBeNull().And.BeOfType(); - - Autoload.InheritedScriptGD1.Should().NotBeNull().And.BeOfType(); - Autoload.InheritedScriptGD2.Should().NotBeNull().And.BeOfType(); - Autoload.InheritedScriptGD3.Should().NotBeNull().And.BeOfType(); - -#if RENAME_TEST - Autoload.NamedAutoLoad1.Should().NotBeNull().And.BeOfType(); - Autoload.NamedAutoLoad2.Should().NotBeNull().And.BeOfType(); -#else - Autoload.namedAutoLoad1.Should().NotBeNull().And.BeOfType(); - Autoload.namedAutoLoad2.Should().NotBeNull().And.BeOfType(); -#endif + MyAutoloads.AutoloadScene.Should().NotBeNull().And.BeOfType(); + MyAutoloads.AutoloadSceneCS.Should().NotBeNull().And.BeOfType(); + MyAutoloads.AutoloadSceneGD.Should().NotBeNull().And.BeOfType(); + + MyAutoloads.InheritedScene.Should().NotBeNull().And.BeOfType(); + MyAutoloads.InheritedSceneCS.Should().NotBeNull().And.BeOfType(); + MyAutoloads.InheritedSceneGD.Should().NotBeNull().And.BeOfType(); + + MyAutoloads.AutoloadScriptCS.Should().NotBeNull().And.BeOfType(); + MyAutoloads.InheritedScriptCS.Should().NotBeNull().And.BeOfType(); + + MyAutoloads.AutoloadScriptGD1.Should().NotBeNull().And.BeOfType(); + MyAutoloads.AutoloadScriptGD2.Should().NotBeNull().And.BeOfType(); + MyAutoloads.AutoloadScriptGD3.Should().NotBeNull().And.BeOfType(); + + MyAutoloads.InheritedScriptGD1.Should().NotBeNull().And.BeOfType(); + MyAutoloads.InheritedScriptGD2.Should().NotBeNull().And.BeOfType(); + MyAutoloads.InheritedScriptGD3.Should().NotBeNull().And.BeOfType(); + + MyAutoloads.namedAutoLoad1.Should().NotBeNull().And.BeOfType(); + MyAutoloads.namedAutoLoad2.Should().NotBeNull().And.BeOfType(); + + // As above, so below (except those so marked) + MyAutoloadsWithRenames.AutoloadScene.Should().NotBeNull().And.BeOfType(); + MyAutoloadsWithRenames.AutoloadSceneCS.Should().NotBeNull().And.BeOfType(); + MyAutoloadsWithRenames.AutoloadSceneGD.Should().NotBeNull().And.BeOfType(); + + MyAutoloadsWithRenames.InheritedScene.Should().NotBeNull().And.BeOfType(); + MyAutoloadsWithRenames.InheritedSceneCS.Should().NotBeNull().And.BeOfType(); + MyAutoloadsWithRenames.InheritedSceneGD.Should().NotBeNull().And.BeOfType(); + + MyAutoloadsWithRenames.AutoloadScriptCS.Should().NotBeNull().And.BeOfType(); + MyAutoloadsWithRenames.InheritedScriptCS.Should().NotBeNull().And.BeOfType(); + + MyAutoloadsWithRenames.AutoloadScriptGD1.Should().NotBeNull().And.BeOfType(); + MyAutoloadsWithRenames.AutoloadScriptGD2.Should().NotBeNull().And.BeOfType(); + MyAutoloadsWithRenames.AutoloadScriptGD3.Should().NotBeNull().And.BeOfType(); + + MyAutoloadsWithRenames.InheritedScriptGD1.Should().NotBeNull().And.BeOfType(); + MyAutoloadsWithRenames.InheritedScriptGD2.Should().NotBeNull().And.BeOfType(); + MyAutoloadsWithRenames.InheritedScriptGD3.Should().NotBeNull().And.BeOfType(); + + MyAutoloadsWithRenames.NamedAutoLoad1.Should().NotBeNull().And.BeOfType(); // Renamed! + MyAutoloadsWithRenames.NamedAutoLoad2.Should().NotBeNull().And.BeOfType(); // Renamed! } void EnsureIsInTree() diff --git a/Godot 3 Tests/TestScenes/Feature93.AutoloadExtensions/AutoloadRenameTest.cs b/Godot 3 Tests/TestScenes/Feature93.AutoloadExtensions/AutoloadRenameTest.cs deleted file mode 100644 index 52ff7d5..0000000 --- a/Godot 3 Tests/TestScenes/Feature93.AutoloadExtensions/AutoloadRenameTest.cs +++ /dev/null @@ -1,11 +0,0 @@ -#define RENAME_TEST - -#if RENAME_TEST -namespace Godot; - -[AutoloadRename("NamedAutoLoad1", "namedAutoLoad1")] -[AutoloadRename("NamedAutoLoad2", "namedAutoLoad2")] -public static partial class Autoload -{ -} -#endif diff --git a/Godot 4 Tests/TestScenes/Feature93.AutoloadExtensions/AutoloadExtensionTests.cs b/Godot 4 Tests/TestScenes/Feature93.AutoloadExtensions/AutoloadExtensionTests.cs index d02b5a8..88e08d8 100644 --- a/Godot 4 Tests/TestScenes/Feature93.AutoloadExtensions/AutoloadExtensionTests.cs +++ b/Godot 4 Tests/TestScenes/Feature93.AutoloadExtensions/AutoloadExtensionTests.cs @@ -1,5 +1,3 @@ -#define RENAME_TEST - using System; using FluentAssertions; using FluentAssertions.Execution; @@ -8,6 +6,14 @@ namespace GodotTests.TestScenes; +[Autoload] +public static partial class MyAutoloads; + +[Autoload] +[AutoloadRename("NamedAutoLoad1", "namedAutoLoad1")] +[AutoloadRename("NamedAutoLoad2", "namedAutoLoad2")] +public static partial class MyAutoloadsWithRenames; + [SceneTree] public partial class AutoloadExtensionTests : Node, ITest { @@ -36,61 +42,98 @@ static void TypeTest() { static Type TypeOf(T _) => typeof(T); - TypeOf(Autoload.AutoloadScene).Should().Be(); - TypeOf(Autoload.AutoloadSceneCS).Should().Be(); - TypeOf(Autoload.AutoloadSceneGD).Should().Be(); - - TypeOf(Autoload.InheritedScene).Should().Be(); - TypeOf(Autoload.InheritedSceneCS).Should().Be(); - TypeOf(Autoload.InheritedSceneGD).Should().Be(); - - TypeOf(Autoload.AutoloadScriptCS).Should().Be(); - TypeOf(Autoload.InheritedScriptCS).Should().Be(); - - TypeOf(Autoload.AutoloadScriptGD1).Should().Be(); - TypeOf(Autoload.AutoloadScriptGD2).Should().Be(); - TypeOf(Autoload.AutoloadScriptGD3).Should().Be(); - - TypeOf(Autoload.InheritedScriptGD1).Should().Be(); // Can't currently resolve if extending by class name - TypeOf(Autoload.InheritedScriptGD2).Should().Be(); - TypeOf(Autoload.InheritedScriptGD3).Should().Be(); -#if RENAME_TEST - TypeOf(Autoload.NamedAutoLoad1).Should().Be(); - TypeOf(Autoload.NamedAutoLoad2).Should().Be(); -#else - TypeOf(Autoload.namedAutoLoad1).Should().Be(); - TypeOf(Autoload.namedAutoLoad2).Should().Be(); -#endif + TypeOf(MyAutoloads.AutoloadScene).Should().Be(); + TypeOf(MyAutoloads.AutoloadSceneCS).Should().Be(); + TypeOf(MyAutoloads.AutoloadSceneGD).Should().Be(); + + TypeOf(MyAutoloads.InheritedScene).Should().Be(); + TypeOf(MyAutoloads.InheritedSceneCS).Should().Be(); + TypeOf(MyAutoloads.InheritedSceneGD).Should().Be(); + + TypeOf(MyAutoloads.AutoloadScriptCS).Should().Be(); + TypeOf(MyAutoloads.InheritedScriptCS).Should().Be(); + + TypeOf(MyAutoloads.AutoloadScriptGD1).Should().Be(); + TypeOf(MyAutoloads.AutoloadScriptGD2).Should().Be(); + TypeOf(MyAutoloads.AutoloadScriptGD3).Should().Be(); + + TypeOf(MyAutoloads.InheritedScriptGD1).Should().Be(); // Can't currently resolve if extending by class name + TypeOf(MyAutoloads.InheritedScriptGD2).Should().Be(); + TypeOf(MyAutoloads.InheritedScriptGD3).Should().Be(); + + TypeOf(MyAutoloads.namedAutoLoad1).Should().Be(); + TypeOf(MyAutoloads.namedAutoLoad2).Should().Be(); + + // As above, so below (except those so marked) + TypeOf(MyAutoloadsWithRenames.AutoloadScene).Should().Be(); + TypeOf(MyAutoloadsWithRenames.AutoloadSceneCS).Should().Be(); + TypeOf(MyAutoloadsWithRenames.AutoloadSceneGD).Should().Be(); + + TypeOf(MyAutoloadsWithRenames.InheritedScene).Should().Be(); + TypeOf(MyAutoloadsWithRenames.InheritedSceneCS).Should().Be(); + TypeOf(MyAutoloadsWithRenames.InheritedSceneGD).Should().Be(); + + TypeOf(MyAutoloadsWithRenames.AutoloadScriptCS).Should().Be(); + TypeOf(MyAutoloadsWithRenames.InheritedScriptCS).Should().Be(); + + TypeOf(MyAutoloadsWithRenames.AutoloadScriptGD1).Should().Be(); + TypeOf(MyAutoloadsWithRenames.AutoloadScriptGD2).Should().Be(); + TypeOf(MyAutoloadsWithRenames.AutoloadScriptGD3).Should().Be(); + + TypeOf(MyAutoloadsWithRenames.InheritedScriptGD1).Should().Be(); // Can't currently resolve if extending by class name + TypeOf(MyAutoloadsWithRenames.InheritedScriptGD2).Should().Be(); + TypeOf(MyAutoloadsWithRenames.InheritedScriptGD3).Should().Be(); + + TypeOf(MyAutoloadsWithRenames.NamedAutoLoad1).Should().Be(); // Renamed! + TypeOf(MyAutoloadsWithRenames.NamedAutoLoad2).Should().Be(); // Renamed! } static void ValueTest() { - Autoload.AutoloadScene.Should().NotBeNull().And.BeOfType(); - Autoload.AutoloadSceneCS.Should().NotBeNull().And.BeOfType(); - Autoload.AutoloadSceneGD.Should().NotBeNull().And.BeOfType(); - - Autoload.InheritedScene.Should().NotBeNull().And.BeOfType(); - Autoload.InheritedSceneCS.Should().NotBeNull().And.BeOfType(); - Autoload.InheritedSceneGD.Should().NotBeNull().And.BeOfType(); - - Autoload.AutoloadScriptCS.Should().NotBeNull().And.BeOfType(); - Autoload.InheritedScriptCS.Should().NotBeNull().And.BeOfType(); - - Autoload.AutoloadScriptGD1.Should().NotBeNull().And.BeOfType(); - Autoload.AutoloadScriptGD2.Should().NotBeNull().And.BeOfType(); - Autoload.AutoloadScriptGD3.Should().NotBeNull().And.BeOfType(); - - Autoload.InheritedScriptGD1.Should().NotBeNull().And.BeOfType(); - Autoload.InheritedScriptGD2.Should().NotBeNull().And.BeOfType(); - Autoload.InheritedScriptGD3.Should().NotBeNull().And.BeOfType(); - -#if RENAME_TEST - Autoload.NamedAutoLoad1.Should().NotBeNull().And.BeOfType(); - Autoload.NamedAutoLoad2.Should().NotBeNull().And.BeOfType(); -#else - Autoload.namedAutoLoad1.Should().NotBeNull().And.BeOfType(); - Autoload.namedAutoLoad2.Should().NotBeNull().And.BeOfType(); -#endif + MyAutoloads.AutoloadScene.Should().NotBeNull().And.BeOfType(); + MyAutoloads.AutoloadSceneCS.Should().NotBeNull().And.BeOfType(); + MyAutoloads.AutoloadSceneGD.Should().NotBeNull().And.BeOfType(); + + MyAutoloads.InheritedScene.Should().NotBeNull().And.BeOfType(); + MyAutoloads.InheritedSceneCS.Should().NotBeNull().And.BeOfType(); + MyAutoloads.InheritedSceneGD.Should().NotBeNull().And.BeOfType(); + + MyAutoloads.AutoloadScriptCS.Should().NotBeNull().And.BeOfType(); + MyAutoloads.InheritedScriptCS.Should().NotBeNull().And.BeOfType(); + + MyAutoloads.AutoloadScriptGD1.Should().NotBeNull().And.BeOfType(); + MyAutoloads.AutoloadScriptGD2.Should().NotBeNull().And.BeOfType(); + MyAutoloads.AutoloadScriptGD3.Should().NotBeNull().And.BeOfType(); + + MyAutoloads.InheritedScriptGD1.Should().NotBeNull().And.BeOfType(); + MyAutoloads.InheritedScriptGD2.Should().NotBeNull().And.BeOfType(); + MyAutoloads.InheritedScriptGD3.Should().NotBeNull().And.BeOfType(); + + MyAutoloads.namedAutoLoad1.Should().NotBeNull().And.BeOfType(); + MyAutoloads.namedAutoLoad2.Should().NotBeNull().And.BeOfType(); + + // As above, so below (except those so marked) + MyAutoloadsWithRenames.AutoloadScene.Should().NotBeNull().And.BeOfType(); + MyAutoloadsWithRenames.AutoloadSceneCS.Should().NotBeNull().And.BeOfType(); + MyAutoloadsWithRenames.AutoloadSceneGD.Should().NotBeNull().And.BeOfType(); + + MyAutoloadsWithRenames.InheritedScene.Should().NotBeNull().And.BeOfType(); + MyAutoloadsWithRenames.InheritedSceneCS.Should().NotBeNull().And.BeOfType(); + MyAutoloadsWithRenames.InheritedSceneGD.Should().NotBeNull().And.BeOfType(); + + MyAutoloadsWithRenames.AutoloadScriptCS.Should().NotBeNull().And.BeOfType(); + MyAutoloadsWithRenames.InheritedScriptCS.Should().NotBeNull().And.BeOfType(); + + MyAutoloadsWithRenames.AutoloadScriptGD1.Should().NotBeNull().And.BeOfType(); + MyAutoloadsWithRenames.AutoloadScriptGD2.Should().NotBeNull().And.BeOfType(); + MyAutoloadsWithRenames.AutoloadScriptGD3.Should().NotBeNull().And.BeOfType(); + + MyAutoloadsWithRenames.InheritedScriptGD1.Should().NotBeNull().And.BeOfType(); + MyAutoloadsWithRenames.InheritedScriptGD2.Should().NotBeNull().And.BeOfType(); + MyAutoloadsWithRenames.InheritedScriptGD3.Should().NotBeNull().And.BeOfType(); + + MyAutoloadsWithRenames.NamedAutoLoad1.Should().NotBeNull().And.BeOfType(); // Renamed! + MyAutoloadsWithRenames.NamedAutoLoad2.Should().NotBeNull().And.BeOfType(); // Renamed! } void EnsureIsInTree() diff --git a/Godot 4 Tests/TestScenes/Feature93.AutoloadExtensions/AutoloadRenameTest.cs b/Godot 4 Tests/TestScenes/Feature93.AutoloadExtensions/AutoloadRenameTest.cs deleted file mode 100644 index 52ff7d5..0000000 --- a/Godot 4 Tests/TestScenes/Feature93.AutoloadExtensions/AutoloadRenameTest.cs +++ /dev/null @@ -1,11 +0,0 @@ -#define RENAME_TEST - -#if RENAME_TEST -namespace Godot; - -[AutoloadRename("NamedAutoLoad1", "namedAutoLoad1")] -[AutoloadRename("NamedAutoLoad2", "namedAutoLoad2")] -public static partial class Autoload -{ -} -#endif diff --git a/README.md b/README.md index 3b9c7f7..3a6cf35 100644 --- a/README.md +++ b/README.md @@ -2,10 +2,13 @@ C# Source Generators for use with the Godot Game Engine -- NB: On GitHub, items marked as [NEW] are only available in pre-release (ie, well tested, but subject to subtle API changes - a good opportunity to test against your own use cases!) -- NB: Version 2.7 introduces an ever so slight [BREAKING CHANGE] in that identifiers comprised of unicode characters no longer need to be prefixed with `_` and other invalid characters are now removed instead of being replaced with `_`. -- NB: Version 2.7 introduces an ever so slight [BREAKING CHANGE] in that scope strings have been replaced with a more definitive enum set. +## Notes + - On GitHub, items marked as [NEW] are only available in pre-release (ie, well tested, but subject to subtle API changes - a good opportunity to test against your own use cases!) + - Version 2.7 introduces an ever so slight [BREAKING CHANGE] in that identifiers comprised of unicode characters no longer need to be prefixed with `_` and other invalid characters are now removed instead of being replaced with `_`. + - Version 2.7 introduces an ever so slight [BREAKING CHANGE] in that the Autoload class must now be explicitly decorated instead of implicitly generated. + - Version 2.7 introduces an ever so slight [BREAKING CHANGE] in that scope strings have been replaced with a more definitive enum set. +## Features * `SceneTree` class attribute: * Provides strongly typed access to the scene hierarchy (via `_` operator) * Generates direct access to uniquely named nodes via class properties @@ -64,13 +67,14 @@ C# Source Generators for use with the Godot Game Engine - Version 1.x supports Godot 3 only - Version 2.x supports Godot 3 & 4 - Version 3.x will support Godot 4 only -- Post comments/questions/suggestions in the discussion area or raise an issue :) ## Table of Contents - [GodotSharp.SourceGenerators](#godotsharpsourcegenerators) + - [Notes](#notes) + - [Features](#features) - [Table of Contents](#table-of-contents) - [Installation](#installation) - - [Attributes](#attributes) + - [Documentation](#documentation) - [`SceneTree`](#scenetree) - [`ResourceTree`](#resourcetree) - [`Singleton`](#singleton) @@ -94,7 +98,7 @@ C# Source Generators for use with the Godot Game Engine ## Installation Install via [NuGet](https://www.nuget.org/packages/GodotSharp.SourceGenerators) -## Attributes +## Documentation ### `SceneTree` * Class attribute @@ -1161,12 +1165,12 @@ public static partial class MyLayers ``` ### `Autoload` - * `Autoload` is a generated class (ie, not attribute) in Godot namespace + * `Autoload` class attribute * Provides strongly typed access to autoload nodes defined in editor project settings * Supports tscn nodes & gd/cs scripts with C# compatible types inferred wherever possible - * `AutoloadRename` is an additional attribute that can be used to provide C# friendly names -eg, for the following autoloads (defined in project.godot): + * `AutoloadRename` is an additional attribute that can be used to provide C# friendly names if required #### Examples: +project.godot: ```project.godot [autoload] @@ -1174,18 +1178,15 @@ gd_utils="*res://addons/handy_utils/gd_utils.gd" cs_utils="*res://addons/silly_sausage/MyUtils.cs" DebugMenu="*res://addons/debug_menu/debug_menu.tscn" ``` -With the following renames (optionally defined in your project): +C#: ```cs -namespace Godot; - +[Autoload] [AutoloadRename("UtilsGD", "gd_utils")] [AutoloadRename("UtilsCS", "cs_utils")] static partial class Autoload; ``` Generates: ```cs -namespace Godot; - static partial class Autoload { private static Node root = (Engine.GetMainLoop() as SceneTree)?.Root; diff --git a/SourceGenerators/AutoloadExtensions/AutoloadAttribute.cs b/SourceGenerators/AutoloadExtensions/AutoloadAttribute.cs index 3c6fe2a..0a9d0bd 100644 --- a/SourceGenerators/AutoloadExtensions/AutoloadAttribute.cs +++ b/SourceGenerators/AutoloadExtensions/AutoloadAttribute.cs @@ -1,12 +1,7 @@ -using System.Runtime.CompilerServices; - -namespace Godot; +namespace Godot; [AttributeUsage(AttributeTargets.Class)] -public class AutoloadAttribute([CallerFilePath] string ClassPath = null) : Attribute -{ - public string ClassPath { get; } = ClassPath; -} +public sealed class AutoloadAttribute() : Attribute; [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] public sealed class AutoloadRenameAttribute(string DisplayName, string GodotName) : Attribute diff --git a/SourceGenerators/AutoloadExtensions/AutoloadDataModel.cs b/SourceGenerators/AutoloadExtensions/AutoloadDataModel.cs index 9c21869..b9296ab 100644 --- a/SourceGenerators/AutoloadExtensions/AutoloadDataModel.cs +++ b/SourceGenerators/AutoloadExtensions/AutoloadDataModel.cs @@ -2,19 +2,13 @@ namespace GodotSharp.SourceGenerators.AutoloadExtensions; -internal class AutoloadDataModel : ClassDataModel -{ - public record AutoloadData(string Type, string GodotName, string DisplayName); - - public IList Autoloads { get; } +internal record AutoloadData(string Type, string GodotName, string DisplayName); - public AutoloadDataModel(Compilation compilation, INamedTypeSymbol symbol, string csPath, string gdRoot, IDictionary lookup) - : base(symbol) - { - Autoloads = AutoloadScraper.GetAutoloads(compilation, csPath, gdRoot) - .Select(autoload => new AutoloadData(autoload.Type, autoload.Name, lookup.Get(autoload.Name) ?? autoload.Name)) - .ToArray(); - } +internal class AutoloadDataModel(Compilation compilation, INamedTypeSymbol symbol, string csPath, string gdRoot, IDictionary lookup) : ClassDataModel(symbol) +{ + public IList Autoloads { get; } = [.. + AutoloadScraper.GetAutoloads(compilation, csPath, gdRoot) + .Select(autoload => new AutoloadData(autoload.Type, autoload.Name, lookup.Get(autoload.Name) ?? autoload.Name))]; protected override string Str() => string.Join("\n", Autoloads); diff --git a/SourceGenerators/AutoloadExtensions/AutoloadSourceGenerator.cs b/SourceGenerators/AutoloadExtensions/AutoloadSourceGenerator.cs index 69f0018..fcf27fb 100644 --- a/SourceGenerators/AutoloadExtensions/AutoloadSourceGenerator.cs +++ b/SourceGenerators/AutoloadExtensions/AutoloadSourceGenerator.cs @@ -8,37 +8,29 @@ namespace GodotSharp.SourceGenerators.AutoloadExtensions; internal class AutoloadSourceGenerator : SourceGeneratorForDeclaredTypeWithAttribute { private static Template AutoloadTemplate => field ??= Template.Parse(Resources.AutoloadTemplate); + private static readonly string RenameAttribute = typeof(Godot.AutoloadRenameAttribute).Name; - protected override IEnumerable<(string Name, string Source)> StaticSources + protected override (string GeneratedCode, DiagnosticDetail Error) GenerateCode(Compilation compilation, SyntaxNode node, INamedTypeSymbol symbol, AttributeData attribute, AnalyzerConfigOptions options) { - get - { - yield return (nameof(Resources.AutoloadExtensions), Resources.AutoloadExtensions); - } - } + var csPath = GD.CS(node); + var gdRoot = GD.ROOT(options, csPath); + var lookup = GetAutoloadRenames(); - protected override (string GeneratedCode, DiagnosticDetail Error) GenerateCode(Compilation compilation, SyntaxNode _, INamedTypeSymbol symbol, AttributeData attribute, AnalyzerConfigOptions options) - { - var model = new AutoloadDataModel(compilation, symbol, ReconstructAttribute().ClassPath, options.TryGetGodotProjectDir(), GetAutoloadRenameLookup()); + var model = new AutoloadDataModel(compilation, symbol, csPath, gdRoot, lookup); Log.Debug($"--- MODEL ---\n{model}\n"); - var output = AutoloadTemplate.Render(model, member => member.Name); + var output = AutoloadTemplate.Render(model, Shared.Utils); Log.Debug($"--- OUTPUT ---\n{output}\n"); return (output, null); - Godot.AutoloadAttribute ReconstructAttribute() - => new((string)attribute.ConstructorArguments[0].Value); - - IDictionary GetAutoloadRenameLookup() + IDictionary GetAutoloadRenames() { return symbol.GetAttributes() .Where(x => x.AttributeClass.Name == RenameAttribute) .ToDictionary( - x => (string)x.ConstructorArguments[1].Value, // GodotName - x => (string)x.ConstructorArguments[0].Value); // DisplayName + x => (string)x.ConstructorArguments[1].Value, // 1: GodotName + x => (string)x.ConstructorArguments[0].Value); // 0: DisplayName } } - - private static readonly string RenameAttribute = typeof(Godot.AutoloadRenameAttribute).Name; } diff --git a/SourceGenerators/AutoloadExtensions/AutoloadTemplate.scriban b/SourceGenerators/AutoloadExtensions/AutoloadTemplate.scriban index ab17f65..6bbc934 100644 --- a/SourceGenerators/AutoloadExtensions/AutoloadTemplate.scriban +++ b/SourceGenerators/AutoloadExtensions/AutoloadTemplate.scriban @@ -1,17 +1,17 @@ -using System; -using System.ComponentModel; +{{-#####-CONTENT-#####-}} -namespace Godot; - -static partial class {{ClassName}} -{ +{{~ capture body ~}} private static Node root = (Engine.GetMainLoop() as SceneTree)?.Root; {{~ for autoload in Autoloads ~}} - [EditorBrowsable(EditorBrowsableState.Never)] + [{{EditorBrowsableNever}}] private static {{autoload.Type}} _{{autoload.DisplayName}}; /// Autoload: {{autoload.GodotName}} public static {{autoload.Type}} {{autoload.DisplayName}} => _{{autoload.DisplayName}} ??= root?.GetNodeOrNull<{{autoload.Type}}>("{{autoload.GodotName}}"); {{~ end ~}} -} +{{~ end ~}} + +{{-#####-MAIN-#####-}} + +{{~ RenderClass body ~}} diff --git a/SourceGenerators/AutoloadExtensions/Resources.cs b/SourceGenerators/AutoloadExtensions/Resources.cs index 0c42384..fbda4eb 100644 --- a/SourceGenerators/AutoloadExtensions/Resources.cs +++ b/SourceGenerators/AutoloadExtensions/Resources.cs @@ -6,19 +6,4 @@ internal static class Resources { private const string autoloadTemplate = "GodotSharp.SourceGenerators.AutoloadExtensions.AutoloadTemplate.scriban"; public static readonly string AutoloadTemplate = Assembly.GetExecutingAssembly().GetEmbeddedResource(autoloadTemplate); - - public static readonly string AutoloadExtensions = @" - -#if GODOT - -namespace Godot; - -[Autoload] -public static partial class Autoload -{ -} - -#endif - -".Trim(); } diff --git a/SourceGenerators/InstantiableExtensions/InstantiableTemplate.scriban b/SourceGenerators/InstantiableExtensions/InstantiableTemplate.scriban index c02eca3..03d8e00 100644 --- a/SourceGenerators/InstantiableExtensions/InstantiableTemplate.scriban +++ b/SourceGenerators/InstantiableExtensions/InstantiableTemplate.scriban @@ -1,10 +1,10 @@ {{-#####-CONTENT-#####-}} {{~ capture body ~}} - [EditorBrowsable(EditorBrowsableState.Never)] + [{{EditorBrowsableNever}}] private static PackedScene __{{ClassName}}; - [EditorBrowsable(EditorBrowsableState.Never)] + [{{EditorBrowsableNever}}] private static PackedScene _{{ClassName}} => __{{ClassName}} ??= GD.Load("{{Tscn}}"); #nullable restore diff --git a/SourceGenerators/Shared/Utils.scriban b/SourceGenerators/Shared/Utils.scriban index 29a95cb..f5b0764 100644 --- a/SourceGenerators/Shared/Utils.scriban +++ b/SourceGenerators/Shared/Utils.scriban @@ -43,14 +43,20 @@ end-}} ret lines | array.join '\n' end-}} +{{-func EditorBrowsable(state)-}} + System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.{{state}}) +{{-end-}} + +{{-func EditorBrowsableNever-}} + {{EditorBrowsable "Never"}} +{{-end-}} + {{-#######################-}} {{-#####-RenderClass-#####-}} {{-#######################-}} {{-func RenderClass(body, extension_methods=null, helper_classes=null)-}} using System; -using System.ComponentModel; - using Godot; {{~ Namespace ~}} diff --git a/SourceGenerators/SingletonExtensions/SingletonTemplate.scriban b/SourceGenerators/SingletonExtensions/SingletonTemplate.scriban index 7ac3f1d..e11f8bf 100644 --- a/SourceGenerators/SingletonExtensions/SingletonTemplate.scriban +++ b/SourceGenerators/SingletonExtensions/SingletonTemplate.scriban @@ -11,7 +11,13 @@ {{- capture init -}} {{- if Init -}} {{Init}}({{new}}); - [EditorBrowsable(EditorBrowsableState.Never)] private static {{ClassName}} {{Init}}({{ClassName}} x) { x.{{Init}}(); return x; } + + [{{EditorBrowsableNever}}] + private static {{ClassName}} {{Init}}({{ClassName}} x) + { + x.{{Init}}(); + return x; + } {{- else -}} {{new}}; {{- end -}} @@ -19,6 +25,7 @@ {{~ capture body ~}} public static {{ClassName}} Instance { get; } = {{init}} + private {{ClassName}}() {} {{~ end ~}} diff --git a/SourceGenerators/SourceGenerators.csproj b/SourceGenerators/SourceGenerators.csproj index 0549783..96cfb6e 100644 --- a/SourceGenerators/SourceGenerators.csproj +++ b/SourceGenerators/SourceGenerators.csproj @@ -14,137 +14,139 @@ - C# Source Generators for use with the Godot Game Engine - - - NB: Version 2.7 introduces an ever so slight [BREAKING CHANGE] in that identifiers comprised of unicode characters no longer need to be prefixed with `_` and other invalid characters are now removed instead of being replaced with `_`. - - NB: Version 2.7 introduces an ever so slight [BREAKING CHANGE] in that scope strings have been replaced with a more definitive enum set. - - * `SceneTree` class attribute: - -- Provides strongly typed access to the scene hierarchy (via `_` operator) - -- Generates direct access to uniquely named nodes via class properties - -- Provides static access to TscnFilePath - -- Provides static Instantiate method - * [NEW] `ResourceTree` class attribute (GD4 only): - -- Provides strongly typed access to the resource hierarchy - * [NEW] `Singleton` class attribute (GD4 only): - -- Provides single instance access to data or scene objects - * [NEW] `Shader` class attribute (GD4 only): - -- Provides strongly typed access to shader uniforms - * [NEW] `AutoEnum` class attribute (GD4 only): - -- Generates enum conversions for static data classes - * [NEW] `AutoEnum` enum attribute (GD4 only): - -- Generates efficient Str/Parse for enums - * [NEW] `AudioBus` class attribute (GD4 only): - -- Provides strongly typed access to audio bus names and ids - * [NEW] `AnimNames` class attribute (GD4 only): - -- Provides strongly typed access to animation names defined in .tres and .tscn files - * [NEW] `GlobalGroups` class attribute (GD4 only): - -- Provides strongly typed access to global groups defined in godot.project - * [NEW] `Instantiable` class attribute (GD4 only): - -- Generates configurable static methods to instantiate scene - * [NEW] `TR` class attribute (GD4 only): - -- Provides strongly typed access to translation locales and keys (as defined in csv) - * `GodotOverride` method attribute: - -- Allows use of On*, instead of virtual _* overrides - -- (Requires partial method declaration for use with Godot 4) - * `Notify` property attribute: - -- Generates boiler plate code, triggering only when values differ - -- (Automagically triggers nested changes for Resource and Resource[]) - * `InputMap` class attribute: - -- Provides strongly typed access to input actions defined in godot.project - -- Attribute option to replace StringName with your own custom object/handler - * `LayerNames` class attribute: - -- Provide strongly typed access to layer names defined in godot.project - * `Autoload`/`AutoloadRename` class attribute: - -- Provide strongly typed access to autoload nodes defined in godot.project - * `CodeComments` class attribute: - -- Provides a nested static class to access property comments from code (useful for in-game tooltips, etc) - * `OnInstantiate` method attribute: - -- Generates a static Instantiate method with matching args that calls attributed method as part of the instantiation process - -- (Also generates a protected constructor to ensure proper initialisation - can be deactivated via attribute) - * `OnImport` method attribute (GD4 only): - -- Generates default plugin overrides and options to make plugin class cleaner (inherit from OnImportEditorPlugin) - * Includes base classes/helpers to create project specific source generators - + C# Source Generators for use with the Godot Game Engine + + - NB: Version 2.7 introduces an ever so slight [BREAKING CHANGE] in that identifiers comprised of unicode characters no longer need to be prefixed with `_` and other invalid characters are now removed instead of being replaced with `_`. + - NB: Version 2.7 introduces an ever so slight [BREAKING CHANGE] in that the Autoload class must now be explicitly decorated instead of implicitly generated. + - NB: Version 2.7 introduces an ever so slight [BREAKING CHANGE] in that scope strings have been replaced with a more definitive enum set. + + * `SceneTree` class attribute: + -- Provides strongly typed access to the scene hierarchy (via `_` operator) + -- Generates direct access to uniquely named nodes via class properties + -- Provides static access to TscnFilePath + -- Provides static Instantiate method + * [NEW] `ResourceTree` class attribute (GD4 only): + -- Provides strongly typed access to the resource hierarchy + * [NEW] `Singleton` class attribute (GD4 only): + -- Provides single instance access to data or scene objects + * [NEW] `Shader` class attribute (GD4 only): + -- Provides strongly typed access to shader uniforms + * [NEW] `AutoEnum` class attribute (GD4 only): + -- Generates enum conversions for static data classes + * [NEW] `AutoEnum` enum attribute (GD4 only): + -- Generates efficient Str/Parse for enums + * [NEW] `AudioBus` class attribute (GD4 only): + -- Provides strongly typed access to audio bus names and ids + * [NEW] `AnimNames` class attribute (GD4 only): + -- Provides strongly typed access to animation names defined in .tres and .tscn files + * [NEW] `GlobalGroups` class attribute (GD4 only): + -- Provides strongly typed access to global groups defined in godot.project + * [NEW] `Instantiable` class attribute (GD4 only): + -- Generates configurable static methods to instantiate scene + * [NEW] `TR` class attribute (GD4 only): + -- Provides strongly typed access to translation locales and keys (as defined in csv) + * `GodotOverride` method attribute: + -- Allows use of On*, instead of virtual _* overrides + -- (Requires partial method declaration for use with Godot 4) + * `Notify` property attribute: + -- Generates boiler plate code, triggering only when values differ + -- (Automagically triggers nested changes for Resource and Resource[]) + * `InputMap` class attribute: + -- Provides strongly typed access to input actions defined in godot.project + -- Attribute option to replace StringName with your own custom object/handler + * `LayerNames` class attribute: + -- Provide strongly typed access to layer names defined in godot.project + * `Autoload` class attribute: + -- Provide strongly typed access to autoload nodes defined in godot.project + * `CodeComments` class attribute: + -- Provides a nested static class to access property comments from code (useful for in-game tooltips, etc) + * `OnInstantiate` method attribute: + -- Generates a static Instantiate method with matching args that calls attributed method as part of the instantiation process + -- (Also generates a protected constructor to ensure proper initialisation - can be deactivated via attribute) + * `OnImport` method attribute (GD4 only): + -- Generates default plugin overrides and options to make plugin class cleaner (inherit from OnImportEditorPlugin) + * Includes base classes/helpers to create project specific source generators + - v.2.7.0 (pre-release) - - ADDED: ResourceTree class attribute - - ADDED: Singleton class attribute - - ADDED: Shader class attribute - - ADDED: AutoEnum class attribute - - ADDED: AudioBus class attribute - - ADDED: AnimNames class attribute - - ADDED: AnimNames class attribute - - ADDED: GlobalGroups class attribute - - ADDED: Instantiable class attribute - - ADDED: IInstantiable interface - - ADDED: ISceneTree interface - - ADDED: TR class attribute - - ADDED: Support for multiple methods [OnInstantiate] - - ADDED: Custom scope for uniquely named nodes [SceneTree] - - v.2.6.0 - - ADDED: Generated Autoload class - - ADDED: InputMap data type override - - ADDED: TscnFilePath static property - - FIXED: Generated LayerName values are no longer offset by 1 - - v.2.5.0 - - Documentation updates: - -- Add comments for generated InputMap classes (credit to @Delsin-Yu) - -- Add note about [SceneTree] leaf nodes in README.md (credit to @valkyrienyanko) - - Bug fixes: - -- Added more explicit prepend of res:// to Instantiate resource paths - -- Disabled hidden inherited member warning for generated Instantiate methods - - Enhancements: - -- Adding support for default parameters for generated Instantiate methods - -- Adding support for SceneTree usage on subnodes (credit to @benjiwolff) - -- Adding parameter to SceneTreeAttribute to override _ (credit to @benjiwolff) - -- Adding support for partial properties with NotifyAttribute (credit to @willnationsdev) - - v.2.4.0 - - ADDED: LayerNames attribute - - ADDED: Support for Nullable Reference Types (for `Notify` and `OnInstantiate`) - - v.2.3.4 - - ADDED: Support for .NET 8.0 - - ADDED: Nested InputMap entries - - ADDED: OnImport attribute for editor only builds (GD4 only) - - v.2.1.0 - - ADDED: CodeComments attribute - - ADDED: OnInstantiate attribute (with protected constructor) - - ADDED: Inline changed action on Notify setter - - ADDED: Implicit operators as an alternative to calling .Get() on scene tree for non-leaf nodes - - v.2.0.0 - - ADDED: Support for Godot 4.0 - -- KnownIssue: GodotOverride requires an additional partial method override declaration - - CHANGED: Notify must be used on property instead of field to access privately generated content - - ADDED: InputMap attribute - - v.1.3.3 - - ADDED: Support for placeholder scenes - - ADDED: Support for editable instanced scenes - - FIXED: GodotOverride in derived class now calls rather than hides base method - - FIXED: Previously, types could not share the same name. This has now been fixed. - - ADDED: Notify attribute (with support for [Export]) - - ADDED: Support for uniquely named nodes (ie, Godot 3.5 - GetNode("%MyUniqueNode")) - - v.1.2.0 - - Replaces ISourceGenerator with IIncrementalGenerator for faster builds - - Hierarchy of inherited scenes are now fully accessible from base classes - - Hierarchy of instanced scenes can be made accessible using [SceneTree(traverseInstancedScenes=true)] - - FIXED: Modifications (overrides) of inheritance hierarchy now supported - - FIXED: Inheriting/Instancing scenes without scripts now supported - - FIXED: Consumers with implicit usings enabled now supported - - v.1.1.4 - - Exposed base classes/helpers to help create project specific source generators - - v.1.0.0 - - Initial release (SceneTree/GodotOverride) - + v.2.7.0 (pre-release) + - ADDED: ResourceTree class attribute + - ADDED: Singleton class attribute + - ADDED: Shader class attribute + - ADDED: AutoEnum class attribute + - ADDED: AudioBus class attribute + - ADDED: AnimNames class attribute + - ADDED: AnimNames class attribute + - ADDED: GlobalGroups class attribute + - ADDED: Instantiable class attribute + - ADDED: IInstantiable interface + - ADDED: ISceneTree interface + - ADDED: TR class attribute + - ADDED: Support for multiple methods [OnInstantiate] + - ADDED: Custom scope for uniquely named nodes [SceneTree] + - FIXED: Autoload class must now be explicitly decorated instead of implicitly generated + + v.2.6.0 + - ADDED: Generated Autoload class + - ADDED: InputMap data type override + - ADDED: TscnFilePath static property + - FIXED: Generated LayerName values are no longer offset by 1 + + v.2.5.0 + - Documentation updates: + -- Add comments for generated InputMap classes (credit to @Delsin-Yu) + -- Add note about [SceneTree] leaf nodes in README.md (credit to @valkyrienyanko) + - Bug fixes: + -- Added more explicit prepend of res:// to Instantiate resource paths + -- Disabled hidden inherited member warning for generated Instantiate methods + - Enhancements: + -- Adding support for default parameters for generated Instantiate methods + -- Adding support for SceneTree usage on subnodes (credit to @benjiwolff) + -- Adding parameter to SceneTreeAttribute to override _ (credit to @benjiwolff) + -- Adding support for partial properties with NotifyAttribute (credit to @willnationsdev) + + v.2.4.0 + - ADDED: LayerNames attribute + - ADDED: Support for Nullable Reference Types (for `Notify` and `OnInstantiate`) + + v.2.3.4 + - ADDED: Support for .NET 8.0 + - ADDED: Nested InputMap entries + - ADDED: OnImport attribute for editor only builds (GD4 only) + + v.2.1.0 + - ADDED: CodeComments attribute + - ADDED: OnInstantiate attribute (with protected constructor) + - ADDED: Inline changed action on Notify setter + - ADDED: Implicit operators as an alternative to calling .Get() on scene tree for non-leaf nodes + + v.2.0.0 + - ADDED: Support for Godot 4.0 + -- KnownIssue: GodotOverride requires an additional partial method override declaration + - CHANGED: Notify must be used on property instead of field to access privately generated content + - ADDED: InputMap attribute + + v.1.3.3 + - ADDED: Support for placeholder scenes + - ADDED: Support for editable instanced scenes + - FIXED: GodotOverride in derived class now calls rather than hides base method + - FIXED: Previously, types could not share the same name. This has now been fixed. + - ADDED: Notify attribute (with support for [Export]) + - ADDED: Support for uniquely named nodes (ie, Godot 3.5 - GetNode("%MyUniqueNode")) + + v.1.2.0 + - Replaces ISourceGenerator with IIncrementalGenerator for faster builds + - Hierarchy of inherited scenes are now fully accessible from base classes + - Hierarchy of instanced scenes can be made accessible using [SceneTree(traverseInstancedScenes=true)] + - FIXED: Modifications (overrides) of inheritance hierarchy now supported + - FIXED: Inheriting/Instancing scenes without scripts now supported + - FIXED: Consumers with implicit usings enabled now supported + + v.1.1.4 + - Exposed base classes/helpers to help create project specific source generators + + v.1.0.0 + - Initial release (SceneTree/GodotOverride) + Cat-Lips README.md Godot C# SourceGenerator @@ -172,7 +174,7 @@ - + diff --git a/SourceGenerators/Utilities/Extensions/CompilationExtensions.cs b/SourceGenerators/Utilities/Extensions/CompilationExtensions.cs index d97919b..bc63a08 100644 --- a/SourceGenerators/Utilities/Extensions/CompilationExtensions.cs +++ b/SourceGenerators/Utilities/Extensions/CompilationExtensions.cs @@ -24,12 +24,12 @@ string SearchReferencedAssemblies() { if (asm.Name is "GodotSharp") { - // Some names in Godot have mismatched case (mostly 2d/2D & 3d,3D) + // Some names in Godot have mismatched case (mostly 2d/2D & 3d/3D) var csType = asm.TypeNames.FirstOrDefault(x => x.Equals(type, StringComparison.OrdinalIgnoreCase)); if (csType is not null) return csType; } - Log.Debug($"*** Searching for {type} in {asm.Name}"); + //Log.Debug($"*** Searching for {type} in {asm.Name}"); if (asm.TypeNames.Contains(type)) return type; @@ -60,12 +60,12 @@ string SearchReferencedAssemblies() { if (asm.Name is "GodotSharp") { - // Some names in Godot have mismatched case (mostly 2d/2D & 3d,3D) + // Some names in Godot have mismatched case (mostly 2d/2D & 3d/3D) var csType = asm.TypeNames.FirstOrDefault(x => x.Equals(type, StringComparison.OrdinalIgnoreCase)); if (csType is not null) return $"Godot.{csType}"; } - Log.Debug($"*** Searching for {type} in {asm.Name}"); + //Log.Debug($"*** Searching for {type} in {asm.Name}"); if (asm.TypeNames.Contains(type)) return type; // TODO: Walk namspace/type symbols if required diff --git a/SourceGenerators/Utilities/Extensions/GodotExtensions.cs b/SourceGenerators/Utilities/Extensions/GodotExtensions.cs index a628c7b..ab74ed9 100644 --- a/SourceGenerators/Utilities/Extensions/GodotExtensions.cs +++ b/SourceGenerators/Utilities/Extensions/GodotExtensions.cs @@ -87,6 +87,12 @@ static string DIR(string source, SyntaxNode node, AnalyzerConfigOptions options) } } + public static string CS(SyntaxNode node) + => node.SyntaxTree.FilePath; + + public static string ROOT(AnalyzerConfigOptions options, string csPath) + => options.TryGetGodotProjectDir() ?? GetProjectRoot(csPath); + public static string ROOT(SyntaxNode node, AnalyzerConfigOptions options) => options.TryGetGodotProjectDir() ?? GetProjectRoot(node.SyntaxTree.FilePath);