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

@@ -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);
}
}
}