2022-02-09 16:10:55 +13:00
|
|
|
using Content.Server.NodeContainer.Nodes;
|
2020-11-06 12:52:01 +01:00
|
|
|
using JetBrains.Annotations;
|
2021-02-11 01:13:03 -08:00
|
|
|
using Robust.Shared.GameObjects;
|
2022-02-09 16:10:55 +13:00
|
|
|
using Robust.Shared.IoC;
|
2020-11-06 12:52:01 +01:00
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Server.NodeContainer.EntitySystems
|
2020-11-06 12:52:01 +01:00
|
|
|
{
|
2021-07-06 21:25:04 +02:00
|
|
|
/// <summary>
|
|
|
|
|
/// Manages <see cref="NodeContainerComponent"/> events.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <seealso cref="NodeGroupSystem"/>
|
2020-11-06 12:52:01 +01:00
|
|
|
[UsedImplicitly]
|
2022-02-09 16:10:55 +13:00
|
|
|
public sealed class NodeContainerSystem : EntitySystem
|
2020-11-06 12:52:01 +01:00
|
|
|
{
|
2022-02-09 16:10:55 +13:00
|
|
|
[Dependency] private readonly NodeGroupSystem _nodeGroupSystem = default!;
|
|
|
|
|
|
2020-11-06 12:52:01 +01:00
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
|
2021-07-04 18:11:52 +02:00
|
|
|
SubscribeLocalEvent<NodeContainerComponent, ComponentInit>(OnInitEvent);
|
|
|
|
|
SubscribeLocalEvent<NodeContainerComponent, ComponentStartup>(OnStartupEvent);
|
|
|
|
|
SubscribeLocalEvent<NodeContainerComponent, ComponentShutdown>(OnShutdownEvent);
|
2021-06-19 19:41:26 -07:00
|
|
|
SubscribeLocalEvent<NodeContainerComponent, AnchorStateChangedEvent>(OnAnchorStateChanged);
|
2021-04-09 20:47:31 +02:00
|
|
|
SubscribeLocalEvent<NodeContainerComponent, RotateEvent>(OnRotateEvent);
|
2020-11-06 12:52:01 +01:00
|
|
|
}
|
|
|
|
|
|
2022-02-09 16:10:55 +13:00
|
|
|
private void OnInitEvent(EntityUid uid, NodeContainerComponent component, ComponentInit args)
|
2020-11-06 12:52:01 +01:00
|
|
|
{
|
2021-07-04 18:11:52 +02:00
|
|
|
foreach (var (key, node) in component.Nodes)
|
|
|
|
|
{
|
|
|
|
|
node.Name = key;
|
2022-02-09 16:10:55 +13:00
|
|
|
node.Initialize(component.Owner, EntityManager);
|
2021-07-04 18:11:52 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-09 16:10:55 +13:00
|
|
|
private void OnStartupEvent(EntityUid uid, NodeContainerComponent component, ComponentStartup args)
|
2021-07-04 18:11:52 +02:00
|
|
|
{
|
|
|
|
|
foreach (var node in component.Nodes.Values)
|
|
|
|
|
{
|
2022-02-09 16:10:55 +13:00
|
|
|
_nodeGroupSystem.QueueReflood(node);
|
2021-07-04 18:11:52 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-09 16:10:55 +13:00
|
|
|
private void OnShutdownEvent(EntityUid uid, NodeContainerComponent component, ComponentShutdown args)
|
2021-07-04 18:11:52 +02:00
|
|
|
{
|
|
|
|
|
foreach (var node in component.Nodes.Values)
|
|
|
|
|
{
|
2022-02-09 16:10:55 +13:00
|
|
|
_nodeGroupSystem.QueueNodeRemove(node);
|
|
|
|
|
node.Deleting = true;
|
2021-07-04 18:11:52 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-09 16:10:55 +13:00
|
|
|
private void OnAnchorStateChanged(
|
2021-07-04 18:11:52 +02:00
|
|
|
EntityUid uid,
|
|
|
|
|
NodeContainerComponent component,
|
2021-08-21 11:49:31 +02:00
|
|
|
ref AnchorStateChangedEvent args)
|
2021-07-04 18:11:52 +02:00
|
|
|
{
|
|
|
|
|
foreach (var node in component.Nodes.Values)
|
|
|
|
|
{
|
2022-02-09 16:10:55 +13:00
|
|
|
if (!node.NeedAnchored)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (args.Anchored)
|
|
|
|
|
_nodeGroupSystem.QueueReflood(node);
|
|
|
|
|
else
|
|
|
|
|
_nodeGroupSystem.QueueNodeRemove(node);
|
2021-07-04 18:11:52 +02:00
|
|
|
}
|
2021-04-09 20:47:31 +02:00
|
|
|
}
|
2020-11-06 12:52:01 +01:00
|
|
|
|
2022-02-09 16:10:55 +13:00
|
|
|
private void OnRotateEvent(EntityUid uid, NodeContainerComponent container, ref RotateEvent ev)
|
2021-04-09 20:47:31 +02:00
|
|
|
{
|
2020-11-06 12:52:01 +01:00
|
|
|
if (ev.NewRotation == ev.OldRotation)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-09 20:47:31 +02:00
|
|
|
foreach (var node in container.Nodes.Values)
|
2020-11-06 12:52:01 +01:00
|
|
|
{
|
2022-02-09 16:10:55 +13:00
|
|
|
if (node is not IRotatableNode rotatableNode)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (rotatableNode.RotateEvent(ref ev))
|
|
|
|
|
_nodeGroupSystem.QueueReflood(node);
|
2020-11-06 12:52:01 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|