diff --git a/README.md b/README.md index 25fd4ec..3bc4e96 100644 --- a/README.md +++ b/README.md @@ -175,18 +175,18 @@ public void NextScene() where T : ISceneTree public partial interface IInstantiable { static T Instantiate() where T : Node, ISceneTree - => GD.Load(T.TscnFilePath).Instantiate(); + => ResourceLoader.Load(T.TscnFilePath, cacheMode: ResourceLoader.CacheMode.IgnoreDeep).Instantiate(); } public partial interface IInstantiable where T : Node, IInstantiable, ISceneTree { - static T Instantiate() => GD.Load(T.TscnFilePath).Instantiate(); + static T Instantiate() => ResourceLoader.Load(T.TscnFilePath, cacheMode: ResourceLoader.CacheMode.IgnoreDeep).Instantiate(); } public static partial class Instantiator { public static T Instantiate() where T : Node, ISceneTree - => GD.Load(T.TscnFilePath).Instantiate(); + => ResourceLoader.Load(T.TscnFilePath, cacheMode: ResourceLoader.CacheMode.IgnoreDeep).Instantiate(); } ``` Usage: @@ -612,7 +612,7 @@ Generates: partial class Scene1 { [EditorBrowsable(EditorBrowsableState.Never)] - private static PackedScene _Scene1 => field ??= GD.Load("res://Path/To/Scene1.tscn"); + private static PackedScene _Scene1 => field ??= ResourceLoader.Load("res://Path/To/Scene1.tscn", cacheMode: ResourceLoader.CacheMode.IgnoreDeep); public static Scene1 New() => (Scene1)_Scene1.Instantiate(); @@ -622,7 +622,7 @@ partial class Scene1 partial class Scene2 { [EditorBrowsable(EditorBrowsableState.Never)] - private static PackedScene _Scene2 => field ??= GD.Load("res://Path/To/Scene2.tscn"); + private static PackedScene _Scene2 => field ??= ResourceLoader.Load("res://Path/To/Scene2.tscn", cacheMode: ResourceLoader.CacheMode.IgnoreDeep); public static Scene2 New() { @@ -644,7 +644,7 @@ partial class Scene2 partial class Scene3 { [EditorBrowsable(EditorBrowsableState.Never)] - private static PackedScene _Scene3 => field ??= GD.Load("res://Path/To/Scene3.tscn"); + private static PackedScene _Scene3 => field ??= ResourceLoader.Load("res://Path/To/Scene3.tscn", cacheMode: ResourceLoader.CacheMode.IgnoreDeep); public static Scene3 Instantiate(int arg1, string arg2, object arg3 = null) { @@ -845,7 +845,7 @@ Generates: partial class MyScene { [EditorBrowsable(EditorBrowsableState.Never)] - private static PackedScene _MyScene => field ??= GD.Load("res://Path/To/MyScene.tscn"); + private static PackedScene _MyScene => field ??= ResourceLoader.Load("res://Path/To/MyScene.tscn", cacheMode: ResourceLoader.CacheMode.IgnoreDeep); public static MyScene Instantiate(string myArg1, int myArg2) { @@ -894,8 +894,8 @@ Usage: //[ResourceTree("./Assets")] // Scan from /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 @@ -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(ResPath); + public static CompressedTexture2D Load() => ResourceLoader.Load(ResPath, cacheMode: ResourceLoader.CacheMode.IgnoreDeep); } public static string HelpTxt => "res://Assets/Help.txt"; // -- (xtras - always generated as resource path) @@ -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(ResPath); + public static OptimizedTranslation Load() => ResourceLoader.Load(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(ResPath); + public static OptimizedTranslation Load() => ResourceLoader.Load(ResPath, cacheMode: ResourceLoader.CacheMode.IgnoreDeep); } } } @@ -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(ResPath); + public static PackedScene Load() => ResourceLoader.Load(ResPath, cacheMode: ResourceLoader.CacheMode.IgnoreDeep); } public static class MySceneGd { public static string ResPath => "res://Scenes/MyScene.gd"; - public static GDScript Load() => GD.Load(ResPath); + public static GDScript Load() => ResourceLoader.Load(ResPath, cacheMode: ResourceLoader.CacheMode.IgnoreDeep); } public static class MySceneCs { public static string ResPath => "res://Scenes/MyScene.cs"; - public static CSharpScript Load() => GD.Load(ResPath); + public static CSharpScript Load() => ResourceLoader.Load(ResPath, cacheMode: ResourceLoader.CacheMode.IgnoreDeep); } public static string MySceneCsUid => "uid://tyjsxc2njtw2"; // -- (Res.Uid) @@ -993,12 +993,12 @@ partial class MyRes { public static partial class Assets { - public static CompressedTexture2D IconSvg => GD.Load("res://Assets/icon.svg"); + public static CompressedTexture2D IconSvg => ResourceLoader.Load("res://Assets/icon.svg", cacheMode: ResourceLoader.CacheMode.IgnoreDeep); public static class Tr { - public static OptimizedTranslation TrEnTranslation => GD.Load("res://Assets/tr/tr.en.translation"); - public static OptimizedTranslation TrFrTranslation => GD.Load("res://Assets/tr/tr.fr.translation"); + public static OptimizedTranslation TrEnTranslation => ResourceLoader.Load("res://Assets/tr/tr.en.translation", cacheMode: ResourceLoader.CacheMode.IgnoreDeep); + public static OptimizedTranslation TrFrTranslation => ResourceLoader.Load("res://Assets/tr/tr.fr.translation", cacheMode: ResourceLoader.CacheMode.IgnoreDeep); } } } @@ -1090,7 +1090,7 @@ Generates: partial class MyShader { public const string ShaderPath = "res://Path/To/MyShader.gdshader"; - public static Shader LoadShader() => GD.Load(ShaderPath); + public static Shader LoadShader() => ResourceLoader.Load(ShaderPath, cacheMode: ResourceLoader.CacheMode.IgnoreDeep); public ShaderMaterial Material { get; private init; } @@ -1154,7 +1154,7 @@ Generates: static partial class MyShader { public const string ShaderPath = "res://Path/To/MyShader.gdshader"; - public static Shader LoadShader() => GD.Load(ShaderPath); + public static Shader LoadShader() => ResourceLoader.Load(ShaderPath, cacheMode: ResourceLoader.CacheMode.IgnoreDeep); public static ShaderMaterial New() => NewMaterial(); public static ShaderMaterial NewMaterial() { @@ -1205,7 +1205,7 @@ Generates: partial class MyShader { public const string ShaderPath = "res://Path/To/MyShader.gdshader"; - public static Shader LoadShader() => GD.Load(ShaderPath); + public static Shader LoadShader() => ResourceLoader.Load(ShaderPath, cacheMode: ResourceLoader.CacheMode.IgnoreDeep); public MyShader() { @@ -1336,7 +1336,7 @@ partial class MyNode partial class MyScene { - public static MyScene Instance { get; } = InitScene((MyScene)GD.Load("res://PathTo/MyScene.tscn").Instantiate()); + public static MyScene Instance { get; } = InitScene((MyScene)ResourceLoader.Load("res://PathTo/MyScene.tscn", cacheMode: ResourceLoader.CacheMode.IgnoreDeep).Instantiate()); [EditorBrowsable(EditorBrowsableState.Never)] private static MyScene InitScene(MyScene x) { x.InitScene(); return x; } private MyScene() { } } diff --git a/SourceGenerators/InstantiableExtensions/InstantiableTemplate.scriban b/SourceGenerators/InstantiableExtensions/InstantiableTemplate.scriban index 03d8e00..325b6cb 100644 --- a/SourceGenerators/InstantiableExtensions/InstantiableTemplate.scriban +++ b/SourceGenerators/InstantiableExtensions/InstantiableTemplate.scriban @@ -5,7 +5,7 @@ private static PackedScene __{{ClassName}}; [{{EditorBrowsableNever}}] - private static PackedScene _{{ClassName}} => __{{ClassName}} ??= GD.Load("{{Tscn}}"); + private static PackedScene _{{ClassName}} => __{{ClassName}} ??= ResourceLoader.Load("{{Tscn}}", cacheMode: ResourceLoader.CacheMode.IgnoreDeep); #nullable restore {{~ if InitList.empty? ~}} diff --git a/SourceGenerators/OnInstantiateExtensions/OnInstantiateTemplate.scriban b/SourceGenerators/OnInstantiateExtensions/OnInstantiateTemplate.scriban index d653b35..e59cca3 100644 --- a/SourceGenerators/OnInstantiateExtensions/OnInstantiateTemplate.scriban +++ b/SourceGenerators/OnInstantiateExtensions/OnInstantiateTemplate.scriban @@ -12,7 +12,7 @@ partial class {{ClassName}} private static PackedScene __scene__; [EditorBrowsable(EditorBrowsableState.Never)] - private static PackedScene __Scene__ => __scene__ ??= GD.Load("{{ResourcePath}}"); + private static PackedScene __Scene__ => __scene__ ??= ResourceLoader.Load("{{ResourcePath}}", cacheMode: ResourceLoader.CacheMode.IgnoreDeep); {{~ end ~}} #nullable restore diff --git a/SourceGenerators/ResourceTreeExtensions/ResourceTreeTemplate.scriban b/SourceGenerators/ResourceTreeExtensions/ResourceTreeTemplate.scriban index 23d9e30..a0308ea 100644 --- a/SourceGenerators/ResourceTreeExtensions/ResourceTreeTemplate.scriban +++ b/SourceGenerators/ResourceTreeExtensions/ResourceTreeTemplate.scriban @@ -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 ~}} diff --git a/SourceGenerators/SceneTreeExtensions/Resources.cs b/SourceGenerators/SceneTreeExtensions/Resources.cs index 62de57d..22bb2cc 100644 --- a/SourceGenerators/SceneTreeExtensions/Resources.cs +++ b/SourceGenerators/SceneTreeExtensions/Resources.cs @@ -23,19 +23,19 @@ namespace Godot; public partial interface IInstantiable where T : Node, IInstantiable, ISceneTree { - static T Instantiate() => GD.Load(T.TscnFilePath).Instantiate(); + static T Instantiate() => ResourceLoader.Load(T.TscnFilePath, cacheMode: ResourceLoader.CacheMode.IgnoreDeep).Instantiate(); } public partial interface IInstantiable { static T Instantiate() where T : Node, ISceneTree - => GD.Load(T.TscnFilePath).Instantiate(); + => ResourceLoader.Load(T.TscnFilePath, cacheMode: ResourceLoader.CacheMode.IgnoreDeep).Instantiate(); } public static partial class Instantiator { public static T Instantiate() where T : Node, ISceneTree - => GD.Load(T.TscnFilePath).Instantiate(); + => ResourceLoader.Load(T.TscnFilePath, cacheMode: ResourceLoader.CacheMode.IgnoreDeep).Instantiate(); } #endif".Trim(); } diff --git a/SourceGenerators/ShaderExtensions/ShaderTemplate.scriban b/SourceGenerators/ShaderExtensions/ShaderTemplate.scriban index 779e024..0ee9d06 100644 --- a/SourceGenerators/ShaderExtensions/ShaderTemplate.scriban +++ b/SourceGenerators/ShaderExtensions/ShaderTemplate.scriban @@ -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() { @@ -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}}() { @@ -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; } diff --git a/SourceGenerators/ShaderGlobalsExtensions/ShaderGlobalsDataModel.cs b/SourceGenerators/ShaderGlobalsExtensions/ShaderGlobalsDataModel.cs index f9398e9..b8aafa3 100644 --- a/SourceGenerators/ShaderGlobalsExtensions/ShaderGlobalsDataModel.cs +++ b/SourceGenerators/ShaderGlobalsExtensions/ShaderGlobalsDataModel.cs @@ -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() { diff --git a/SourceGenerators/SingletonExtensions/SingletonTemplate.scriban b/SourceGenerators/SingletonExtensions/SingletonTemplate.scriban index e11f8bf..ac93451 100644 --- a/SourceGenerators/SingletonExtensions/SingletonTemplate.scriban +++ b/SourceGenerators/SingletonExtensions/SingletonTemplate.scriban @@ -2,7 +2,7 @@ {{- capture new -}} {{- if TSCN -}} - ({{ClassName}})GD.Load("{{TSCN}}").Instantiate() + ({{ClassName}})ResourceLoader.Load("{{TSCN}}", cacheMode: ResourceLoader.CacheMode.IgnoreDeep).Instantiate() {{- else -}} new() {{- end -}}