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:
@@ -1,4 +1,5 @@
|
||||
using System.Threading.Tasks;
|
||||
#nullable enable
|
||||
using System.Threading.Tasks;
|
||||
using Content.Server.GameObjects.Components.GUI;
|
||||
using Content.Server.GameObjects.Components.Items.Clothing;
|
||||
using Content.Server.GameObjects.Components.Items.Storage;
|
||||
@@ -29,25 +30,20 @@ namespace Content.Server.GameObjects.Components.Interactable
|
||||
[RegisterComponent]
|
||||
internal sealed class HandheldLightComponent : SharedHandheldLightComponent, IUse, IExamine, IInteractUsing, IMapInit
|
||||
{
|
||||
#pragma warning disable 649
|
||||
[Dependency] private readonly ISharedNotifyManager _notifyManager;
|
||||
[Dependency] private readonly ILocalizationManager _localizationManager;
|
||||
#pragma warning restore 649
|
||||
[Dependency] private readonly ISharedNotifyManager _notifyManager = default!;
|
||||
[Dependency] private readonly ILocalizationManager _localizationManager = default!;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)] public float Wattage { get; set; } = 10;
|
||||
[ViewVariables] private ContainerSlot _cellContainer;
|
||||
private PointLightComponent _pointLight;
|
||||
private SpriteComponent _spriteComponent;
|
||||
private ClothingComponent _clothingComponent;
|
||||
[ViewVariables] private ContainerSlot _cellContainer = default!;
|
||||
|
||||
[ViewVariables]
|
||||
private BatteryComponent Cell
|
||||
private BatteryComponent? Cell
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_cellContainer.ContainedEntity == null) return null;
|
||||
|
||||
_cellContainer.ContainedEntity.TryGetComponent(out BatteryComponent cell);
|
||||
_cellContainer.ContainedEntity.TryGetComponent(out BatteryComponent? cell);
|
||||
return cell;
|
||||
}
|
||||
}
|
||||
@@ -98,11 +94,10 @@ namespace Content.Server.GameObjects.Components.Interactable
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
_pointLight = Owner.GetComponent<PointLightComponent>();
|
||||
_spriteComponent = Owner.GetComponent<SpriteComponent>();
|
||||
Owner.TryGetComponent(out _clothingComponent);
|
||||
Owner.EnsureComponent<PointLightComponent>();
|
||||
_cellContainer =
|
||||
ContainerManagerComponent.Ensure<ContainerSlot>("flashlight_cell_container", Owner, out _);
|
||||
|
||||
Dirty();
|
||||
}
|
||||
|
||||
@@ -179,11 +174,19 @@ namespace Content.Server.GameObjects.Components.Interactable
|
||||
|
||||
private void SetState(bool on)
|
||||
{
|
||||
_spriteComponent.LayerSetVisible(1, on);
|
||||
_pointLight.Enabled = on;
|
||||
if (_clothingComponent != null)
|
||||
if (Owner.TryGetComponent(out SpriteComponent? sprite))
|
||||
{
|
||||
_clothingComponent.ClothingEquippedPrefix = on ? "On" : "Off";
|
||||
sprite.LayerSetVisible(1, on);
|
||||
}
|
||||
|
||||
if (Owner.TryGetComponent(out PointLightComponent? light))
|
||||
{
|
||||
light.Enabled = on;
|
||||
}
|
||||
|
||||
if (Owner.TryGetComponent(out ClothingComponent? clothing))
|
||||
{
|
||||
clothing.ClothingEquippedPrefix = on ? "On" : "Off";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -211,7 +214,7 @@ namespace Content.Server.GameObjects.Components.Interactable
|
||||
return;
|
||||
}
|
||||
|
||||
if (!user.TryGetComponent(out HandsComponent hands))
|
||||
if (!user.TryGetComponent(out HandsComponent? hands))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user