Files
Polonium/src/Utils.cs

49 lines
1.3 KiB
C#

#pragma warning disable CS0618
#pragma warning disable CS0168
using System.Reflection;
using Godot;
namespace Polonium;
public static class Utils
{
public static IEnumerable<Type> GetLoadableTypes(Assembly assembly)
{
try
{
return assembly.GetTypes();
}
catch (ReflectionTypeLoadException e)
{
return e.Types.Where(t => t != null);
}
}
private static Dictionary<StringName, AnimatedTexture> AnimatedTextureCache { get; } = 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;
}
}
}
#pragma warning restore CS0618
#pragma warning restore CS0168