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
44 changes: 22 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,18 +175,18 @@ public void NextScene<T>() where T : ISceneTree
public partial interface IInstantiable
{
static T Instantiate<T>() where T : Node, ISceneTree
=> GD.Load<PackedScene>(T.TscnFilePath).Instantiate<T>();
=> ResourceLoader.Load<PackedScene>(T.TscnFilePath, cacheMode: ResourceLoader.CacheMode.IgnoreDeep).Instantiate<T>();
}

public partial interface IInstantiable<T> where T : Node, IInstantiable<T>, ISceneTree
{
static T Instantiate() => GD.Load<PackedScene>(T.TscnFilePath).Instantiate<T>();
static T Instantiate() => ResourceLoader.Load<PackedScene>(T.TscnFilePath, cacheMode: ResourceLoader.CacheMode.IgnoreDeep).Instantiate<T>();
}

public static partial class Instantiator
{
public static T Instantiate<T>() where T : Node, ISceneTree
=> GD.Load<PackedScene>(T.TscnFilePath).Instantiate<T>();
=> ResourceLoader.Load<PackedScene>(T.TscnFilePath, cacheMode: ResourceLoader.CacheMode.IgnoreDeep).Instantiate<T>();
}
```
Usage:
Expand Down Expand Up @@ -612,7 +612,7 @@ Generates:
partial class Scene1
{
[EditorBrowsable(EditorBrowsableState.Never)]
private static PackedScene _Scene1 => field ??= GD.Load<PackedScene>("res://Path/To/Scene1.tscn");
private static PackedScene _Scene1 => field ??= ResourceLoader.Load<PackedScene>("res://Path/To/Scene1.tscn", cacheMode: ResourceLoader.CacheMode.IgnoreDeep);

public static Scene1 New() => (Scene1)_Scene1.Instantiate();

Expand All @@ -622,7 +622,7 @@ partial class Scene1
partial class Scene2
{
[EditorBrowsable(EditorBrowsableState.Never)]
private static PackedScene _Scene2 => field ??= GD.Load<PackedScene>("res://Path/To/Scene2.tscn");
private static PackedScene _Scene2 => field ??= ResourceLoader.Load<PackedScene>("res://Path/To/Scene2.tscn", cacheMode: ResourceLoader.CacheMode.IgnoreDeep);

public static Scene2 New()
{
Expand All @@ -644,7 +644,7 @@ partial class Scene2
partial class Scene3
{
[EditorBrowsable(EditorBrowsableState.Never)]
private static PackedScene _Scene3 => field ??= GD.Load<PackedScene>("res://Path/To/Scene3.tscn");
private static PackedScene _Scene3 => field ??= ResourceLoader.Load<PackedScene>("res://Path/To/Scene3.tscn", cacheMode: ResourceLoader.CacheMode.IgnoreDeep);

public static Scene3 Instantiate(int arg1, string arg2, object arg3 = null)
{
Expand Down Expand Up @@ -845,7 +845,7 @@ Generates:
partial class MyScene
{
[EditorBrowsable(EditorBrowsableState.Never)]
private static PackedScene _MyScene => field ??= GD.Load<PackedScene>("res://Path/To/MyScene.tscn");
private static PackedScene _MyScene => field ??= ResourceLoader.Load<PackedScene>("res://Path/To/MyScene.tscn", cacheMode: ResourceLoader.CacheMode.IgnoreDeep);

public static MyScene Instantiate(string myArg1, int myArg2)
{
Expand Down Expand Up @@ -894,8 +894,8 @@ Usage:
//[ResourceTree("./Assets")] // Scan from <classpath>/Assets
//[ResourceTree("res://Assets")] // Scan from res://Assets

//[ResourceTree(resg: ResG.LoadRes)] // Generate strongly typed properties that call GD.Load (default)
//[ResourceTree(resg: ResG.ResPaths)] // Generate resource paths for files (in addition to or instead of GD.Load)
//[ResourceTree(resg: ResG.LoadRes)] // Generate strongly typed properties that call ResourceLoader.Load (default)
//[ResourceTree(resg: ResG.ResPaths)] // Generate resource paths for files (in addition to or instead of ResourceLoader.Load)
//[ResourceTree(resg: ResG.DirPaths)] // Generate resource paths for directories

//[ResourceTree(resg: ResG.All)] // Everything
Expand Down Expand Up @@ -932,7 +932,7 @@ partial class MyRes
public static partial class IconSvg // -- (Res.ResPaths | Res.Load - generates nested type)
{
public static string ResPath => "res://Assets/icon.svg";
public static CompressedTexture2D Load() => GD.Load<CompressedTexture2D>(ResPath);
public static CompressedTexture2D Load() => ResourceLoader.Load<CompressedTexture2D>(ResPath, cacheMode: ResourceLoader.CacheMode.IgnoreDeep);
}

public static string HelpTxt => "res://Assets/Help.txt"; // -- (xtras - always generated as resource path)
Expand All @@ -944,13 +944,13 @@ partial class MyRes
public static class TrEnTranslation // -- (uses importer generated files instead of raw input file)
{
public static string ResPath => "res://Assets/tr/tr.en.translation";
public static OptimizedTranslation Load() => GD.Load<OptimizedTranslation>(ResPath);
public static OptimizedTranslation Load() => ResourceLoader.Load<OptimizedTranslation>(ResPath, cacheMode: ResourceLoader.CacheMode.IgnoreDeep);
}

public static class TrFrTranslation
{
public static string ResPath => "res://Assets/tr/tr.fr.translation";
public static OptimizedTranslation Load() => GD.Load<OptimizedTranslation>(ResPath);
public static OptimizedTranslation Load() => ResourceLoader.Load<OptimizedTranslation>(ResPath, cacheMode: ResourceLoader.CacheMode.IgnoreDeep);
}
}
}
Expand All @@ -962,19 +962,19 @@ partial class MyRes
public static class MySceneTscn
{
public static string ResPath => "res://Scenes/MyScene.tscn";
public static PackedScene Load() => GD.Load<PackedScene>(ResPath);
public static PackedScene Load() => ResourceLoader.Load<PackedScene>(ResPath, cacheMode: ResourceLoader.CacheMode.IgnoreDeep);
}

public static class MySceneGd
{
public static string ResPath => "res://Scenes/MyScene.gd";
public static GDScript Load() => GD.Load<GDScript>(ResPath);
public static GDScript Load() => ResourceLoader.Load<GDScript>(ResPath, cacheMode: ResourceLoader.CacheMode.IgnoreDeep);
}

public static class MySceneCs
{
public static string ResPath => "res://Scenes/MyScene.cs";
public static CSharpScript Load() => GD.Load<CSharpScript>(ResPath);
public static CSharpScript Load() => ResourceLoader.Load<CSharpScript>(ResPath, cacheMode: ResourceLoader.CacheMode.IgnoreDeep);
}

public static string MySceneCsUid => "uid://tyjsxc2njtw2"; // -- (Res.Uid)
Expand All @@ -993,12 +993,12 @@ partial class MyRes
{
public static partial class Assets
{
public static CompressedTexture2D IconSvg => GD.Load<CompressedTexture2D>("res://Assets/icon.svg");
public static CompressedTexture2D IconSvg => ResourceLoader.Load<CompressedTexture2D>("res://Assets/icon.svg", cacheMode: ResourceLoader.CacheMode.IgnoreDeep);

public static class Tr
{
public static OptimizedTranslation TrEnTranslation => GD.Load<OptimizedTranslation>("res://Assets/tr/tr.en.translation");
public static OptimizedTranslation TrFrTranslation => GD.Load<OptimizedTranslation>("res://Assets/tr/tr.fr.translation");
public static OptimizedTranslation TrEnTranslation => ResourceLoader.Load<OptimizedTranslation>("res://Assets/tr/tr.en.translation", cacheMode: ResourceLoader.CacheMode.IgnoreDeep);
public static OptimizedTranslation TrFrTranslation => ResourceLoader.Load<OptimizedTranslation>("res://Assets/tr/tr.fr.translation", cacheMode: ResourceLoader.CacheMode.IgnoreDeep);
}
}
}
Expand Down Expand Up @@ -1090,7 +1090,7 @@ Generates:
partial class MyShader
{
public const string ShaderPath = "res://Path/To/MyShader.gdshader";
public static Shader LoadShader() => GD.Load<Shader>(ShaderPath);
public static Shader LoadShader() => ResourceLoader.Load<Shader>(ShaderPath, cacheMode: ResourceLoader.CacheMode.IgnoreDeep);

public ShaderMaterial Material { get; private init; }

Expand Down Expand Up @@ -1154,7 +1154,7 @@ Generates:
static partial class MyShader
{
public const string ShaderPath = "res://Path/To/MyShader.gdshader";
public static Shader LoadShader() => GD.Load<Shader>(ShaderPath);
public static Shader LoadShader() => ResourceLoader.Load<Shader>(ShaderPath, cacheMode: ResourceLoader.CacheMode.IgnoreDeep);
public static ShaderMaterial New() => NewMaterial();
public static ShaderMaterial NewMaterial()
{
Expand Down Expand Up @@ -1205,7 +1205,7 @@ Generates:
partial class MyShader
{
public const string ShaderPath = "res://Path/To/MyShader.gdshader";
public static Shader LoadShader() => GD.Load<Shader>(ShaderPath);
public static Shader LoadShader() => ResourceLoader.Load<Shader>(ShaderPath, cacheMode: ResourceLoader.CacheMode.IgnoreDeep);

public MyShader()
{
Expand Down Expand Up @@ -1336,7 +1336,7 @@ partial class MyNode

partial class MyScene
{
public static MyScene Instance { get; } = InitScene((MyScene)GD.Load<PackedScene>("res://PathTo/MyScene.tscn").Instantiate());
public static MyScene Instance { get; } = InitScene((MyScene)ResourceLoader.Load<PackedScene>("res://PathTo/MyScene.tscn", cacheMode: ResourceLoader.CacheMode.IgnoreDeep).Instantiate());
[EditorBrowsable(EditorBrowsableState.Never)] private static MyScene InitScene(MyScene x) { x.InitScene(); return x; }
private MyScene() { }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
private static PackedScene __{{ClassName}};

[{{EditorBrowsableNever}}]
private static PackedScene _{{ClassName}} => __{{ClassName}} ??= GD.Load<PackedScene>("{{Tscn}}");
private static PackedScene _{{ClassName}} => __{{ClassName}} ??= ResourceLoader.Load<PackedScene>("{{Tscn}}", cacheMode: ResourceLoader.CacheMode.IgnoreDeep);

#nullable restore
{{~ if InitList.empty? ~}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ partial class {{ClassName}}
private static PackedScene __scene__;

[EditorBrowsable(EditorBrowsableState.Never)]
private static PackedScene __Scene__ => __scene__ ??= GD.Load<PackedScene>("{{ResourcePath}}");
private static PackedScene __Scene__ => __scene__ ??= ResourceLoader.Load<PackedScene>("{{ResourcePath}}", cacheMode: ResourceLoader.CacheMode.IgnoreDeep);

{{~ end ~}}
#nullable restore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
{{~ TAB depth}}public static class {{SAFE_NAME node depth}}
{{~ TAB depth}}{
{{~ TAB depth}} public static string ResPath => "{{node.Value.Path}}";
{{~ TAB depth}} public static {{node.Value.Type}} Load() => GD.Load<{{node.Value.Type}}>(ResPath);
{{~ TAB depth}} public static {{node.Value.Type}} Load() => ResourceLoader.Load<{{node.Value.Type}}>(ResPath, cacheMode: ResourceLoader.CacheMode.IgnoreDeep);
{{~ TAB depth}}}
{{~ else ~}}
{{~ TAB depth}}public static {{node.Value.Type}} {{node.Value.Name}} => GD.Load<{{node.Value.Type}}>("{{node.Value.Path}}");
{{~ TAB depth}}public static {{node.Value.Type}} {{node.Value.Name}} => ResourceLoader.Load<{{node.Value.Type}}>("{{node.Value.Path}}", cacheMode: ResourceLoader.CacheMode.IgnoreDeep);
{{~ end ~}}
{{~ else ~}}
{{~ if node.Value.Show ~}}
Expand Down
6 changes: 3 additions & 3 deletions SourceGenerators/SceneTreeExtensions/Resources.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@ namespace Godot;

public partial interface IInstantiable<T> where T : Node, IInstantiable<T>, ISceneTree
{
static T Instantiate() => GD.Load<PackedScene>(T.TscnFilePath).Instantiate<T>();
static T Instantiate() => ResourceLoader.Load<PackedScene>(T.TscnFilePath, cacheMode: ResourceLoader.CacheMode.IgnoreDeep).Instantiate<T>();
}

public partial interface IInstantiable
{
static T Instantiate<T>() where T : Node, ISceneTree
=> GD.Load<PackedScene>(T.TscnFilePath).Instantiate<T>();
=> ResourceLoader.Load<PackedScene>(T.TscnFilePath, cacheMode: ResourceLoader.CacheMode.IgnoreDeep).Instantiate<T>();
}

public static partial class Instantiator
{
public static T Instantiate<T>() where T : Node, ISceneTree
=> GD.Load<PackedScene>(T.TscnFilePath).Instantiate<T>();
=> ResourceLoader.Load<PackedScene>(T.TscnFilePath, cacheMode: ResourceLoader.CacheMode.IgnoreDeep).Instantiate<T>();
}
#endif".Trim();
}
6 changes: 3 additions & 3 deletions SourceGenerators/ShaderExtensions/ShaderTemplate.scriban
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

{{~ func STATIC ~}}
public const string ShaderPath = "{{ShaderPath}}";
public static {{ShaderType}} LoadShader() => GD.Load<{{ShaderType}}>(ShaderPath);
public static {{ShaderType}} LoadShader() => ResourceLoader.Load<{{ShaderType}}>(ShaderPath, cacheMode: ResourceLoader.CacheMode.IgnoreDeep);
public static ShaderMaterial New() => NewMaterial();
public static ShaderMaterial NewMaterial()
{
Expand Down Expand Up @@ -124,7 +124,7 @@

{{~ func MATERIAL ~}}
public const string ShaderPath = "{{ShaderPath}}";
public static {{ShaderType}} LoadShader() => GD.Load<{{ShaderType}}>(ShaderPath);
public static {{ShaderType}} LoadShader() => ResourceLoader.Load<{{ShaderType}}>(ShaderPath, cacheMode: ResourceLoader.CacheMode.IgnoreDeep);

public {{ClassName}}()
{
Expand Down Expand Up @@ -233,7 +233,7 @@

{{~ func OTHER ~}}
public const string ShaderPath = "{{ShaderPath}}";
public static {{ShaderType}} LoadShader() => GD.Load<{{ShaderType}}>(ShaderPath);
public static {{ShaderType}} LoadShader() => ResourceLoader.Load<{{ShaderType}}>(ShaderPath, cacheMode: ResourceLoader.CacheMode.IgnoreDeep);

public ShaderMaterial Material { get; private init; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ string ConvertValue(string v)
return v is null ? null : TryAsRes() ?? TryAsCtor() ?? SafeValue(v);

string TryAsRes()
=> v.StartsWith("res://") ? @$"GD.Load<{csType}>(""{v}"")" : null;
=> v.StartsWith("res://") ? @$"ResourceLoader.Load<{csType}>(""{v}"", cacheMode: ResourceLoader.CacheMode.IgnoreDeep)" : null;

string TryAsCtor()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

{{- capture new -}}
{{- if TSCN -}}
({{ClassName}})GD.Load<PackedScene>("{{TSCN}}").Instantiate()
({{ClassName}})ResourceLoader.Load<PackedScene>("{{TSCN}}", cacheMode: ResourceLoader.CacheMode.IgnoreDeep).Instantiate()
{{- else -}}
new()
{{- end -}}
Expand Down