Files
Polonium/Package/embedded/Patches/GlobalRegistry.p.cs
2025-02-28 08:49:32 +00:00

55 lines
1.8 KiB
C#

#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;
using Polonium.Agents;
// ReSharper disable once CheckNamespace
public static partial class GlobalRegistry
{
public static void Start()
{
PoloniumRegistry.Prepare();
Assembly assembly = Assembly.GetExecutingAssembly();
IEnumerable<Type> 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<T> where T : Node
{
// ReSharper disable once StaticMemberInGenericType
// ReSharper disable once UnusedAutoPropertyAccessor.Global
public static PackedScene Scene => PoloniumRegistry.Asset<T>.Scene;
public static T Get() => PoloniumRegistry.Asset<T>.Get();
public static void Return(T obj) => PoloniumRegistry.Asset<T>.Return(obj);
}
public static partial class Action<TAction> where TAction : AgentAction
{
public static string Name => PoloniumRegistry.Action<TAction>.Name;
}
public static PoloniumRegistry PoloniumRegistry => PoloniumRegistry.Instance;
public static bool Paused { get; set; }
public static void Prepare() => PoloniumRegistry.Prepare();
// ReSharper disable once PartialTypeWithSinglePart
public static partial class TextureSets
{
}
}
#pragma warning restore IDE0130
#pragma warning restore CA1000