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

@@ -41,7 +41,7 @@ namespace Content.Server.Construction.Completions
var board = container.ContainedEntities[0];
if (!board.TryGetComponent(out ComputerBoardComponent? boardComponent))
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(board.Uid, out ComputerBoardComponent? boardComponent))
{
Logger.Warning($"Computer entity {uid} had an invalid entity in container \"{Container}\"! Aborting build computer action.");
return;

View File

@@ -5,6 +5,7 @@ using Content.Shared.Construction;
using JetBrains.Annotations;
using Robust.Shared.Containers;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Log;
using Robust.Shared.Serialization.Manager.Attributes;
@@ -53,7 +54,7 @@ namespace Content.Server.Construction.Completions
var board = entBoardContainer.ContainedEntities[0];
if (!board.TryGetComponent(out MachineBoardComponent? boardComponent))
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(board.Uid, out MachineBoardComponent? boardComponent))
{
Logger.Warning($"Machine frame entity {uid} had an invalid entity in container \"{MachineFrameComponent.BoardContainer}\"! Aborting build machine action.");
return;
@@ -91,14 +92,14 @@ namespace Content.Server.Construction.Completions
}
var constructionSystem = entityManager.EntitySysManager.GetEntitySystem<ConstructionSystem>();
if (machine.TryGetComponent(out ConstructionComponent? construction))
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(machine.Uid, out ConstructionComponent? construction))
{
// We only add these two container. If some construction needs to take other containers into account, fix this.
constructionSystem.AddContainer(machine.Uid, MachineFrameComponent.BoardContainer, construction);
constructionSystem.AddContainer(machine.Uid, MachineFrameComponent.PartContainer, construction);
}
if (machine.TryGetComponent(out MachineComponent? machineComp))
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(machine.Uid, out MachineComponent? machineComp))
{
machineComp.RefreshParts();
}

View File

@@ -32,7 +32,7 @@ namespace Content.Server.Construction.Components
{
foreach (var entity in _partContainer.ContainedEntities)
{
if (entity.TryGetComponent<MachinePartComponent>(out var machinePart))
if (IoCManager.Resolve<IEntityManager>().TryGetComponent<MachinePartComponent?>(entity.Uid, out var machinePart))
yield return machinePart;
}
}
@@ -70,7 +70,7 @@ namespace Content.Server.Construction.Components
throw new Exception($"Couldn't insert board with prototype {BoardPrototype} to machine with prototype {IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(Owner.Uid).EntityPrototype?.ID ?? "N/A"}!");
}
if (!board.TryGetComponent<MachineBoardComponent>(out var machineBoard))
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent<MachineBoardComponent?>(board.Uid, out var machineBoard))
{
throw new Exception($"Entity with prototype {BoardPrototype} doesn't have a {nameof(MachineBoardComponent)}!");
}

View File

