2023-12-29 17:45:36 -08:00
|
|
|
using Godot;
|
|
|
|
|
|
|
|
namespace SupaLidlGame.Utils;
|
|
|
|
|
|
|
|
[GlobalClass]
|
|
|
|
public partial class ScenePath : ResourcePath
|
|
|
|
{
|
|
|
|
private static Godot.Collections.Dictionary<string, PackedScene> _loaded;
|
|
|
|
|
|
|
|
static ScenePath()
|
|
|
|
{
|
|
|
|
_loaded = new();
|
|
|
|
}
|
|
|
|
|
|
|
|
public PackedScene Load(bool useCached = false)
|
|
|
|
{
|
|
|
|
if (useCached && _loaded.ContainsKey(Path))
|
|
|
|
{
|
|
|
|
return _loaded[Path];
|
|
|
|
}
|
|
|
|
|
|
|
|
// add scene to loaded to not have to reload scene when called again
|
|
|
|
var scene = base.Load<PackedScene>();
|
2024-10-05 15:32:26 -07:00
|
|
|
|
|
|
|
if (useCached)
|
|
|
|
{
|
|
|
|
_loaded.Add(Path, scene);
|
|
|
|
}
|
|
|
|
|
2023-12-29 17:45:36 -08:00
|
|
|
return scene;
|
|
|
|
}
|
|
|
|
|
|
|
|
public T Instantiate<T>() where T : Node
|
|
|
|
{
|
|
|
|
return Load().Instantiate<T>();
|
|
|
|
}
|
|
|
|
}
|