2021-02-11 01:13:03 -08:00
|
|
|
using Robust.Shared.Reflection;
|
2020-07-08 09:37:35 +10:00
|
|
|
|
|
|
|
|
namespace Content.Server.AI.Utility.Considerations
|
|
|
|
|
{
|
2022-02-16 00:23:23 -07:00
|
|
|
public sealed class ConsiderationsManager
|
2020-07-08 09:37:35 +10:00
|
|
|
{
|
2020-11-27 11:00:49 +01:00
|
|
|
private readonly Dictionary<Type, Consideration> _considerations = new();
|
2020-07-08 09:37:35 +10:00
|
|
|
|
|
|
|
|
public void Initialize()
|
|
|
|
|
{
|
|
|
|
|
var reflectionManager = IoCManager.Resolve<IReflectionManager>();
|
|
|
|
|
var typeFactory = IoCManager.Resolve<IDynamicTypeFactory>();
|
2020-11-21 14:02:00 +01:00
|
|
|
|
2020-07-08 09:37:35 +10:00
|
|
|
foreach (var conType in reflectionManager.GetAllChildren(typeof(Consideration)))
|
|
|
|
|
{
|
|
|
|
|
var con = (Consideration) typeFactory.CreateInstance(conType);
|
|
|
|
|
_considerations.Add(conType, con);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-11-21 14:02:00 +01:00
|
|
|
|
2020-07-08 09:37:35 +10:00
|
|
|
public T Get<T>() where T : Consideration
|
|
|
|
|
{
|
|
|
|
|
return (T) _considerations[typeof(T)];
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-11-21 14:02:00 +01:00
|
|
|
}
|