Unrevert "Remove references to obsolete GridId" (#11531) (#11801)

This commit is contained in:
Leon Friedrich
2022-10-10 10:41:32 +13:00
committed by GitHub
parent e17e08f344
commit 41b1044ddb
7 changed files with 30 additions and 32 deletions

View File

@@ -45,17 +45,15 @@ public sealed class PricingSystem : EntitySystem
foreach (var gid in args)
{
if (!int.TryParse(gid, out var i) || i <= 0)
if (!EntityUid.TryParse(gid, out var gridId) || !gridId.IsValid())
{
shell.WriteError($"Invalid grid ID \"{gid}\".");
continue;
}
var gridId = new GridId(i);
if (!_mapManager.TryGetGrid(gridId, out var mapGrid))
{
shell.WriteError($"Grid \"{i}\" doesn't exist.");
shell.WriteError($"Grid \"{gridId}\" doesn't exist.");
continue;
}

View File

@@ -15,11 +15,11 @@ namespace Content.Server.Coordinates.Helpers
{
IoCManager.Resolve(ref entMan, ref mapManager);
var gridId = coordinates.GetGridId(entMan);
var gridIdOpt = coordinates.GetGridUid(entMan);
var tileSize = 1f;
if (gridId.IsValid())
if (gridIdOpt is EntityUid gridId && gridId.IsValid())
{
var grid = mapManager.GetGrid(gridId);
tileSize = grid.TileSize;

View File

@@ -18,7 +18,7 @@ public sealed partial class ExplosionSystem : EntitySystem
/// </summary>
private void OnGridStartup(GridStartupEvent ev)
{
var grid = _mapManager.GetGrid(ev.GridId);
var grid = _mapManager.GetGrid(ev.EntityUid);
Dictionary<Vector2i, NeighborFlag> edges = new();
_gridEdges[ev.EntityUid] = edges;

View File

@@ -27,7 +27,7 @@ public sealed class ImmovableRodSystem : EntitySystem
{
if (!rod.DestroyTiles)
continue;
if (!_map.TryGetGrid(trans.GridID, out var grid))
if (!_map.TryGetGrid(trans.GridUid, out var grid))
continue;
grid.SetTile(trans.Coordinates, Tile.Empty);

View File

@@ -73,17 +73,18 @@ namespace Content.Server.RCD.Systems
return;
// Try to fix it (i.e. if clicking on space)
// Note: Ideally there'd be a better way, but there isn't right now.
var gridID = clickLocationMod.GetGridId(EntityManager);
if (!gridID.IsValid())
var gridIdOpt = clickLocationMod.GetGridUid(EntityManager);
if (!(gridIdOpt is EntityUid gridId) || !gridId.IsValid())
{
clickLocationMod = clickLocationMod.AlignWithClosestGridTile();
gridID = clickLocationMod.GetGridId(EntityManager);
}
gridIdOpt = clickLocationMod.GetGridUid(EntityManager);
// Check if fixing it failed / get final grid ID
if (!gridID.IsValid())
if (!(gridIdOpt is EntityUid gridId2) || !gridId2.IsValid())
return;
gridId = gridId2;
}
var mapGrid = _mapManager.GetGrid(gridID);
var mapGrid = _mapManager.GetGrid(gridId);
var tile = mapGrid.GetTileRef(clickLocationMod);
var snapPos = mapGrid.TileIndicesFor(clickLocationMod);
@@ -114,14 +115,14 @@ namespace Content.Server.RCD.Systems
//Floor mode just needs the tile to be a space tile (subFloor)
case RcdMode.Floors:
mapGrid.SetTile(snapPos, new Tile(_tileDefinitionManager["FloorSteel"].TileId));
_adminLogger.Add(LogType.RCD, LogImpact.High, $"{ToPrettyString(args.User):user} used RCD to set grid: {tile.GridIndex} {snapPos} to FloorSteel");
_adminLogger.Add(LogType.RCD, LogImpact.High, $"{ToPrettyString(args.User):user} used RCD to set grid: {tile.GridUid} {snapPos} to FloorSteel");
break;
//We don't want to place a space tile on something that's already a space tile. Let's do the inverse of the last check.
case RcdMode.Deconstruct:
if (!tile.IsBlockedTurf(true)) //Delete the turf
{
mapGrid.SetTile(snapPos, Tile.Empty);
_adminLogger.Add(LogType.RCD, LogImpact.High, $"{ToPrettyString(args.User):user} used RCD to set grid: {tile.GridIndex} tile: {snapPos} to space");
_adminLogger.Add(LogType.RCD, LogImpact.High, $"{ToPrettyString(args.User):user} used RCD to set grid: {tile.GridUid} tile: {snapPos} to space");
}
else //Delete what the user targeted
{
@@ -137,12 +138,12 @@ namespace Content.Server.RCD.Systems
case RcdMode.Walls:
var ent = EntityManager.SpawnEntity("WallSolid", mapGrid.GridTileToLocal(snapPos));
Transform(ent).LocalRotation = Angle.Zero; // Walls always need to point south.
_adminLogger.Add(LogType.RCD, LogImpact.High, $"{ToPrettyString(args.User):user} used RCD to spawn {ToPrettyString(ent)} at {snapPos} on grid {mapGrid.Index}");
_adminLogger.Add(LogType.RCD, LogImpact.High, $"{ToPrettyString(args.User):user} used RCD to spawn {ToPrettyString(ent)} at {snapPos} on grid {mapGrid.GridEntityId}");
break;
case RcdMode.Airlock:
var airlock = EntityManager.SpawnEntity("Airlock", mapGrid.GridTileToLocal(snapPos));
Transform(airlock).LocalRotation = Transform(rcd.Owner).LocalRotation; //Now apply icon smoothing.
_adminLogger.Add(LogType.RCD, LogImpact.High, $"{ToPrettyString(args.User):user} used RCD to spawn {ToPrettyString(airlock)} at {snapPos} on grid {mapGrid.Index}");
_adminLogger.Add(LogType.RCD, LogImpact.High, $"{ToPrettyString(args.User):user} used RCD to spawn {ToPrettyString(airlock)} at {snapPos} on grid {mapGrid.GridEntityId}");
break;
default:
args.Handled = true;

View File

@@ -40,7 +40,7 @@ namespace Content.Server.Salvage
private static readonly int SalvageLocationPlaceAttempts = 16;
// TODO: This is probably not compatible with multi-station
private readonly Dictionary<GridId, SalvageGridState> _salvageGridStates = new();
private readonly Dictionary<EntityUid, SalvageGridState> _salvageGridStates = new();
public override void Initialize()
{
@@ -66,10 +66,9 @@ namespace Content.Server.Salvage
private void OnGridRemoval(GridRemovalEvent ev)
{
// If we ever want to give magnets names, and announce them individually, we would need to loop this, before removing it.
if (_salvageGridStates.Remove(ev.GridId))
if (_salvageGridStates.Remove(ev.EntityUid))
{
var gridUid = _mapManager.GetGridEuid(ev.GridId);
if (EntityManager.TryGetComponent<SalvageGridComponent>(gridUid, out var salvComp) && salvComp.SpawnerMagnet != null)
if (EntityManager.TryGetComponent<SalvageGridComponent>(ev.EntityUid, out var salvComp) && salvComp.SpawnerMagnet != null)
Report(salvComp.SpawnerMagnet.Owner, salvComp.SpawnerMagnet.SalvageChannel, "salvage-system-announcement-spawn-magnet-lost");
// For the very unlikely possibility that the salvage magnet was on a salvage, we will not return here
}
@@ -92,7 +91,7 @@ namespace Content.Server.Salvage
if (component.MagnetState.StateType == MagnetStateType.Inactive) return;
var magnetTranform = EntityManager.GetComponent<TransformComponent>(component.Owner);
if (!_salvageGridStates.TryGetValue(magnetTranform.GridID, out var salvageGridState))
if (!(magnetTranform.GridUid is EntityUid gridId) || !_salvageGridStates.TryGetValue(gridId, out var salvageGridState))
{
return;
}
@@ -130,8 +129,8 @@ namespace Content.Server.Salvage
args.PushMarkup(Loc.GetString("salvage-system-magnet-examined-cooling-down"));
break;
case MagnetStateType.Holding:
var magnetTranform = EntityManager.GetComponent<TransformComponent>(component.Owner);
if (_salvageGridStates.TryGetValue(magnetTranform.GridID, out var salvageGridState))
var magnetTransform = EntityManager.GetComponent<TransformComponent>(component.Owner);
if (magnetTransform.GridUid is EntityUid gridId && _salvageGridStates.TryGetValue(gridId, out var salvageGridState))
{
var remainingTime = component.MagnetState.Until - salvageGridState.CurrentTime;
args.PushMarkup(Loc.GetString("salvage-system-magnet-examined-active", ("timeLeft", Math.Ceiling(remainingTime.TotalSeconds))));
@@ -160,12 +159,13 @@ namespace Content.Server.Salvage
{
case MagnetStateType.Inactive:
ShowPopup("salvage-system-report-activate-success", component, user);
var magnetTranform = EntityManager.GetComponent<TransformComponent>(component.Owner);
SalvageGridState? gridState;
if (!_salvageGridStates.TryGetValue(magnetTranform.GridID, out gridState))
var magnetTransform = EntityManager.GetComponent<TransformComponent>(component.Owner);
EntityUid gridId = magnetTransform.GridUid ?? throw new InvalidOperationException("Magnet had no grid associated");
if (!_salvageGridStates.TryGetValue(gridId, out gridState))
{
gridState = new SalvageGridState();
_salvageGridStates[magnetTranform.GridID] = gridState;
_salvageGridStates[gridId] = gridState;
}
gridState.ActiveMagnets.Add(component);
component.MagnetState = new MagnetState(MagnetStateType.Attaching, gridState.CurrentTime + AttachingTime);
@@ -227,8 +227,7 @@ namespace Content.Server.Salvage
angle = Angle.Zero;
var tsc = Transform(component.Owner);
coords = new EntityCoordinates(component.Owner, component.Offset).ToMap(EntityManager);
var grid = tsc.GridID;
if (_mapManager.TryGetGrid(grid, out var magnetGrid))
if (_mapManager.TryGetGrid(tsc.GridUid, out var magnetGrid))
{
angle = magnetGrid.WorldRotation;
}

View File

@@ -97,7 +97,7 @@ public sealed partial class ShuttleSystem
foreach (var other in _mapManager.FindGridsIntersecting(xform.MapID, bounds))
{
if (grid.GridIndex == other.Index ||
if (grid.Owner == other.GridEntityId ||
!bodyQuery.TryGetComponent(other.GridEntityId, out var body) ||
body.Mass < ShuttleFTLMassThreshold) continue;