2021-01-04 22:32:59 -06:00
|
|
|
using System.Collections.Generic;
|
2021-04-10 13:25:44 +02:00
|
|
|
using System.Diagnostics.CodeAnalysis;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Server.NodeContainer.NodeGroups;
|
|
|
|
|
using Content.Server.NodeContainer.Nodes;
|
|
|
|
|
using Content.Shared.Examine;
|
2020-06-28 09:23:26 -06:00
|
|
|
using Robust.Shared.GameObjects;
|
2021-01-01 14:20:23 +01:00
|
|
|
using Robust.Shared.Localization;
|
2021-03-05 01:08:38 +01:00
|
|
|
using Robust.Shared.Serialization.Manager.Attributes;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Robust.Shared.Utility;
|
2020-06-28 09:23:26 -06:00
|
|
|
using Robust.Shared.ViewVariables;
|
|
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Server.NodeContainer
|
2020-06-28 09:23:26 -06:00
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Creates and maintains a set of <see cref="Node"/>s.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[RegisterComponent]
|
2021-10-27 18:10:40 +02:00
|
|
|
#pragma warning disable 618
|
2022-02-16 00:23:23 -07:00
|
|
|
public sealed class NodeContainerComponent : Component, IExamine
|
2021-10-27 18:10:40 +02:00
|
|
|
#pragma warning restore 618
|
2020-06-28 09:23:26 -06:00
|
|
|
{
|
2021-10-16 15:40:21 -05:00
|
|
|
//HACK: THIS BEING readOnly IS A FILTHY HACK AND I HATE IT --moony
|
|
|
|
|
[DataField("nodes", readOnly: true)] [ViewVariables] public Dictionary<string, Node> Nodes { get; } = new();
|
2021-04-09 20:47:31 +02:00
|
|
|
|
2021-07-04 18:11:52 +02:00
|
|
|
[DataField("examinable")] private bool _examinable = false;
|
2021-01-04 22:32:59 -06:00
|
|
|
|
2021-04-10 13:25:44 +02:00
|
|
|
public T GetNode<T>(string identifier) where T : Node
|
|
|
|
|
{
|
2021-07-04 18:11:52 +02:00
|
|
|
return (T) Nodes[identifier];
|
2021-04-10 13:25:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool TryGetNode<T>(string identifier, [NotNullWhen(true)] out T? node) where T : Node
|
|
|
|
|
{
|
2021-07-04 18:11:52 +02:00
|
|
|
if (Nodes.TryGetValue(identifier, out var n) && n is T t)
|
2021-04-10 13:25:44 +02:00
|
|
|
{
|
|
|
|
|
node = t;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
node = null;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-20 12:42:42 +01:00
|
|
|
public void Examine(FormattedMessage message, bool inDetailsRange)
|
2021-01-01 14:20:23 +01:00
|
|
|
{
|
|
|
|
|
if (!_examinable || !inDetailsRange) return;
|
|
|
|
|
|
2021-04-09 20:47:31 +02:00
|
|
|
foreach (var node in Nodes.Values)
|
2021-01-01 14:20:23 +01:00
|
|
|
{
|
|
|
|
|
if (node == null) continue;
|
2021-12-20 12:42:42 +01:00
|
|
|
switch (node.NodeGroupID)
|
2021-01-01 14:20:23 +01:00
|
|
|
{
|
2021-12-20 12:42:42 +01:00
|
|
|
case NodeGroupID.HVPower:
|
|
|
|
|
message.AddMarkup(
|
|
|
|
|
Loc.GetString("node-container-component-on-examine-details-hvpower") + "\n");
|
|
|
|
|
break;
|
|
|
|
|
case NodeGroupID.MVPower:
|
|
|
|
|
message.AddMarkup(
|
|
|
|
|
Loc.GetString("node-container-component-on-examine-details-mvpower") + "\n");
|
|
|
|
|
break;
|
|
|
|
|
case NodeGroupID.Apc:
|
|
|
|
|
message.AddMarkup(
|
|
|
|
|
Loc.GetString("node-container-component-on-examine-details-apc") + "\n");
|
|
|
|
|
break;
|
|
|
|
|
}
|
2021-01-01 14:20:23 +01:00
|
|
|
}
|
|
|
|
|
}
|
2020-06-28 09:23:26 -06:00
|
|
|
}
|
|
|
|
|
}
|