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

@@ -43,7 +43,7 @@ namespace Content.Server.Atmos.Components
private int _integrity = 3;
[ComponentDependency] private readonly ItemActionsComponent? _itemActions = null;
[Dependency] private readonly IEntityManager _entityManager = default!;
[ViewVariables] private BoundUserInterface? _userInterface;
@@ -190,8 +190,8 @@ namespace Content.Server.Atmos.Components
CanConnectInternals = IsFunctional && internals != null
});
if (internals == null) return;
_itemActions?.GrantOrUpdate(ItemActionType.ToggleInternals, IsFunctional, IsConnected);
if (internals == null || !_entityManager.TryGetComponent<ItemActionsComponent>(Owner, out var itemActions)) return;
itemActions.GrantOrUpdate(ItemActionType.ToggleInternals, IsFunctional, IsConnected);
}
private void UserInterfaceOnOnReceiveMessage(ServerBoundUserInterfaceMessage message)

View File

@@ -8,6 +8,7 @@ using Content.Server.VendingMachines; // TODO: Move this out of vending machines
using Content.Server.WireHacking;
using Content.Shared.Atmos.Monitor.Components;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Maths;
using Robust.Shared.Network;
using Robust.Shared.ViewVariables;
@@ -19,10 +20,7 @@ namespace Content.Server.Atmos.Monitor.Components
[RegisterComponent]
public class AirAlarmComponent : Component, IWires
{
[ComponentDependency] public readonly ApcPowerReceiverComponent? DeviceRecvComponent = default!;
[ComponentDependency] public readonly AtmosMonitorComponent? AtmosMonitorComponent = default!;
[ComponentDependency] public readonly DeviceNetworkComponent? DeviceNetComponent = default!;
[ComponentDependency] public readonly WiresComponent? WiresComponent = null;
[Dependency] private readonly IEntityManager _entMan = default!;
private AirAlarmSystem? _airAlarmSystem;
@@ -79,7 +77,7 @@ namespace Content.Server.Atmos.Monitor.Components
if (_airAlarmSystem == null)
_airAlarmSystem = EntitySystem.Get<AirAlarmSystem>();
if (WiresComponent == null) return;
if (!_entMan.TryGetComponent<WiresComponent>(Owner, out var wires)) return;
var pwrLightState = (PowerPulsed, PowerCut) switch {
(true, false) => StatusLightState.BlinkingFast,
@@ -91,7 +89,7 @@ namespace Content.Server.Atmos.Monitor.Components
var accessLight = new StatusLightData(
Color.Green,
WiresComponent.IsWireCut(Wires.Access) ? StatusLightState.Off : StatusLightState.On,
wires.IsWireCut(Wires.Access) ? StatusLightState.Off : StatusLightState.On,
"ACC"
);
@@ -103,17 +101,17 @@ namespace Content.Server.Atmos.Monitor.Components
var syncLightState = StatusLightState.BlinkingSlow;
if (AtmosMonitorComponent != null && !AtmosMonitorComponent.NetEnabled)
if (_entMan.TryGetComponent<AtmosMonitorComponent>(Owner, out var atmosMonitorComponent) && !atmosMonitorComponent.NetEnabled)
syncLightState = StatusLightState.Off;
else if (DeviceData.Count != 0)
syncLightState = StatusLightState.On;
var syncLight = new StatusLightData(Color.Orange, syncLightState, "NET");
WiresComponent.SetStatus(AirAlarmWireStatus.Power, powerLight);
WiresComponent.SetStatus(AirAlarmWireStatus.Access, accessLight);
WiresComponent.SetStatus(AirAlarmWireStatus.Panic, panicLight);
WiresComponent.SetStatus(AirAlarmWireStatus.DeviceSync, syncLight);
wires.SetStatus(AirAlarmWireStatus.Power, powerLight);
wires.SetStatus(AirAlarmWireStatus.Access, accessLight);
wires.SetStatus(AirAlarmWireStatus.Panic, panicLight);
wires.SetStatus(AirAlarmWireStatus.DeviceSync, syncLight);
}
private bool _powerCut;
@@ -140,14 +138,14 @@ namespace Content.Server.Atmos.Monitor.Components
private void SetPower()
{
if (DeviceRecvComponent != null
&& WiresComponent != null)
DeviceRecvComponent.PowerDisabled = PowerPulsed || PowerCut;
if (_entMan.TryGetComponent<ApcPowerReceiverComponent>(Owner, out var receiverComponent)
&& _entMan.HasComponent<WiresComponent>(Owner))
receiverComponent.PowerDisabled = PowerPulsed || PowerCut;
}
public void WiresUpdate(WiresUpdateEventArgs args)
{
if (DeviceNetComponent == null) return;
if (!_entMan.TryGetComponent<DeviceNetworkComponent>(Owner, out var deviceNetworkComponent)) return;
if (_airAlarmSystem == null)
_airAlarmSystem = EntitySystem.Get<AirAlarmSystem>();
@@ -167,7 +165,7 @@ namespace Content.Server.Atmos.Monitor.Components
break;
case Wires.Panic:
if (CurrentMode != AirAlarmMode.Panic)
_airAlarmSystem.SetMode(Owner, DeviceNetComponent.Address, AirAlarmMode.Panic, true, false);
_airAlarmSystem.SetMode(Owner, deviceNetworkComponent.Address, AirAlarmMode.Panic, true, false);
break;
case Wires.DeviceSync:
_airAlarmSystem.SyncAllDevices(Owner);
@@ -184,14 +182,14 @@ namespace Content.Server.Atmos.Monitor.Components
break;
case Wires.Panic:
if (CurrentMode == AirAlarmMode.Panic)
_airAlarmSystem.SetMode(Owner, DeviceNetComponent.Address, AirAlarmMode.Filtering, true, false);
_airAlarmSystem.SetMode(Owner, deviceNetworkComponent.Address, AirAlarmMode.Filtering, true, false);
break;
case Wires.Access:
FullAccess = false;
break;
case Wires.DeviceSync:
if (AtmosMonitorComponent != null)
AtmosMonitorComponent.NetEnabled = true;
if (_entMan.TryGetComponent<AtmosMonitorComponent>(Owner, out var atmosMonitorComponent))
atmosMonitorComponent.NetEnabled = true;
break;
}
@@ -201,10 +199,10 @@ namespace Content.Server.Atmos.Monitor.Components
{
case Wires.DeviceSync:
DeviceData.Clear();
if (AtmosMonitorComponent != null)
if (_entMan.TryGetComponent<AtmosMonitorComponent>(Owner, out var atmosMonitorComponent))
{
AtmosMonitorComponent.NetworkAlarmStates.Clear();
AtmosMonitorComponent.NetEnabled = false;
atmosMonitorComponent.NetworkAlarmStates.Clear();
atmosMonitorComponent.NetEnabled = false;
}
break;

View File

@@ -16,12 +16,6 @@ namespace Content.Server.Atmos.Monitor.Components
{
public override string Name => "AtmosMonitor";
// Requires power. No logic related to this will be performed here, however,
// save for ensuring that the data is valid upon set.
// This is how the system discovers entities that are alarmable.
[ComponentDependency] public readonly ApcPowerReceiverComponent? PowerRecvComponent = default!;
[ComponentDependency] public readonly AtmosDeviceComponent? AtmosDeviceComponent = default!;
// Whether this monitor can send alarms,
// or recieve atmos command events.
//

View File

@@ -9,6 +9,7 @@ using Content.Shared.Atmos.Monitor;
using Content.Shared.Atmos.Monitor.Components;
using Robust.Server.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Log;
using Robust.Shared.Maths;
using static Content.Shared.Wires.SharedWiresComponent;
@@ -20,9 +21,7 @@ namespace Content.Server.Atmos.Monitor.Components
[RegisterComponent]
public class FireAlarmComponent : Component, IWires
{
[ComponentDependency] public readonly ApcPowerReceiverComponent? DeviceRecvComponent = default!;
[ComponentDependency] public readonly AtmosMonitorComponent? AtmosMonitorComponent = default!;
[ComponentDependency] public readonly WiresComponent? WiresComponent = null;
[Dependency] private readonly IEntityManager _entMan = default!;
private AtmosMonitorSystem? _atmosMonitorSystem;
@@ -69,9 +68,8 @@ namespace Content.Server.Atmos.Monitor.Components
private void SetPower()
{
if (DeviceRecvComponent != null
&& WiresComponent != null)
DeviceRecvComponent.PowerDisabled = PowerPulsed || PowerCut;
if (_entMan.TryGetComponent<ApcPowerReceiverComponent>(Owner, out var receiverComponent) && _entMan.HasComponent<WiresComponent>(Owner))
receiverComponent.PowerDisabled = PowerPulsed || PowerCut;
}
@@ -87,7 +85,7 @@ namespace Content.Server.Atmos.Monitor.Components
public void UpdateWires()
{
if (WiresComponent == null) return;
if (!_entMan.TryGetComponent<WiresComponent>(Owner, out var wiresComponent)) return;
var powerLight = new StatusLightData(Color.Yellow, StatusLightState.On, "POWR");
@@ -98,14 +96,14 @@ namespace Content.Server.Atmos.Monitor.Components
var syncLight = new StatusLightData(Color.Orange, StatusLightState.On, "NET");
if (AtmosMonitorComponent != null)
if (!AtmosMonitorComponent.NetEnabled)
if (_entMan.TryGetComponent<AtmosMonitorComponent>(Owner, out var atmosMonitorComponent))
if (!atmosMonitorComponent.NetEnabled)
syncLight = new StatusLightData(Color.Orange, StatusLightState.Off, "NET");
else if (AtmosMonitorComponent.HighestAlarmInNetwork == AtmosMonitorAlarmType.Danger)
else if (atmosMonitorComponent.HighestAlarmInNetwork == AtmosMonitorAlarmType.Danger)
syncLight = new StatusLightData(Color.Orange, StatusLightState.BlinkingFast, "NET");
WiresComponent.SetStatus(FireAlarmWireStatus.Power, powerLight);
WiresComponent.SetStatus(FireAlarmWireStatus.Alarm, syncLight);
wiresComponent.SetStatus(FireAlarmWireStatus.Power, powerLight);
wiresComponent.SetStatus(FireAlarmWireStatus.Alarm, syncLight);
}
public void WiresUpdate(WiresUpdateEventArgs args)
@@ -127,8 +125,8 @@ namespace Content.Server.Atmos.Monitor.Components
_powerPulsedCancel.Token);
break;
case Wires.Alarm:
if (AtmosMonitorComponent != null)
_atmosMonitorSystem.Alert(Owner, AtmosMonitorAlarmType.Danger);
if (_entMan.TryGetComponent<AtmosMonitorComponent>(Owner, out var atmosMonitorComponent))
_atmosMonitorSystem.Alert(Owner, AtmosMonitorAlarmType.Danger, monitor: atmosMonitorComponent);
break;
}
@@ -142,8 +140,8 @@ namespace Content.Server.Atmos.Monitor.Components
PowerCut = false;
break;
case Wires.Alarm:
if (AtmosMonitorComponent != null)
AtmosMonitorComponent.NetEnabled = true;
if (_entMan.TryGetComponent<AtmosMonitorComponent>(Owner, out var atmosMonitorComponent))
atmosMonitorComponent.NetEnabled = true;
break;
}
@@ -155,8 +153,8 @@ namespace Content.Server.Atmos.Monitor.Components
PowerCut = true;
break;
case Wires.Alarm:
if (AtmosMonitorComponent != null)
AtmosMonitorComponent.NetEnabled = false;
if (_entMan.TryGetComponent<AtmosMonitorComponent>(Owner, out var atmosMonitorComponent))
atmosMonitorComponent.NetEnabled = false;
break;
}

