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,21 +37,24 @@ namespace Content.Server.GameObjects.Components.PDA
[Dependency] private readonly IEntityManager _entityManager = default!;
[ViewVariables] private Container _idSlot = default!;
[ViewVariables] private PointLightComponent _pdaLight = default!;
[ViewVariables] private bool _lightOn;
[ViewVariables] private BoundUserInterface _interface = default!;
[ViewVariables] private string _startingIdCard = default!;
[ViewVariables] public bool IdSlotEmpty => _idSlot.ContainedEntities.Count < 1;
[ViewVariables] public string? OwnerName { get; private set; }
[ViewVariables] public IdCardComponent? ContainedID { get; private set; }
[ViewVariables] private AppearanceComponent _appearance = default!;
[ViewVariables] private UplinkAccount? _syndicateUplinkAccount;
[ViewVariables] private readonly PdaAccessSet _accessSet;
[ViewVariables]
private BoundUserInterface? UserInterface =>
Owner.TryGetComponent(out ServerUserInterfaceComponent? ui) &&
ui.TryGetBoundUserInterface(PDAUiKey.Key, out var boundUi)
? boundUi
: null;
public PDAComponent()
{
_accessSet = new PdaAccessSet(this);
@@ -67,11 +70,12 @@ namespace Content.Server.GameObjects.Components.PDA
{
base.Initialize();
_idSlot = ContainerManagerComponent.Ensure<Container>("pda_entity_container", Owner, out var existed);
_pdaLight = Owner.GetComponent<PointLightComponent>();
_appearance = Owner.GetComponent<AppearanceComponent>();
_interface = Owner.GetComponent<ServerUserInterfaceComponent>()
.GetBoundUserInterface(PDAUiKey.Key);
_interface.OnReceiveMessage += UserInterfaceOnReceiveMessage;
if (UserInterface != null)
{
UserInterface.OnReceiveMessage += UserInterfaceOnReceiveMessage;
}
var idCard = _entityManager.SpawnEntity(_startingIdCard, Owner.Transform.GridPosition);
var idCardComponent = idCard.GetComponent<IdCardComponent>();
_idSlot.Insert(idCardComponent.Owner);
@@ -129,11 +133,11 @@ namespace Content.Server.GameObjects.Components.PDA
var accData = new UplinkAccountData(_syndicateUplinkAccount.AccountHolder,
_syndicateUplinkAccount.Balance);
var listings = _uplinkManager.FetchListings.ToArray();
_interface.SetState(new PDAUpdateState(_lightOn, ownerInfo, accData, listings));
UserInterface?.SetState(new PDAUpdateState(_lightOn, ownerInfo, accData, listings));
}
else
{
_interface.SetState(new PDAUpdateState(_lightOn, ownerInfo));
UserInterface?.SetState(new PDAUpdateState(_lightOn, ownerInfo));
}
UpdatePDAAppearance();
@@ -141,7 +145,10 @@ namespace Content.Server.GameObjects.Components.PDA
private void UpdatePDAAppearance()
{
_appearance?.SetData(PDAVisuals.FlashlightLit, _lightOn);
if (Owner.TryGetComponent(out AppearanceComponent? appearance))
{
appearance.SetData(PDAVisuals.FlashlightLit, _lightOn);
}
}
public async Task<bool> InteractUsing(InteractUsingEventArgs eventArgs)
@@ -169,7 +176,7 @@ namespace Content.Server.GameObjects.Components.PDA
return;
}
_interface.Open(actor.playerSession);
UserInterface?.Open(actor.playerSession);
UpdatePDAAppearance();
}
@@ -180,7 +187,7 @@ namespace Content.Server.GameObjects.Components.PDA
return false;
}
_interface.Open(actor.playerSession);
UserInterface?.Open(actor.playerSession);
UpdatePDAAppearance();
return true;
}
@@ -217,8 +224,13 @@ namespace Content.Server.GameObjects.Components.PDA
private void ToggleLight()
{
if (!Owner.TryGetComponent(out PointLightComponent? light))
{
return;
}
_lightOn = !_lightOn;
_pdaLight.Enabled = _lightOn;
light.Enabled = _lightOn;
EntitySystem.Get<AudioSystem>().PlayFromEntity("/Audio/Items/flashlight_toggle.ogg", Owner);
UpdatePDAUserInterface();
}