Files
tbd-station-14/Content.Client/GameObjects/Components/SubFloorHideComponent.cs
Acruid 6edc416afc EntitySystemMessage Removal & InteractionSystem directed events (#3572)
* Removed obsolete EntitySystemMessage, now everything uses the base EntityEventArgs or the derived HandledEntityEventArgs.
Setup InteractionSystem to use new directed events.

* Update Submodule.
2021-03-09 11:22:48 -08:00

65 lines
1.9 KiB
C#

using Robust.Client.GameObjects;
using Robust.Shared.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 : EntityEventArgs
{
public IEntity Sender { get; }
public SubFloorHideDirtyEvent(IEntity sender)
{
Sender = sender;
}
}
}