74 lines
2.2 KiB
C#
74 lines
2.2 KiB
C#
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<string, Agent> Agents { get; } = new();
|
|
|
|
// ReSharper disable once CollectionNeverQueried.Global
|
|
[RegistryPassThrough(true)]
|
|
public HashSet<ITimeConsumer> TimeConsumers { get; } = new();
|
|
|
|
public static class Action<TAction>
|
|
where TAction : AgentAction
|
|
{
|
|
// ReSharper disable once StaticMemberInGenericType
|
|
public static string Name { get; set; }
|
|
}
|
|
|
|
|
|
public static class SkinRegistry<TSkin>
|
|
where TSkin : Polonium.SkinManagers.Skin
|
|
{
|
|
// ReSharper disable once StaticMemberInGenericType
|
|
public static Color[] PaletteRoots { get; set; }
|
|
// ReSharper disable once StaticMemberInGenericType
|
|
public static Dictionary<Color, Color[]> PaletteMap { get; set; }
|
|
}
|
|
|
|
public static class Asset<TAsset>
|
|
where TAsset : Node
|
|
{
|
|
private static readonly Queue<TAsset> Pool = new();
|
|
public static PackedScene Scene { get; set; }
|
|
private static TAsset Instance => Scene.Instantiate<TAsset>();
|
|
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();
|
|
}
|
|
}
|
|
|
|
}
|