draft: texture button

This commit is contained in:
h z
2025-02-15 08:25:01 +00:00
parent 0d75ed106d
commit 5a981c91ee
11 changed files with 193 additions and 18 deletions

View File

@@ -1,4 +1,5 @@
using System.Reflection;
using Godot;
namespace Polonium;
@@ -15,4 +16,31 @@ public static class Utils
return e.Types.Where(t => t != null);
}
}
private static Dictionary<StringName, AnimatedTexture> AnimatedTextureCache = new ();
public static AnimatedTexture LoadAnimatedTextureFromDirectory(StringName path)
{
try
{
if (!AnimatedTextureCache.ContainsKey(path))
{
AnimatedTextureCache[path] = new AnimatedTexture();
int f = 0;
foreach (string fname in DirAccess.GetFilesAt(path))
{
if (!fname.EndsWith(".png"))
continue;
AnimatedTextureCache[path].SetFrameTexture(f, ResourceLoader.Load<Texture2D>(fname));
}
}
return AnimatedTextureCache[path];
}
catch (Exception e)
{
return null;
}
}
}