Remove disposal tubes component references and ECS some of it (#15188)
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Content.Server.Construction.Completions;
|
||||
using Content.Server.Disposal.Tube.Components;
|
||||
using Content.Server.Hands.Components;
|
||||
using Content.Server.Popups;
|
||||
using Content.Server.UserInterface;
|
||||
using Content.Shared.Destructible;
|
||||
using Content.Shared.Disposal.Components;
|
||||
@@ -9,8 +12,8 @@ using Content.Shared.Popups;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Random;
|
||||
using Robust.Shared.Timing;
|
||||
using System.Text;
|
||||
|
||||
namespace Content.Server.Disposal.Tube
|
||||
{
|
||||
@@ -18,7 +21,9 @@ namespace Content.Server.Disposal.Tube
|
||||
{
|
||||
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
||||
[Dependency] private readonly IMapManager _mapManager = default!;
|
||||
[Dependency] private readonly IRobustRandom _random = default!;
|
||||
[Dependency] private readonly SharedAppearanceSystem _appearanceSystem = default!;
|
||||
[Dependency] private readonly PopupSystem _popups = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
@@ -27,10 +32,153 @@ namespace Content.Server.Disposal.Tube
|
||||
SubscribeLocalEvent<DisposalTubeComponent, AnchorStateChangedEvent>(OnAnchorChange);
|
||||
SubscribeLocalEvent<DisposalTubeComponent, ContainerRelayMovementEntityEvent>(OnRelayMovement);
|
||||
SubscribeLocalEvent<DisposalTubeComponent, BreakageEventArgs>(OnBreak);
|
||||
SubscribeLocalEvent<DisposalRouterComponent, ActivatableUIOpenAttemptEvent>(OnOpenRouterUIAttempt);
|
||||
SubscribeLocalEvent<DisposalTaggerComponent, ActivatableUIOpenAttemptEvent>(OnOpenTaggerUIAttempt);
|
||||
SubscribeLocalEvent<DisposalTubeComponent, ComponentStartup>(OnStartup);
|
||||
SubscribeLocalEvent<DisposalTubeComponent, ConstructionBeforeDeleteEvent>(OnDeconstruct);
|
||||
|
||||
SubscribeLocalEvent<DisposalBendComponent, GetDisposalsConnectableDirectionsEvent>(OnGetBendConnectableDirections);
|
||||
SubscribeLocalEvent<DisposalBendComponent, GetDisposalsNextDirectionEvent>(OnGetBendNextDirection);
|
||||
|
||||
SubscribeLocalEvent<DisposalEntryComponent, GetDisposalsConnectableDirectionsEvent>(OnGetEntryConnectableDirections);
|
||||
SubscribeLocalEvent<DisposalEntryComponent, GetDisposalsNextDirectionEvent>(OnGetEntryNextDirection);
|
||||
|
||||
SubscribeLocalEvent<DisposalJunctionComponent, GetDisposalsConnectableDirectionsEvent>(OnGetJunctionConnectableDirections);
|
||||
SubscribeLocalEvent<DisposalJunctionComponent, GetDisposalsNextDirectionEvent>(OnGetJunctionNextDirection);
|
||||
|
||||
SubscribeLocalEvent<DisposalRouterComponent, GetDisposalsConnectableDirectionsEvent>(OnGetRouterConnectableDirections);
|
||||
SubscribeLocalEvent<DisposalRouterComponent, GetDisposalsNextDirectionEvent>(OnGetRouterNextDirection);
|
||||
|
||||
SubscribeLocalEvent<DisposalTransitComponent, GetDisposalsConnectableDirectionsEvent>(OnGetTransitConnectableDirections);
|
||||
SubscribeLocalEvent<DisposalTransitComponent, GetDisposalsNextDirectionEvent>(OnGetTransitNextDirection);
|
||||
|
||||
SubscribeLocalEvent<DisposalTaggerComponent, GetDisposalsConnectableDirectionsEvent>(OnGetTaggerConnectableDirections);
|
||||
SubscribeLocalEvent<DisposalTaggerComponent, GetDisposalsNextDirectionEvent>(OnGetTaggerNextDirection);
|
||||
|
||||
SubscribeLocalEvent<DisposalRouterComponent, ActivatableUIOpenAttemptEvent>(OnOpenRouterUIAttempt);
|
||||
SubscribeLocalEvent<DisposalTaggerComponent, ActivatableUIOpenAttemptEvent>(OnOpenTaggerUIAttempt);
|
||||
}
|
||||
|
||||
private void OnGetBendConnectableDirections(EntityUid uid, DisposalBendComponent component, ref GetDisposalsConnectableDirectionsEvent args)
|
||||
{
|
||||
var direction = Transform(uid).LocalRotation;
|
||||
var side = new Angle(MathHelper.DegreesToRadians(direction.Degrees - 90));
|
||||
|
||||
args.Connectable = new[] {direction.GetDir(), side.GetDir()};
|
||||
}
|
||||
|
||||
private void OnGetBendNextDirection(EntityUid uid, DisposalBendComponent component, ref GetDisposalsNextDirectionEvent args)
|
||||
{
|
||||
var ev = new GetDisposalsConnectableDirectionsEvent();
|
||||
RaiseLocalEvent(uid, ref ev);
|
||||
|
||||
var previousDF = args.Holder.PreviousDirectionFrom;
|
||||
|
||||
if (previousDF == Direction.Invalid)
|
||||
{
|
||||
args.Next = ev.Connectable[0];
|
||||
return;
|
||||
}
|
||||
|
||||
args.Next = previousDF == ev.Connectable[0] ? ev.Connectable[1] : ev.Connectable[0];
|
||||
}
|
||||
|
||||
private void OnGetEntryConnectableDirections(EntityUid uid, DisposalEntryComponent component, ref GetDisposalsConnectableDirectionsEvent args)
|
||||
{
|
||||
args.Connectable = new[] {Transform(uid).LocalRotation.GetDir()};
|
||||
}
|
||||
|
||||
private void OnGetEntryNextDirection(EntityUid uid, DisposalEntryComponent component, ref GetDisposalsNextDirectionEvent args)
|
||||
{
|
||||
// Ejects contents when they come from the same direction the entry is facing.
|
||||
if (args.Holder.PreviousDirectionFrom != Direction.Invalid)
|
||||
{
|
||||
args.Next = Direction.Invalid;
|
||||
return;
|
||||
}
|
||||
|
||||
var ev = new GetDisposalsConnectableDirectionsEvent();
|
||||
RaiseLocalEvent(uid, ref ev);
|
||||
args.Next = ev.Connectable[0];
|
||||
}
|
||||
|
||||
private void OnGetJunctionConnectableDirections(EntityUid uid, DisposalJunctionComponent component, ref GetDisposalsConnectableDirectionsEvent args)
|
||||
{
|
||||
var direction = Transform(uid).LocalRotation;
|
||||
|
||||
args.Connectable = component.Degrees
|
||||
.Select(degree => new Angle(degree.Theta + direction.Theta).GetDir())
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
private void OnGetJunctionNextDirection(EntityUid uid, DisposalJunctionComponent component, ref GetDisposalsNextDirectionEvent args)
|
||||
{
|
||||
var next = Transform(uid).LocalRotation.GetDir();
|
||||
var ev = new GetDisposalsConnectableDirectionsEvent();
|
||||
RaiseLocalEvent(uid, ref ev);
|
||||
var directions = ev.Connectable.Skip(1).ToArray();
|
||||
|
||||
if (args.Holder.PreviousDirectionFrom == Direction.Invalid ||
|
||||
args.Holder.PreviousDirectionFrom == next)
|
||||
{
|
||||
args.Next = _random.Pick(directions);
|
||||
return;
|
||||
}
|
||||
|
||||
args.Next = next;
|
||||
}
|
||||
|
||||
private void OnGetRouterConnectableDirections(EntityUid uid, DisposalRouterComponent component, ref GetDisposalsConnectableDirectionsEvent args)
|
||||
{
|
||||
OnGetJunctionConnectableDirections(uid, component, ref args);
|
||||
}
|
||||
|
||||
private void OnGetRouterNextDirection(EntityUid uid, DisposalRouterComponent component, ref GetDisposalsNextDirectionEvent args)
|
||||
{
|
||||
var ev = new GetDisposalsConnectableDirectionsEvent();
|
||||
RaiseLocalEvent(uid, ref ev);
|
||||
|
||||
if (args.Holder.Tags.Overlaps(component.Tags))
|
||||
{
|
||||
args.Next = ev.Connectable[1];
|
||||
return;
|
||||
}
|
||||
|
||||
args.Next = Transform(uid).LocalRotation.GetDir();
|
||||
}
|
||||
|
||||
private void OnGetTransitConnectableDirections(EntityUid uid, DisposalTransitComponent component, ref GetDisposalsConnectableDirectionsEvent args)
|
||||
{
|
||||
var rotation = Transform(uid).LocalRotation;
|
||||
var opposite = new Angle(rotation.Theta + Math.PI);
|
||||
|
||||
args.Connectable = new[] {rotation.GetDir(), opposite.GetDir()};
|
||||
}
|
||||
|
||||
private void OnGetTransitNextDirection(EntityUid uid, DisposalTransitComponent component, ref GetDisposalsNextDirectionEvent args)
|
||||
{
|
||||
var ev = new GetDisposalsConnectableDirectionsEvent();
|
||||
RaiseLocalEvent(uid, ref ev);
|
||||
var previousDF = args.Holder.PreviousDirectionFrom;
|
||||
var forward = ev.Connectable[0];
|
||||
|
||||
if (previousDF == Direction.Invalid)
|
||||
{
|
||||
args.Next = forward;
|
||||
return;
|
||||
}
|
||||
|
||||
var backward = ev.Connectable[1];
|
||||
args.Next = previousDF == forward ? backward : forward;
|
||||
}
|
||||
|
||||
private void OnGetTaggerConnectableDirections(EntityUid uid, DisposalTaggerComponent component, ref GetDisposalsConnectableDirectionsEvent args)
|
||||
{
|
||||
OnGetTransitConnectableDirections(uid, component, ref args);
|
||||
}
|
||||
|
||||
private void OnGetTaggerNextDirection(EntityUid uid, DisposalTaggerComponent component, ref GetDisposalsNextDirectionEvent args)
|
||||
{
|
||||
args.Holder.Tags.Add(component.Tag);
|
||||
OnGetTransitNextDirection(uid, component, ref args);
|
||||
}
|
||||
|
||||
private void OnDeconstruct(EntityUid uid, DisposalTubeComponent component, ConstructionBeforeDeleteEvent args)
|
||||
@@ -139,7 +287,7 @@ namespace Content.Server.Disposal.Tube
|
||||
}
|
||||
}
|
||||
|
||||
public IDisposalTubeComponent? NextTubeFor(EntityUid target, Direction nextDirection, IDisposalTubeComponent? targetTube = null)
|
||||
public DisposalTubeComponent? NextTubeFor(EntityUid target, Direction nextDirection, DisposalTubeComponent? targetTube = null)
|
||||
{
|
||||
if (!Resolve(target, ref targetTube))
|
||||
return null;
|
||||
@@ -152,17 +300,17 @@ namespace Content.Server.Disposal.Tube
|
||||
var position = xform.Coordinates;
|
||||
foreach (var entity in grid.GetInDir(position, nextDirection))
|
||||
{
|
||||
if (!EntityManager.TryGetComponent(entity, out IDisposalTubeComponent? tube))
|
||||
if (!TryComp(entity, out DisposalTubeComponent? tube))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!tube.CanConnect(oppositeDirection, targetTube))
|
||||
if (!CanConnect(entity, tube, oppositeDirection))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!targetTube.CanConnect(nextDirection, tube))
|
||||
if (!CanConnect(target, targetTube, nextDirection))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -172,5 +320,27 @@ namespace Content.Server.Disposal.Tube
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public bool CanConnect(EntityUid tubeId, DisposalTubeComponent tube, Direction direction)
|
||||
{
|
||||
if (!tube.Connected)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var ev = new GetDisposalsConnectableDirectionsEvent();
|
||||
RaiseLocalEvent(tubeId, ref ev);
|
||||
return ev.Connectable.Contains(direction);
|
||||
}
|
||||
|
||||
public void PopupDirections(EntityUid tubeId, DisposalTubeComponent tube, EntityUid recipient)
|
||||
{
|
||||
var ev = new GetDisposalsConnectableDirectionsEvent();
|
||||
RaiseLocalEvent(tubeId, ref ev);
|
||||
var directions = string.Join(", ", ev.Connectable);
|
||||
|
||||
_popups.PopupEntity(Loc.GetString("disposal-tube-component-popup-directions-text", ("directions", directions)), tubeId, recipient);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user