Skip to content

Commit 5beb7ca

Browse files
committed
[#142] Updating readme
1 parent ece5277 commit 5beb7ca

File tree

6 files changed

+66
-56
lines changed

6 files changed

+66
-56
lines changed

Godot 4 Tests/TestScenes/Feature148.ResourceTree/ResourceTreeTests.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,34 @@ namespace GodotTests.TestScenes;
88

99
#region Test Cases
1010

11-
[ResourceTree("res://", ResI.LoadRes, xclude: ["TestScenes"])]
11+
[ResourceTree("res://", ResG.LoadRes, xclude: ["TestScenes"])]
1212
public static partial class RootResWithLoad;
1313

14-
[ResourceTree("res://", ResI.ResPaths, xclude: ["TestScenes"])]
14+
[ResourceTree("res://", ResG.ResPaths, xclude: ["TestScenes"])]
1515
public static partial class RootResWithResPaths;
1616

17-
[ResourceTree("res://", ResI.DirPaths, xclude: ["TestScenes"])]
17+
[ResourceTree("res://", ResG.DirPaths, xclude: ["TestScenes"])]
1818
public static partial class RootResWithDirPaths;
1919

20-
[ResourceTree("res://", ResI.LoadRes | ResI.ResPaths, xclude: ["TestScenes"])]
20+
[ResourceTree("res://", ResG.LoadRes | ResG.ResPaths, xclude: ["TestScenes"])]
2121
public static partial class RootResWithLoadAndResPaths;
2222

23-
[ResourceTree("/", ResI.DirPaths)]
23+
[ResourceTree("/", ResG.DirPaths)]
2424
public static partial class AbsoluteRes;
25-
[ResourceTree("Assets", ResI.DirPaths)]
25+
[ResourceTree("Assets", ResG.DirPaths)]
2626
public static partial class AbsoluteResDir1;
27-
[ResourceTree("/Assets", ResI.DirPaths)]
27+
[ResourceTree("/Assets", ResG.DirPaths)]
2828
public static partial class AbsoluteResDir2;
2929

30-
[ResourceTree(null, ResI.DirPaths)]
30+
[ResourceTree(null, ResG.DirPaths)]
3131
public static partial class RelativeRes1;
32-
[ResourceTree(".", ResI.DirPaths)]
32+
[ResourceTree(".", ResG.DirPaths)]
3333
public static partial class RelativeRes2;
34-
[ResourceTree("", ResI.DirPaths)]
34+
[ResourceTree("", ResG.DirPaths)]
3535
public static partial class RelativeRes3;
36-
[ResourceTree("Resources", ResI.DirPaths)]
36+
[ResourceTree("Resources", ResG.DirPaths)]
3737
public static partial class RelativeResDir1;
38-
[ResourceTree("./Resources", ResI.DirPaths)]
38+
[ResourceTree("./Resources", ResG.DirPaths)]
3939
public static partial class RelativeResDir2;
4040

4141
[ResourceTree("Resources", resx: ResX.All, xtras: ["csv", "cfg", "txt", "zip"])]

README.md

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -220,35 +220,45 @@ var scene3 = Instantiate<Scene3>();
220220
* Provides strongly typed access to the resource hierarchy
221221
* By default, scans files & folders from location of decorated class
222222
* Advanced options available as attribute arguments:
223-
* source: relative or absolute path (use "", ".", "/" for root)
224-
* res: flags to configure generated output (see examples below)
223+
* source: relative or absolute path (use `/` as shortcut for `res://`)
224+
* resg: flags to configure generated output (see examples below)
225+
* resx: flags to configure extra input (see examples below)
225226
* xtras: scan for other file types (eg, txt, cfg, etc)
226227
* xclude: directories to exclude (addons is always excluded)
227228
#### Examples:
228229
```cs
229-
//[ResourceTree] // Scan for resources from class location
230-
//[ResourceTree(".")] // Scan for resources from res:// (can also use "/" or empty string)
231-
//[ResourceTree("Assets")] // Scans for resources from res://Assets or (if not found) <classpath>/Assets
232-
233-
//[ResourceTree(res: Res.Uid)] // Include uid files
234-
//[ResourceTree(res: Res.Scenes)] // Include tscn/scn files
235-
//[ResourceTree(res: Res.Scripts)] // Include cs/gd files
236-
237-
//[ResourceTree(res: Res.Load)] // (default) Properties will call GD.Load to get new resource with correct type
238-
//[ResourceTree(res: Res.ResPaths)] // Properties provide resource path rather than GD.Loading a new resource instance
239-
//[ResourceTree(res: Res.DirPaths)] // Include resource paths for directories
240-
241-
//[ResourceTree(res: Res.All)] // All of the above
242-
//[ResourceTree(res: Res.AllIn)] // Equivalent to Res.Uid | Res.Scenes | Res.Scripts
243-
//[ResourceTree(res: Res.AllOut)] // Equivalent to Res.Load | Res.ResPaths | Res.DirPaths
244-
245-
//[ResourceTree(xtras: ["cfg", "txt"])] // Include file types not recognised as a Godot resource (these should be added to export configs if required in-game)
246-
//[ResourceTree(xclude: ["Tests"])] // Ignore specified folders
230+
//[ResourceTree] // Scan from <classpath>
231+
//[ResourceTree(".")] // Scan from <classpath>
232+
//[ResourceTree("/")] // Scan from 'res://'
233+
//[ResourceTree("res://")] // Scan from 'res://'
234+
//[ResourceTree("Assets")] // Scan from <classpath>/Assets or res://Assets if former not found
235+
//[ResourceTree("/Assets")] // Scan from res://Assets
236+
//[ResourceTree("./Assets")] // Scan from <classpath>/Assets
237+
//[ResourceTree("res://Assets")] // Scan from res://Assets
238+
239+
//[ResourceTree(resg: ResG.LoadRes)] // Generate strongly typed properties that call GD.Load (default)
240+
//[ResourceTree(resg: ResG.ResPaths)] // Generate resource paths for files (in addition to or instead of GD.Load)
241+
//[ResourceTree(resg: ResG.DirPaths)] // Generate resource paths for directories
242+
243+
//[ResourceTree(resg: ResG.All)] // Everything
244+
//[ResourceTree(resg: ResG.LoadRes | ResG.ResPaths)] // Generate nested type with Load method and ResPath property
245+
//[ResourceTree(resg: ResG.ResPaths | ResG.DirPaths)] // Just paths
246+
247+
//[ResourceTree(resx: ResX.Uid)] // Include uid files (as uid string)
248+
//[ResourceTree(resx: ResX.Scenes)] // Include tscn/scn files (as PackedScene)
249+
//[ResourceTree(resx: ResX.Scripts)] // Include cs/gd files (as CSharpScript/GdScript)
250+
251+
//[ResourceTree(resx: ResX.All)] // Include all of the above
252+
//[ResourceTree(resx: ResX.None)] // Include none of the above (default)
253+
//[ResourceTree(resx: ResX.Scenes | ResX.Scripts)] // Just scenes & scripts (or any combination)
254+
255+
//[ResourceTree(xtras: ["cfg", "txt"])] // Include file types not recognised as a Godot resource (these could match those added to export configs)
256+
//[ResourceTree(xclude: ["Tests"])] // Ignore specified folders
247257
```
248258
#### Generated Output:
249259
**Example 1:**
250260
```cs
251-
[ResourceTree(".", Res.All, ["txt"])]
261+
[ResourceTree("/", Res.All, ["txt"])]
252262
public static partial class MyRes;
253263
```
254264
Generates:
@@ -309,14 +319,14 @@ static partial class MyRes
309319
public static CSharpScript Load() => GD.Load<CSharpScript>(ResPath);
310320
}
311321
312-
public static string MySceneCsUid => "uid://tyjsxc2njtw2"; // -- (Res.Uid - always generated as uid)
322+
public static string MySceneCsUid => "uid://tyjsxc2njtw2"; // -- (Res.Uid)
313323
public static string MySceneGdUid => "uid://sho6tst545eo";
314324
}
315325
}
316326
```
317-
**Example 2:** with Res.Load (default); without Res.ResPath
327+
**Example 2:**
318328
```cs
319-
[ResourceTree(".")]
329+
[ResourceTree("/")]
320330
public static partial class MyRes;
321331
```
322332
Generates:
@@ -335,9 +345,9 @@ static partial class MyRes
335345
}
336346
}
337347
```
338-
**Example 3:** with Res.ResPath; without Res.Load
348+
**Example 3:**
339349
```cs
340-
[ResourceTree(".", Res.ResPath)]
350+
[ResourceTree("/", Res.ResPath)]
341351
public static partial class MyRes;
342352
```
343353
Generates:

