Inline TryGetComponent completely, for real

This commit is contained in:
Vera Aguilera Puerto
2021-12-03 14:17:01 +01:00
parent 2ff4ec65d5
commit 69b270017b
425 changed files with 1143 additions and 995 deletions

View File

@@ -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;
}

View File

@@ -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);
}

View File

@@ -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;

View File

@@ -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)

View File

@@ -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;

View File

@@ -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;

View File

@@ -43,7 +43,7 @@ namespace Content.Server.Power.EntitySystems
if (args.IsInDetailsRange)
{
// Determine if they are holding a multitool.
if (args.Examiner.TryGetComponent<HandsComponent>(out var hands) && hands.TryGetActiveHand(out var hand))
if (IoCManager.Resolve<IEntityManager>().TryGetComponent<HandsComponent?>(args.Examiner.Uid, out var hands) && hands.TryGetActiveHand(out var hand))
{
var held = hand.HeldEntity;
// Pulsing is hardcoded here because I don't think it needs to be more complex than that right now.

View File

@@ -120,7 +120,7 @@ namespace Content.Server.Power.EntitySystems
private void OnReceiverStarted(EntityUid uid, ExtensionCableReceiverComponent receiver, ComponentStartup args)
{
if (receiver.Owner.TryGetComponent(out PhysicsComponent? physicsComponent))
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(receiver.Owner.Uid, out PhysicsComponent? physicsComponent))
{
receiver.Connectable = physicsComponent.BodyType == BodyType.Static;
}
@@ -181,7 +181,7 @@ namespace Content.Server.Power.EntitySystems
foreach (var entity in nearbyEntities)
{
if (!entity.TryGetComponent<ExtensionCableProviderComponent>(out var provider)) continue;
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent<ExtensionCableProviderComponent?>(entity.Uid, out var provider)) continue;
if (!provider.Connectable) continue;

View File

@@ -7,6 +7,7 @@ using Content.Server.Power.EntitySystems;
using Content.Server.Power.Pow3r;
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.ViewVariables;
@@ -66,7 +67,7 @@ namespace Content.Server.Power.NodeGroups
public void AddApc(ApcComponent apc)
{
if (apc.Owner.TryGetComponent(out PowerNetworkBatteryComponent? netBattery))
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(apc.Owner.Uid, out PowerNetworkBatteryComponent? netBattery))
netBattery.NetworkBattery.LinkedNetworkDischarging = default;
QueueNetworkReconnect();
@@ -75,7 +76,7 @@ namespace Content.Server.Power.NodeGroups
public void RemoveApc(ApcComponent apc)
{
if (apc.Owner.TryGetComponent(out PowerNetworkBatteryComponent? netBattery))
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(apc.Owner.Uid, out PowerNetworkBatteryComponent? netBattery))
netBattery.NetworkBattery.LinkedNetworkDischarging = default;
QueueNetworkReconnect();

View File

@@ -100,7 +100,7 @@ namespace Content.Server.Power.NodeGroups
public void RemoveDischarger(BatteryDischargerComponent discharger)
{
// Can be missing if the entity is being deleted, not a big deal.
if (discharger.Owner.TryGetComponent(out PowerNetworkBatteryComponent? battery))
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(discharger.Owner.Uid, out PowerNetworkBatteryComponent? battery))
battery.NetworkBattery.LinkedNetworkCharging = default;
Dischargers.Remove(discharger);
@@ -118,7 +118,7 @@ namespace Content.Server.Power.NodeGroups
public void RemoveCharger(BatteryChargerComponent charger)
{
// Can be missing if the entity is being deleted, not a big deal.
if (charger.Owner.TryGetComponent(out PowerNetworkBatteryComponent? battery))
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(charger.Owner.Uid, out PowerNetworkBatteryComponent? battery))
battery.NetworkBattery.LinkedNetworkCharging = default;
Chargers.Remove(charger);

View File

@@ -47,7 +47,7 @@ namespace Content.Server.Power.SMES
_lastChargeLevel = newLevel;
_lastChargeLevelChange = _gameTiming.CurTime;
if (Owner.TryGetComponent(out AppearanceComponent? appearance))
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner.Uid, out AppearanceComponent? appearance))
{
appearance.SetData(SmesVisuals.LastChargeLevel, newLevel);
}
@@ -59,7 +59,7 @@ namespace Content.Server.Power.SMES
_lastChargeState = newChargeState;
_lastChargeStateChange = _gameTiming.CurTime;
if (Owner.TryGetComponent(out AppearanceComponent? appearance))
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner.Uid, out AppearanceComponent? appearance))
{
appearance.SetData(SmesVisuals.LastChargeState, newChargeState);
}
@@ -68,7 +68,7 @@ namespace Content.Server.Power.SMES
private int GetNewChargeLevel()
{
if (!Owner.TryGetComponent(out BatteryComponent? battery))
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner.Uid, out BatteryComponent? battery))
{
return 0;
}