Cleanup all instances of IMapManager.GetMapEntityId (#37814)

* Cleanup all instances of IMapManager.GetMapEntityId

* Dependencies

* LocalizedEntityCommands
This commit is contained in:
Tayrtahn
2025-05-25 13:09:47 -04:00
committed by GitHub
parent e08a7f3c84
commit 50fb48de2e
8 changed files with 39 additions and 41 deletions

View File

@@ -22,6 +22,7 @@ public sealed class ProjectileAnomalySystem : EntitySystem
[Dependency] private readonly IRobustRandom _random = default!; [Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly IMapManager _mapManager = default!; [Dependency] private readonly IMapManager _mapManager = default!;
[Dependency] private readonly GunSystem _gunSystem = default!; [Dependency] private readonly GunSystem _gunSystem = default!;
[Dependency] private readonly SharedMapSystem _map = default!;
public override void Initialize() public override void Initialize()
{ {
@@ -41,7 +42,7 @@ public sealed class ProjectileAnomalySystem : EntitySystem
private void ShootProjectilesAtEntities(EntityUid uid, ProjectileAnomalyComponent component, float severity) private void ShootProjectilesAtEntities(EntityUid uid, ProjectileAnomalyComponent component, float severity)
{ {
var projectileCount = (int) MathF.Round(MathHelper.Lerp(component.MinProjectiles, component.MaxProjectiles, severity)); var projectileCount = (int)MathF.Round(MathHelper.Lerp(component.MinProjectiles, component.MaxProjectiles, severity));
var xformQuery = GetEntityQuery<TransformComponent>(); var xformQuery = GetEntityQuery<TransformComponent>();
var mobQuery = GetEntityQuery<MobStateComponent>(); var mobQuery = GetEntityQuery<MobStateComponent>();
var xform = xformQuery.GetComponent(uid); var xform = xformQuery.GetComponent(uid);
@@ -85,7 +86,7 @@ public sealed class ProjectileAnomalySystem : EntitySystem
var spawnCoords = _mapManager.TryFindGridAt(mapPos, out var gridUid, out _) var spawnCoords = _mapManager.TryFindGridAt(mapPos, out var gridUid, out _)
? _xform.WithEntityId(coords, gridUid) ? _xform.WithEntityId(coords, gridUid)
: new(_mapManager.GetMapEntityId(mapPos.MapId), mapPos.Position); : new(_map.GetMapOrInvalid(mapPos.MapId), mapPos.Position);
var ent = Spawn(component.ProjectilePrototype, spawnCoords); var ent = Spawn(component.ProjectilePrototype, spawnCoords);
var direction = _xform.ToMapCoordinates(targetCoords).Position - mapPos.Position; var direction = _xform.ToMapCoordinates(targetCoords).Position - mapPos.Position;

View File

@@ -9,10 +9,10 @@ using Robust.Shared.Map;
namespace Content.Server.Atmos.Commands; namespace Content.Server.Atmos.Commands;
[AdminCommand(AdminFlags.Admin)] [AdminCommand(AdminFlags.Admin)]
public sealed class AddMapAtmosCommand : LocalizedCommands public sealed class AddMapAtmosCommand : LocalizedEntityCommands
{ {
[Dependency] private readonly IEntityManager _entities = default!; [Dependency] private readonly IEntityManager _entities = default!;
[Dependency] private readonly IMapManager _map = default!; [Dependency] private readonly SharedMapSystem _map = default!;
private const string _cmd = "cmd-set-map-atmos"; private const string _cmd = "cmd-set-map-atmos";
public override string Command => "setmapatmos"; public override string Command => "setmapatmos";
@@ -28,7 +28,7 @@ public sealed class AddMapAtmosCommand : LocalizedCommands
} }
int.TryParse(args[0], out var id); int.TryParse(args[0], out var id);
var map = _map.GetMapEntityId(new MapId(id)); var map = _map.GetMapOrInvalid(new MapId(id));
if (!map.IsValid()) if (!map.IsValid())
{ {
shell.WriteError(Loc.GetString("cmd-parse-failure-mapid", ("arg", args[0]))); shell.WriteError(Loc.GetString("cmd-parse-failure-mapid", ("arg", args[0])));
@@ -54,15 +54,15 @@ public sealed class AddMapAtmosCommand : LocalizedCommands
return; return;
} }
var mix = new GasMixture(Atmospherics.CellVolume) {Temperature = Math.Max(temp, Atmospherics.TCMB)}; var mix = new GasMixture(Atmospherics.CellVolume) { Temperature = Math.Max(temp, Atmospherics.TCMB) };
for (var i = 0; i < Atmospherics.TotalNumberOfGases; i++) for (var i = 0; i < Atmospherics.TotalNumberOfGases; i++)
{ {
if (args.Length == 3 + i) if (args.Length == 3 + i)
break; break;
if (!float.TryParse(args[3+i], out var moles)) if (!float.TryParse(args[3 + i], out var moles))
{ {
shell.WriteError(Loc.GetString("cmd-parse-failure-float", ("arg", args[3+i]))); shell.WriteError(Loc.GetString("cmd-parse-failure-float", ("arg", args[3 + i])));
return; return;
} }
@@ -80,7 +80,7 @@ public sealed class AddMapAtmosCommand : LocalizedCommands
return CompletionResult.FromHintOptions(CompletionHelper.MapIds(_entities), Loc.GetString($"{_cmd}-hint-map")); return CompletionResult.FromHintOptions(CompletionHelper.MapIds(_entities), Loc.GetString($"{_cmd}-hint-map"));
if (args.Length == 2) if (args.Length == 2)
return CompletionResult.FromHintOptions(new[]{ "false", "true"}, Loc.GetString($"{_cmd}-hint-space")); return CompletionResult.FromHintOptions(new[] { "false", "true" }, Loc.GetString($"{_cmd}-hint-space"));
if (!bool.TryParse(args[1], out var space) || space) if (!bool.TryParse(args[1], out var space) || space)
return CompletionResult.Empty; return CompletionResult.Empty;
@@ -88,7 +88,7 @@ public sealed class AddMapAtmosCommand : LocalizedCommands
if (args.Length == 3) if (args.Length == 3)
return CompletionResult.FromHint(Loc.GetString($"{_cmd}-hint-temp")); return CompletionResult.FromHint(Loc.GetString($"{_cmd}-hint-temp"));
var gas = (Gas) args.Length - 4; var gas = (Gas)args.Length - 4;
return CompletionResult.FromHint(Loc.GetString($"{_cmd}-hint-gas" , ("gas", gas.ToString()))); return CompletionResult.FromHint(Loc.GetString($"{_cmd}-hint-gas", ("gas", gas.ToString())));
} }
} }

View File

@@ -275,7 +275,7 @@ namespace Content.Server.GameTicking
_mind.TransferTo(newMind, mob); _mind.TransferTo(newMind, mob);
_roles.MindAddJobRole(newMind, silent: silent, jobPrototype:jobId); _roles.MindAddJobRole(newMind, silent: silent, jobPrototype: jobId);
var jobName = _jobs.MindTryGetJobName(newMind); var jobName = _jobs.MindTryGetJobName(newMind);
_admin.UpdatePlayerList(player); _admin.UpdatePlayerList(player);
@@ -475,17 +475,17 @@ namespace Content.Server.GameTicking
return spawn; return spawn;
} }
if (_mapManager.MapExists(DefaultMap)) if (_map.MapExists(DefaultMap))
{ {
var mapUid = _mapManager.GetMapEntityId(DefaultMap); var mapUid = _map.GetMapOrInvalid(DefaultMap);
if (!TerminatingOrDeleted(mapUid)) if (!TerminatingOrDeleted(mapUid))
return new EntityCoordinates(mapUid, Vector2.Zero); return new EntityCoordinates(mapUid, Vector2.Zero);
} }
// Just pick a point at this point I guess. // Just pick a point at this point I guess.
foreach (var map in _mapManager.GetAllMapIds()) foreach (var map in _map.GetAllMapIds())
{ {
var mapUid = _mapManager.GetMapEntityId(map); var mapUid = _map.GetMapOrInvalid(map);
if (!metaQuery.TryGetComponent(mapUid, out var meta) if (!metaQuery.TryGetComponent(mapUid, out var meta)
|| meta.EntityPaused || meta.EntityPaused

View File

@@ -100,8 +100,7 @@ public sealed class GatewayGeneratorSystem : EntitySystem
var tiles = new List<(Vector2i Index, Tile Tile)>(); var tiles = new List<(Vector2i Index, Tile Tile)>();
var seed = _random.Next(); var seed = _random.Next();
var random = new Random(seed); var random = new Random(seed);
var mapId = _mapManager.CreateMap(); var mapUid = _maps.CreateMap();
var mapUid = _mapManager.GetMapEntityId(mapId);
var gatewayName = _salvage.GetFTLName(_protoManager.Index<LocalizedDatasetPrototype>(PlanetNames), seed); var gatewayName = _salvage.GetFTLName(_protoManager.Index<LocalizedDatasetPrototype>(PlanetNames), seed);
_metadata.SetEntityName(mapUid, gatewayName); _metadata.SetEntityName(mapUid, gatewayName);
@@ -121,7 +120,7 @@ public sealed class GatewayGeneratorSystem : EntitySystem
{ {
for (var y = -2; y <= 2; y++) for (var y = -2; y <= 2; y++)
{ {
tiles.Add((new Vector2i(x, y) + origin, new Tile(tileDef.TileId, variant: _tile.PickVariant((ContentTileDefinition) tileDef, random)))); tiles.Add((new Vector2i(x, y) + origin, new Tile(tileDef.TileId, variant: _tile.PickVariant((ContentTileDefinition)tileDef, random))));
} }
} }

View File

@@ -22,16 +22,16 @@ namespace Content.Server.Maps;
/// Converts the supplied map into a "planet" with defaults. /// Converts the supplied map into a "planet" with defaults.
/// </summary> /// </summary>
[AdminCommand(AdminFlags.Mapping)] [AdminCommand(AdminFlags.Mapping)]
public sealed class PlanetCommand : IConsoleCommand public sealed class PlanetCommand : LocalizedEntityCommands
{ {
[Dependency] private readonly IEntityManager _entManager = default!; [Dependency] private readonly IEntityManager _entManager = default!;
[Dependency] private readonly IMapManager _mapManager = default!;
[Dependency] private readonly IPrototypeManager _protoManager = default!; [Dependency] private readonly IPrototypeManager _protoManager = default!;
[Dependency] private readonly SharedMapSystem _map = default!;
public string Command => "planet"; public override string Command => "planet";
public string Description => Loc.GetString("cmd-planet-desc"); public override string Description => Loc.GetString("cmd-planet-desc");
public string Help => Loc.GetString("cmd-planet-help", ("command", Command)); public override string Help => Loc.GetString("cmd-planet-help", ("command", Command));
public void Execute(IConsoleShell shell, string argStr, string[] args) public override void Execute(IConsoleShell shell, string argStr, string[] args)
{ {
if (args.Length != 2) if (args.Length != 2)
{ {
@@ -46,8 +46,7 @@ public sealed class PlanetCommand : IConsoleCommand
} }
var mapId = new MapId(mapInt); var mapId = new MapId(mapInt);
if (!_map.MapExists(mapId))
if (!_mapManager.MapExists(mapId))
{ {
shell.WriteError(Loc.GetString($"cmd-planet-map", ("map", mapId))); shell.WriteError(Loc.GetString($"cmd-planet-map", ("map", mapId)));
return; return;
@@ -60,13 +59,13 @@ public sealed class PlanetCommand : IConsoleCommand
} }
var biomeSystem = _entManager.System<BiomeSystem>(); var biomeSystem = _entManager.System<BiomeSystem>();
var mapUid = _mapManager.GetMapEntityId(mapId); var mapUid = _map.GetMapOrInvalid(mapId);
biomeSystem.EnsurePlanet(mapUid, biomeTemplate); biomeSystem.EnsurePlanet(mapUid, biomeTemplate);
shell.WriteLine(Loc.GetString("cmd-planet-success", ("mapId", mapId))); shell.WriteLine(Loc.GetString("cmd-planet-success", ("mapId", mapId)));
} }
public CompletionResult GetCompletion(IConsoleShell shell, string[] args) public override CompletionResult GetCompletion(IConsoleShell shell, string[] args)
{ {
if (args.Length == 1) if (args.Length == 1)
return CompletionResult.FromHintOptions(CompletionHelper.MapIds(_entManager), "Map Id"); return CompletionResult.FromHintOptions(CompletionHelper.MapIds(_entManager), "Map Id");

View File

@@ -90,7 +90,7 @@ public sealed partial class DungeonSystem
roomRotation = GetRoomRotation(room, random); roomRotation = GetRoomRotation(room, random);
} }
var roomTransform = Matrix3Helpers.CreateTransform((Vector2) room.Size / 2f, roomRotation); var roomTransform = Matrix3Helpers.CreateTransform((Vector2)room.Size / 2f, roomRotation);
var finalTransform = Matrix3x2.Multiply(roomTransform, originTransform); var finalTransform = Matrix3x2.Multiply(roomTransform, originTransform);
SpawnRoom(gridUid, grid, finalTransform, room, reservedTiles, clearExisting); SpawnRoom(gridUid, grid, finalTransform, room, reservedTiles, clearExisting);
@@ -123,7 +123,7 @@ public sealed partial class DungeonSystem
{ {
// Ensure the underlying template exists. // Ensure the underlying template exists.
var roomMap = GetOrCreateTemplate(room); var roomMap = GetOrCreateTemplate(room);
var templateMapUid = _mapManager.GetMapEntityId(roomMap); var templateMapUid = _maps.GetMapOrInvalid(roomMap);
var templateGrid = Comp<MapGridComponent>(templateMapUid); var templateGrid = Comp<MapGridComponent>(templateMapUid);
var roomDimensions = room.Size; var roomDimensions = room.Size;
@@ -250,7 +250,7 @@ public sealed partial class DungeonSystem
// but place 1 nanometre off grid and fail the add. // but place 1 nanometre off grid and fail the add.
if (!_maps.TryGetTileRef(gridUid, grid, tilePos, out var tileRef) || tileRef.Tile.IsEmpty) if (!_maps.TryGetTileRef(gridUid, grid, tilePos, out var tileRef) || tileRef.Tile.IsEmpty)
{ {
_maps.SetTile(gridUid, grid, tilePos, _tile.GetVariantTile((ContentTileDefinition) _tileDefManager[FallbackTileId], _random.GetRandom())); _maps.SetTile(gridUid, grid, tilePos, _tile.GetVariantTile((ContentTileDefinition)_tileDefManager[FallbackTileId], _random.GetRandom()));
} }
var result = _decals.TryAddDecal( var result = _decals.TryAddDecal(

View File

@@ -74,7 +74,7 @@ public sealed partial class SalvageSystem
ChatChannel.Radio, ChatChannel.Radio,
text, text,
text, text,
_mapManager.GetMapEntityId(mapId), _mapSystem.GetMapOrInvalid(mapId),
false, false,
true, true,
null); null);
@@ -170,11 +170,11 @@ public sealed partial class SalvageSystem
// Auto-FTL out any shuttles // Auto-FTL out any shuttles
else if (remaining < TimeSpan.FromSeconds(_shuttle.DefaultStartupTime) + TimeSpan.FromSeconds(0.5)) else if (remaining < TimeSpan.FromSeconds(_shuttle.DefaultStartupTime) + TimeSpan.FromSeconds(0.5))
{ {
var ftlTime = (float) remaining.TotalSeconds; var ftlTime = (float)remaining.TotalSeconds;
if (remaining < TimeSpan.FromSeconds(_shuttle.DefaultStartupTime)) if (remaining < TimeSpan.FromSeconds(_shuttle.DefaultStartupTime))
{ {
ftlTime = MathF.Max(0, (float) remaining.TotalSeconds - 0.5f); ftlTime = MathF.Max(0, (float)remaining.TotalSeconds - 0.5f);
} }
ftlTime = MathF.Min(ftlTime, _shuttle.DefaultStartupTime); ftlTime = MathF.Min(ftlTime, _shuttle.DefaultStartupTime);

View File

@@ -1,17 +1,16 @@
using Content.Server.Parallax; using Content.Server.Parallax;
using Content.Server.Station.Components; using Content.Server.Station.Components;
using Content.Server.Station.Events; using Content.Server.Station.Events;
using Content.Server.Station.Systems;
using Robust.Shared.Map;
using Robust.Shared.Prototypes; using Robust.Shared.Prototypes;
namespace Content.Server.Station.Systems; namespace Content.Server.Station.Systems;
public sealed partial class StationBiomeSystem : EntitySystem public sealed partial class StationBiomeSystem : EntitySystem
{ {
[Dependency] private readonly BiomeSystem _biome = default!; [Dependency] private readonly BiomeSystem _biome = default!;
[Dependency] private readonly IMapManager _mapManager = default!;
[Dependency] private readonly IPrototypeManager _proto = default!; [Dependency] private readonly IPrototypeManager _proto = default!;
[Dependency] private readonly StationSystem _station = default!; [Dependency] private readonly StationSystem _station = default!;
[Dependency] private readonly SharedMapSystem _map = default!;
public override void Initialize() public override void Initialize()
{ {
@@ -28,7 +27,7 @@ public sealed partial class StationBiomeSystem : EntitySystem
if (station == null) return; if (station == null) return;
var mapId = Transform(station.Value).MapID; var mapId = Transform(station.Value).MapID;
var mapUid = _mapManager.GetMapEntityId(mapId); var mapUid = _map.GetMapOrInvalid(mapId);
_biome.EnsurePlanet(mapUid, _proto.Index(map.Comp.Biome), map.Comp.Seed, mapLight: map.Comp.MapLightColor); _biome.EnsurePlanet(mapUid, _proto.Index(map.Comp.Biome), map.Comp.Seed, mapLight: map.Comp.MapLightColor);
} }