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 _random.Pick(directions);
} }
return next; return next;
} }
} }

View File

@@ -19,14 +19,14 @@ namespace Content.Server.Disposal.Tube.Components
[Dependency] private readonly IEntityManager _entMan = default!; [Dependency] private readonly IEntityManager _entMan = default!;
[ViewVariables] [ViewVariables]
private readonly HashSet<string> _tags = new(); public readonly HashSet<string> Tags = new();
[ViewVariables] [ViewVariables]
public bool Anchored => public bool Anchored =>
!_entMan.TryGetComponent(Owner, out IPhysBody? physics) || !_entMan.TryGetComponent(Owner, out IPhysBody? physics) ||
physics.BodyType == BodyType.Static; 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"); [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(); var directions = ConnectableDirections();
if (holder.Tags.Overlaps(_tags)) if (holder.Tags.Overlaps(Tags))
{ {
return directions[1]; return directions[1];
} }
@@ -50,8 +50,6 @@ namespace Content.Server.Disposal.Tube.Components
{ {
UserInterface.OnReceiveMessage += OnUiReceiveMessage; UserInterface.OnReceiveMessage += OnUiReceiveMessage;
} }
UpdateUserInterface();
} }
/// <summary> /// <summary>
@@ -74,45 +72,15 @@ namespace Content.Server.Disposal.Tube.Components
//Check for correct message and ignore maleformed strings //Check for correct message and ignore maleformed strings
if (msg.Action == UiAction.Ok && TagRegex.IsMatch(msg.Tags)) if (msg.Action == UiAction.Ok && TagRegex.IsMatch(msg.Tags))
{ {
_tags.Clear(); Tags.Clear();
foreach (var tag in msg.Tags.Split(',', StringSplitOptions.RemoveEmptyEntries)) foreach (var tag in msg.Tags.Split(',', StringSplitOptions.RemoveEmptyEntries))
{ {
_tags.Add(tag.Trim()); Tags.Add(tag.Trim());
ClickSound(); 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() private void ClickSound()
{ {
SoundSystem.Play(_clickSound.GetSound(), Filter.Pvs(Owner), Owner, AudioParams.Default.WithVolume(-2f)); SoundSystem.Play(_clickSound.GetSound(), Filter.Pvs(Owner), Owner, AudioParams.Default.WithVolume(-2f));
@@ -123,11 +91,5 @@ namespace Content.Server.Disposal.Tube.Components
UserInterface?.CloseAll(); UserInterface?.CloseAll();
base.OnRemove(); 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"; public override string ContainerId => "DisposalTagger";
[ViewVariables(VVAccess.ReadWrite)] [ViewVariables(VVAccess.ReadWrite)]
private string _tag = ""; public string Tag = "";
[ViewVariables] [ViewVariables]
public bool Anchored => public bool Anchored =>
!_entMan.TryGetComponent(Owner, out PhysicsComponent? physics) || !_entMan.TryGetComponent(Owner, out PhysicsComponent? physics) ||
physics.BodyType == BodyType.Static; 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"); [DataField("clickSound")] private SoundSpecifier _clickSound = new SoundPathSpecifier("/Audio/Machines/machine_switch.ogg");
public override Direction NextDirection(DisposalHolderComponent holder) public override Direction NextDirection(DisposalHolderComponent holder)
{ {
holder.Tags.Add(_tag); holder.Tags.Add(Tag);
return base.NextDirection(holder); return base.NextDirection(holder);
} }
@@ -43,8 +43,6 @@ namespace Content.Server.Disposal.Tube.Components
{ {
UserInterface.OnReceiveMessage += OnUiReceiveMessage; UserInterface.OnReceiveMessage += OnUiReceiveMessage;
} }
UpdateUserInterface();
} }
/// <summary> /// <summary>
@@ -62,26 +60,11 @@ namespace Content.Server.Disposal.Tube.Components
//Check for correct message and ignore maleformed strings //Check for correct message and ignore maleformed strings
if (msg.Action == UiAction.Ok && TagRegex.IsMatch(msg.Tag)) if (msg.Action == UiAction.Ok && TagRegex.IsMatch(msg.Tag))
{ {
_tag = msg.Tag; Tag = msg.Tag;
ClickSound(); 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() private void ClickSound()
{ {
SoundSystem.Play(_clickSound.GetSound(), Filter.Pvs(Owner), Owner, AudioParams.Default.WithVolume(-2f)); SoundSystem.Play(_clickSound.GetSound(), Filter.Pvs(Owner), Owner, AudioParams.Default.WithVolume(-2f));
@@ -92,10 +75,5 @@ namespace Content.Server.Disposal.Tube.Components
base.OnRemove(); base.OnRemove();
UserInterface?.CloseAll(); 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.Disposal.Tube.Components;
using Content.Server.UserInterface; using Content.Server.UserInterface;
using Content.Server.Hands.Components; using Content.Server.Hands.Components;
using Content.Shared.Destructible; using Content.Shared.Destructible;
using Content.Shared.Disposal.Components;
using Content.Shared.Movement; using Content.Shared.Movement;
using Content.Shared.Movement.Events; using Content.Shared.Movement.Events;
using Content.Shared.Verbs; using Content.Shared.Verbs;
@@ -60,9 +62,11 @@ namespace Content.Server.Disposal.Tube
{ {
args.Cancel(); 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)) if (!TryComp<HandsComponent>(args.User, out var hands))
{ {
@@ -75,8 +79,34 @@ namespace Content.Server.Disposal.Tube
{ {
args.Cancel(); 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( private static void BodyTypeChanged(
EntityUid uid, EntityUid uid,

View File

@@ -177,7 +177,7 @@
id: DisposalRouter id: DisposalRouter
parent: DisposalPipeBase parent: DisposalPipeBase
name: disposal router 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: components:
- type: Sprite - type: Sprite
drawdepth: ThickPipe drawdepth: ThickPipe