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()
{ {
@@ -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])));

View File

@@ -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);

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

@@ -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;

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);

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);
} }