Remove disposal tubes component references and ECS some of it (#15188)

This commit is contained in:
DrSmugleaf
2023-04-06 20:20:50 -07:00
committed by GitHub
parent 9ee1c61ca2
commit 97a8b64c1d
16 changed files with 261 additions and 233 deletions

View File

@@ -1,36 +1,7 @@
using Content.Server.Disposal.Unit.Components;
namespace Content.Server.Disposal.Tube.Components;
namespace Content.Server.Disposal.Tube.Components
[RegisterComponent]
[Access(typeof(DisposalTubeSystem))]
public sealed class DisposalBendComponent : Component
{
[RegisterComponent]
[ComponentReference(typeof(IDisposalTubeComponent))]
[ComponentReference(typeof(DisposalTubeComponent))]
public sealed class DisposalBendComponent : DisposalTubeComponent
{
public override string ContainerId => "DisposalBend";
[DataField("sideDegrees")]
private int _sideDegrees = -90;
protected override Direction[] ConnectableDirections()
{
var direction = IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(Owner).LocalRotation;
var side = new Angle(MathHelper.DegreesToRadians(direction.Degrees + _sideDegrees));
return new[] {direction.GetDir(), side.GetDir()};
}
public override Direction NextDirection(DisposalHolderComponent holder)
{
var directions = ConnectableDirections();
var previousDF = holder.PreviousDirectionFrom;
if (previousDF == Direction.Invalid)
{
return directions[0];
}
return previousDF == directions[0] ? directions[1] : directions[0];
}
}
}

View File

@@ -6,14 +6,12 @@ using Content.Server.Disposal.Unit.EntitySystems;
namespace Content.Server.Disposal.Tube.Components
{
[RegisterComponent]
[ComponentReference(typeof(IDisposalTubeComponent))]
[ComponentReference(typeof(DisposalTubeComponent))]
public sealed class DisposalEntryComponent : DisposalTubeComponent
[Access(typeof(DisposalTubeSystem), typeof(DisposalUnitSystem))]
public sealed class DisposalEntryComponent : Component
{
[Dependency] private readonly IEntityManager _entMan = default!;
private const string HolderPrototypeId = "DisposalHolder";
public override string ContainerId => "DisposalEntry";
public bool TryInsert(DisposalUnitComponent from, IEnumerable<string>? tags = default)
{
@@ -31,25 +29,7 @@ namespace Content.Server.Disposal.Tube.Components
if (tags != default)
holderComponent.Tags.UnionWith(tags);
return EntitySystem.Get<DisposableSystem>().EnterTube((holderComponent).Owner, Owner, holderComponent, null, this);
}
protected override Direction[] ConnectableDirections()
{
return new[] {_entMan.GetComponent<TransformComponent>(Owner).LocalRotation.GetDir()};
}
/// <summary>
/// Ejects contents when they come from the same direction the entry is facing.
/// </summary>
public override Direction NextDirection(DisposalHolderComponent holder)
{
if (holder.PreviousDirectionFrom != Direction.Invalid)
{
return Direction.Invalid;
}
return ConnectableDirections()[0];
return EntitySystem.Get<DisposableSystem>().EnterTube((holderComponent).Owner, Owner, holderComponent);
}
}
}

View File

@@ -1,45 +1,12 @@
using System.Linq;
using Content.Server.Disposal.Unit.Components;
using Robust.Shared.Random;
namespace Content.Server.Disposal.Tube.Components;
namespace Content.Server.Disposal.Tube.Components
[RegisterComponent]
[Access(typeof(DisposalTubeSystem))]
[Virtual]
public class DisposalJunctionComponent : Component
{
[Virtual]
[RegisterComponent]
[ComponentReference(typeof(IDisposalTubeComponent))]
[ComponentReference(typeof(DisposalTubeComponent))]
public class DisposalJunctionComponent : DisposalTubeComponent
{
public override string ContainerId => "DisposalJunction";
[Dependency] private readonly IEntityManager _entMan = default!;
[Dependency] private readonly IRobustRandom _random = default!;
/// <summary>
/// The angles to connect to.
/// </summary>
[DataField("degrees")]
private List<Angle> _degrees = new();
protected override Direction[] ConnectableDirections()
{
var direction = _entMan.GetComponent<TransformComponent>(Owner).LocalRotation;
return _degrees.Select(degree => new Angle(degree.Theta + direction.Theta).GetDir()).ToArray();
}
public override Direction NextDirection(DisposalHolderComponent holder)
{
var next = _entMan.GetComponent<TransformComponent>(Owner).LocalRotation.GetDir();
var directions = ConnectableDirections().Skip(1).ToArray();
if (holder.PreviousDirectionFrom == Direction.Invalid ||
holder.PreviousDirectionFrom == next)
{
return _random.Pick(directions);
}
return next;
}
}
/// <summary>
/// The angles to connect to.
/// </summary>
[DataField("degrees")] public List<Angle> Degrees = new();
}

View File

@@ -1,4 +1,3 @@
using Content.Server.Disposal.Unit.Components;
using Content.Server.UserInterface;
using Robust.Server.GameObjects;
using Robust.Shared.Audio;
@@ -10,12 +9,9 @@ using static Content.Shared.Disposal.Components.SharedDisposalRouterComponent;
namespace Content.Server.Disposal.Tube.Components
{
[RegisterComponent]
[ComponentReference(typeof(IDisposalTubeComponent))]
[ComponentReference(typeof(DisposalTubeComponent))]
[Access(typeof(DisposalTubeSystem))]
public sealed class DisposalRouterComponent : DisposalJunctionComponent
{
public override string ContainerId => "DisposalRouter";
[Dependency] private readonly IEntityManager _entMan = default!;
[DataField("tags")]
@@ -30,18 +26,6 @@ namespace Content.Server.Disposal.Tube.Components
[DataField("clickSound")] private SoundSpecifier _clickSound = new SoundPathSpecifier("/Audio/Machines/machine_switch.ogg");
public override Direction NextDirection(DisposalHolderComponent holder)
{
var directions = ConnectableDirections();
if (holder.Tags.Overlaps(Tags))
{
return directions[1];
}
return _entMan.GetComponent<TransformComponent>(Owner).LocalRotation.GetDir();
}
protected override void Initialize()
{
base.Initialize();

View File

@@ -10,14 +10,10 @@ using static Content.Shared.Disposal.Components.SharedDisposalTaggerComponent;
namespace Content.Server.Disposal.Tube.Components
{
[RegisterComponent]
[ComponentReference(typeof(IDisposalTubeComponent))]
[ComponentReference(typeof(DisposalTubeComponent))]
public sealed class DisposalTaggerComponent : DisposalTransitComponent
{
[Dependency] private readonly IEntityManager _entMan = default!;
public override string ContainerId => "DisposalTagger";
[ViewVariables(VVAccess.ReadWrite)]
[DataField("tag")]
public string Tag = "";
@@ -31,12 +27,6 @@ namespace Content.Server.Disposal.Tube.Components
[DataField("clickSound")] private SoundSpecifier _clickSound = new SoundPathSpecifier("/Audio/Machines/machine_switch.ogg");
public override Direction NextDirection(DisposalHolderComponent holder)
{
holder.Tags.Add(Tag);
return base.NextDirection(holder);
}
protected override void Initialize()
{
base.Initialize();

View File

@@ -1,37 +1,10 @@
using Content.Server.Disposal.Unit.Components;
namespace Content.Server.Disposal.Tube.Components
{
// TODO: Different types of tubes eject in random direction with no exit point
[RegisterComponent]
[ComponentReference(typeof(IDisposalTubeComponent))]
[Access(typeof(DisposalTubeSystem))]
[Virtual]
[ComponentReference(typeof(DisposalTubeComponent))]
public class DisposalTransitComponent : DisposalTubeComponent
public class DisposalTransitComponent : Component
{
public override string ContainerId => "DisposalTransit";
protected override Direction[] ConnectableDirections()
{
var rotation = IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(Owner).LocalRotation;
var opposite = new Angle(rotation.Theta + Math.PI);
return new[] {rotation.GetDir(), opposite.GetDir()};
}
public override Direction NextDirection(DisposalHolderComponent holder)
{
var directions = ConnectableDirections();
var previousDF = holder.PreviousDirectionFrom;
var forward = directions[0];
if (previousDF == Direction.Invalid)
{
return forward;
}
var backward = directions[1];
return previousDF == forward ? backward : forward;
}
}
}

View File

@@ -2,24 +2,24 @@ using System.Linq;
using Content.Server.Disposal.Unit.Components;
using Content.Server.Disposal.Unit.EntitySystems;
using Content.Shared.Construction.Components;
using Content.Shared.Disposal.Components;
using Content.Shared.Popups;
using Robust.Shared.Audio;
using Robust.Shared.Containers;
using Robust.Shared.Physics;
namespace Content.Server.Disposal.Tube.Components
{
public abstract class DisposalTubeComponent : Component, IDisposalTubeComponent
[RegisterComponent]
[Access(typeof(DisposalTubeSystem), typeof(DisposableSystem))]
public sealed class DisposalTubeComponent : Component
{
public virtual string ContainerId => "DisposalTube";
[DataField("containerId")] public string ContainerId { get; set; } = "DisposalTube";
[Dependency] private readonly IEntityManager _entMan = default!;
public static readonly TimeSpan ClangDelay = TimeSpan.FromSeconds(0.5);
public TimeSpan LastClang;
private bool _connected;
public bool Connected;
[DataField("clangSound")] public SoundSpecifier ClangSound = new SoundPathSpecifier("/Audio/Effects/clang.ogg");
/// <summary>
@@ -28,49 +28,26 @@ namespace Content.Server.Disposal.Tube.Components
[ViewVariables]
public Container Contents { get; private set; } = default!;
/// <summary>
/// The directions that this tube can connect to others from
/// </summary>
/// <returns>a new array of the directions</returns>
protected abstract Direction[] ConnectableDirections();
public abstract Direction NextDirection(DisposalHolderComponent holder);
// TODO: Make disposal pipes extend the grid
// ???
public void Connect()
{
if (_connected)
if (Connected)
{
return;
}
_connected = true;
}
public bool CanConnect(Direction direction, IDisposalTubeComponent with)
{
if (!_connected)
{
return false;
}
if (!ConnectableDirections().Contains(direction))
{
return false;
}
return true;
Connected = true;
}
public void Disconnect()
{
if (!_connected)
if (!Connected)
{
return;
}
_connected = false;
Connected = false;
foreach (var entity in Contents.ContainedEntities.ToArray())
{
@@ -83,13 +60,6 @@ namespace Content.Server.Disposal.Tube.Components
}
}
public void PopupDirections(EntityUid entity)
{
var directions = string.Join(", ", ConnectableDirections());
Owner.PopupMessage(entity, Loc.GetString("disposal-tube-component-popup-directions-text", ("directions", directions)));
}
protected override void Initialize()
{
base.Initialize();

View File

@@ -1,14 +0,0 @@
using Content.Server.Disposal.Unit.Components;
using Robust.Shared.Containers;
namespace Content.Server.Disposal.Tube.Components
{
public interface IDisposalTubeComponent : IComponent
{
Container Contents { get; }
Direction NextDirection(DisposalHolderComponent holder);
bool CanConnect(Direction direction, IDisposalTubeComponent with);
void PopupDirections(EntityUid entity);
}
}