#pragma warning disable IDE0130 #pragma warning disable CA1000 using Godot; using System; using System.Linq; using System.Reflection; using Polonium.Attributes; using Polonium; using Polonium.Interfaces; using System.Collections.Generic; // ReSharper disable once CheckNamespace public static partial class GlobalRegistry { public static void Start() { PoloniumRegistry.Prepare(); Assembly assembly = Assembly.GetExecutingAssembly(); IEnumerable registerTypes = Utils.GetLoadableTypes(assembly); registerTypes = registerTypes.Where(t => t.IsClass && t.GetCustomAttributes(typeof(AutoRegister), false).Any()); foreach (Type t in registerTypes) { MethodInfo registerMethod = t.GetMethod("Register", BindingFlags.Static | BindingFlags.Public); if (registerMethod != null) registerMethod.Invoke(null, null); } } public static class Asset where T : Node { private static readonly Queue Pool = new(); // ReSharper disable once StaticMemberInGenericType // ReSharper disable once UnusedAutoPropertyAccessor.Global public static PackedScene Scene { get; set; } private static T Instance => Scene.Instantiate(); public static T Get() => Pool.Count > 0 ? Pool.Dequeue() : Instance; public static void Return(T obj) { if(Pool.Count < 10) Pool.Enqueue(obj); else obj.QueueFree(); } } public static PoloniumRegistry PoloniumRegistry => PoloniumRegistry.Instance; public static bool Paused { get; set; } public static HashSet TimeConsumers { get; } = []; public static void Prepare() => PoloniumRegistry.Prepare(); // ReSharper disable once PartialTypeWithSinglePart public static partial class TextureSets { } } #pragma warning restore IDE0130 #pragma warning restore CA1000