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;
#nullable enable
using System;
using System.Collections.Generic;
using Content.Shared.GameObjects.Components.Movement;
using Robust.Server.GameObjects;
@@ -18,9 +19,7 @@ namespace Content.Server.GameObjects.Components.Movement
[RegisterComponent]
public class ServerPortalComponent : SharedPortalComponent
{
#pragma warning disable 649
[Dependency] private readonly IServerEntityManager _serverEntityManager;
#pragma warning restore 649
[Dependency] private readonly IServerEntityManager _serverEntityManager = default!;
// Potential improvements: Different sounds,
// Add Gateways
@@ -28,15 +27,14 @@ namespace Content.Server.GameObjects.Components.Movement
// Put portal above most other things layer-wise
// Add telefragging (get entities on connecting portal and force brute damage)
private AppearanceComponent _appearanceComponent;
private IEntity _connectingTeleporter;
private IEntity? _connectingTeleporter;
private PortalState _state = PortalState.Pending;
[ViewVariables(VVAccess.ReadWrite)] private float _individualPortalCooldown;
[ViewVariables] private float _overallPortalCooldown;
[ViewVariables] private bool _onCooldown;
[ViewVariables] private string _departureSound;
[ViewVariables] private string _arrivalSound;
public List<IEntity> immuneEntities = new List<IEntity>(); // K
[ViewVariables] private string _departureSound = "";
[ViewVariables] private string _arrivalSound = "";
public readonly List<IEntity> ImmuneEntities = new List<IEntity>(); // K
[ViewVariables(VVAccess.ReadWrite)] private float _aliveTime;
public override void ExposeData(ObjectSerializer serializer)
@@ -52,12 +50,6 @@ namespace Content.Server.GameObjects.Components.Movement
serializer.DataField(ref _arrivalSound, "arrival_sound", "/Audio/Effects/teleport_arrival.ogg");
}
public override void Initialize()
{
base.Initialize();
_appearanceComponent = Owner.GetComponent<AppearanceComponent>();
}
public override void OnAdd()
{
// This will blow up an entity it's attached to
@@ -74,13 +66,6 @@ namespace Content.Server.GameObjects.Components.Movement
}
}
public override void OnRemove()
{
_appearanceComponent = null;
base.OnRemove();
}
public bool CanBeConnected()
{
if (_connectingTeleporter == null)
@@ -108,23 +93,24 @@ namespace Content.Server.GameObjects.Components.Movement
}
_state = targetState;
if (_appearanceComponent != null)
if (Owner.TryGetComponent(out AppearanceComponent? appearance))
{
_appearanceComponent.SetData(PortalVisuals.State, _state);
appearance.SetData(PortalVisuals.State, _state);
}
}
private void releaseCooldown(IEntity entity)
private void ReleaseCooldown(IEntity entity)
{
if (immuneEntities.Contains(entity))
if (ImmuneEntities.Contains(entity))
{
immuneEntities.Remove(entity);
ImmuneEntities.Remove(entity);
}
if (_connectingTeleporter != null &&
_connectingTeleporter.TryGetComponent<ServerPortalComponent>(out var otherPortal))
{
otherPortal.immuneEntities.Remove(entity);
otherPortal.ImmuneEntities.Remove(entity);
}
}
@@ -142,7 +128,7 @@ namespace Content.Server.GameObjects.Components.Movement
private bool IsEntityPortable(IEntity entity)
{
// TODO: Check if it's slotted etc. Otherwise the slot item itself gets ported.
if (!immuneEntities.Contains(entity) && entity.HasComponent<TeleportableComponent>())
if (!ImmuneEntities.Contains(entity) && entity.HasComponent<TeleportableComponent>())
{
return true;
}
@@ -192,7 +178,7 @@ namespace Content.Server.GameObjects.Components.Movement
public void TryPortalEntity(IEntity entity)
{
if (immuneEntities.Contains(entity) || _connectingTeleporter == null)
if (ImmuneEntities.Contains(entity) || _connectingTeleporter == null)
{
return;
}
@@ -208,9 +194,9 @@ namespace Content.Server.GameObjects.Components.Movement
soundPlayer.PlayAtCoords(_arrivalSound, entity.Transform.GridPosition);
TryChangeState(PortalState.RecentlyTeleported);
// To stop spam teleporting. Could potentially look at adding a timer to flush this from the portal
immuneEntities.Add(entity);
_connectingTeleporter.GetComponent<ServerPortalComponent>().immuneEntities.Add(entity);
Timer.Spawn(TimeSpan.FromSeconds(_individualPortalCooldown), () => releaseCooldown(entity));
ImmuneEntities.Add(entity);
_connectingTeleporter.GetComponent<ServerPortalComponent>().ImmuneEntities.Add(entity);
Timer.Spawn(TimeSpan.FromSeconds(_individualPortalCooldown), () => ReleaseCooldown(entity));
StartCooldown();
}
}