View File

@@ -392,7 +392,7 @@ namespace Content.Server.Atmos.Monitor.Systems
// _airAlarmDataSystem.UpdateDeviceData(uid, args.SenderAddress, data);
//
_uiSystem.TrySendUiMessage(uid, SharedAirAlarmInterfaceKey.Key, new AirAlarmUpdateDeviceDataMessage(args.SenderAddress, data));
if (controller.WiresComponent != null) controller.UpdateWires();
if (HasComp<WiresComponent>(uid)) controller.UpdateWires();
if (!controller.DeviceData.TryAdd(args.SenderAddress, data))
controller.DeviceData[args.SenderAddress] = data;

View File

@@ -98,10 +98,10 @@ namespace Content.Server.Atmos.Monitor.Systems
private void OnAtmosMonitorStartup(EntityUid uid, AtmosMonitorComponent component, ComponentStartup args)
{
if (component.PowerRecvComponent == null
&& component.AtmosDeviceComponent != null)
if (!HasComp<ApcPowerReceiverComponent>(uid)
&& TryComp<AtmosDeviceComponent>(uid, out var atmosDeviceComponent))
{
_atmosDeviceSystem.LeaveAtmosphere(component.AtmosDeviceComponent);
_atmosDeviceSystem.LeaveAtmosphere(atmosDeviceComponent);
return;
}
@@ -204,28 +204,29 @@ namespace Content.Server.Atmos.Monitor.Systems
private void OnPowerChangedEvent(EntityUid uid, AtmosMonitorComponent component, PowerChangedEvent args)
{
if (!args.Powered)
if (TryComp<AtmosDeviceComponent>(uid, out var atmosDeviceComponent))
{
if (component.AtmosDeviceComponent != null
&& component.AtmosDeviceComponent.JoinedGrid != null)
if (!args.Powered)
{
_atmosDeviceSystem.LeaveAtmosphere(component.AtmosDeviceComponent);
component.TileGas = null;
}
if (atmosDeviceComponent.JoinedGrid != null)
{
_atmosDeviceSystem.LeaveAtmosphere(atmosDeviceComponent);
component.TileGas = null;
}
// clear memory when power cycled
component.LastAlarmState = AtmosMonitorAlarmType.Normal;
component.NetworkAlarmStates.Clear();
}
else if (args.Powered)
{
if (component.AtmosDeviceComponent != null
&& component.AtmosDeviceComponent.JoinedGrid == null)
// clear memory when power cycled
component.LastAlarmState = AtmosMonitorAlarmType.Normal;
component.NetworkAlarmStates.Clear();
}
else if (args.Powered)
{
_atmosDeviceSystem.JoinAtmosphere(component.AtmosDeviceComponent);
var coords = Transform(component.Owner).Coordinates;
var air = _atmosphereSystem.GetTileMixture(coords);
component.TileGas = air;
if (atmosDeviceComponent.JoinedGrid == null)
{
_atmosDeviceSystem.JoinAtmosphere(atmosDeviceComponent);
var coords = Transform(component.Owner).Coordinates;
var air = _atmosphereSystem.GetTileMixture(coords);
component.TileGas = air;
}
}
}
@@ -238,8 +239,8 @@ namespace Content.Server.Atmos.Monitor.Systems
private void OnFireEvent(EntityUid uid, AtmosMonitorComponent component, TileFireEvent args)
{
if (component.PowerRecvComponent == null
|| !component.PowerRecvComponent.Powered)
if (!TryComp<ApcPowerReceiverComponent>(uid, out var powerReceiverComponent)
|| !powerReceiverComponent.Powered)
return;
// if we're monitoring for atmos fire, then we make it similar to a smoke detector
@@ -261,15 +262,15 @@ namespace Content.Server.Atmos.Monitor.Systems
private void OnAtmosUpdate(EntityUid uid, AtmosMonitorComponent component, AtmosDeviceUpdateEvent args)
{
if (component.PowerRecvComponent == null
|| !component.PowerRecvComponent.Powered)
if (!TryComp<ApcPowerReceiverComponent>(uid, out var powerReceiverComponent)
|| !powerReceiverComponent.Powered)
return;
// can't hurt
// (in case something is making AtmosDeviceUpdateEvents
// outside the typical device loop)
if (component.AtmosDeviceComponent == null
|| component.AtmosDeviceComponent.JoinedGrid == null)
if (!TryComp<AtmosDeviceComponent>(uid, out var atmosDeviceComponent)
|| atmosDeviceComponent.JoinedGrid == null)
return;
// if we're not monitoring atmos, don't bother