2021-06-09 22:19:39 +02: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;
|
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
|
|
|
|
{
|
|
|
|
|
|
[UsedImplicitly]
|
|
|
|
|
|
public class NodeContainerSystem : EntitySystem
|
|
|
|
|
|
{
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
2021-07-04 18:11:52 +02:00
|
|
|
|
private static 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;
|
|
|
|
|
|
node.Initialize(component.Owner);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static void OnStartupEvent(EntityUid uid, NodeContainerComponent component, ComponentStartup args)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var node in component.Nodes.Values)
|
|
|
|
|
|
{
|
|
|
|
|
|
node.OnContainerStartup();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static void OnShutdownEvent(EntityUid uid, NodeContainerComponent component, ComponentShutdown args)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var node in component.Nodes.Values)
|
|
|
|
|
|
{
|
|
|
|
|
|
node.OnContainerShutdown();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static void OnAnchorStateChanged(
|
|
|
|
|
|
EntityUid uid,
|
|
|
|
|
|
NodeContainerComponent component,
|
|
|
|
|
|
AnchorStateChangedEvent args)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var node in component.Nodes.Values)
|
|
|
|
|
|
{
|
|
|
|
|
|
node.AnchorUpdate();
|
|
|
|
|
|
node.AnchorStateChanged();
|
|
|
|
|
|
}
|
2021-04-09 20:47:31 +02:00
|
|
|
|
}
|
2020-11-06 12:52:01 +01:00
|
|
|
|
|
2021-07-04 18:11:52 +02:00
|
|
|
|
private static void OnRotateEvent(EntityUid uid, NodeContainerComponent container, 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
|
|
|
|
{
|
2021-04-09 20:47:31 +02:00
|
|
|
|
if (node is not IRotatableNode rotatableNode) continue;
|
2020-11-06 12:52:01 +01:00
|
|
|
|
rotatableNode.RotateEvent(ev);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|