Nullable grid Uid (#8798)

This commit is contained in:
Leon Friedrich
2022-06-20 12:14:35 +12:00
committed by GitHub
parent ef41cd5aa8
commit fa4c6f63f8
82 changed files with 318 additions and 242 deletions

View File

@@ -18,7 +18,7 @@ namespace Content.Server.Atmos.Commands
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
var player = shell.Player as IPlayerSession;
EntityUid gridId;
EntityUid? gridId;
Gas? gas = null;
var entMan = IoCManager.Resolve<IEntityManager>();
@@ -39,9 +39,9 @@ namespace Content.Server.Atmos.Commands
return;
}
gridId = entMan.GetComponent<TransformComponent>(playerEntity).GridEntityId;
gridId = entMan.GetComponent<TransformComponent>(playerEntity).GridUid;
if (gridId == EntityUid.Invalid)
if (gridId == null)
{
shell.WriteLine("You aren't on a grid to delete gas from.");
return;
@@ -66,9 +66,9 @@ namespace Content.Server.Atmos.Commands
return;
}
gridId = entMan.GetComponent<TransformComponent>(playerEntity).GridEntityId;
gridId = entMan.GetComponent<TransformComponent>(playerEntity).GridUid;
if (gridId == EntityUid.Invalid)
if (gridId == null)
{
shell.WriteLine("You aren't on a grid to delete gas from.");
return;
@@ -98,7 +98,7 @@ namespace Content.Server.Atmos.Commands
gridId = first;
if (gridId == EntityUid.Invalid)
if (gridId.Value.IsValid())
{
shell.WriteLine($"{gridId} is not a valid grid id.");
return;
@@ -134,7 +134,7 @@ namespace Content.Server.Atmos.Commands
if (gas == null)
{
foreach (var tile in atmosphereSystem.GetAllTileMixtures(gridId, true))
foreach (var tile in atmosphereSystem.GetAllTileMixtures(gridId.Value, true))
{
if (tile.Immutable) continue;
@@ -146,7 +146,7 @@ namespace Content.Server.Atmos.Commands
}
else
{
foreach (var tile in atmosphereSystem.GetAllTileMixtures(gridId, true))
foreach (var tile in atmosphereSystem.GetAllTileMixtures(gridId.Value, true))
{
if (tile.Immutable) continue;

View File

@@ -44,7 +44,7 @@ namespace Content.Server.Atmos.EntitySystems
var xform = Transform(uid);
// If the grid is deleting no point updating atmos.
if (_mapManager.TryGetGrid(xform.GridEntityId, out var grid))
if (_mapManager.TryGetGrid(xform.GridUid, out var grid))
{
if (MetaData(grid.GridEntityId).EntityLifeStage > EntityLifeStage.MapInitialized) return;
}
@@ -56,15 +56,17 @@ namespace Content.Server.Atmos.EntitySystems
{
var xform = Transform(uid);
var gridId = xform.GridEntityId;
if (!TryComp(xform.GridUid, out IMapGridComponent? grid))
return;
var gridId = xform.GridUid;
var coords = xform.Coordinates;
var grid = _mapManager.GetGrid(gridId);
var tilePos = grid.TileIndicesFor(coords);
var tilePos = grid.Grid.TileIndicesFor(coords);
// Update and invalidate new position.
airtight.LastPosition = (gridId, tilePos);
InvalidatePosition(gridId, tilePos);
airtight.LastPosition = (gridId.Value, tilePos);
InvalidatePosition(gridId.Value, tilePos);
}
private void OnAirtightReAnchor(EntityUid uid, AirtightComponent airtight, ref ReAnchorEvent args)
@@ -100,11 +102,10 @@ namespace Content.Server.Atmos.EntitySystems
{
if (!Resolve(airtight.Owner, ref xform)) return;
if (!xform.Anchored || !xform.GridEntityId.IsValid())
if (!xform.Anchored || !_mapManager.TryGetGrid(xform.GridUid, out var grid))
return;
var grid = _mapManager.GetGrid(xform.GridEntityId);
airtight.LastPosition = (xform.GridEntityId, grid.TileIndicesFor(xform.Coordinates));
airtight.LastPosition = (xform.GridUid.Value, grid.TileIndicesFor(xform.Coordinates));
InvalidatePosition(airtight.LastPosition.Item1, airtight.LastPosition.Item2, airtight.FixVacuum && !airtight.AirBlocked);
}

View File

@@ -125,7 +125,7 @@ namespace Content.Server.Atmos.EntitySystems
/// </summary>
/// <param name="grid">Grid to be checked.</param>
/// <returns>Whether the grid has a simulated atmosphere.</returns>
public bool IsSimulatedGrid(EntityUid grid)
public bool IsSimulatedGrid(EntityUid? grid)
{
if (!_mapManager.TryGetGrid(grid, out var mapGrid))
return false;
@@ -1376,7 +1376,7 @@ namespace Content.Server.Atmos.EntitySystems
public bool AddAtmosDevice(AtmosDeviceComponent atmosDevice)
{
var grid = Comp<TransformComponent>(atmosDevice.Owner).GridEntityId;
var grid = Comp<TransformComponent>(atmosDevice.Owner).GridUid;
if (!_mapManager.TryGetGrid(grid, out var mapGrid))
return false;
@@ -1578,7 +1578,7 @@ namespace Content.Server.Atmos.EntitySystems
return false;
}
var gridId = coordinates.GetGridEntityId(EntityManager);
var gridId = coordinates.GetGridUid(EntityManager);
if (!_mapManager.TryGetGrid(gridId, out var grid))
{
@@ -1586,7 +1586,7 @@ namespace Content.Server.Atmos.EntitySystems
return false;
}
tuple = (gridId, grid.TileIndicesFor(coordinates));
tuple = (gridId.Value, grid.TileIndicesFor(coordinates));
return true;
}

View File

@@ -161,7 +161,6 @@ namespace Content.Server.Atmos.EntitySystems
xforms.GetComponent(entity),
body);
}
}
}

View File

@@ -29,7 +29,7 @@ public sealed class AtmosPipeAppearanceSystem : EntitySystem
if (!Resolve(uid, ref appearance, ref container, ref xform, false))
return;
if (!_mapManager.TryGetGrid(xform.GridEntityId, out var grid))
if (!_mapManager.TryGetGrid(xform.GridUid, out var grid))
return;
// get connected entities

View File

@@ -30,7 +30,7 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
return;
// If we can't find any ports, cancel the anchoring.
if(!FindGasPortIn(transform.GridEntityId, transform.Coordinates, out _))
if(!FindGasPortIn(transform.GridUid, transform.Coordinates, out _))
args.Cancel();
}
@@ -50,15 +50,13 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
}
}
private bool FindGasPortIn(EntityUid gridId, EntityCoordinates coordinates, [NotNullWhen(true)] out GasPortComponent? port)
private bool FindGasPortIn(EntityUid? gridId, EntityCoordinates coordinates, [NotNullWhen(true)] out GasPortComponent? port)
{
port = null;
if (!gridId.IsValid())
if (!_mapManager.TryGetGrid(gridId, out var grid))
return false;
var grid = _mapManager.GetGrid(gridId);
foreach (var entityUid in grid.GetLocal(coordinates))
{
if (EntityManager.TryGetComponent<GasPortComponent>(entityUid, out port))