Files
tbd-station-14/Content.Server/Maps/ResaveCommand.cs
Leon Friedrich 9a3342d972 Remove uses of TransformComponent.ChildEntities (#22442)
* Make output of ChildEnumerator non-nullable

* Remove uses of ChildEntities

* poke tests

---------

Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
2023-12-17 03:09:50 +11:00

58 lines
1.8 KiB
C#

using System.Linq;
using Content.Server.Administration;
using Content.Shared.Administration;
using Robust.Server.GameObjects;
using Robust.Server.Maps;
using Robust.Shared.Console;
using Robust.Shared.ContentPack;
using Robust.Shared.Map;
using Robust.Shared.Utility;
namespace Content.Server.Maps;
/// <summary>
/// Loads every map and resaves it into the data folder.
/// </summary>
[AdminCommand(AdminFlags.Mapping)]
public sealed class ResaveCommand : LocalizedCommands
{
[Dependency] private readonly IEntityManager _entManager = default!;
[Dependency] private readonly IMapManager _mapManager = default!;
[Dependency] private readonly IResourceManager _res = default!;
public override string Command => "resave";
public override void Execute(IConsoleShell shell, string argStr, string[] args)
{
var loader = _entManager.System<MapLoaderSystem>();
foreach (var fn in _res.ContentFindFiles(new ResPath("/Maps/")))
{
var mapId = _mapManager.CreateMap();
_mapManager.AddUninitializedMap(mapId);
loader.Load(mapId, fn.ToString(), new MapLoadOptions()
{
StoreMapUids = true,
LoadMap = true,
});
// Process deferred component removals.
_entManager.CullRemovedComponents();
var mapUid = _mapManager.GetMapEntityId(mapId);
var mapXform = _entManager.GetComponent<TransformComponent>(mapUid);
if (_entManager.HasComponent<LoadedMapComponent>(mapUid) || mapXform.ChildCount != 1)
{
loader.SaveMap(mapId, fn.ToString());
}
else if (mapXform.ChildEnumerator.MoveNext(out var child))
{
loader.Save(child, fn.ToString());
}
_mapManager.DeleteMap(mapId);
}
}
}