Inline TryGetComponent completely, for real
This commit is contained in:
@@ -56,7 +56,7 @@ namespace Content.Server.Power.Components
|
||||
|
||||
[ViewVariables] private BoundUserInterface? UserInterface => Owner.GetUIOrNull(ApcUiKey.Key);
|
||||
|
||||
public BatteryComponent? Battery => Owner.TryGetComponent(out BatteryComponent? batteryComponent) ? batteryComponent : null;
|
||||
public BatteryComponent? Battery => IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner.Uid, out BatteryComponent? batteryComponent) ? batteryComponent : null;
|
||||
|
||||
[ComponentDependency] private AccessReader? _accessReader = null;
|
||||
|
||||
@@ -117,12 +117,12 @@ namespace Content.Server.Power.Components
|
||||
_lastChargeState = newState;
|
||||
_lastChargeStateChange = _gameTiming.CurTime;
|
||||
|
||||
if (Owner.TryGetComponent(out AppearanceComponent? appearance))
|
||||
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner.Uid, out AppearanceComponent? appearance))
|
||||
{
|
||||
appearance.SetData(ApcVisuals.ChargeState, newState);
|
||||
}
|
||||
|
||||
if (Owner.TryGetComponent(out SharedPointLightComponent? light))
|
||||
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner.Uid, out SharedPointLightComponent? light))
|
||||
{
|
||||
light.Color = newState switch
|
||||
{
|
||||
@@ -135,7 +135,7 @@ namespace Content.Server.Power.Components
|
||||
}
|
||||
}
|
||||
|
||||
Owner.TryGetComponent(out BatteryComponent? battery);
|
||||
IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner.Uid, out BatteryComponent? battery);
|
||||
|
||||
var newCharge = battery?.CurrentCharge;
|
||||
if (newCharge != null && newCharge != _lastCharge && _lastChargeChange + TimeSpan.FromSeconds(VisualsChangeDelay) < _gameTiming.CurTime)
|
||||
@@ -162,7 +162,7 @@ namespace Content.Server.Power.Components
|
||||
|
||||
private ApcChargeState CalcChargeState()
|
||||
{
|
||||
if (!Owner.TryGetComponent(out BatteryComponent? battery))
|
||||
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner.Uid, out BatteryComponent? battery))
|
||||
{
|
||||
return ApcChargeState.Lack;
|
||||
}
|
||||
@@ -203,7 +203,7 @@ namespace Content.Server.Power.Components
|
||||
|
||||
void IActivate.Activate(ActivateEventArgs eventArgs)
|
||||
{
|
||||
if (!eventArgs.User.TryGetComponent(out ActorComponent? actor))
|
||||
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(eventArgs.User.Uid, out ActorComponent? actor))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ namespace Content.Server.Power.Components
|
||||
#pragma warning restore 618
|
||||
IoCManager.Resolve<IEntityManager>().EventBus.RaiseLocalEvent(Owner.Uid, new PowerChangedEvent(Powered, NetworkLoad.ReceivingPower));
|
||||
|
||||
if (Owner.TryGetComponent<AppearanceComponent>(out var appearance))
|
||||
if (IoCManager.Resolve<IEntityManager>().TryGetComponent<AppearanceComponent?>(Owner.Uid, out var appearance))
|
||||
{
|
||||
appearance.SetData(PowerDeviceVisuals.Powered, Powered);
|
||||
}
|
||||
|
||||
@@ -98,12 +98,12 @@ namespace Content.Server.Power.Components
|
||||
|
||||
Container.Remove(heldItem);
|
||||
_heldBattery = null;
|
||||
if (user.TryGetComponent(out HandsComponent? handsComponent))
|
||||
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(user.Uid, out HandsComponent? handsComponent))
|
||||
{
|
||||
handsComponent.PutInHandOrDrop(IoCManager.Resolve<IEntityManager>().GetComponent<ItemComponent>(heldItem.Uid));
|
||||
}
|
||||
|
||||
if (heldItem.TryGetComponent(out ServerBatteryBarrelComponent? batteryBarrelComponent))
|
||||
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(heldItem.Uid, out ServerBatteryBarrelComponent? batteryBarrelComponent))
|
||||
{
|
||||
batteryBarrelComponent.UpdateAppearance();
|
||||
}
|
||||
@@ -118,7 +118,7 @@ namespace Content.Server.Power.Components
|
||||
|
||||
private CellChargerStatus GetStatus()
|
||||
{
|
||||
if (Owner.TryGetComponent(out ApcPowerReceiverComponent? receiver) &&
|
||||
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner.Uid, out ApcPowerReceiverComponent? receiver) &&
|
||||
!receiver.Powered)
|
||||
{
|
||||
return CellChargerStatus.Off;
|
||||
@@ -161,13 +161,13 @@ namespace Content.Server.Power.Components
|
||||
// Not called UpdateAppearance just because it messes with the load
|
||||
var status = GetStatus();
|
||||
if (_status == status ||
|
||||
!Owner.TryGetComponent(out ApcPowerReceiverComponent? receiver))
|
||||
!IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner.Uid, out ApcPowerReceiverComponent? receiver))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_status = status;
|
||||
Owner.TryGetComponent(out AppearanceComponent? appearance);
|
||||
IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner.Uid, out AppearanceComponent? appearance);
|
||||
|
||||
switch (_status)
|
||||
{
|
||||
@@ -206,7 +206,7 @@ namespace Content.Server.Power.Components
|
||||
|
||||
private void TransferPower(float frameTime)
|
||||
{
|
||||
if (Owner.TryGetComponent(out ApcPowerReceiverComponent? receiver) &&
|
||||
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner.Uid, out ApcPowerReceiverComponent? receiver) &&
|
||||
!receiver.Powered)
|
||||
{
|
||||
return;
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Linq;
|
||||
using Content.Server.NodeContainer;
|
||||
using Content.Server.NodeContainer.NodeGroups;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
@@ -67,7 +68,7 @@ namespace Content.Server.Power.Components
|
||||
|
||||
private bool TryFindNet([NotNullWhen(true)] out TNetType? foundNet)
|
||||
{
|
||||
if (Owner.TryGetComponent<NodeContainerComponent>(out var container))
|
||||
if (IoCManager.Resolve<IEntityManager>().TryGetComponent<NodeContainerComponent?>(Owner.Uid, out var container))
|
||||
{
|
||||
var compatibleNet = container.Nodes.Values
|
||||
.Where(node => (NodeId == null || NodeId == node.Name) && node.NodeGroupID == (NodeGroupID) Voltage)
|
||||
|
||||
@@ -51,7 +51,7 @@ namespace Content.Server.Power.Components
|
||||
var droppedEnt = IoCManager.Resolve<IEntityManager>().SpawnEntity(_cableDroppedOnCutPrototype, eventArgs.ClickLocation);
|
||||
|
||||
// TODO: Literally just use a prototype that has a single thing in the stack, it's not that complicated...
|
||||
if (droppedEnt.TryGetComponent<StackComponent>(out var stack))
|
||||
if (IoCManager.Resolve<IEntityManager>().TryGetComponent<StackComponent?>(droppedEnt.Uid, out var stack))
|
||||
EntitySystem.Get<StackSystem>().SetCount(droppedEnt.Uid, 1, stack);
|
||||
|
||||
return true;
|
||||
|
||||
@@ -57,7 +57,7 @@ namespace Content.Server.Power.Components
|
||||
}
|
||||
}
|
||||
|
||||
if (Owner.TryGetComponent<StackComponent>(out var stack)
|
||||
if (IoCManager.Resolve<IEntityManager>().TryGetComponent<StackComponent?>(Owner.Uid, out var stack)
|
||||
&& !EntitySystem.Get<StackSystem>().Use(Owner.Uid, 1, stack))
|
||||
return false;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user