Resave every map (#15964)

This commit is contained in:
metalgearsloth
2023-05-02 11:38:01 +10:00
committed by GitHub
parent e9b5849ddb
commit ac9970a50f
75 changed files with 1985930 additions and 2246198 deletions

View File

@@ -0,0 +1,55 @@
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,
});
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
{
loader.Save(mapXform.ChildEntities.First(), fn.ToString());
}
_mapManager.DeleteMap(mapId);
}
}
}