Little NodeContainer ECS (#17702)
This commit is contained in:
@@ -2,6 +2,7 @@ using Content.Server.NodeContainer.Nodes;
|
||||
using Content.Server.NodeContainer.NodeGroups;
|
||||
using Content.Shared.Examine;
|
||||
using JetBrains.Annotations;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace Content.Server.NodeContainer.EntitySystems
|
||||
{
|
||||
@@ -27,6 +28,24 @@ namespace Content.Server.NodeContainer.EntitySystems
|
||||
SubscribeLocalEvent<NodeContainerComponent, ExaminedEvent>(OnExamine);
|
||||
}
|
||||
|
||||
public bool TryGetNode<T>(NodeContainerComponent component, string? identifier, [NotNullWhen(true)] out T? node) where T : Node
|
||||
{
|
||||
if (identifier == null)
|
||||
{
|
||||
node = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (component.Nodes.TryGetValue(identifier, out var n) && n is T t)
|
||||
{
|
||||
node = t;
|
||||
return true;
|
||||
}
|
||||
|
||||
node = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
private void OnInitEvent(EntityUid uid, NodeContainerComponent component, ComponentInit args)
|
||||
{
|
||||
foreach (var (key, node) in component.Nodes)
|
||||
|
||||
Reference in New Issue
Block a user