Helper methods for NodeContainer

Including a GetNode<T> and TryGetNode<T>
This commit is contained in:
Vera Aguilera Puerto
2021-04-10 13:25:44 +02:00
parent 252881776d
commit c4d0c249af

View File

@@ -1,5 +1,6 @@
#nullable enable
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using Content.Server.GameObjects.Components.NodeContainer.NodeGroups;
using Content.Server.GameObjects.Components.NodeContainer.Nodes;
using Content.Shared.GameObjects.EntitySystems;
@@ -64,6 +65,23 @@ namespace Content.Server.GameObjects.Components.NodeContainer
}
}
public T GetNode<T>(string identifier) where T : Node
{
return (T)_nodes[identifier];
}
public bool TryGetNode<T>(string identifier, [NotNullWhen(true)] out T? node) where T : Node
{
if (_nodes.TryGetValue(identifier, out var n) && n is T t)
{
node = t;
return true;
}
node = null;
return false;
}
public void Examine(FormattedMessage message, bool inDetailsRange)
{
if (!_examinable || !inDetailsRange) return;