From 5274b0320a980d7d82fb45433ab67f1844ca8813 Mon Sep 17 00:00:00 2001 From: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com> Date: Fri, 26 Aug 2022 16:16:08 +1200 Subject: [PATCH] Fix disposal pipe visuals (#10873) --- .../Tube/Components/DisposalTubeComponent.cs | 61 +------------------ .../Disposal/Tube/DisposalTubeSystem.cs | 31 ++++++++-- 2 files changed, 27 insertions(+), 65 deletions(-) diff --git a/Content.Server/Disposal/Tube/Components/DisposalTubeComponent.cs b/Content.Server/Disposal/Tube/Components/DisposalTubeComponent.cs index 5547157676..44fab27a48 100644 --- a/Content.Server/Disposal/Tube/Components/DisposalTubeComponent.cs +++ b/Content.Server/Disposal/Tube/Components/DisposalTubeComponent.cs @@ -37,7 +37,8 @@ namespace Content.Server.Disposal.Tube.Components public abstract Direction NextDirection(DisposalHolderComponent holder); // TODO: Make disposal pipes extend the grid - private void Connect() + // ??? + public void Connect() { if (_connected) { @@ -89,50 +90,6 @@ namespace Content.Server.Disposal.Tube.Components Owner.PopupMessage(entity, Loc.GetString("disposal-tube-component-popup-directions-text", ("directions", directions))); } - private void UpdateVisualState() - { - if (!_entMan.TryGetComponent(Owner, out AppearanceComponent? appearance)) - { - return; - } - - // TODO this should just generalized into some anchored-visuals system/comp, this has nothing to do with disposal tubes. - var state = _entMan.GetComponent(Owner).Anchored - ? DisposalTubeVisualState.Anchored - : DisposalTubeVisualState.Free; - - appearance.SetData(DisposalTubeVisuals.VisualState, state); - } - - public void AnchoredChanged() - { - if (!_entMan.TryGetComponent(Owner, out PhysicsComponent? physics)) - { - return; - } - - if (physics.BodyType == BodyType.Static) - { - OnAnchor(); - } - else - { - OnUnAnchor(); - } - } - - private void OnAnchor() - { - Connect(); - UpdateVisualState(); - } - - private void OnUnAnchor() - { - Disconnect(); - UpdateVisualState(); - } - protected override void Initialize() { base.Initialize(); @@ -141,20 +98,6 @@ namespace Content.Server.Disposal.Tube.Components Owner.EnsureComponent(); } - protected override void Startup() - { - base.Startup(); - - Owner.EnsureComponent(out var physicsComponent); - if (physicsComponent.BodyType != BodyType.Static) - { - return; - } - - Connect(); - UpdateVisualState(); - } - protected override void OnRemove() { base.OnRemove(); diff --git a/Content.Server/Disposal/Tube/DisposalTubeSystem.cs b/Content.Server/Disposal/Tube/DisposalTubeSystem.cs index 833892084e..f08cbb4c59 100644 --- a/Content.Server/Disposal/Tube/DisposalTubeSystem.cs +++ b/Content.Server/Disposal/Tube/DisposalTubeSystem.cs @@ -20,17 +20,23 @@ namespace Content.Server.Disposal.Tube { [Dependency] private readonly IGameTiming _gameTiming = default!; [Dependency] private readonly IMapManager _mapManager = default!; + [Dependency] private readonly SharedAppearanceSystem _appearanceSystem = default!; public override void Initialize() { base.Initialize(); - SubscribeLocalEvent(BodyTypeChanged); + SubscribeLocalEvent(OnAnchorChange); SubscribeLocalEvent(OnRelayMovement); SubscribeLocalEvent(OnBreak); SubscribeLocalEvent(OnOpenRouterUIAttempt); SubscribeLocalEvent(OnOpenTaggerUIAttempt); + SubscribeLocalEvent(OnStartup); + } + private void OnStartup(EntityUid uid, DisposalTubeComponent component, ComponentStartup args) + { + UpdateAnchored(uid, component, Transform(uid).Anchored); } private void OnRelayMovement(EntityUid uid, DisposalTubeComponent component, ref ContainerRelayMovementEntityEvent args) @@ -108,12 +114,25 @@ namespace Content.Server.Disposal.Tube router.UserInterface?.SetState(new SharedDisposalRouterComponent.DisposalRouterUserInterfaceState(taglist.ToString())); } - private static void BodyTypeChanged( - EntityUid uid, - DisposalTubeComponent component, - ref PhysicsBodyTypeChangedEvent args) + private void OnAnchorChange(EntityUid uid, DisposalTubeComponent component, ref AnchorStateChangedEvent args) { - component.AnchoredChanged(); + UpdateAnchored(uid, component, args.Anchored); + } + + private void UpdateAnchored(EntityUid uid, DisposalTubeComponent component, bool anchored) + { + if (anchored) + { + component.Connect(); + + // TODO this visual data should just generalized into some anchored-visuals system/comp, this has nothing to do with disposal tubes. + _appearanceSystem.SetData(uid, DisposalTubeVisuals.VisualState, DisposalTubeVisualState.Anchored); + } + else + { + component.Disconnect(); + _appearanceSystem.SetData(uid, DisposalTubeVisuals.VisualState, DisposalTubeVisualState.Free); + } } public IDisposalTubeComponent? NextTubeFor(EntityUid target, Direction nextDirection, IDisposalTubeComponent? targetTube = null)