Replace MaybeNullWhen(false) with NotNullWhen(true)

This commit is contained in:
DrSmugleaf
2020-12-20 04:14:41 +01:00
parent f7edb9ce7e
commit 026d96fd2d
11 changed files with 41 additions and 48 deletions

View File

@@ -55,7 +55,7 @@ namespace Content.Client.GameObjects.Components.Items
return Hands.FirstOrDefault(hand => hand.Name == name); return Hands.FirstOrDefault(hand => hand.Name == name);
} }
private bool TryHand(string name, [MaybeNullWhen(false)] out Hand hand) private bool TryHand(string name, [NotNullWhen(true)] out Hand? hand)
{ {
return (hand = GetHand(name)) != null; return (hand = GetHand(name)) != null;
} }

View File

@@ -13,7 +13,7 @@ namespace Content.Server.Atmos
{ {
public static class AtmosHelpers public static class AtmosHelpers
{ {
public static TileAtmosphere GetTileAtmosphere(this EntityCoordinates coordinates, IEntityManager? entityManager = null) public static TileAtmosphere? GetTileAtmosphere(this EntityCoordinates coordinates, IEntityManager? entityManager = null)
{ {
entityManager ??= IoCManager.Resolve<IEntityManager>(); entityManager ??= IoCManager.Resolve<IEntityManager>();
@@ -24,19 +24,19 @@ namespace Content.Server.Atmos
public static GasMixture? GetTileAir(this EntityCoordinates coordinates, IEntityManager? entityManager = null) public static GasMixture? GetTileAir(this EntityCoordinates coordinates, IEntityManager? entityManager = null)
{ {
return coordinates.GetTileAtmosphere(entityManager).Air; return coordinates.GetTileAtmosphere(entityManager)?.Air;
} }
public static bool TryGetTileAtmosphere(this EntityCoordinates coordinates, [MaybeNullWhen(false)] out TileAtmosphere atmosphere) public static bool TryGetTileAtmosphere(this EntityCoordinates coordinates, [NotNullWhen(true)] out TileAtmosphere? atmosphere)
{ {
// ReSharper disable once ConditionIsAlwaysTrueOrFalse // ReSharper disable once ConditionIsAlwaysTrueOrFalse
return !Equals(atmosphere = coordinates.GetTileAtmosphere()!, default); return !Equals(atmosphere = coordinates.GetTileAtmosphere(), default);
} }
public static bool TryGetTileAir(this EntityCoordinates coordinates, [MaybeNullWhen(false)] out GasMixture air, IEntityManager? entityManager = null) public static bool TryGetTileAir(this EntityCoordinates coordinates, [NotNullWhen(true)] out GasMixture? air, IEntityManager? entityManager = null)
{ {
// ReSharper disable once ConditionIsAlwaysTrueOrFalse // ReSharper disable once ConditionIsAlwaysTrueOrFalse
return !Equals(air = coordinates.GetTileAir(entityManager)!, default); return !Equals(air = coordinates.GetTileAir(entityManager), default);
} }
public static bool IsTileAirProbablySafe(this EntityCoordinates coordinates) public static bool IsTileAirProbablySafe(this EntityCoordinates coordinates)
@@ -56,7 +56,7 @@ namespace Content.Server.Atmos
return true; return true;
} }
public static TileAtmosphere GetTileAtmosphere(this Vector2i indices, GridId gridId) public static TileAtmosphere? GetTileAtmosphere(this Vector2i indices, GridId gridId)
{ {
var gridAtmos = EntitySystem.Get<AtmosphereSystem>().GetGridAtmosphere(gridId); var gridAtmos = EntitySystem.Get<AtmosphereSystem>().GetGridAtmosphere(gridId);
@@ -69,28 +69,25 @@ namespace Content.Server.Atmos
} }
public static bool TryGetTileAtmosphere(this Vector2i indices, GridId gridId, public static bool TryGetTileAtmosphere(this Vector2i indices, GridId gridId,
[MaybeNullWhen(false)] out TileAtmosphere atmosphere) [NotNullWhen(true)] out TileAtmosphere? atmosphere)
{ {
// ReSharper disable once ConditionIsAlwaysTrueOrFalse // ReSharper disable once ConditionIsAlwaysTrueOrFalse
return !Equals(atmosphere = indices.GetTileAtmosphere(gridId)!, default); return !Equals(atmosphere = indices.GetTileAtmosphere(gridId), default);
} }
public static bool TryGetTileAir(this Vector2i indices, GridId gridId, [MaybeNullWhen(false)] out GasMixture air) public static bool TryGetTileAir(this Vector2i indices, GridId gridId, [NotNullWhen(true)] out GasMixture? air)
{ {
// ReSharper disable once ConditionIsAlwaysTrueOrFalse // ReSharper disable once ConditionIsAlwaysTrueOrFalse
return !Equals(air = indices.GetTileAir(gridId)!, default); return !Equals(air = indices.GetTileAir(gridId), default);
} }
public static bool InvalidateTileAir(this ITransformComponent transform, AtmosphereSystem? atmosSystem = null) public static bool InvalidateTileAir(this ITransformComponent transform, AtmosphereSystem? atmosSystem = null)
{ {
return InvalidateTileAir(transform.Coordinates, atmosSystem); return InvalidateTileAir(transform.Coordinates);
} }
public static bool InvalidateTileAir(this EntityCoordinates coordinates, AtmosphereSystem? atmosSystem = null, IEntityManager? entityManager = null) public static bool InvalidateTileAir(this EntityCoordinates coordinates)
{ {
atmosSystem ??= EntitySystem.Get<AtmosphereSystem>();
entityManager ??= IoCManager.Resolve<IEntityManager>();
if (!coordinates.TryGetTileAtmosphere(out var tileAtmos)) if (!coordinates.TryGetTileAtmosphere(out var tileAtmos))
{ {
return false; return false;

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic; #nullable enable
using System.Collections.Generic;
using Content.Server.GameObjects.Components.Atmos; using Content.Server.GameObjects.Components.Atmos;
using Content.Server.GameObjects.Components.Atmos.Piping; using Content.Server.GameObjects.Components.Atmos.Piping;
using Content.Server.GameObjects.Components.NodeContainer.NodeGroups; using Content.Server.GameObjects.Components.NodeContainer.NodeGroups;
@@ -120,7 +121,7 @@ namespace Content.Server.Atmos
/// <param name="indices"></param> /// <param name="indices"></param>
/// <param name="createSpace"></param> /// <param name="createSpace"></param>
/// <returns></returns> /// <returns></returns>
TileAtmosphere GetTile(Vector2i indices, bool createSpace = true); TileAtmosphere? GetTile(Vector2i indices, bool createSpace = true);
/// <summary> /// <summary>
/// Returns a tile. /// Returns a tile.
@@ -128,7 +129,7 @@ namespace Content.Server.Atmos
/// <param name="coordinates"></param> /// <param name="coordinates"></param>
/// <param name="createSpace"></param> /// <param name="createSpace"></param>
/// <returns></returns> /// <returns></returns>
TileAtmosphere GetTile(EntityCoordinates coordinates, bool createSpace = true); TileAtmosphere? GetTile(EntityCoordinates coordinates, bool createSpace = true);
/// <summary> /// <summary>
/// Returns if the tile in question is air-blocked. /// Returns if the tile in question is air-blocked.

View File

@@ -42,7 +42,7 @@ namespace Content.Server.GameObjects.Components
/// <param name="utilizing">The tool being used, can be null if forcing it</param> /// <param name="utilizing">The tool being used, can be null if forcing it</param>
/// <param name="force">Whether or not to check if the tool is valid</param> /// <param name="force">Whether or not to check if the tool is valid</param>
/// <returns>true if it is valid, false otherwise</returns> /// <returns>true if it is valid, false otherwise</returns>
private async Task<bool> Valid(IEntity user, IEntity? utilizing, [MaybeNullWhen(false)] bool force = false) private async Task<bool> Valid(IEntity user, IEntity? utilizing, [NotNullWhen(true)] bool force = false)
{ {
if (!Owner.HasComponent<IPhysicsComponent>()) if (!Owner.HasComponent<IPhysicsComponent>())
{ {

View File

@@ -130,7 +130,7 @@ namespace Content.Server.GameObjects.Components.Atmos
// Already get the pressure before Dirty(), because we can't get the EntitySystem in that thread or smth // Already get the pressure before Dirty(), because we can't get the EntitySystem in that thread or smth
var pressure = 0f; var pressure = 0f;
var gam = EntitySystem.Get<AtmosphereSystem>().GetGridAtmosphere(Owner.Transform.GridID); var gam = EntitySystem.Get<AtmosphereSystem>().GetGridAtmosphere(Owner.Transform.GridID);
var tile = gam?.GetTile(Owner.Transform.Coordinates).Air; var tile = gam?.GetTile(Owner.Transform.Coordinates)?.Air;
if (tile != null) if (tile != null)
{ {
pressure = tile.Pressure; pressure = tile.Pressure;
@@ -190,7 +190,7 @@ namespace Content.Server.GameObjects.Components.Atmos
var atmosSystem = EntitySystem.Get<AtmosphereSystem>(); var atmosSystem = EntitySystem.Get<AtmosphereSystem>();
var gam = atmosSystem.GetGridAtmosphere(pos.GetGridId(Owner.EntityManager)); var gam = atmosSystem.GetGridAtmosphere(pos.GetGridId(Owner.EntityManager));
var tile = gam?.GetTile(pos).Air; var tile = gam.GetTile(pos)?.Air;
if (tile == null) if (tile == null)
{ {
error = "No Atmosphere!"; error = "No Atmosphere!";

View File

@@ -2,7 +2,6 @@
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq; using System.Linq;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using Content.Server.Atmos; using Content.Server.Atmos;
@@ -10,7 +9,6 @@ using Content.Server.GameObjects.Components.Atmos.Piping;
using Content.Server.GameObjects.Components.NodeContainer.NodeGroups; using Content.Server.GameObjects.Components.NodeContainer.NodeGroups;
using Content.Server.GameObjects.EntitySystems; using Content.Server.GameObjects.EntitySystems;
using Content.Server.GameObjects.EntitySystems.Atmos; using Content.Server.GameObjects.EntitySystems.Atmos;
using Content.Shared;
using Content.Shared.Atmos; using Content.Shared.Atmos;
using Content.Shared.Maps; using Content.Shared.Maps;
using Robust.Server.GameObjects.EntitySystems.TileLookup; using Robust.Server.GameObjects.EntitySystems.TileLookup;
@@ -19,7 +17,6 @@ using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.ComponentDependencies; using Robust.Shared.GameObjects.ComponentDependencies;
using Robust.Shared.GameObjects.Components.Map; using Robust.Shared.GameObjects.Components.Map;
using Robust.Shared.GameObjects.Systems; using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.Configuration;
using Robust.Shared.Interfaces.Map; using Robust.Shared.Interfaces.Map;
using Robust.Shared.Log; using Robust.Shared.Log;
using Robust.Shared.Map; using Robust.Shared.Map;

View File

@@ -9,7 +9,6 @@ using Content.Server.GameObjects.Components.Strap;
using Content.Server.GameObjects.EntitySystems; using Content.Server.GameObjects.EntitySystems;
using Content.Shared.Alert; using Content.Shared.Alert;
using Content.Shared.GameObjects.Components.Buckle; using Content.Shared.GameObjects.Components.Buckle;
using Content.Shared.GameObjects.Components.Mobs;
using Content.Shared.GameObjects.Components.Strap; using Content.Shared.GameObjects.Components.Strap;
using Content.Shared.GameObjects.EntitySystems; using Content.Shared.GameObjects.EntitySystems;
using Content.Shared.GameObjects.Verbs; using Content.Shared.GameObjects.Verbs;
@@ -27,7 +26,6 @@ using Robust.Shared.Interfaces.Timing;
using Robust.Shared.IoC; using Robust.Shared.IoC;
using Robust.Shared.Localization; using Robust.Shared.Localization;
using Robust.Shared.Maths; using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.Shared.Serialization; using Robust.Shared.Serialization;
using Robust.Shared.ViewVariables; using Robust.Shared.ViewVariables;
@@ -69,7 +67,7 @@ namespace Content.Server.GameObjects.Components.Buckle
public Vector2 BuckleOffset { get; private set; } public Vector2 BuckleOffset { get; private set; }
private StrapComponent? _buckledTo; private StrapComponent? _buckledTo;
/// <summary> /// <summary>
/// The strap that this component is buckled to. /// The strap that this component is buckled to.
@@ -157,7 +155,7 @@ namespace Content.Server.GameObjects.Components.Buckle
} }
} }
private bool CanBuckle(IEntity? user, IEntity to, [MaybeNullWhen(false)] out StrapComponent strap) private bool CanBuckle(IEntity? user, IEntity to, [NotNullWhen(true)] out StrapComponent? strap)
{ {
strap = null; strap = null;
@@ -421,7 +419,7 @@ namespace Content.Server.GameObjects.Components.Buckle
{ {
drawDepth = BuckledTo.SpriteComponent.DrawDepth - 1; drawDepth = BuckledTo.SpriteComponent.DrawDepth - 1;
} }
return new BuckleComponentState(Buckled, drawDepth, LastEntityBuckledTo, DontCollide); return new BuckleComponentState(Buckled, drawDepth, LastEntityBuckledTo, DontCollide);
} }

View File

@@ -105,10 +105,9 @@ namespace Content.Server.GameObjects.Components.GUI
return GetHand(handName)?.Entity?.GetComponent<ItemComponent>(); return GetHand(handName)?.Entity?.GetComponent<ItemComponent>();
} }
public bool TryGetItem(string handName, [MaybeNullWhen(false)] out ItemComponent item) public bool TryGetItem(string handName, [NotNullWhen(true)] out ItemComponent? item)
{ {
item = GetItem(handName); return (item = GetItem(handName)) != null;
return item != null;
} }
public ItemComponent? GetActiveHand => ActiveHand == null public ItemComponent? GetActiveHand => ActiveHand == null
@@ -240,7 +239,7 @@ namespace Content.Server.GameObjects.Components.GUI
return true; return true;
} }
public bool TryHand(IEntity entity, [MaybeNullWhen(false)] out string handName) public bool TryHand(IEntity entity, [NotNullWhen(true)] out string? handName)
{ {
handName = null; handName = null;

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic; #nullable enable
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using Content.Server.GameObjects.Components.Conveyor; using Content.Server.GameObjects.Components.Conveyor;
using Content.Server.GameObjects.Components.Items.Storage; using Content.Server.GameObjects.Components.Items.Storage;
@@ -40,12 +41,12 @@ namespace Content.Server.GameObjects.Components.Recycling
private int _efficiency; // TODO private int _efficiency; // TODO
private bool Powered => private bool Powered =>
!Owner.TryGetComponent(out PowerReceiverComponent receiver) || !Owner.TryGetComponent(out PowerReceiverComponent? receiver) ||
receiver.Powered; receiver.Powered;
private void Bloodstain() private void Bloodstain()
{ {
if (Owner.TryGetComponent(out AppearanceComponent appearance)) if (Owner.TryGetComponent(out AppearanceComponent? appearance))
{ {
appearance.SetData(RecyclerVisuals.Bloody, true); appearance.SetData(RecyclerVisuals.Bloody, true);
} }
@@ -53,7 +54,7 @@ namespace Content.Server.GameObjects.Components.Recycling
private void Clean() private void Clean()
{ {
if (Owner.TryGetComponent(out AppearanceComponent appearance)) if (Owner.TryGetComponent(out AppearanceComponent? appearance))
{ {
appearance.SetData(RecyclerVisuals.Bloody, false); appearance.SetData(RecyclerVisuals.Bloody, false);
} }
@@ -64,7 +65,7 @@ namespace Content.Server.GameObjects.Components.Recycling
return entity.HasComponent<IBody>() && !_safe && Powered; return entity.HasComponent<IBody>() && !_safe && Powered;
} }
private bool CanRecycle(IEntity entity, [MaybeNullWhen(false)] out ConstructionPrototype prototype) private bool CanRecycle(IEntity entity, [NotNullWhen(true)] out ConstructionPrototype? prototype)
{ {
prototype = null; prototype = null;
@@ -100,7 +101,7 @@ namespace Content.Server.GameObjects.Components.Recycling
private bool CanRun() private bool CanRun()
{ {
if (Owner.TryGetComponent(out PowerReceiverComponent receiver) && if (Owner.TryGetComponent(out PowerReceiverComponent? receiver) &&
!receiver.Powered) !receiver.Powered)
{ {
return false; return false;
@@ -121,7 +122,7 @@ namespace Content.Server.GameObjects.Components.Recycling
return false; return false;
} }
if (!entity.TryGetComponent(out IPhysicsComponent physics) || if (!entity.TryGetComponent(out IPhysicsComponent? physics) ||
physics.Anchored) physics.Anchored)
{ {
return false; return false;
@@ -165,7 +166,7 @@ namespace Content.Server.GameObjects.Components.Recycling
continue; continue;
} }
if (entity.TryGetComponent(out IPhysicsComponent physics)) if (entity.TryGetComponent(out IPhysicsComponent? physics))
{ {
var controller = physics.EnsureController<ConveyedController>(); var controller = physics.EnsureController<ConveyedController>();
controller.Move(direction, frameTime, entity.Transform.WorldPosition - Owner.Transform.WorldPosition); controller.Move(direction, frameTime, entity.Transform.WorldPosition - Owner.Transform.WorldPosition);

View File

@@ -47,7 +47,7 @@ namespace Content.Server.Interfaces.GameObjects.Components.Items
/// <param name="handName">The name of the hand to get.</param> /// <param name="handName">The name of the hand to get.</param>
/// <param name="item">The item in the held, null if no item is held</param> /// <param name="item">The item in the held, null if no item is held</param>
/// <returns>Whether it was holding an item</returns> /// <returns>Whether it was holding an item</returns>
bool TryGetItem(string handName, [MaybeNullWhen(false)] out ItemComponent item); bool TryGetItem(string handName, [NotNullWhen(true)] out ItemComponent? item);
/// <summary> /// <summary>
/// Gets item held by the current active hand /// Gets item held by the current active hand
@@ -102,7 +102,7 @@ namespace Content.Server.Interfaces.GameObjects.Components.Items
/// <returns> /// <returns>
/// true if the entity is held, false otherwise /// true if the entity is held, false otherwise
/// </returns> /// </returns>
bool TryHand(IEntity entity, [MaybeNullWhen(false)] out string handName); bool TryHand(IEntity entity, [NotNullWhen(true)] out string? handName);
/// <summary> /// <summary>
/// Drops the item contained in the slot to the same position as our entity. /// Drops the item contained in the slot to the same position as our entity.

View File

@@ -50,7 +50,7 @@ namespace Content.Shared.GameObjects.EntitySystems
} }
//TODO: reorganize this to make more logical sense //TODO: reorganize this to make more logical sense
protected void UpdateKinematics(ITransformComponent transform, IMoverComponent mover, IPhysicsComponent physics) protected void UpdateKinematics(ITransformComponent transform, IMoverComponent mover, IPhysicsComponent physics)
{ {
physics.EnsureController<MoverController>(); physics.EnsureController<MoverController>();
@@ -71,7 +71,7 @@ namespace Content.Shared.GameObjects.EntitySystems
// TODO: movement check. // TODO: movement check.
var (walkDir, sprintDir) = mover.VelocityDir; var (walkDir, sprintDir) = mover.VelocityDir;
var combined = walkDir + sprintDir; var combined = walkDir + sprintDir;
if (combined.LengthSquared < 0.001 || !ActionBlockerSystem.CanMove(mover.Owner) && !weightless) if (combined.LengthSquared < 0.001 || !ActionBlockerSystem.CanMove(mover.Owner) && !weightless)
{ {
if (physics.TryGetController(out MoverController controller)) if (physics.TryGetController(out MoverController controller))
{ {
@@ -177,7 +177,7 @@ namespace Content.Shared.GameObjects.EntitySystems
moverComp.SetSprinting(subTick, walking); moverComp.SetSprinting(subTick, walking);
} }
private static bool TryGetAttachedComponent<T>(ICommonSession? session, [MaybeNullWhen(false)] out T component) private static bool TryGetAttachedComponent<T>(ICommonSession? session, [NotNullWhen(true)] out T? component)
where T : class, IComponent where T : class, IComponent
{ {
component = default; component = default;