Files
tbd-station-14/Content.Client/GameObjects/Components/SubFloorHideComponent.cs
Acruid ece6e0a833 Map & Grid Entities (#493)
* Client & Server load with new scene hierarchy.

* Engine Update.
2019-12-22 13:23:38 +01:00

58 lines
1.8 KiB
C#

using Robust.Client.Interfaces.GameObjects.Components;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Components.Transform;
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(Owner, new SubFloorHideDirtyEvent());
}
/// <inheritdoc />
protected override void Shutdown()
{
base.Shutdown();
if(Owner.Transform.Running == false)
return;
_snapGridComponent.OnPositionChanged -= SnapGridOnPositionChanged;
Owner.EntityManager.EventBus.RaiseEvent(Owner, new SubFloorHideDirtyEvent());
}
private void SnapGridOnPositionChanged()
{
Owner.EntityManager.EventBus.RaiseEvent(Owner, new SubFloorHideDirtyEvent());
}
}
internal sealed class SubFloorHideDirtyEvent : EntitySystemMessage { }
}