Move all logic from SubFloorHideComponent to SubFloorHideSystem. (#3824)

This commit is contained in:
Vera Aguilera Puerto
2021-04-09 16:46:45 +02:00
committed by GitHub
parent a03e9686ea
commit 0827a95bee
2 changed files with 45 additions and 62 deletions

View File

@@ -1,6 +1,6 @@
#nullable enable
using Content.Shared.GameObjects.EntitySystems;
using Robust.Shared.GameObjects;
using Robust.Shared.Log;
namespace Content.Shared.GameObjects.Components
{
@@ -13,60 +13,7 @@ namespace Content.Shared.GameObjects.Components
[RegisterComponent]
public sealed class SubFloorHideComponent : Component
{
[ComponentDependency(nameof(OnAddSnapGrid))]
private SnapGridComponent? _snapGridComponent;
/// <inheritdoc />
public override string Name => "SubFloorHide";
/// <inheritdoc />
protected override void Startup()
{
base.Startup();
Owner.EntityManager.EventBus.RaiseEvent(EventSource.Local, new SubFloorHideDirtyEvent(Owner));
}
/// <inheritdoc />
protected override void Shutdown()
{
base.Shutdown();
if (Owner.Transform.Running == false)
return;
if (_snapGridComponent != null)
{
_snapGridComponent.OnPositionChanged -= SnapGridOnPositionChanged;
}
Owner.EntityManager.EventBus.RaiseEvent(EventSource.Local, new SubFloorHideDirtyEvent(Owner));
}
private void OnAddSnapGrid()
{
if (_snapGridComponent == null)
{
// Shouldn't happen but allows us to use nullables. OnPositionChanged needs to be componentbus anyway.
Logger.Error("Snapgrid was null for subfloor {Owner}");
return;
}
_snapGridComponent.OnPositionChanged += SnapGridOnPositionChanged;
}
private void SnapGridOnPositionChanged()
{
Owner.EntityManager.EventBus.RaiseEvent(EventSource.Local, new SubFloorHideDirtyEvent(Owner));
}
}
internal sealed class SubFloorHideDirtyEvent : EntityEventArgs
{
public IEntity Sender { get; }
public SubFloorHideDirtyEvent(IEntity sender)
{
Sender = sender;
}
}
}