Inline GetAllComponents

This commit is contained in:
Vera Aguilera Puerto
2021-12-03 11:42:24 +01:00
parent e0fe09cb46
commit f10ed6c0c3
18 changed files with 48 additions and 38 deletions

View File

@@ -42,7 +42,7 @@ namespace Content.Client.CharacterInterface
base.Initialize(); base.Initialize();
//Use all the character ui interfaced components to create the character window //Use all the character ui interfaced components to create the character window
_uiComponents = Owner.GetAllComponents<ICharacterUI>().ToList(); _uiComponents = IoCManager.Resolve<IEntityManager>().GetComponents<ICharacterUI>(Owner.Uid).ToList();
if (_uiComponents.Count == 0) if (_uiComponents.Count == 0)
{ {
return; return;

View File

@@ -142,7 +142,7 @@ namespace Content.Client.DragDrop
} }
var canDrag = false; var canDrag = false;
foreach (var draggable in entity.GetAllComponents<IDraggable>()) foreach (var draggable in IoCManager.Resolve<IEntityManager>().GetComponents<IDraggable>(entity.Uid))
{ {
var dragEventArgs = new StartDragDropEvent(dragger, entity); var dragEventArgs = new StartDragDropEvent(dragger, entity);
@@ -422,7 +422,7 @@ namespace Content.Client.DragDrop
bool? valid = null; bool? valid = null;
foreach (var comp in eventArgs.Target.GetAllComponents<IDragDropOn>()) foreach (var comp in IoCManager.Resolve<IEntityManager>().GetComponents<IDragDropOn>(eventArgs.Target.Uid))
{ {
if (!comp.CanDragDropOn(eventArgs)) if (!comp.CanDragDropOn(eventArgs))
{ {
@@ -440,7 +440,7 @@ namespace Content.Client.DragDrop
// Need at least one IDraggable to return true or else we can't do shit // Need at least one IDraggable to return true or else we can't do shit
valid = false; valid = false;
foreach (var comp in eventArgs.User.GetAllComponents<IDraggable>()) foreach (var comp in IoCManager.Resolve<IEntityManager>().GetComponents<IDraggable>(eventArgs.User.Uid))
{ {
if (!comp.CanDrop(eventArgs)) continue; if (!comp.CanDrop(eventArgs)) continue;
valid = true; valid = true;

View File

@@ -185,7 +185,7 @@ namespace Content.Client.Items.UI
ClearOldStatus(); ClearOldStatus();
foreach (var statusComponent in _entity!.GetAllComponents<IItemStatus>()) foreach (var statusComponent in IoCManager.Resolve<IEntityManager>().GetComponents<IItemStatus>(_entity!.Uid))
{ {
var control = statusComponent.MakeControl(); var control = statusComponent.MakeControl();
_statusContents.AddChild(control); _statusContents.AddChild(control);

View File

@@ -21,6 +21,7 @@ using Robust.Shared.Random;
using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.ViewVariables; using Robust.Shared.ViewVariables;
using System; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using Content.Server.Administration.Logs; using Content.Server.Administration.Logs;
using Content.Server.Popups; using Content.Server.Popups;
@@ -48,7 +49,7 @@ namespace Content.Server.Actions.Actions
public void DoTargetEntityAction(TargetEntityActionEventArgs args) public void DoTargetEntityAction(TargetEntityActionEventArgs args)
{ {
var disarmedActs = args.Target.GetAllComponents<IDisarmedAct>().ToArray(); var disarmedActs = IoCManager.Resolve<IEntityManager>().GetComponents<IDisarmedAct>(args.Target.Uid).ToArray();
if (!args.Performer.InRangeUnobstructed(args.Target)) return; if (!args.Performer.InRangeUnobstructed(args.Target)) return;

View File

@@ -1,4 +1,5 @@
using Content.Shared.Administration; using System.Collections.Generic;
using Content.Shared.Administration;
using Robust.Shared.Console; using Robust.Shared.Console;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.IoC; using Robust.Shared.IoC;
@@ -39,7 +40,7 @@ namespace Content.Server.Administration.Commands
var modified = false; var modified = false;
foreach (var component in entity.GetAllComponents()) foreach (var component in IoCManager.Resolve<IEntityManager>().GetComponents(entity.Uid))
{ {
if (IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(entity.Uid).EntityPrototype.Components.ContainsKey(component.Name)) if (IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(entity.Uid).EntityPrototype.Components.ContainsKey(component.Name))
continue; continue;

View File

@@ -1,3 +1,4 @@
using System.Collections.Generic;
using System.Linq; using System.Linq;
using Content.Server.Act; using Content.Server.Act;
using Content.Server.Administration; using Content.Server.Administration;
@@ -91,7 +92,7 @@ namespace Content.Server.Chat.Commands
var itemComponent = handsComponent.GetActiveHand; var itemComponent = handsComponent.GetActiveHand;
if (itemComponent != null) if (itemComponent != null)
{ {
var suicide = itemComponent.Owner.GetAllComponents<ISuicideAct>().FirstOrDefault(); var suicide = IoCManager.Resolve<IEntityManager>().GetComponents<ISuicideAct>(itemComponent.Owner.Uid).FirstOrDefault();
if (suicide != null) if (suicide != null)
{ {
@@ -108,7 +109,7 @@ namespace Content.Server.Chat.Commands
{ {
if (entity.HasComponent<ItemComponent>()) if (entity.HasComponent<ItemComponent>())
continue; continue;
var suicide = entity.GetAllComponents<ISuicideAct>().FirstOrDefault(); var suicide = IoCManager.Resolve<IEntityManager>().GetComponents<ISuicideAct>(entity.Uid).FirstOrDefault();
if (suicide != null) if (suicide != null)
{ {
DealDamage(suicide, chat, owner); DealDamage(suicide, chat, owner);

View File

@@ -39,7 +39,7 @@ namespace Content.Server.Construction.Components
public void RefreshParts() public void RefreshParts()
{ {
foreach (var refreshable in Owner.GetAllComponents<IRefreshParts>()) foreach (var refreshable in IoCManager.Resolve<IEntityManager>().GetComponents<IRefreshParts>(Owner.Uid))
{ {
refreshable.RefreshParts(GetAllParts()); refreshable.RefreshParts(GetAllParts());
} }

View File

@@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
@@ -176,7 +177,7 @@ namespace Content.Server.Interaction
// trigger dragdrops on the dropped entity // trigger dragdrops on the dropped entity
RaiseLocalEvent(dropped.Uid, interactionArgs); RaiseLocalEvent(dropped.Uid, interactionArgs);
foreach (var dragDrop in dropped.GetAllComponents<IDraggable>()) foreach (var dragDrop in IoCManager.Resolve<IEntityManager>().GetComponents<IDraggable>(dropped.Uid))
{ {
if (dragDrop.CanDrop(interactionArgs) && if (dragDrop.CanDrop(interactionArgs) &&
dragDrop.Drop(interactionArgs)) dragDrop.Drop(interactionArgs))
@@ -187,7 +188,7 @@ namespace Content.Server.Interaction
// trigger dragdropons on the targeted entity // trigger dragdropons on the targeted entity
RaiseLocalEvent(target.Uid, interactionArgs, false); RaiseLocalEvent(target.Uid, interactionArgs, false);
foreach (var dragDropOn in target.GetAllComponents<IDragDropOn>()) foreach (var dragDropOn in IoCManager.Resolve<IEntityManager>().GetComponents<IDragDropOn>(target.Uid))
{ {
if (dragDropOn.CanDragDropOn(interactionArgs) && if (dragDropOn.CanDragDropOn(interactionArgs) &&
dragDropOn.DragDropOn(interactionArgs)) dragDropOn.DragDropOn(interactionArgs))
@@ -404,7 +405,7 @@ namespace Content.Server.Interaction
var interactHandEventArgs = new InteractHandEventArgs(user, target); var interactHandEventArgs = new InteractHandEventArgs(user, target);
var interactHandComps = target.GetAllComponents<IInteractHand>().ToList(); var interactHandComps = IoCManager.Resolve<IEntityManager>().GetComponents<IInteractHand>(target.Uid).ToList();
foreach (var interactHandComp in interactHandComps) foreach (var interactHandComp in interactHandComps)
{ {
// If an InteractHand returns a status completion we finish our interaction // If an InteractHand returns a status completion we finish our interaction
@@ -434,7 +435,7 @@ namespace Content.Server.Interaction
if (rangedMsg.Handled) if (rangedMsg.Handled)
return true; return true;
var rangedInteractions = target.GetAllComponents<IRangedInteract>().ToList(); var rangedInteractions = IoCManager.Resolve<IEntityManager>().GetComponents<IRangedInteract>(target.Uid).ToList();
var rangedInteractionEventArgs = new RangedInteractEventArgs(user, used, clickLocation); var rangedInteractionEventArgs = new RangedInteractEventArgs(user, used, clickLocation);
// See if we have a ranged interaction // See if we have a ranged interaction

View File

@@ -545,7 +545,7 @@ namespace Content.Server.Inventory.Components
{ {
foreach (var entity in slot.ContainedEntities) foreach (var entity in slot.ContainedEntities)
{ {
var exActs = entity.GetAllComponents<IExAct>().ToList(); var exActs = IoCManager.Resolve<IEntityManager>().GetComponents<IExAct>(entity.Uid).ToList();
foreach (var exAct in exActs) foreach (var exAct in exActs)
{ {
exAct.OnExplosion(eventArgs); exAct.OnExplosion(eventArgs);

View File

@@ -1,6 +1,8 @@
using System.Collections.Generic;
using Content.Shared.Item; using Content.Shared.Item;
using Robust.Server.GameObjects; using Robust.Server.GameObjects;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
namespace Content.Server.Items namespace Content.Server.Items
{ {
@@ -10,7 +12,7 @@ namespace Content.Server.Items
{ {
public override void RemovedFromSlot() public override void RemovedFromSlot()
{ {
foreach (var component in Owner.GetAllComponents<ISpriteRenderableComponent>()) foreach (var component in IoCManager.Resolve<IEntityManager>().GetComponents<ISpriteRenderableComponent>(Owner.Uid))
{ {
component.Visible = true; component.Visible = true;
} }
@@ -18,7 +20,7 @@ namespace Content.Server.Items
public override void EquippedToSlot() public override void EquippedToSlot()
{ {
foreach (var component in Owner.GetAllComponents<ISpriteRenderableComponent>()) foreach (var component in IoCManager.Resolve<IEntityManager>().GetComponents<ISpriteRenderableComponent>(Owner.Uid))
{ {
component.Visible = false; component.Visible = false;
} }

View File

@@ -3,6 +3,8 @@ using System.Linq;
using Content.Server.NodeContainer.NodeGroups; using Content.Server.NodeContainer.NodeGroups;
using Content.Server.NodeContainer.Nodes; using Content.Server.NodeContainer.Nodes;
using Content.Server.Power.Components; using Content.Server.Power.Components;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
namespace Content.Server.Power.NodeGroups namespace Content.Server.Power.NodeGroups
{ {
@@ -14,8 +16,7 @@ namespace Content.Server.Power.NodeGroups
foreach (var node in groupNodes) foreach (var node in groupNodes)
{ {
var newNetConnectorComponents = node.Owner var newNetConnectorComponents = IoCManager.Resolve<IEntityManager>().GetComponents<IBaseNetConnectorComponent<TNetType>>(node.Owner.Uid)
.GetAllComponents<IBaseNetConnectorComponent<TNetType>>()
.Where(powerComp => (powerComp.NodeId == null || powerComp.NodeId == node.Name) && .Where(powerComp => (powerComp.NodeId == null || powerComp.NodeId == node.Name) &&
(NodeGroupID) powerComp.Voltage == node.NodeGroupID) (NodeGroupID) powerComp.Voltage == node.NodeGroupID)
.ToList(); .ToList();

View File

@@ -1,3 +1,4 @@
using System.Collections.Generic;
using System.Linq; using System.Linq;
using Content.Shared.Radiation; using Content.Shared.Radiation;
using Content.Shared.Sound; using Content.Shared.Sound;
@@ -41,7 +42,7 @@ namespace Content.Server.Radiation
// Note: Radiation is liable for a refactor (stinky Sloth coding a basic version when he did StationEvents) // Note: Radiation is liable for a refactor (stinky Sloth coding a basic version when he did StationEvents)
// so this ToArray doesn't really matter. // so this ToArray doesn't really matter.
foreach (var radiation in entity.GetAllComponents<IRadiationAct>().ToArray()) foreach (var radiation in IoCManager.Resolve<IEntityManager>().GetComponents<IRadiationAct>(entity.Uid).ToArray())
{ {
radiation.RadiationAct(RadiationCooldown, comp); radiation.RadiationAct(RadiationCooldown, comp);
} }

View File

@@ -463,7 +463,7 @@ namespace Content.Server.Storage.Components
var containedEntities = Contents.ContainedEntities.ToList(); var containedEntities = Contents.ContainedEntities.ToList();
foreach (var entity in containedEntities) foreach (var entity in containedEntities)
{ {
var exActs = entity.GetAllComponents<IExAct>().ToArray(); var exActs = IoCManager.Resolve<IEntityManager>().GetComponents<IExAct>(entity.Uid).ToArray();
foreach (var exAct in exActs) foreach (var exAct in exActs)
{ {
exAct.OnExplosion(eventArgs); exAct.OnExplosion(eventArgs);

View File

@@ -685,7 +685,7 @@ namespace Content.Server.Storage.Components
foreach (var entity in storedEntities) foreach (var entity in storedEntities)
{ {
var exActs = entity.GetAllComponents<IExAct>().ToArray(); var exActs = IoCManager.Resolve<IEntityManager>().GetComponents<IExAct>(entity.Uid).ToArray();
foreach (var exAct in exActs) foreach (var exAct in exActs)
{ {
exAct.OnExplosion(eventArgs); exAct.OnExplosion(eventArgs);

View File

@@ -230,7 +230,7 @@ namespace Content.Server.WireHacking
hackingSystem.TryGetLayout(_layoutId, out layout); hackingSystem.TryGetLayout(_layoutId, out layout);
} }
foreach (var wiresProvider in Owner.GetAllComponents<IWires>()) foreach (var wiresProvider in IoCManager.Resolve<IEntityManager>().GetComponents<IWires>(Owner.Uid))
{ {
var builder = new WiresBuilder(this, wiresProvider, layout); var builder = new WiresBuilder(this, wiresProvider, layout);
wiresProvider.RegisterWires(builder); wiresProvider.RegisterWires(builder);

View File

@@ -147,7 +147,7 @@ namespace Content.Shared.Body.Components
var argsAdded = new BodyPartAddedEventArgs(slot.Id, part); var argsAdded = new BodyPartAddedEventArgs(slot.Id, part);
EntitySystem.Get<SharedHumanoidAppearanceSystem>().BodyPartAdded(OwnerUid, argsAdded); EntitySystem.Get<SharedHumanoidAppearanceSystem>().BodyPartAdded(OwnerUid, argsAdded);
foreach (var component in Owner.GetAllComponents<IBodyPartAdded>().ToArray()) foreach (var component in IoCManager.Resolve<IEntityManager>().GetComponents<IBodyPartAdded>(Owner.Uid).ToArray())
{ {
component.BodyPartAdded(argsAdded); component.BodyPartAdded(argsAdded);
} }
@@ -175,7 +175,7 @@ namespace Content.Shared.Body.Components
EntitySystem.Get<SharedHumanoidAppearanceSystem>().BodyPartRemoved(OwnerUid, args); EntitySystem.Get<SharedHumanoidAppearanceSystem>().BodyPartRemoved(OwnerUid, args);
foreach (var component in Owner.GetAllComponents<IBodyPartRemoved>()) foreach (var component in IoCManager.Resolve<IEntityManager>().GetComponents<IBodyPartRemoved>(Owner.Uid))
{ {
component.BodyPartRemoved(args); component.BodyPartRemoved(args);
} }

View File

@@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using Content.Shared.DragDrop; using Content.Shared.DragDrop;
using Content.Shared.Interaction; using Content.Shared.Interaction;
@@ -226,7 +227,7 @@ namespace Content.Shared.Examine
RaiseLocalEvent(entity.Uid, examinedEvent); RaiseLocalEvent(entity.Uid, examinedEvent);
//Add component statuses from components that report one //Add component statuses from components that report one
foreach (var examineComponent in entity.GetAllComponents<IExamine>()) foreach (var examineComponent in IoCManager.Resolve<IEntityManager>().GetComponents<IExamine>(entity.Uid))
{ {
var subMessage = new FormattedMessage(); var subMessage = new FormattedMessage();
examineComponent.Examine(subMessage, isInDetailsRange); examineComponent.Examine(subMessage, isInDetailsRange);

View File

@@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Content.Shared.ActionBlocker; using Content.Shared.ActionBlocker;
@@ -391,7 +392,7 @@ namespace Content.Shared.Interaction
var interactUsingEventArgs = new InteractUsingEventArgs(user, clickLocation, used, target); var interactUsingEventArgs = new InteractUsingEventArgs(user, clickLocation, used, target);
var interactUsings = target.GetAllComponents<IInteractUsing>().OrderByDescending(x => x.Priority); var interactUsings = IoCManager.Resolve<IEntityManager>().GetComponents<IInteractUsing>(target.Uid).OrderByDescending(x => x.Priority);
foreach (var interactUsing in interactUsings) foreach (var interactUsing in interactUsings)
{ {
// If an InteractUsing returns a status completion we finish our interaction // If an InteractUsing returns a status completion we finish our interaction
@@ -414,7 +415,7 @@ namespace Content.Shared.Interaction
return true; return true;
var afterInteractEventArgs = new AfterInteractEventArgs(user, clickLocation, target, canReach); var afterInteractEventArgs = new AfterInteractEventArgs(user, clickLocation, target, canReach);
var afterInteracts = used.GetAllComponents<IAfterInteract>().OrderByDescending(x => x.Priority).ToList(); var afterInteracts = IoCManager.Resolve<IEntityManager>().GetComponents<IAfterInteract>(used.Uid).OrderByDescending(x => x.Priority).ToList();
foreach (var afterInteract in afterInteracts) foreach (var afterInteract in afterInteracts)
{ {
@@ -515,7 +516,7 @@ namespace Content.Shared.Interaction
if (useMsg.Handled) if (useMsg.Handled)
return; return;
var uses = used.GetAllComponents<IUse>().ToList(); var uses = IoCManager.Resolve<IEntityManager>().GetComponents<IUse>(used.Uid).ToList();
// Try to use item on any components which have the interface // Try to use item on any components which have the interface
foreach (var use in uses) foreach (var use in uses)
@@ -556,7 +557,7 @@ namespace Content.Shared.Interaction
return; return;
} }
var comps = thrown.GetAllComponents<IThrown>().ToList(); var comps = IoCManager.Resolve<IEntityManager>().GetComponents<IThrown>(thrown.Uid).ToList();
var args = new ThrownEventArgs(user); var args = new ThrownEventArgs(user);
// Call Thrown on all components that implement the interface // Call Thrown on all components that implement the interface
@@ -580,7 +581,7 @@ namespace Content.Shared.Interaction
if (equipMsg.Handled) if (equipMsg.Handled)
return; return;
var comps = equipped.GetAllComponents<IEquipped>().ToList(); var comps = IoCManager.Resolve<IEntityManager>().GetComponents<IEquipped>(equipped.Uid).ToList();
// Call Thrown on all components that implement the interface // Call Thrown on all components that implement the interface
foreach (var comp in comps) foreach (var comp in comps)
@@ -600,7 +601,7 @@ namespace Content.Shared.Interaction
if (unequipMsg.Handled) if (unequipMsg.Handled)
return; return;
var comps = equipped.GetAllComponents<IUnequipped>().ToList(); var comps = IoCManager.Resolve<IEntityManager>().GetComponents<IUnequipped>(equipped.Uid).ToList();
// Call Thrown on all components that implement the interface // Call Thrown on all components that implement the interface
foreach (var comp in comps) foreach (var comp in comps)
@@ -621,7 +622,7 @@ namespace Content.Shared.Interaction
if (equippedHandMessage.Handled) if (equippedHandMessage.Handled)
return; return;
var comps = item.GetAllComponents<IEquippedHand>().ToList(); var comps = IoCManager.Resolve<IEntityManager>().GetComponents<IEquippedHand>(item.Uid).ToList();
foreach (var comp in comps) foreach (var comp in comps)
{ {
@@ -640,7 +641,7 @@ namespace Content.Shared.Interaction
if (unequippedHandMessage.Handled) if (unequippedHandMessage.Handled)
return; return;
var comps = item.GetAllComponents<IUnequippedHand>().ToList(); var comps = IoCManager.Resolve<IEntityManager>().GetComponents<IUnequippedHand>(item.Uid).ToList();
foreach (var comp in comps) foreach (var comp in comps)
{ {
@@ -679,7 +680,7 @@ namespace Content.Shared.Interaction
item.Transform.LocalRotation = Angle.Zero; item.Transform.LocalRotation = Angle.Zero;
var comps = item.GetAllComponents<IDropped>().ToList(); var comps = IoCManager.Resolve<IEntityManager>().GetComponents<IDropped>(item.Uid).ToList();
// Call Land on all components that implement the interface // Call Land on all components that implement the interface
foreach (var comp in comps) foreach (var comp in comps)
@@ -702,7 +703,7 @@ namespace Content.Shared.Interaction
if (handSelectedMsg.Handled) if (handSelectedMsg.Handled)
return; return;
var comps = item.GetAllComponents<IHandSelected>().ToList(); var comps = IoCManager.Resolve<IEntityManager>().GetComponents<IHandSelected>(item.Uid).ToList();
// Call Land on all components that implement the interface // Call Land on all components that implement the interface
foreach (var comp in comps) foreach (var comp in comps)
@@ -722,7 +723,7 @@ namespace Content.Shared.Interaction
if (handDeselectedMsg.Handled) if (handDeselectedMsg.Handled)
return; return;
var comps = item.GetAllComponents<IHandDeselected>().ToList(); var comps = IoCManager.Resolve<IEntityManager>().GetComponents<IHandDeselected>(item.Uid).ToList();
// Call Land on all components that implement the interface // Call Land on all components that implement the interface
foreach (var comp in comps) foreach (var comp in comps)