SourceGenerators/ResourceTreeExtensions/ResourceTreeAttribute.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@
33
namespace Godot;
44

55
[AttributeUsage(AttributeTargets.Class)]
6-
public sealed class ResourceTreeAttribute(string source = null, ResI resi = ResI.LoadRes, ResX resx = ResX.None, string[] xtras = null, string[] xclude = null) : Attribute, IResourceTreeConfig
6+
public sealed class ResourceTreeAttribute(string source = null, ResG resg = ResG.LoadRes, ResX resx = ResX.None, string[] xtras = null, string[] xclude = null) : Attribute, IResourceTreeConfig
77
{
88
public string Source { get; } = source;
99
public bool Uid { get; } = (resx & ResX.Uid) != 0;
1010
public bool Scenes { get; } = (resx & ResX.Scenes) != 0;
1111
public bool Scripts { get; } = (resx & ResX.Scripts) != 0;
12-
public bool UseGdLoad { get; } = (resi & ResI.LoadRes) != 0;
13-
public bool UseResPaths { get; } = (resi & ResI.ResPaths) != 0;
14-
public bool ShowDirPaths { get; } = (resi & ResI.DirPaths) != 0;
12+
public bool UseGdLoad { get; } = (resg & ResG.LoadRes) != 0;
13+
public bool UseResPaths { get; } = (resg & ResG.ResPaths) != 0;
14+
public bool ShowDirPaths { get; } = (resg & ResG.DirPaths) != 0;
1515
public HashSet<string> Xtras { get; } = [.. xtras ?? []];
1616
public HashSet<string> Xclude { get; } = [.. xclude ?? []];
1717

1818
public override string ToString() => $"ResourceTreeAttribute [Source: {Source}, {((IResourceTreeConfig)this).ToString()}]";
19-
string IResourceTreeConfig.ToString() => $"ResI: {resi}, ResX: {resx}, Xtras: {string.Join("|", Xtras)}, Xclude: {string.Join("|", Xclude)}";
19+
string IResourceTreeConfig.ToString() => $"ResG: {resg}, ResX: {resx}, Xtras: {string.Join("|", Xtras)}, Xclude: {string.Join("|", Xclude)}";
2020
}

