Add static "IsPowered" method (#8434)

* Add static "IsPowered" method

* Use IsPowered in more places

Co-authored-by: wrexbe <wrexbe@protonmail.com>
This commit is contained in:
metalgearsloth
2022-05-27 10:36:12 +10:00
committed by GitHub
parent 33c03fa0a0
commit 2d873a2cf2
20 changed files with 104 additions and 141 deletions

View File

@@ -1,6 +1,7 @@
using Content.Server.MachineLinking.Events;
using Content.Server.MachineLinking.System;
using Content.Server.Power.Components;
using Content.Server.Power.EntitySystems;
using Content.Server.Recycling;
using Content.Server.Recycling.Components;
using Content.Shared.Conveyor;
@@ -34,17 +35,9 @@ namespace Content.Server.Conveyor
private void UpdateAppearance(ConveyorComponent component)
{
if (EntityManager.TryGetComponent<AppearanceComponent?>(component.Owner, out var appearance))
{
if (EntityManager.TryGetComponent<ApcPowerReceiverComponent?>(component.Owner, out var receiver) && receiver.Powered)
{
appearance.SetData(ConveyorVisuals.State, component.State);
}
else
{
appearance.SetData(ConveyorVisuals.State, ConveyorState.Off);
}
}
if (!EntityManager.TryGetComponent<AppearanceComponent?>(component.Owner, out var appearance)) return;
var isPowered = this.IsPowered(component.Owner, EntityManager);
appearance.SetData(ConveyorVisuals.State, isPowered ? component.State : ConveyorState.Off);
}
private void OnSignalReceived(EntityUid uid, ConveyorComponent component, SignalReceivedEvent args)
@@ -74,23 +67,9 @@ namespace Content.Server.Conveyor
public bool CanRun(ConveyorComponent component)
{
if (component.State == ConveyorState.Off)
{
return false;
}
if (EntityManager.TryGetComponent(component.Owner, out ApcPowerReceiverComponent? receiver) &&
!receiver.Powered)
{
return false;
}
if (EntityManager.HasComponent<SharedItemComponent>(component.Owner))
{
return false;
}
return true;
return component.State != ConveyorState.Off &&
!EntityManager.HasComponent<SharedItemComponent>(component.Owner) &&
this.IsPowered(component.Owner, EntityManager);
}
}
}