Files
tbd-station-14/Content.Client/GameObjects/Components/SubFloorHideComponent.cs
Acruid ee6eec9c40 SubscribeEvent() has been split into SubscribeNetworkEvent() and SubscribeLocalEvent() methods on EntitySystem.
Most methods on EntityEventBus now require callers to specify the source (Local or Network) of the events.
2020-02-19 17:08:59 -08:00

67 lines
2.0 KiB
C#

using Robust.Client.Interfaces.GameObjects.Components;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Components.Transform;
using Robust.Shared.Interfaces.GameObjects;
namespace Content.Client.GameObjects.Components
{
/// <summary>
/// Simple component that automatically hides the sibling
/// <see cref="ISpriteComponent" /> when the tile it's on is not a sub floor
/// (plating).
/// </summary>
/// <seealso cref="P:Content.Shared.Maps.ContentTileDefinition.IsSubFloor" />
[RegisterComponent]
public sealed class SubFloorHideComponent : Component
{
private SnapGridComponent _snapGridComponent;
/// <inheritdoc />
public override string Name => "SubFloorHide";
/// <inheritdoc />
public override void Initialize()
{
base.Initialize();
_snapGridComponent = Owner.GetComponent<SnapGridComponent>();
}
/// <inheritdoc />
protected override void Startup()
{
base.Startup();
_snapGridComponent.OnPositionChanged += SnapGridOnPositionChanged;
Owner.EntityManager.EventBus.RaiseEvent(EventSource.Local, new SubFloorHideDirtyEvent(Owner));
}
/// <inheritdoc />
protected override void Shutdown()
{
base.Shutdown();
if(Owner.Transform.Running == false)
return;
_snapGridComponent.OnPositionChanged -= SnapGridOnPositionChanged;
Owner.EntityManager.EventBus.RaiseEvent(EventSource.Local, new SubFloorHideDirtyEvent(Owner));
}
private void SnapGridOnPositionChanged()
{
Owner.EntityManager.EventBus.RaiseEvent(EventSource.Local, new SubFloorHideDirtyEvent(Owner));
}
}
internal sealed class SubFloorHideDirtyEvent : EntitySystemMessage
{
public IEntity Sender { get; }
public SubFloorHideDirtyEvent(IEntity sender)
{
Sender = sender;
}
}
}