SourceGenerators/ResourceTreeExtensions/ResourceTreeConfig.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
namespace GodotSharp.SourceGenerators.ResourceTreeExtensions;
22

33
[Flags]
4-
public enum ResX // (Res Xtras)
4+
public enum ResG
5+
{
6+
LoadRes = 1,
7+
ResPaths = 2,
8+
DirPaths = 4,
9+
All = LoadRes | ResPaths | DirPaths
10+
}
11+
12+
[Flags]
13+
public enum ResX
514
{
615
None,
716
Uid = 1,
@@ -10,15 +19,6 @@ public enum ResX // (Res Xtras)
1019
All = Uid | Scenes | Scripts
1120
}
1221

13-
[Flags]
14-
public enum ResI // (Res Include)
15-
{
16-
LoadRes = 1,
17-
ResPaths = 2,
18-
DirPaths = 4,
19-
All = LoadRes | ResPaths | DirPaths
20-
}
21-
2222
public interface IResourceTreeConfig
2323
{
2424
bool Uid { get; }

SourceGenerators/ResourceTreeExtensions/ResourceTreeSourceGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ protected override (string GeneratedCode, DiagnosticDetail Error) GenerateCode(C
2727

2828
Godot.ResourceTreeAttribute ReconstructAttribute() => new(
2929
(string)attribute.ConstructorArguments[0].Value,
30-
(ResI)attribute.ConstructorArguments[1].Value,
30+
(ResG)attribute.ConstructorArguments[1].Value,
3131
(ResX)attribute.ConstructorArguments[2].Value,
3232
attribute.ConstructorArguments[3].Values.Args<string>(),
3333
attribute.ConstructorArguments[4].Values.Args<string>());

SourceGenerators/SourceGenerators.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
<PropertyGroup>
1616
<Description>
1717
C# Source Generators for use with the Godot Game Engine
18-
18+
1919
- 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 `_`.
20-
20+
2121
* `SceneTree` class attribute:
2222
-- Provides strongly typed access to the scene hierarchy (via `_` operator)
2323
-- Generates direct access to uniquely named nodes via class properties

0 commit comments

Comments
 (0)