Files
tbd-station-14/Content.Server/NodeContainer/EntitySystems/NodeContainerSystem.cs
Pieter-Jan Briers 103bc19508 Pow3r: stage 1 (#4208)
Co-authored-by: 20kdc <asdd2808@gmail.com>
2021-07-04 18:11:52 +02:00

73 lines
2.4 KiB
C#

using Content.Server.NodeContainer.Nodes;
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
namespace Content.Server.NodeContainer.EntitySystems
{
[UsedImplicitly]
public class NodeContainerSystem : EntitySystem
{
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<NodeContainerComponent, ComponentInit>(OnInitEvent);
SubscribeLocalEvent<NodeContainerComponent, ComponentStartup>(OnStartupEvent);
SubscribeLocalEvent<NodeContainerComponent, ComponentShutdown>(OnShutdownEvent);
SubscribeLocalEvent<NodeContainerComponent, AnchorStateChangedEvent>(OnAnchorStateChanged);
SubscribeLocalEvent<NodeContainerComponent, RotateEvent>(OnRotateEvent);
}
private static void OnInitEvent(EntityUid uid, NodeContainerComponent component, ComponentInit args)
{
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();
}
}
private static void OnRotateEvent(EntityUid uid, NodeContainerComponent container, RotateEvent ev)
{
if (ev.NewRotation == ev.OldRotation)
{
return;
}
foreach (var node in container.Nodes.Values)
{
if (node is not IRotatableNode rotatableNode) continue;
rotatableNode.RotateEvent(ev);
}
}
}
}