Little NodeContainer ECS (#17702)

This commit is contained in:
faint
2023-06-28 14:28:38 +03:00
committed by GitHub
parent c25f3f08ed
commit 2f85b5ea3c
27 changed files with 143 additions and 88 deletions

View File

@@ -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)