From f21282cb7519bdd432b5a68996d2b1bf19997418 Mon Sep 17 00:00:00 2001 From: Julian Giebel Date: Thu, 18 Aug 2022 23:48:00 +0200 Subject: [PATCH] Disposal routing fixes (#10583) --- .../Components/DisposalJunctionComponent.cs | 2 +- .../Components/DisposalRouterComponent.cs | 48 ++----------------- .../Components/DisposalTaggerComponent.cs | 30 ++---------- .../Disposal/Tube/DisposalTubeSystem.cs | 32 ++++++++++++- .../Structures/Piping/Disposal/pipes.yml | 2 +- 5 files changed, 42 insertions(+), 72 deletions(-) diff --git a/Content.Server/Disposal/Tube/Components/DisposalJunctionComponent.cs b/Content.Server/Disposal/Tube/Components/DisposalJunctionComponent.cs index ba6276c028..e105f4cc59 100644 --- a/Content.Server/Disposal/Tube/Components/DisposalJunctionComponent.cs +++ b/Content.Server/Disposal/Tube/Components/DisposalJunctionComponent.cs @@ -39,7 +39,7 @@ namespace Content.Server.Disposal.Tube.Components { return _random.Pick(directions); } - + return next; } } diff --git a/Content.Server/Disposal/Tube/Components/DisposalRouterComponent.cs b/Content.Server/Disposal/Tube/Components/DisposalRouterComponent.cs index 550b5e94d6..92c7cbff6b 100644 --- a/Content.Server/Disposal/Tube/Components/DisposalRouterComponent.cs +++ b/Content.Server/Disposal/Tube/Components/DisposalRouterComponent.cs @@ -19,14 +19,14 @@ namespace Content.Server.Disposal.Tube.Components [Dependency] private readonly IEntityManager _entMan = default!; [ViewVariables] - private readonly HashSet _tags = new(); + public readonly HashSet Tags = new(); [ViewVariables] public bool Anchored => !_entMan.TryGetComponent(Owner, out IPhysBody? physics) || physics.BodyType == BodyType.Static; - [ViewVariables] private BoundUserInterface? UserInterface => Owner.GetUIOrNull(DisposalRouterUiKey.Key); + [ViewVariables] public BoundUserInterface? UserInterface => Owner.GetUIOrNull(DisposalRouterUiKey.Key); [DataField("clickSound")] private SoundSpecifier _clickSound = new SoundPathSpecifier("/Audio/Machines/machine_switch.ogg"); @@ -34,7 +34,7 @@ namespace Content.Server.Disposal.Tube.Components { var directions = ConnectableDirections(); - if (holder.Tags.Overlaps(_tags)) + if (holder.Tags.Overlaps(Tags)) { return directions[1]; } @@ -50,8 +50,6 @@ namespace Content.Server.Disposal.Tube.Components { UserInterface.OnReceiveMessage += OnUiReceiveMessage; } - - UpdateUserInterface(); } /// @@ -74,45 +72,15 @@ namespace Content.Server.Disposal.Tube.Components //Check for correct message and ignore maleformed strings if (msg.Action == UiAction.Ok && TagRegex.IsMatch(msg.Tags)) { - _tags.Clear(); + Tags.Clear(); foreach (var tag in msg.Tags.Split(',', StringSplitOptions.RemoveEmptyEntries)) { - _tags.Add(tag.Trim()); + Tags.Add(tag.Trim()); ClickSound(); } } } - /// - /// Gets component data to be used to update the user interface client-side. - /// - /// Returns a - private DisposalRouterUserInterfaceState GetUserInterfaceState() - { - if (_tags.Count <= 0) - { - return new DisposalRouterUserInterfaceState(""); - } - - var taglist = new StringBuilder(); - - foreach (var tag in _tags) - { - taglist.Append(tag); - taglist.Append(", "); - } - - taglist.Remove(taglist.Length - 2, 2); - - return new DisposalRouterUserInterfaceState(taglist.ToString()); - } - - private void UpdateUserInterface() - { - var state = GetUserInterfaceState(); - UserInterface?.SetState(state); - } - private void ClickSound() { SoundSystem.Play(_clickSound.GetSound(), Filter.Pvs(Owner), Owner, AudioParams.Default.WithVolume(-2f)); @@ -123,11 +91,5 @@ namespace Content.Server.Disposal.Tube.Components UserInterface?.CloseAll(); base.OnRemove(); } - - public void OpenUserInterface(ActorComponent actor) - { - UpdateUserInterface(); - UserInterface?.Open(actor.PlayerSession); - } } } diff --git a/Content.Server/Disposal/Tube/Components/DisposalTaggerComponent.cs b/Content.Server/Disposal/Tube/Components/DisposalTaggerComponent.cs index bdef8a8b5d..ad3ede65a6 100644 --- a/Content.Server/Disposal/Tube/Components/DisposalTaggerComponent.cs +++ b/Content.Server/Disposal/Tube/Components/DisposalTaggerComponent.cs @@ -18,20 +18,20 @@ namespace Content.Server.Disposal.Tube.Components public override string ContainerId => "DisposalTagger"; [ViewVariables(VVAccess.ReadWrite)] - private string _tag = ""; + public string Tag = ""; [ViewVariables] public bool Anchored => !_entMan.TryGetComponent(Owner, out PhysicsComponent? physics) || physics.BodyType == BodyType.Static; - [ViewVariables] private BoundUserInterface? UserInterface => Owner.GetUIOrNull(DisposalTaggerUiKey.Key); + [ViewVariables] public BoundUserInterface? UserInterface => Owner.GetUIOrNull(DisposalTaggerUiKey.Key); [DataField("clickSound")] private SoundSpecifier _clickSound = new SoundPathSpecifier("/Audio/Machines/machine_switch.ogg"); public override Direction NextDirection(DisposalHolderComponent holder) { - holder.Tags.Add(_tag); + holder.Tags.Add(Tag); return base.NextDirection(holder); } @@ -43,8 +43,6 @@ namespace Content.Server.Disposal.Tube.Components { UserInterface.OnReceiveMessage += OnUiReceiveMessage; } - - UpdateUserInterface(); } /// @@ -62,26 +60,11 @@ namespace Content.Server.Disposal.Tube.Components //Check for correct message and ignore maleformed strings if (msg.Action == UiAction.Ok && TagRegex.IsMatch(msg.Tag)) { - _tag = msg.Tag; + Tag = msg.Tag; ClickSound(); } } - /// - /// Gets component data to be used to update the user interface client-side. - /// - /// Returns a - private DisposalTaggerUserInterfaceState GetUserInterfaceState() - { - return new(_tag); - } - - private void UpdateUserInterface() - { - var state = GetUserInterfaceState(); - UserInterface?.SetState(state); - } - private void ClickSound() { SoundSystem.Play(_clickSound.GetSound(), Filter.Pvs(Owner), Owner, AudioParams.Default.WithVolume(-2f)); @@ -92,10 +75,5 @@ namespace Content.Server.Disposal.Tube.Components base.OnRemove(); UserInterface?.CloseAll(); } - public void OpenUserInterface(ActorComponent actor) - { - UpdateUserInterface(); - UserInterface?.Open(actor.PlayerSession); - } } } diff --git a/Content.Server/Disposal/Tube/DisposalTubeSystem.cs b/Content.Server/Disposal/Tube/DisposalTubeSystem.cs index a58f9e7d80..833892084e 100644 --- a/Content.Server/Disposal/Tube/DisposalTubeSystem.cs +++ b/Content.Server/Disposal/Tube/DisposalTubeSystem.cs @@ -1,7 +1,9 @@ +using System.Text; using Content.Server.Disposal.Tube.Components; using Content.Server.UserInterface; using Content.Server.Hands.Components; using Content.Shared.Destructible; +using Content.Shared.Disposal.Components; using Content.Shared.Movement; using Content.Shared.Movement.Events; using Content.Shared.Verbs; @@ -60,9 +62,11 @@ namespace Content.Server.Disposal.Tube { args.Cancel(); } + + UpdateRouterUserInterface(router); } - private void OnOpenTaggerUIAttempt(EntityUid uid, DisposalTaggerComponent router, ActivatableUIOpenAttemptEvent args) + private void OnOpenTaggerUIAttempt(EntityUid uid, DisposalTaggerComponent tagger, ActivatableUIOpenAttemptEvent args) { if (!TryComp(args.User, out var hands)) { @@ -75,8 +79,34 @@ namespace Content.Server.Disposal.Tube { args.Cancel(); } + + tagger.UserInterface?.SetState(new SharedDisposalTaggerComponent.DisposalTaggerUserInterfaceState(tagger.Tag)); } + /// + /// Gets component data to be used to update the user interface client-side. + /// + /// Returns a + private void UpdateRouterUserInterface(DisposalRouterComponent router) + { + if (router.Tags.Count <= 0) + { + router.UserInterface?.SetState(new SharedDisposalRouterComponent.DisposalRouterUserInterfaceState("")); + return; + } + + var taglist = new StringBuilder(); + + foreach (var tag in router.Tags) + { + taglist.Append(tag); + taglist.Append(", "); + } + + taglist.Remove(taglist.Length - 2, 2); + + router.UserInterface?.SetState(new SharedDisposalRouterComponent.DisposalRouterUserInterfaceState(taglist.ToString())); + } private static void BodyTypeChanged( EntityUid uid, diff --git a/Resources/Prototypes/Entities/Structures/Piping/Disposal/pipes.yml b/Resources/Prototypes/Entities/Structures/Piping/Disposal/pipes.yml index 6578ee8f7b..0c38066c52 100644 --- a/Resources/Prototypes/Entities/Structures/Piping/Disposal/pipes.yml +++ b/Resources/Prototypes/Entities/Structures/Piping/Disposal/pipes.yml @@ -177,7 +177,7 @@ id: DisposalRouter parent: DisposalPipeBase name: disposal router - description: A three-way router. Entities with matching tags get routed to the side. + description: A three-way router. Entities with matching tags get routed to the side via configurable filters. components: - type: Sprite drawdepth: ThickPipe