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

@@ -27,7 +27,7 @@ namespace Content.Server.Research.Components
[DataField("sound")]
private SoundSpecifier _soundCollectionName = new SoundCollectionSpecifier("keyboard");
[ViewVariables] private bool Powered => !Owner.TryGetComponent(out ApcPowerReceiverComponent? receiver) || receiver.Powered;
[ViewVariables] private bool Powered => !IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner.Uid, out ApcPowerReceiverComponent? receiver) || receiver.Powered;
[ViewVariables] private BoundUserInterface? UserInterface => Owner.GetUIOrNull(ResearchConsoleUiKey.Key);
@@ -47,9 +47,9 @@ namespace Content.Server.Research.Components
private void UserInterfaceOnOnReceiveMessage(ServerBoundUserInterfaceMessage message)
{
if (!Owner.TryGetComponent(out TechnologyDatabaseComponent? database))
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner.Uid, out TechnologyDatabaseComponent? database))
return;
if (!Owner.TryGetComponent(out ResearchClientComponent? client))
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner.Uid, out ResearchClientComponent? client))
return;
if (!Powered)
return;
@@ -90,7 +90,7 @@ namespace Content.Server.Research.Components
private ResearchConsoleBoundInterfaceState GetNewUiState()
{
if (!Owner.TryGetComponent(out ResearchClientComponent? client) ||
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner.Uid, out ResearchClientComponent? client) ||
client.Server == null)
return new ResearchConsoleBoundInterfaceState(default, default);
@@ -111,7 +111,7 @@ namespace Content.Server.Research.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;
if (!Powered)
{

View File

@@ -1,6 +1,7 @@
using Content.Server.Power.Components;
using Content.Shared.Interaction;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.ViewVariables;
@@ -42,7 +43,7 @@ namespace Content.Server.Research.Components
protected override void Initialize()
{
base.Initialize();
Owner.TryGetComponent(out _powerReceiver);
IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner.Uid, out _powerReceiver);
}
}
}

View File

@@ -2,6 +2,7 @@ using System.Collections.Generic;
using Content.Server.Power.Components;
using Content.Shared.Research.Prototypes;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.ViewVariables;
@@ -73,7 +74,7 @@ namespace Content.Server.Research.Components
Id = ServerCount++;
EntitySystem.Get<ResearchSystem>()?.RegisterServer(this);
Database = Owner.EnsureComponent<TechnologyDatabaseComponent>();
Owner.TryGetComponent(out _powerReceiver);
IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner.Uid, out _powerReceiver);
}
/// <inheritdoc />

View File

@@ -1,6 +1,7 @@
using Content.Shared.Research.Components;
using Content.Shared.Research.Prototypes;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Players;
namespace Content.Server.Research.Components
@@ -41,7 +42,7 @@ namespace Content.Server.Research.Components
/// <returns>Whether it could sync or not</returns>
public bool SyncWithServer()
{
if (!Owner.TryGetComponent(out ResearchClientComponent? client)) return false;
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner.Uid, out ResearchClientComponent? client)) return false;
if (client.Server?.Database == null) return false;
Sync(client.Server.Database);