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

@@ -1,6 +1,7 @@
using System;
using Content.Shared.Actions.Components;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
namespace Content.Shared.Actions.Behaviors
{
@@ -34,7 +35,7 @@ namespace Content.Shared.Actions.Behaviors
{
Performer = performer;
ActionType = actionType;
if (!Performer.TryGetComponent(out PerformerActions))
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(Performer.Uid, out PerformerActions))
{
throw new InvalidOperationException($"performer {performer.Name} tried to perform action {actionType} " +
$" but the performer had no actions component," +

View File

@@ -1,6 +1,7 @@
using System;
using Content.Shared.Actions.Components;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
namespace Content.Shared.Actions.Behaviors.Item
{
@@ -40,7 +41,7 @@ namespace Content.Shared.Actions.Behaviors.Item
Performer = performer;
ActionType = actionType;
Item = item;
if (!Item.TryGetComponent(out ItemActions))
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(Item.Uid, out ItemActions))
{
throw new InvalidOperationException($"performer {performer.Name} tried to perform item action {actionType} " +
$" for item {Item.Name} but the item had no ItemActionsComponent," +

View File

@@ -4,6 +4,7 @@ using Content.Shared.Hands;
using Content.Shared.Hands.Components;
using Content.Shared.Inventory;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Log;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.Manager.Attributes;
@@ -183,7 +184,7 @@ namespace Content.Shared.Actions.Components
void IEquippedHand.EquippedHand(EquippedHandEventArgs eventArgs)
{
// this entity cannot be granted actions if no actions component
if (!eventArgs.User.TryGetComponent<SharedActionsComponent>(out var actionsComponent))
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent<SharedActionsComponent?>(eventArgs.User.Uid, out var actionsComponent))
return;
Holder = eventArgs.User;
_holderActionsComponent = actionsComponent;
@@ -195,7 +196,7 @@ namespace Content.Shared.Actions.Components
void IEquipped.Equipped(EquippedEventArgs eventArgs)
{
// this entity cannot be granted actions if no actions component
if (!eventArgs.User.TryGetComponent<SharedActionsComponent>(out var actionsComponent))
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent<SharedActionsComponent?>(eventArgs.User.Uid, out var actionsComponent))
return;
Holder = eventArgs.User;
_holderActionsComponent = actionsComponent;