mirror of
https://github.com/DeltaV-Station/Delta-v.git
synced 2026-10-01 08:37:26 +00:00
* Implement device networking * Implement device configuration menu * Fix device network * Implement disposal mailing unit * Implement base network connection Implement wired and wireless network connection Implement device network metadata * Fix dereference null error * Fix wired network null checks * Change BaseNetworks enum to NetworkUtils class Add PingResponse function to NetworkUtils Change device network file structure * Add doc comments * Apply suggestions from code review Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com> * Add tag validation to disposal mailing unit * Add tag validation to the mailing unit component * Address reviews Change WiredNetwork can connect check Change device networking string literals to constants * Address reviews Revert changes to PowerProvider and PowerReceiver Add new NodeGroup WELP * Fix recursive access to Owner property * Integrate suggested changes * Fix TryGetWireNet acting on NullPowerProvider Fix network connections not checking if their owner has been deleted * Close device network connection when the owning entity got deleted Fix mailing unit not closing the device network connection on remove * Remove GetWireNet from NullPowerProvider Co-authored-by: Julian Giebel <j.giebel@netrocks.info> Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com>
70 lines
2.2 KiB
C#
70 lines
2.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Reflection;
|
|
using Content.Server.GameObjects.Components.NodeContainer.Nodes;
|
|
using Robust.Shared.Interfaces.Reflection;
|
|
using Robust.Shared.IoC;
|
|
|
|
namespace Content.Server.GameObjects.Components.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(Node sourceNode);
|
|
}
|
|
|
|
public class NodeGroupFactory : INodeGroupFactory
|
|
{
|
|
[Dependency] private readonly IReflectionManager _reflectionManager = default!;
|
|
[Dependency] private readonly IDynamicTypeFactory _typeFactory = default!;
|
|
|
|
private readonly Dictionary<NodeGroupID, Type> _groupTypes = new Dictionary<NodeGroupID, Type>();
|
|
|
|
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(Node sourceNode)
|
|
{
|
|
if (_groupTypes.TryGetValue(sourceNode.NodeGroupID, out var type))
|
|
{
|
|
var nodeGroup = _typeFactory.CreateInstance<INodeGroup>(type);
|
|
nodeGroup.Initialize(sourceNode);
|
|
return nodeGroup;
|
|
}
|
|
throw new ArgumentException($"{sourceNode.NodeGroupID} did not have an associated {nameof(INodeGroup)}.");
|
|
}
|
|
}
|
|
|
|
public enum NodeGroupID
|
|
{
|
|
Default,
|
|
HVPower,
|
|
MVPower,
|
|
Apc,
|
|
AMEngine,
|
|
Pipe,
|
|
WireNet
|
|
}
|
|
}
|