@@ -122,7 +122,7 @@ namespace Content.Server.Construction.Components
RegenerateProgress();
if (Owner.TryGetComponent<ConstructionComponent>(out var construction))
if (IoCManager.Resolve<IEntityManager>().TryGetComponent<ConstructionComponent?>(Owner.Uid, out var construction))
{
// Attempt to set pathfinding to the machine node...
EntitySystem.Get<ConstructionSystem>().SetPathfindingTarget(OwnerUid, "machine", construction);
@@ -168,7 +168,7 @@ namespace Content.Server.Construction.Components
if (!HasBoard)
{
if (Owner.TryGetComponent(out appearance))
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner.Uid, out appearance))
{
appearance.SetData(MachineFrameVisuals.State, 1);
}
@@ -187,10 +187,10 @@ namespace Content.Server.Construction.Components
var board = _boardContainer.ContainedEntities[0];
if (!board.TryGetComponent<MachineBoardComponent>(out var machineBoard))
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent<MachineBoardComponent?>(board.Uid, out var machineBoard))
return;
if (Owner.TryGetComponent(out appearance))
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner.Uid, out appearance))
{
appearance.SetData(MachineFrameVisuals.State, 2);
}
@@ -199,7 +199,7 @@ namespace Content.Server.Construction.Components
foreach (var part in _partContainer.ContainedEntities)
{
if (part.TryGetComponent<MachinePartComponent>(out var machinePart))
if (IoCManager.Resolve<IEntityManager>().TryGetComponent<MachinePartComponent?>(part.Uid, out var machinePart))
{
// Check this is part of the requirements...
if (!Requirements.ContainsKey(machinePart.PartType))
@@ -211,7 +211,7 @@ namespace Content.Server.Construction.Components
_progress[machinePart.PartType]++;
}
if (part.TryGetComponent<StackComponent>(out var stack))
if (IoCManager.Resolve<IEntityManager>().TryGetComponent<StackComponent?>(part.Uid, out var stack))
{
var type = stack.StackTypeId;
// Check this is part of the requirements...
@@ -254,7 +254,7 @@ namespace Content.Server.Construction.Components
async Task<bool> IInteractUsing.InteractUsing(InteractUsingEventArgs eventArgs)
{
if (!HasBoard && eventArgs.Using.TryGetComponent<MachineBoardComponent>(out var machineBoard))
if (!HasBoard && IoCManager.Resolve<IEntityManager>().TryGetComponent<MachineBoardComponent?>(eventArgs.Using.Uid, out var machineBoard))
{
if (eventArgs.Using.TryRemoveFromContainer())
{
@@ -264,12 +264,12 @@ namespace Content.Server.Construction.Components
// Setup requirements and progress...
ResetProgressAndRequirements(machineBoard);
if (Owner.TryGetComponent<AppearanceComponent>(out var appearance))
if (IoCManager.Resolve<IEntityManager>().TryGetComponent<AppearanceComponent?>(Owner.Uid, out var appearance))
{
appearance.SetData(MachineFrameVisuals.State, 2);
}
if (Owner.TryGetComponent(out ConstructionComponent? construction))
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner.Uid, out ConstructionComponent? construction))
{
// So prying the components off works correctly.
EntitySystem.Get<ConstructionSystem>().ResetEdge(OwnerUid, construction);
@@ -280,7 +280,7 @@ namespace Content.Server.Construction.Components
}
else if (HasBoard)
{
if (eventArgs.Using.TryGetComponent<MachinePartComponent>(out var machinePart))
if (IoCManager.Resolve<IEntityManager>().TryGetComponent<MachinePartComponent?>(eventArgs.Using.Uid, out var machinePart))
{
if (!Requirements.ContainsKey(machinePart.PartType))
return false;
@@ -293,7 +293,7 @@ namespace Content.Server.Construction.Components
}
}
if (eventArgs.Using.TryGetComponent<StackComponent>(out var stack))
if (IoCManager.Resolve<IEntityManager>().TryGetComponent<StackComponent?>(eventArgs.Using.Uid, out var stack))
{
var type = stack.StackTypeId;
if (!MaterialRequirements.ContainsKey(type))

View File

@@ -41,7 +41,7 @@ namespace Content.Server.Construction.Components
async Task<bool> IInteractUsing.InteractUsing(InteractUsingEventArgs eventArgs)
{
// check if object is welder
if (!eventArgs.Using.TryGetComponent(out ToolComponent? tool))
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(eventArgs.Using.Uid, out ToolComponent? tool))
return false;
// check if someone is already welding object
@@ -70,7 +70,7 @@ namespace Content.Server.Construction.Components
// TODO: If something has a stack... Just use a prototype with a single thing in the stack.
// This is not a good way to do it.
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);
}

View File

@@ -8,6 +8,7 @@ using Robust.Shared.Utility;
using System.Threading.Tasks;
using Content.Server.Doors.Components;
using Content.Shared.Examine;
using Robust.Shared.IoC;
namespace Content.Server.Construction.Conditions
{
@@ -30,7 +31,7 @@ namespace Content.Server.Construction.Conditions
{
var entity = args.Examined;
if (!entity.TryGetComponent(out AirlockComponent? airlock)) return false;
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(entity.Uid, out AirlockComponent? airlock)) return false;
if (airlock.BoltsDown != Value)
{

View File

@@ -6,6 +6,7 @@ using JetBrains.Annotations;
using Robust.Server.Containers;
using Robust.Shared.Containers;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.Utility;
@@ -44,7 +45,7 @@ namespace Content.Server.Construction.Conditions
var entity = args.Examined;
if (!entity.TryGetComponent(out ContainerManagerComponent? containerManager) ||
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(entity.Uid, out ContainerManagerComponent? containerManager) ||
!containerManager.TryGetContainer(Container, out var container)) return false;
if (container.ContainedEntities.Count == 0)

View File

@@ -6,6 +6,7 @@ using JetBrains.Annotations;
using Robust.Server.Containers;
using Robust.Shared.Containers;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.Utility;
@@ -37,7 +38,7 @@ namespace Content.Server.Construction.Conditions
var entity = args.Examined;
if (!entity.TryGetComponent(out ContainerManagerComponent? containerManager) ||
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(entity.Uid, out ContainerManagerComponent? containerManager) ||
!containerManager.TryGetContainer(Container, out var container)) return false;
if (container.ContainedEntities.Count != 0)

View File

@@ -4,6 +4,7 @@ using Content.Shared.Construction;
using Content.Shared.Examine;
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Serialization.Manager.Attributes;
@@ -28,7 +29,7 @@ namespace Content.Server.Construction.Conditions
{
var entity = args.Examined;
if (!entity.TryGetComponent(out ServerDoorComponent? door)) return false;
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(entity.Uid, out ServerDoorComponent? door)) return false;
if (door.IsWeldedShut != Welded)
{

View File

@@ -5,6 +5,7 @@ using Content.Shared.Construction;
using Content.Shared.Examine;
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.Utility;
@@ -37,7 +38,7 @@ namespace Content.Server.Construction.Conditions
{
var entity = args.Examined;
if (!entity.TryGetComponent<MachineFrameComponent>(out var machineFrame))
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent<MachineFrameComponent?>(entity.Uid, out var machineFrame))
return false;
if (!machineFrame.HasBoard)

View File

@@ -4,6 +4,7 @@ using Content.Shared.Construction;
using Content.Shared.Examine;
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Serialization.Manager.Attributes;
@@ -25,7 +26,7 @@ namespace Content.Server.Construction.Conditions
{
var entity = args.Examined;
if (!entity.TryGetComponent(out ToiletComponent? toilet)) return false;
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(entity.Uid, out ToiletComponent? toilet)) return false;
if (!toilet.LidOpen) return false;
args.PushMarkup(Loc.GetString("construction-examine-condition-toilet-lid-closed") + "\n");

View File

@@ -5,6 +5,7 @@ using Content.Shared.Construction;
using Content.Shared.Examine;
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.Utility;
@@ -29,7 +30,7 @@ namespace Content.Server.Construction.Conditions
{
var entity = args.Examined;
if (!entity.TryGetComponent(out WiresComponent? wires)) return false;
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(entity.Uid, out WiresComponent? wires)) return false;
switch (Open)
{

View File

@@ -45,11 +45,11 @@ namespace Content.Server.Construction
// LEGACY CODE. See warning at the top of the file!
private IEnumerable<IEntity> EnumerateNearby(IEntity user)
{
if (user.TryGetComponent(out HandsComponent? hands))
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(user.Uid, out HandsComponent? hands))
{
foreach (var itemComponent in hands?.GetAllHeldItems()!)
{
if (itemComponent.Owner.TryGetComponent(out ServerStorageComponent? storage))
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(itemComponent.Owner.Uid, out ServerStorageComponent? storage))
{
foreach (var storedEntity in storage.StoredEntities!)
{
@@ -61,11 +61,11 @@ namespace Content.Server.Construction
}
}
if (user!.TryGetComponent(out InventoryComponent? inventory))
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(user!.Uid, out InventoryComponent? inventory))
{
foreach (var held in inventory.GetAllHeldItems())
{
if (held.TryGetComponent(out ServerStorageComponent? storage))
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(held.Uid, out ServerStorageComponent? storage))
{
foreach (var storedEntity in storage.StoredEntities!)
{
@@ -299,7 +299,7 @@ namespace Content.Server.Construction
if (user == null || !Get<ActionBlockerSystem>().CanInteract(user.Uid)) return;
if (!user.TryGetComponent(out HandsComponent? hands)) return;
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(user.Uid, out HandsComponent? hands)) return;
foreach (var condition in constructionPrototype.Conditions)
{
@@ -328,7 +328,7 @@ namespace Content.Server.Construction
var item = await Construct(user, "item_construction", constructionGraph, edge, targetNode);
if(item != null && item.TryGetComponent(out ItemComponent? itemComp))
if(item != null && IoCManager.Resolve<IEntityManager>().TryGetComponent(item.Uid, out ItemComponent? itemComp))
hands.PutInHandOrDrop(itemComp);
}
@@ -399,7 +399,7 @@ namespace Content.Server.Construction
if (user == null
|| !Get<ActionBlockerSystem>().CanInteract(user.Uid)
|| !user.TryGetComponent(out HandsComponent? hands) || hands.GetActiveHand == null
|| !IoCManager.Resolve<IEntityManager>().TryGetComponent(user.Uid, out HandsComponent? hands) || hands.GetActiveHand == null
|| !user.InRangeUnobstructed(ev.Location, ignoreInsideBlocker:constructionPrototype.CanBuildInImpassable))
{
Cleanup();