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

@@ -37,9 +37,7 @@ namespace Content.Server.GameObjects.Components.GUI
[ComponentReference(typeof(ISharedHandsComponent))]
public class HandsComponent : SharedHandsComponent, IHandsComponent, IBodyPartAdded, IBodyPartRemoved
{
#pragma warning disable 649
[Dependency] private readonly IEntitySystemManager _entitySystemManager = default!;
#pragma warning restore 649
private string? _activeHand;
private uint _nextHand;

View File

@@ -21,7 +21,7 @@ namespace Content.Server.GameObjects.Components.GUI
{
base.Initialize();
_inventory = Owner.GetComponent<InventoryComponent>();
_inventory = Owner.EnsureComponent<InventoryComponent>();
}
bool IInventoryController.CanEquip(Slots slot, IEntity entity, bool flagsCheck, out string reason)

View File

@@ -1,11 +1,10 @@
using System;
#nullable enable
using System.Collections.Generic;
using System.Threading;
using Content.Server.GameObjects.Components.Items.Storage;
using Content.Server.GameObjects.EntitySystems.DoAfter;
using Content.Server.Interfaces;
using Content.Shared.GameObjects.Components.GUI;
using Content.Shared.GameObjects.Components.Inventory;
using Content.Shared.GameObjects.EntitySystems;
using Content.Shared.Interfaces.GameObjects.Components;
using Robust.Server.GameObjects.Components.UserInterface;
@@ -16,7 +15,6 @@ using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Log;
using Robust.Shared.ViewVariables;
using static Content.Shared.GameObjects.Components.Inventory.EquipmentSlotDefines;
@@ -25,27 +23,33 @@ namespace Content.Server.GameObjects.Components.GUI
[RegisterComponent]
public sealed class StrippableComponent : SharedStrippableComponent, IDragDrop
{
[Dependency] private IServerNotifyManager _notifyManager = default!;
[Dependency] private readonly IServerNotifyManager _notifyManager = default!;
public const float StripDelay = 2f;
[ViewVariables]
private BoundUserInterface _userInterface;
private InventoryComponent _inventoryComponent;
private HandsComponent _handsComponent;
private BoundUserInterface? UserInterface =>
Owner.TryGetComponent(out ServerUserInterfaceComponent? ui) &&
ui.TryGetBoundUserInterface(StrippingUiKey.Key, out var boundUi)
? boundUi
: null;
public override void Initialize()
{
base.Initialize();
_userInterface = Owner.GetComponent<ServerUserInterfaceComponent>().GetBoundUserInterface(StrippingUiKey.Key);
_userInterface.OnReceiveMessage += HandleUserInterfaceMessage;
if (UserInterface != null)
{
UserInterface.OnReceiveMessage += HandleUserInterfaceMessage;
}
_inventoryComponent = Owner.GetComponent<InventoryComponent>();
_handsComponent = Owner.GetComponent<HandsComponent>();
Owner.EnsureComponent<InventoryComponent>();
Owner.EnsureComponent<HandsComponent>();
_inventoryComponent.OnItemChanged += UpdateSubscribed;
if (Owner.TryGetComponent(out InventoryComponent? inventory))
{
inventory.OnItemChanged += UpdateSubscribed;
}
// Initial update.
UpdateSubscribed();
@@ -53,10 +57,15 @@ namespace Content.Server.GameObjects.Components.GUI
private void UpdateSubscribed()
{
if (UserInterface == null)
{
return;
}
var inventory = GetInventorySlots();
var hands = GetHandSlots();
_userInterface.SetState(new StrippingBoundUserInterfaceState(inventory, hands));
UserInterface.SetState(new StrippingBoundUserInterfaceState(inventory, hands));
}
public bool CanDragDrop(DragDropEventArgs eventArgs)
@@ -67,7 +76,7 @@ namespace Content.Server.GameObjects.Components.GUI
public bool DragDrop(DragDropEventArgs eventArgs)
{
if (!eventArgs.User.TryGetComponent(out IActorComponent actor)) return false;
if (!eventArgs.User.TryGetComponent(out IActorComponent? actor)) return false;
OpenUserInterface(actor.playerSession);
return true;
@@ -77,9 +86,14 @@ namespace Content.Server.GameObjects.Components.GUI
{
var dictionary = new Dictionary<Slots, string>();
foreach (var slot in _inventoryComponent.Slots)
if (!Owner.TryGetComponent(out InventoryComponent? inventory))
{
dictionary[slot] = _inventoryComponent.GetSlotItem(slot)?.Owner.Name ?? "None";
return dictionary;
}
foreach (var slot in inventory.Slots)
{
dictionary[slot] = inventory.GetSlotItem(slot)?.Owner.Name ?? "None";
}
return dictionary;
@@ -89,9 +103,14 @@ namespace Content.Server.GameObjects.Components.GUI
{
var dictionary = new Dictionary<string, string>();
foreach (var hand in _handsComponent.Hands)
if (!Owner.TryGetComponent(out HandsComponent? hands))
{
dictionary[hand] = _handsComponent.GetItem(hand)?.Owner.Name ?? "None";
return dictionary;
}
foreach (var hand in hands.Hands)
{
dictionary[hand] = hands.GetItem(hand)?.Owner.Name ?? "None";
}
return dictionary;
@@ -99,7 +118,7 @@ namespace Content.Server.GameObjects.Components.GUI
private void OpenUserInterface(IPlayerSession session)
{
_userInterface.Open(session);
UserInterface?.Open(session);
}
/// <summary>
@@ -336,7 +355,7 @@ namespace Content.Server.GameObjects.Components.GUI
private void HandleUserInterfaceMessage(ServerBoundUserInterfaceMessage obj)
{
var user = obj.Session.AttachedEntity;
if (user == null || !(user.TryGetComponent(out HandsComponent userHands))) return;
if (user == null || !(user.TryGetComponent(out HandsComponent? userHands))) return;
var placingItem = userHands.GetActiveHand != null;