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;
|
||||
#nullable enable
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Content.Shared.GameObjects.Components.Movement;
|
||||
using Content.Shared.Interfaces.GameObjects.Components;
|
||||
@@ -24,11 +25,10 @@ namespace Content.Server.GameObjects.Components.Movement
|
||||
[RegisterComponent]
|
||||
public class ServerTeleporterComponent : Component, IAfterInteract
|
||||
{
|
||||
#pragma warning disable 649
|
||||
[Dependency] private readonly IMapManager _mapManager;
|
||||
[Dependency] private readonly IServerEntityManager _serverEntityManager;
|
||||
[Dependency] private readonly IRobustRandom _spreadRandom;
|
||||
#pragma warning restore 649
|
||||
[Dependency] private readonly IMapManager _mapManager = default!;
|
||||
[Dependency] private readonly IServerEntityManager _serverEntityManager = default!;
|
||||
[Dependency] private readonly IRobustRandom _spreadRandom = default!;
|
||||
|
||||
// TODO: Look at MapManager.Map for Beacons to get all entities on grid
|
||||
public ItemTeleporterState State => _state;
|
||||
|
||||
@@ -39,15 +39,13 @@ namespace Content.Server.GameObjects.Components.Movement
|
||||
[ViewVariables] private int _range;
|
||||
[ViewVariables] private ItemTeleporterState _state;
|
||||
[ViewVariables] private TeleporterType _teleporterType;
|
||||
[ViewVariables] private string _departureSound;
|
||||
[ViewVariables] private string _arrivalSound;
|
||||
[ViewVariables] private string _cooldownSound;
|
||||
[ViewVariables] private string _departureSound = "";
|
||||
[ViewVariables] private string _arrivalSound = "";
|
||||
[ViewVariables] private string? _cooldownSound;
|
||||
// If the direct OR random teleport will try to avoid hitting collidables
|
||||
[ViewVariables] private bool _avoidCollidable;
|
||||
[ViewVariables] private float _portalAliveTime;
|
||||
|
||||
private AppearanceComponent _appearanceComponent;
|
||||
|
||||
public override void ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
base.ExposeData(serializer);
|
||||
@@ -63,22 +61,20 @@ namespace Content.Server.GameObjects.Components.Movement
|
||||
serializer.DataField(ref _portalAliveTime, "portal_alive_time", 5.0f); // TODO: Change this to 0 before PR?
|
||||
}
|
||||
|
||||
public override void OnRemove()
|
||||
{
|
||||
_appearanceComponent = null;
|
||||
|
||||
base.OnRemove();
|
||||
}
|
||||
|
||||
private void SetState(ItemTeleporterState newState)
|
||||
{
|
||||
if (!Owner.TryGetComponent(out AppearanceComponent? appearance))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (newState == ItemTeleporterState.Cooldown)
|
||||
{
|
||||
_appearanceComponent.SetData(TeleporterVisuals.VisualState, TeleporterVisualState.Charging);
|
||||
appearance.SetData(TeleporterVisuals.VisualState, TeleporterVisualState.Charging);
|
||||
}
|
||||
else
|
||||
{
|
||||
_appearanceComponent.SetData(TeleporterVisuals.VisualState, TeleporterVisualState.Ready);
|
||||
appearance.SetData(TeleporterVisuals.VisualState, TeleporterVisualState.Ready);
|
||||
}
|
||||
_state = newState;
|
||||
}
|
||||
@@ -149,12 +145,11 @@ namespace Content.Server.GameObjects.Components.Movement
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
_appearanceComponent = Owner.GetComponent<AppearanceComponent>();
|
||||
_state = ItemTeleporterState.Off;
|
||||
base.Initialize();
|
||||
_state = ItemTeleporterState.Off;
|
||||
}
|
||||
|
||||
private bool emptySpace(IEntity user, Vector2 target)
|
||||
private bool EmptySpace(IEntity user, Vector2 target)
|
||||
{
|
||||
// TODO: Check the user's spot? Upside is no stacking TPs but downside is they can't unstuck themselves from walls.
|
||||
foreach (var entity in _serverEntityManager.GetEntitiesIntersecting(user.Transform.MapID, target))
|
||||
@@ -167,7 +162,7 @@ namespace Content.Server.GameObjects.Components.Movement
|
||||
return true;
|
||||
}
|
||||
|
||||
private Vector2 randomEmptySpot(IEntity user, int range)
|
||||
private Vector2 RandomEmptySpot(IEntity user, int range)
|
||||
{
|
||||
Vector2 targetVector = user.Transform.GridPosition.Position;
|
||||
// Definitely a better way to do this
|
||||
@@ -176,7 +171,7 @@ namespace Content.Server.GameObjects.Components.Movement
|
||||
var randomRange = _spreadRandom.Next(0, range);
|
||||
var angle = Angle.FromDegrees(_spreadRandom.Next(0, 359));
|
||||
targetVector = user.Transform.GridPosition.Position + angle.ToVec() * randomRange;
|
||||
if (emptySpace(user, targetVector))
|
||||
if (EmptySpace(user, targetVector))
|
||||
{
|
||||
return targetVector;
|
||||
}
|
||||
@@ -200,7 +195,7 @@ namespace Content.Server.GameObjects.Components.Movement
|
||||
Vector2 targetVector;
|
||||
if (_avoidCollidable)
|
||||
{
|
||||
targetVector = randomEmptySpot(user, _range);
|
||||
targetVector = RandomEmptySpot(user, _range);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -227,7 +222,7 @@ namespace Content.Server.GameObjects.Components.Movement
|
||||
public void Teleport(IEntity user, Vector2 vector)
|
||||
{
|
||||
// Messy maybe?
|
||||
GridCoordinates targetGrid = new GridCoordinates(vector, user.Transform.GridID);
|
||||
var targetGrid = new GridCoordinates(vector, user.Transform.GridID);
|
||||
var soundPlayer = EntitySystem.Get<AudioSystem>();
|
||||
|
||||
// If portals use those, otherwise just move em over
|
||||
@@ -240,10 +235,11 @@ namespace Content.Server.GameObjects.Components.Movement
|
||||
|
||||
// Arrival portal
|
||||
var arrivalPortal = _serverEntityManager.SpawnEntity("Portal", targetGrid);
|
||||
arrivalPortal.TryGetComponent<ServerPortalComponent>(out var arrivalComponent);
|
||||
|
||||
// Connect. TODO: If the OnUpdate in ServerPortalComponent is changed this may need to change as well.
|
||||
arrivalComponent.TryConnectPortal(departurePortal);
|
||||
if (arrivalPortal.TryGetComponent<ServerPortalComponent>(out var arrivalComponent))
|
||||
{
|
||||
// Connect. TODO: If the OnUpdate in ServerPortalComponent is changed this may need to change as well.
|
||||
arrivalComponent.TryConnectPortal(departurePortal);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user