Enable nullability in Content.Server (#3685)

This commit is contained in:
DrSmugleaf
2021-03-16 15:50:20 +01:00
committed by GitHub
parent 90fec0ed24
commit a5ade526b7
306 changed files with 1616 additions and 1441 deletions

View File

@@ -1,9 +1,9 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Threading;
using Content.Server.GameObjects.Components.Chemistry;
using Content.Server.GameObjects.Components.Movement;
using Content.Shared.Chemistry;
using Content.Shared.GameObjects.Components.Movement;
using Content.Shared.GameObjects.EntitySystems;
@@ -18,8 +18,6 @@ using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.Shared.Random;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.Utility;
using Robust.Shared.ViewVariables;
@@ -48,7 +46,7 @@ namespace Content.Server.GameObjects.Components.Fluids
[Dependency] private readonly IRobustRandom _random = default!;
public override string Name => "Puddle";
private CancellationTokenSource _evaporationToken;
private CancellationTokenSource? _evaporationToken;
[DataField("evaporate_threshold")]
private ReagentUnit _evaporateThreshold = ReagentUnit.New(20); // How few <Solution Quantity> we can hold prior to self-destructing
public ReagentUnit EvaporateThreshold
@@ -77,8 +75,8 @@ namespace Content.Server.GameObjects.Components.Fluids
/// </summary>
private bool _overflown;
private SpriteComponent _spriteComponent;
private SnapGridComponent _snapGrid;
private SpriteComponent _spriteComponent = default!;
private SnapGridComponent _snapGrid = default!;
public ReagentUnit MaxVolume
{
@@ -97,7 +95,7 @@ namespace Content.Server.GameObjects.Components.Fluids
private ReagentUnit _overflowVolume = ReagentUnit.New(20);
private ReagentUnit OverflowLeft => CurrentVolume - OverflowVolume;
private SolutionContainerComponent _contents;
private SolutionContainerComponent _contents = default!;
public bool EmptyHolder => _contents.ReagentList.Count == 0;
[DataField("variants")]
private int _spriteVariants = 1;
@@ -105,21 +103,13 @@ namespace Content.Server.GameObjects.Components.Fluids
[DataField("recolor")]
private bool _recolor = default;
private bool Slippery => Owner.TryGetComponent(out SlipperyComponent slippery) && slippery.Slippery;
private bool Slippery => Owner.TryGetComponent(out SlipperyComponent? slippery) && slippery.Slippery;
public override void Initialize()
{
base.Initialize();
if (Owner.TryGetComponent(out SolutionContainerComponent solutionComponent))
{
_contents = solutionComponent;
}
else
{
_contents = Owner.AddComponent<SolutionContainerComponent>();
}
_contents = Owner.EnsureComponentWarn<SolutionContainerComponent>();
_snapGrid = Owner.EnsureComponent<SnapGridComponent>();
// Smaller than 1m^3 for now but realistically this shouldn't be hit
@@ -253,7 +243,7 @@ namespace Content.Server.GameObjects.Components.Fluids
private void UpdateSlip()
{
if ((_slipThreshold == ReagentUnit.New(-1) || CurrentVolume < _slipThreshold) &&
Owner.TryGetComponent(out SlipperyComponent oldSlippery))
Owner.TryGetComponent(out SlipperyComponent? oldSlippery))
{
oldSlippery.Slippery = false;
}
@@ -351,7 +341,7 @@ namespace Content.Server.GameObjects.Components.Fluids
/// <param name="puddle">The puddle that was found or is to be created, or null if there
/// is a wall in the way</param>
/// <returns>true if a puddle was found or created, false otherwise</returns>
private bool TryGetAdjacentOverflow(Direction direction, out Func<PuddleComponent> puddle)
private bool TryGetAdjacentOverflow(Direction direction, [NotNullWhen(true)] out Func<PuddleComponent>? puddle)
{
puddle = default;
@@ -370,14 +360,14 @@ namespace Content.Server.GameObjects.Components.Fluids
foreach (var entity in _snapGrid.GetInDir(direction))
{
if (entity.TryGetComponent(out IPhysBody physics) &&
if (entity.TryGetComponent(out IPhysBody? physics) &&
(physics.CollisionLayer & (int) CollisionGroup.Impassable) != 0)
{
puddle = default;
return false;
}
if (entity.TryGetComponent(out PuddleComponent existingPuddle))
if (entity.TryGetComponent(out PuddleComponent? existingPuddle))
{
if (existingPuddle._overflown)
{
@@ -391,7 +381,7 @@ namespace Content.Server.GameObjects.Components.Fluids
if (puddle == default)
{
var grid = _snapGrid.DirectionToGrid(direction);
puddle = () => Owner.EntityManager.SpawnEntity(Owner.Prototype.ID, grid).GetComponent<PuddleComponent>();
puddle = () => Owner.EntityManager.SpawnEntity(Owner.Prototype?.ID, grid).GetComponent<PuddleComponent>();
}
return true;