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

@@ -58,9 +58,6 @@ namespace Content.Server.Singularity.Components
}
}
[ComponentDependency] private readonly PhysicsComponent? _collidableComponent = default;
[ComponentDependency] private readonly PointLightComponent? _pointLightComponent = default;
private Tuple<Direction, ContainmentFieldConnection>? _connection1;
private Tuple<Direction, ContainmentFieldConnection>? _connection2;
@@ -69,7 +66,7 @@ namespace Content.Server.Singularity.Components
public void OnAnchoredChanged()
{
if(_collidableComponent?.BodyType != BodyType.Static)
if(_entMan.TryGetComponent<PhysicsComponent>(Owner, out var physicsComponent) && physicsComponent.BodyType != BodyType.Static)
{
_connection1?.Item2.Dispose();
_connection2?.Item2.Dispose();
@@ -91,7 +88,7 @@ namespace Content.Server.Singularity.Components
private bool TryGenerateFieldConnection([NotNullWhen(true)] ref Tuple<Direction, ContainmentFieldConnection>? propertyFieldTuple)
{
if (propertyFieldTuple != null) return false;
if(_collidableComponent?.BodyType != BodyType.Static) return false;
if(_entMan.TryGetComponent<PhysicsComponent>(Owner, out var physicsComponent) && physicsComponent.BodyType != BodyType.Static) return false;
foreach (var direction in new[] {Direction.North, Direction.East, Direction.South, Direction.West})
{
@@ -166,10 +163,10 @@ namespace Content.Server.Singularity.Components
public void UpdateConnectionLights()
{
if (_pointLightComponent != null)
if (_entMan.TryGetComponent<PointLightComponent>(Owner, out var pointLightComponent))
{
bool hasAnyConnection = (_connection1 != null) || (_connection2 != null);
_pointLightComponent.Enabled = hasAnyConnection;
pointLightComponent.Enabled = hasAnyConnection;
}
}

View File

@@ -13,10 +13,6 @@ namespace Content.Server.Singularity.Components
[RegisterComponent]
public class EmitterComponent : Component
{
[ComponentDependency] public readonly AppearanceComponent? Appearance = default;
[ComponentDependency] public readonly AccessReaderComponent? AccessReader = default;
[ComponentDependency] public readonly PowerConsumerComponent? PowerConsumer = default;
public override string Name => "Emitter";
public CancellationTokenSource? TimerCancel;

View File

@@ -16,6 +16,7 @@ namespace Content.Server.Singularity.Components
public class RadiationCollectorComponent : Component, IInteractHand, IRadiationAct
{
[Dependency] private readonly IGameTiming _gameTiming = default!;
[Dependency] private readonly IEntityManager _entMan = default!;
public override string Name => "RadiationCollector";
private bool _enabled;
@@ -32,8 +33,6 @@ namespace Content.Server.Singularity.Components
}
}
[ComponentDependency] private readonly BatteryComponent? _batteryComponent = default!;
bool IInteractHand.InteractHand(InteractHandEventArgs eventArgs)
{
var curTime = _gameTiming.CurTime;
@@ -66,9 +65,9 @@ namespace Content.Server.Singularity.Components
// But the previous logic would also make the radiation collectors never ever stop providing energy.
// And since frameTime was used there, I'm assuming that this is what the intent was.
// This still won't stop things being potentially hilarously unbalanced though.
if (_batteryComponent != null)
if (_entMan.TryGetComponent<BatteryComponent>(Owner, out var batteryComponent))
{
_batteryComponent!.CurrentCharge += frameTime * radiation.RadsPerSecond * 3000f;
batteryComponent.CurrentCharge += frameTime * radiation.RadsPerSecond * 3000f;
}
}

View File

@@ -1,6 +1,7 @@
using System;
using System.Threading;
using Content.Server.Administration.Logs;
using Content.Server.Power.Components;
using Content.Server.Power.EntitySystems;
using Content.Server.Projectiles.Components;
using Content.Server.Singularity.Components;
@@ -94,7 +95,7 @@ namespace Content.Server.Singularity.EntitySystems
public void SwitchOff(EmitterComponent component)
{
component.IsOn = false;
if (component.PowerConsumer != null) component.PowerConsumer.DrawRate = 0;
if (TryComp<PowerConsumerComponent>(component.Owner, out var powerConsumer)) powerConsumer.DrawRate = 0;
PowerOff(component);
UpdateAppearance(component);
}
@@ -102,7 +103,7 @@ namespace Content.Server.Singularity.EntitySystems
public void SwitchOn(EmitterComponent component)
{
component.IsOn = true;
if (component.PowerConsumer != null) component.PowerConsumer.DrawRate = component.PowerUseActive;
if (TryComp<PowerConsumerComponent>(component.Owner, out var powerConsumer)) powerConsumer.DrawRate = component.PowerUseActive;
// Do not directly PowerOn().
// OnReceivedPowerChanged will get fired due to DrawRate change which will turn it on.
UpdateAppearance(component);
@@ -149,7 +150,8 @@ namespace Content.Server.Singularity.EntitySystems
// and thus not firing
DebugTools.Assert(component.IsPowered);
DebugTools.Assert(component.IsOn);
DebugTools.Assert(component.PowerConsumer != null && (component.PowerConsumer.DrawRate <= component.PowerConsumer.ReceivedPower));
DebugTools.Assert(TryComp<PowerConsumerComponent>(component.Owner, out var powerConsumer) &&
powerConsumer.DrawRate <= powerConsumer.ReceivedPower);
Fire(component);
@@ -205,7 +207,7 @@ namespace Content.Server.Singularity.EntitySystems
private void UpdateAppearance(EmitterComponent component)
{
if (component.Appearance == null)
if (!TryComp<AppearanceComponent>(component.Owner, out var appearanceComponent))
{
return;
}
@@ -224,7 +226,7 @@ namespace Content.Server.Singularity.EntitySystems
state = EmitterVisualState.Off;
}
component.Appearance.SetData(EmitterVisuals.VisualState, state);
appearanceComponent.SetData(EmitterVisuals.VisualState, state);
}
}
}