Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using FluentAssertions;
using Godot;
using GodotSharp.BuildingBlocks.TestRunner;
using GodotSharp.SourceGenerators.ResourceTreeExtensions;
using GodotSharp.SourceGenerators;
using GodotTests.TestScenes.ResourceTreeTestAssets;

namespace GodotTests.TestScenes;
Expand Down Expand Up @@ -38,10 +38,10 @@ public static partial class RelativeResDir1;
[ResourceTree("./Resources", ResG.DirPaths)]
public static partial class RelativeResDir2;

[ResourceTree("Resources", resx: ResX.All, xtras: ["csv", "cfg", "txt", "zip"])]
[ResourceTree("Resources", resi: ResI.All, xtras: ["csv", "cfg", "txt", "zip"])]
public static partial class ResWithTypes;

[ResourceTree(resx: ResX.Scenes)]
[ResourceTree(resi: ResI.Scenes)]
public static partial class ResWithScenes;

//[ResourceTree("Invalid")]
Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ var scene3 = Instantiate<Scene3>();
* Advanced options available as attribute arguments:
* source: relative or absolute path (use `/` as shortcut for `res://`)
* resg: flags to configure generated output (see examples below)
* resx: flags to configure extra input (see examples below)
* resi: flags to configure extra input (see examples below)
* xtras: scan for other file types (eg, txt, cfg, etc)
* xclude: directories to exclude (addons is always excluded)
#### Examples:
Expand All @@ -255,13 +255,13 @@ var scene3 = Instantiate<Scene3>();
//[ResourceTree(resg: ResG.LoadRes | ResG.ResPaths)] // Generate nested type with Load method and ResPath property
//[ResourceTree(resg: ResG.ResPaths | ResG.DirPaths)] // Just paths

//[ResourceTree(resx: ResX.Uid)] // Include uid files (as uid string)
//[ResourceTree(resx: ResX.Scenes)] // Include tscn/scn files (as PackedScene)
//[ResourceTree(resx: ResX.Scripts)] // Include cs/gd files (as CSharpScript/GdScript)
//[ResourceTree(resi: ResI.Uid)] // Include uid files (as uid string)
//[ResourceTree(resi: ResI.Scenes)] // Include tscn/scn files (as PackedScene)
//[ResourceTree(resi: ResI.Scripts)] // Include cs/gd files (as CSharpScript/GdScript)

//[ResourceTree(resx: ResX.All)] // Include all of the above
//[ResourceTree(resx: ResX.None)] // Include none of the above (default)
//[ResourceTree(resx: ResX.Scenes | ResX.Scripts)] // Just scenes & scripts (or any combination)
//[ResourceTree(resi: ResI.All)] // Include all of the above
//[ResourceTree(resi: ResI.None)] // Include none of the above (default)
//[ResourceTree(resi: ResI.Scenes | ResI.Scripts)] // Just scenes & scripts (or any combination)

//[ResourceTree(xtras: ["cfg", "txt"])] // Include file types not recognised as a Godot resource (these could match those added to export configs)
//[ResourceTree(xclude: ["Tests"])] // Ignore specified folders
Expand Down
12 changes: 6 additions & 6 deletions SourceGenerators/ResourceTreeExtensions/ResourceTreeAttribute.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
using GodotSharp.SourceGenerators.ResourceTreeExtensions;
using GodotSharp.SourceGenerators;

namespace Godot;

[AttributeUsage(AttributeTargets.Class)]
public sealed class ResourceTreeAttribute(string source = null, ResG resg = ResG.LoadRes, ResX resx = ResX.None, string[] xtras = null, string[] xclude = null) : Attribute, IResourceTreeConfig
public sealed class ResourceTreeAttribute(string source = null, ResG resg = ResG.LoadRes, ResI resi = ResI.None, string[] xtras = null, string[] xclude = null) : Attribute, IResourceTreeConfig
{
public string Source { get; } = source;
public bool Uid { get; } = (resx & ResX.Uid) != 0;
public bool Scenes { get; } = (resx & ResX.Scenes) != 0;
public bool Scripts { get; } = (resx & ResX.Scripts) != 0;
public bool Uid { get; } = (resi & ResI.Uid) != 0;
public bool Scenes { get; } = (resi & ResI.Scenes) != 0;
public bool Scripts { get; } = (resi & ResI.Scripts) != 0;
public bool UseGdLoad { get; } = (resg & ResG.LoadRes) != 0;
public bool UseResPaths { get; } = (resg & ResG.ResPaths) != 0;
public bool ShowDirPaths { get; } = (resg & ResG.DirPaths) != 0;
public HashSet<string> Xtras { get; } = [.. xtras ?? []];
public HashSet<string> Xclude { get; } = [.. xclude ?? []];

public override string ToString() => $"ResourceTreeAttribute [Source: {Source}, {((IResourceTreeConfig)this).ToString()}]";
string IResourceTreeConfig.ToString() => $"ResG: {resg}, ResX: {resx}, Xtras: {string.Join("|", Xtras)}, Xclude: {string.Join("|", Xclude)}";
string IResourceTreeConfig.ToString() => $"ResG: {resg}, ResI: {resi}, Xtras: {string.Join("|", Xtras)}, Xclude: {string.Join("|", Xclude)}";
}
9 changes: 6 additions & 3 deletions SourceGenerators/ResourceTreeExtensions/ResourceTreeConfig.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace GodotSharp.SourceGenerators.ResourceTreeExtensions;
namespace GodotSharp.SourceGenerators;

[Flags]
public enum ResG
Expand All @@ -9,13 +9,16 @@ public enum ResG
All = LoadRes | ResPaths | DirPaths
}

/// <summary>
/// Specify which additional types of items to include.
/// </summary>
[Flags]
public enum ResX
public enum ResI
{
None,
Uid = 1,
Scenes = 2,
Scripts = 3,
Scripts = 4,
All = Uid | Scenes | Scripts
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ protected override (string GeneratedCode, DiagnosticDetail Error) GenerateCode(C
Godot.ResourceTreeAttribute ReconstructAttribute() => new(
(string)attribute.ConstructorArguments[0].Value,
(ResG)attribute.ConstructorArguments[1].Value,
(ResX)attribute.ConstructorArguments[2].Value,
(ResI)attribute.ConstructorArguments[2].Value,
attribute.ConstructorArguments[3].Values.Args<string>(),
attribute.ConstructorArguments[4].Values.Args<string>());
}
Expand Down