using Godot; using Polonium.Agents; using Polonium.Attributes; using Polonium.Interfaces; using Polonium.MessageManager; using Polonium.Resources; namespace Polonium; public class PoloniumRegistry { private static PoloniumRegistry InternalInstance { get; set; } public static PoloniumRegistry Instance => InternalInstance ??= new PoloniumRegistry(); [RegistryPassThrough] public Config Config { get; set; } [RegistryPassThrough] public Save Save { get; set; } [RegistryPassThrough] public World CurrentWorld { get; set; } [RegistryPassThrough] public IPoloniumFactory PoloniumFactory { get; set; } [RegistryPassThrough] public MessageBus MessageBus { get; set; } public static void Prepare() { DirAccess.MakeDirAbsolute("user://saves"); } // ReSharper disable once CollectionNeverQueried.Global [RegistryPassThrough(true)] public Dictionary Agents { get; } = new(); // ReSharper disable once CollectionNeverQueried.Global [RegistryPassThrough(true)] public HashSet TimeConsumers { get; } = new(); public static class Action where TAction : AgentAction { // ReSharper disable once StaticMemberInGenericType public static string Name { get; set; } } public static class SkinRegistry where TSkin : Polonium.SkinManagers.Skin { // ReSharper disable once StaticMemberInGenericType public static Color[] PaletteRoots { get; set; } // ReSharper disable once StaticMemberInGenericType public static Dictionary PaletteMap { get; set; } } public static class Asset where TAsset : Node { private static readonly Queue Pool = new(); public static PackedScene Scene { get; set; } private static TAsset Instance => Scene.Instantiate(); public static TAsset Get() => Pool.Count > 0 ? Pool.Dequeue() : Instance; public static void Return(TAsset asset) { if (Pool.Count < 10) Pool.Enqueue(asset); else asset.QueueFree(); } } }