removes componentdependencies (#6160)

This commit is contained in:
Paul Ritter
2022-01-15 03:26:37 +01:00
committed by GitHub
parent 46405ec165
commit 9e1607722d
33 changed files with 257 additions and 274 deletions

View File

@@ -23,20 +23,10 @@ namespace Content.Server.Doors.Components
[RegisterComponent]
public class AirlockComponent : Component, IWires
{
[Dependency] private readonly IEntityManager _entityManager = default!;
public override string Name => "Airlock";
[ComponentDependency]
public readonly ServerDoorComponent? DoorComponent = null;
[ComponentDependency]
public readonly AppearanceComponent? AppearanceComponent = null;
[ComponentDependency]
public readonly ApcPowerReceiverComponent? ReceiverComponent = null;
[ComponentDependency]
public readonly WiresComponent? WiresComponent = null;
/// <summary>
/// Sound to play when the bolts on the airlock go up.
/// </summary>
@@ -98,7 +88,7 @@ namespace Content.Server.Doors.Components
private bool BoltLightsVisible
{
get => _boltLightsWirePulsed && BoltsDown && IsPowered()
&& DoorComponent != null && DoorComponent.State == SharedDoorComponent.DoorState.Closed;
&& _entityManager.TryGetComponent<ServerDoorComponent>(Owner, out var doorComponent) && doorComponent.State == SharedDoorComponent.DoorState.Closed;
set
{
_boltLightsWirePulsed = value;
@@ -122,9 +112,10 @@ namespace Content.Server.Doors.Components
{
base.Initialize();
if (ReceiverComponent != null && AppearanceComponent != null)
if (_entityManager.TryGetComponent<ApcPowerReceiverComponent>(Owner, out var receiverComponent) &&
_entityManager.TryGetComponent<AppearanceComponent>(Owner, out var appearanceComponent))
{
AppearanceComponent.SetData(DoorVisuals.Powered, ReceiverComponent.Powered);
appearanceComponent.SetData(DoorVisuals.Powered, receiverComponent.Powered);
}
}
@@ -140,23 +131,23 @@ namespace Content.Server.Doors.Components
public bool IsPowered()
{
return ReceiverComponent == null || ReceiverComponent.Powered;
return _entityManager.TryGetComponent<ApcPowerReceiverComponent>(Owner, out var receiverComponent) && receiverComponent.Powered;
}
public void UpdateBoltLightStatus()
{
if (AppearanceComponent != null)
if (_entityManager.TryGetComponent<AppearanceComponent>(Owner, out var appearanceComponent))
{
AppearanceComponent.SetData(DoorVisuals.BoltLights, BoltLightsVisible);
appearanceComponent.SetData(DoorVisuals.BoltLights, BoltLightsVisible);
}
}
public void UpdateWiresStatus()
{
if (WiresComponent == null) return;
if (_entityManager.TryGetComponent<WiresComponent>(Owner, out var wiresComponent)) return;
var mainPowerCut = WiresComponent.IsWireCut(Wires.MainPower);
var backupPowerCut = WiresComponent.IsWireCut(Wires.BackupPower);
var mainPowerCut = wiresComponent.IsWireCut(Wires.MainPower);
var backupPowerCut = wiresComponent.IsWireCut(Wires.BackupPower);
var statusLightState = PowerWiresPulsed ? StatusLightState.BlinkingFast : StatusLightState.On;
StatusLightData powerLight;
if (mainPowerCut && backupPowerCut)
@@ -190,42 +181,42 @@ namespace Content.Server.Doors.Components
new StatusLightData(Color.Red, Safety ? StatusLightState.On : StatusLightState.Off, "SAFETY");
WiresComponent.SetStatus(AirlockWireStatus.PowerIndicator, powerLight);
WiresComponent.SetStatus(AirlockWireStatus.BoltIndicator, boltStatus);
WiresComponent.SetStatus(AirlockWireStatus.BoltLightIndicator, boltLightsStatus);
WiresComponent.SetStatus(AirlockWireStatus.AIControlIndicator, new StatusLightData(Color.Purple, StatusLightState.BlinkingSlow, "AI CTRL"));
WiresComponent.SetStatus(AirlockWireStatus.TimingIndicator, timingStatus);
WiresComponent.SetStatus(AirlockWireStatus.SafetyIndicator, safetyStatus);
wiresComponent.SetStatus(AirlockWireStatus.PowerIndicator, powerLight);
wiresComponent.SetStatus(AirlockWireStatus.BoltIndicator, boltStatus);
wiresComponent.SetStatus(AirlockWireStatus.BoltLightIndicator, boltLightsStatus);
wiresComponent.SetStatus(AirlockWireStatus.AIControlIndicator, new StatusLightData(Color.Purple, StatusLightState.BlinkingSlow, "AI CTRL"));
wiresComponent.SetStatus(AirlockWireStatus.TimingIndicator, timingStatus);
wiresComponent.SetStatus(AirlockWireStatus.SafetyIndicator, safetyStatus);
}
private void UpdatePowerCutStatus()
{
if (ReceiverComponent == null)
if (!_entityManager.TryGetComponent<ApcPowerReceiverComponent>(Owner, out var receiverComponent))
{
return;
}
if (PowerWiresPulsed)
{
ReceiverComponent.PowerDisabled = true;
receiverComponent.PowerDisabled = true;
return;
}
if (WiresComponent == null)
if (!_entityManager.TryGetComponent<WiresComponent>(Owner, out var wiresComponent))
{
return;
}
ReceiverComponent.PowerDisabled =
WiresComponent.IsWireCut(Wires.MainPower) &&
WiresComponent.IsWireCut(Wires.BackupPower);
receiverComponent.PowerDisabled =
wiresComponent.IsWireCut(Wires.MainPower) &&
wiresComponent.IsWireCut(Wires.BackupPower);
}
private void PowerDeviceOnOnPowerStateChanged(PowerChangedMessage e)
{
if (AppearanceComponent != null)
if (_entityManager.TryGetComponent<AppearanceComponent>(Owner, out var appearanceComponent))
{
AppearanceComponent.SetData(DoorVisuals.Powered, e.Powered);
appearanceComponent.SetData(DoorVisuals.Powered, e.Powered);
}
// BoltLights also got out
@@ -290,7 +281,7 @@ namespace Content.Server.Doors.Components
public void WiresUpdate(WiresUpdateEventArgs args)
{
if (DoorComponent == null)
if (!_entityManager.TryGetComponent<ServerDoorComponent>(Owner, out var doorComponent))
{
return;
}
@@ -328,7 +319,7 @@ namespace Content.Server.Doors.Components
break;
case Wires.Timing:
AutoCloseDelayModifier = 0.5f;
DoorComponent.RefreshAutoClose();
doorComponent.RefreshAutoClose();
break;
case Wires.Safety:
Safety = !Safety;
@@ -351,7 +342,7 @@ namespace Content.Server.Doors.Components
break;
case Wires.Timing:
AutoClose = true;
DoorComponent.RefreshAutoClose();
doorComponent.RefreshAutoClose();
break;
case Wires.Safety:
Safety = true;
@@ -371,7 +362,7 @@ namespace Content.Server.Doors.Components
break;
case Wires.Timing:
AutoClose = false;
DoorComponent.RefreshAutoClose();
doorComponent.RefreshAutoClose();
break;
case Wires.Safety:
Safety = false;

View File

@@ -18,9 +18,6 @@ namespace Content.Server.Doors.Components
public override string Name => "Firelock";
[ComponentDependency]
public readonly ServerDoorComponent? DoorComponent = null;
/// <summary>
/// Pry time modifier to be used when the firelock is currently closed due to fire or pressure.
/// </summary>
@@ -30,9 +27,9 @@ namespace Content.Server.Doors.Components
public bool EmergencyPressureStop()
{
if (DoorComponent != null && DoorComponent.State == SharedDoorComponent.DoorState.Open && DoorComponent.CanCloseGeneric())
if (_entMan.TryGetComponent<ServerDoorComponent>(Owner, out var doorComp) && doorComp.State == SharedDoorComponent.DoorState.Open && doorComp.CanCloseGeneric())
{
DoorComponent.Close();
doorComp.Close();
if (_entMan.TryGetComponent(Owner, out AirtightComponent? airtight))
{
EntitySystem.Get<AirtightSystem>().SetAirblocked(airtight, true);

View File

@@ -24,6 +24,7 @@ using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Log;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.Shared.Player;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.Manager.Attributes;
@@ -557,19 +558,19 @@ namespace Content.Server.Doors.Components
/// <returns>True if we crushed somebody, false if we did not.</returns>
private bool TryCrush()
{
if (PhysicsComponent == null)
if (!_entMan.TryGetComponent(Owner, out PhysicsComponent physicsComponent) || physicsComponent is not IPhysBody body)
{
return false;
}
var collidingentities = PhysicsComponent.GetCollidingEntities(Vector2.Zero, false);
var collidingentities = body.GetCollidingEntities(Vector2.Zero, false);
if (!collidingentities.Any())
{
return false;
}
var doorAABB = PhysicsComponent.GetWorldAABB();
var doorAABB = body.GetWorldAABB();
var hitsomebody = false;
// Crush
@@ -718,7 +719,7 @@ namespace Content.Server.Doors.Components
// no interaction occurred
return false;
}
_beingWelded = true;
// perform a do-after delay