Disposal routing fixes (#10583)

This commit is contained in:
Julian Giebel
2022-08-18 23:48:00 +02:00
committed by GitHub
parent 41bb62eb1b
commit f21282cb75
5 changed files with 42 additions and 72 deletions

View File

@@ -39,7 +39,7 @@ namespace Content.Server.Disposal.Tube.Components
{
return _random.Pick(directions);
}
return next;
}
}

View File

@@ -19,14 +19,14 @@ namespace Content.Server.Disposal.Tube.Components
[Dependency] private readonly IEntityManager _entMan = default!;
[ViewVariables]
private readonly HashSet<string> _tags = new();
public readonly HashSet<string> 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();
}
/// <summary>
@@ -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();
}
}
}
/// <summary>
/// Gets component data to be used to update the user interface client-side.
/// </summary>
/// <returns>Returns a <see cref="DisposalRouterUserInterfaceState"/></returns>
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);
}
}
}

View File

@@ -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();
}
/// <summary>
@@ -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();
}
}
/// <summary>
/// Gets component data to be used to update the user interface client-side.
/// </summary>
/// <returns>Returns a <see cref="DisposalTaggerUserInterfaceState"/></returns>
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);
}
}
}

View File

@@ -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<HandsComponent>(args.User, out var hands))
{
@@ -75,8 +79,34 @@ namespace Content.Server.Disposal.Tube
{
args.Cancel();
}
tagger.UserInterface?.SetState(new SharedDisposalTaggerComponent.DisposalTaggerUserInterfaceState(tagger.Tag));
}
/// <summary>
/// Gets component data to be used to update the user interface client-side.
/// </summary>
/// <returns>Returns a <see cref="SharedDisposalRouterComponent.DisposalRouterUserInterfaceState"/></returns>
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,

View File

@@ -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