using Robust.Client.GameObjects; using Robust.Shared.GameObjects; namespace Content.Client.GameObjects.Components { /// /// Simple component that automatically hides the sibling /// when the tile it's on is not a sub floor /// (plating). /// /// [RegisterComponent] public sealed class SubFloorHideComponent : Component { private SnapGridComponent _snapGridComponent; /// public override string Name => "SubFloorHide"; /// public override void Initialize() { base.Initialize(); _snapGridComponent = Owner.GetComponent(); } /// protected override void Startup() { base.Startup(); _snapGridComponent.OnPositionChanged += SnapGridOnPositionChanged; Owner.EntityManager.EventBus.RaiseEvent(EventSource.Local, new SubFloorHideDirtyEvent(Owner)); } /// 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; } } }