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