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

@@ -1,4 +1,5 @@
using System.Linq;
#nullable enable
using System.Linq;
using Content.Server.GameObjects.Components.Power.ApcNetComponents;
using Robust.Server.GameObjects;
using Robust.Server.Interfaces.GameObjects;
@@ -19,18 +20,13 @@ namespace Content.Server.GameObjects.Components.BarSign
{
public override string Name => "BarSign";
#pragma warning disable 649
[Dependency] private readonly IPrototypeManager _prototypeManager;
[Dependency] private readonly IRobustRandom _robustRandom;
#pragma warning restore 649
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly IRobustRandom _robustRandom = default!;
private string _currentSign;
private PowerReceiverComponent _power;
private SpriteComponent _sprite;
private string? _currentSign;
[ViewVariables(VVAccess.ReadWrite)]
public string CurrentSign
public string? CurrentSign
{
get => _currentSign;
set
@@ -40,6 +36,8 @@ namespace Content.Server.GameObjects.Components.BarSign
}
}
private bool Powered => !Owner.TryGetComponent(out PowerReceiverComponent? receiver) || receiver.Powered;
private void UpdateSignInfo()
{
if (_currentSign == null)
@@ -53,15 +51,18 @@ namespace Content.Server.GameObjects.Components.BarSign
return;
}
if (!_power.Powered)
if (Owner.TryGetComponent(out SpriteComponent? sprite))
{
_sprite.LayerSetState(0, "empty");
_sprite.LayerSetShader(0, "shaded");
}
else
{
_sprite.LayerSetState(0, prototype.Icon);
_sprite.LayerSetShader(0, "unshaded");
if (!Powered)
{
sprite.LayerSetState(0, "empty");
sprite.LayerSetShader(0, "shaded");
}
else
{
sprite.LayerSetState(0, prototype.Icon);
sprite.LayerSetShader(0, "unshaded");
}
}
if (!string.IsNullOrEmpty(prototype.Name))
@@ -80,21 +81,25 @@ namespace Content.Server.GameObjects.Components.BarSign
{
base.Initialize();
_power = Owner.GetComponent<PowerReceiverComponent>();
_sprite = Owner.GetComponent<SpriteComponent>();
_power.OnPowerStateChanged += PowerOnOnPowerStateChanged;
if (Owner.TryGetComponent(out PowerReceiverComponent? receiver))
{
receiver.OnPowerStateChanged += PowerOnOnPowerStateChanged;
}
UpdateSignInfo();
}
public override void OnRemove()
{
_power.OnPowerStateChanged -= PowerOnOnPowerStateChanged;
if (Owner.TryGetComponent(out PowerReceiverComponent? receiver))
{
receiver.OnPowerStateChanged -= PowerOnOnPowerStateChanged;
}
base.OnRemove();
}
private void PowerOnOnPowerStateChanged(object sender, PowerStateEventArgs e)
private void PowerOnOnPowerStateChanged(object? sender, PowerStateEventArgs e)
{
UpdateSignInfo();
}