* Predicted gas pumps I wanted to try out atmos and first thing I found. * a * Atmos device prediction - Canisters - Tanks - Internals AirMixes aren't predicted so nothing on that front but all the UIs should be a lot closer. * Remove details range * Gas tank prediction * Even more sweeping changes * Alerts * rehg * Popup fix * Fix merge conflicts * Fix * Review
55 lines
1.8 KiB
C#
55 lines
1.8 KiB
C#
using System.Reflection;
|
|
using Content.Shared.NodeContainer.NodeGroups;
|
|
using Robust.Shared.Reflection;
|
|
|
|
namespace Content.Server.NodeContainer.NodeGroups
|
|
{
|
|
public interface INodeGroupFactory
|
|
{
|
|
/// <summary>
|
|
/// Performs reflection to associate <see cref="INodeGroup"/> implementations with the
|
|
/// string specified in their <see cref="NodeGroupAttribute"/>.
|
|
/// </summary>
|
|
void Initialize();
|
|
|
|
/// <summary>
|
|
/// Returns a new <see cref="INodeGroup"/> instance.
|
|
/// </summary>
|
|
INodeGroup MakeNodeGroup(NodeGroupID id);
|
|
}
|
|
|
|
public sealed class NodeGroupFactory : INodeGroupFactory
|
|
{
|
|
[Dependency] private readonly IReflectionManager _reflectionManager = default!;
|
|
[Dependency] private readonly IDynamicTypeFactory _typeFactory = default!;
|
|
|
|
private readonly Dictionary<NodeGroupID, Type> _groupTypes = new();
|
|
|
|
public void Initialize()
|
|
{
|
|
var nodeGroupTypes = _reflectionManager.GetAllChildren<INodeGroup>();
|
|
foreach (var nodeGroupType in nodeGroupTypes)
|
|
{
|
|
var att = nodeGroupType.GetCustomAttribute<NodeGroupAttribute>();
|
|
if (att != null)
|
|
{
|
|
foreach (var groupID in att.NodeGroupIDs)
|
|
{
|
|
_groupTypes.Add(groupID, nodeGroupType);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public INodeGroup MakeNodeGroup(NodeGroupID id)
|
|
{
|
|
if (!_groupTypes.TryGetValue(id, out var type))
|
|
throw new ArgumentException($"{id} did not have an associated {nameof(INodeGroup)} implementation.");
|
|
|
|
var instance = _typeFactory.CreateInstance<INodeGroup>(type);
|
|
instance.Create(id);
|
|
return instance;
|
|
}
|
|
}
|
|
}
|