Add a test that puts all components on an entity and checks for no exceptions (#1815)

* Add test that puts all components on an entity and checks for no exceptions

Also fix all the exceptions that happened because of this

* Add comments to the test

* Fix nullable errors

* Fix more nullable errors

* More nullable error fixes

* Unignore basic actor component

* Fix more nullable errors

* NULLABLE ERROR

* Add string interpolation

* Merge if checks

* Remove redundant pragma warning disable 649

* Address reviews

* Remove null wrappers around TryGetComponent

* Merge conflict fixes

* APC battery component error fix

* Fix power test

* Fix atmos mapgrid usages
This commit is contained in:
DrSmugleaf
2020-08-22 22:29:20 +02:00
committed by GitHub
parent c8178550b8
commit b9196d0a10
84 changed files with 1790 additions and 1123 deletions

View File

@@ -39,10 +39,8 @@ namespace Content.Server.GameObjects.Components.Disposal
[ComponentReference(typeof(IInteractUsing))]
public class DisposalUnitComponent : SharedDisposalUnitComponent, IInteractHand, IInteractUsing, IDragDropOn
{
#pragma warning disable 649
[Dependency] private readonly IServerNotifyManager _notifyManager = default!;
[Dependency] private readonly IGameTiming _gameTiming = default!;
#pragma warning restore 649
public override string Name => "DisposalUnit";
@@ -81,9 +79,6 @@ namespace Content.Server.GameObjects.Components.Disposal
[ViewVariables] public IReadOnlyList<IEntity> ContainedEntities => _container.ContainedEntities;
[ViewVariables]
private BoundUserInterface _userInterface = default!;
[ViewVariables]
public bool Powered =>
!Owner.TryGetComponent(out PowerReceiverComponent? receiver) ||
@@ -115,6 +110,13 @@ namespace Content.Server.GameObjects.Components.Disposal
}
}
[ViewVariables]
private BoundUserInterface? UserInterface =>
Owner.TryGetComponent(out ServerUserInterfaceComponent? ui) &&
ui.TryGetBoundUserInterface(DisposalUnitUiKey.Key, out var boundUi)
? boundUi
: null;
public bool CanInsert(IEntity entity)
{
if (!Anchored)
@@ -161,7 +163,7 @@ namespace Content.Server.GameObjects.Components.Disposal
if (entity.TryGetComponent(out IActorComponent? actor))
{
_userInterface.Close(actor.playerSession);
UserInterface?.Close(actor.playerSession);
}
UpdateVisualState();
@@ -291,10 +293,10 @@ namespace Content.Server.GameObjects.Components.Disposal
private void UpdateInterface()
{
var state = GetInterfaceState();
_userInterface.SetState(state);
UserInterface?.SetState(state);
}
private bool PlayerCanUse(IEntity player)
private bool PlayerCanUse(IEntity? player)
{
if (player == null)
{
@@ -472,9 +474,11 @@ namespace Content.Server.GameObjects.Components.Disposal
base.Initialize();
_container = ContainerManagerComponent.Ensure<Container>(Name, Owner);
_userInterface = Owner.GetComponent<ServerUserInterfaceComponent>()
.GetBoundUserInterface(DisposalUnitUiKey.Key);
_userInterface.OnReceiveMessage += OnUiReceiveMessage;
if (UserInterface != null)
{
UserInterface.OnReceiveMessage += OnUiReceiveMessage;
}
UpdateInterface();
}
@@ -513,7 +517,7 @@ namespace Content.Server.GameObjects.Components.Disposal
_container.ForceRemove(entity);
}
_userInterface.CloseAll();
UserInterface?.CloseAll();
_automaticEngageToken?.Cancel();
_automaticEngageToken = null;
@@ -571,7 +575,7 @@ namespace Content.Server.GameObjects.Components.Disposal
return false;
}
_userInterface.Open(actor.playerSession);
UserInterface?.Open(actor.playerSession);
return true;
}