This commit is contained in:
ElectroJr
2025-02-17 01:16:22 +13:00
664 changed files with 79784 additions and 224737 deletions

View File

@@ -9,7 +9,6 @@ using Content.Server.Spawners.Components;
using Content.Server.Station.Components;
using Content.Shared.CCVar;
using Content.Shared.Roles;
using Robust.Server.GameObjects;
using Robust.Shared.Configuration;
using Robust.Shared.ContentPack;
using Robust.Shared.GameObjects;
@@ -17,6 +16,9 @@ using Robust.Shared.Map;
using Robust.Shared.Map.Components;
using Robust.Shared.Prototypes;
using Content.Shared.Station.Components;
using Robust.Shared.EntitySerialization;
using Robust.Shared.EntitySerialization.Systems;
using Robust.Shared.IoC;
using Robust.Shared.Utility;
using YamlDotNet.RepresentationModel;
@@ -36,10 +38,7 @@ namespace Content.IntegrationTests.Tests
private static readonly string[] Grids =
{
"/Maps/centcomm.yml",
"/Maps/Shuttles/cargo.yml",
"/Maps/Shuttles/emergency.yml",
"/Maps/Shuttles/infiltrator.yml",
"/Maps/centcomm.yml"
};
private static readonly string[] DoNotMapWhitelist =
@@ -65,14 +64,13 @@ namespace Content.IntegrationTests.Tests
"Reach",
"Train",
"Oasis",
"Cog",
"Gate",
"Amber",
"Loop",
"Plasma",
"Elkridge",
"Convex"
"Convex",
"Relic"
};
/// <summary>
@@ -87,33 +85,72 @@ namespace Content.IntegrationTests.Tests
var entManager = server.ResolveDependency<IEntityManager>();
var mapLoader = entManager.System<MapLoaderSystem>();
var mapSystem = entManager.System<SharedMapSystem>();
var mapManager = server.ResolveDependency<IMapManager>();
var cfg = server.ResolveDependency<IConfigurationManager>();
Assert.That(cfg.GetCVar(CCVars.GridFill), Is.False);
var path = new ResPath(mapFile);
await server.WaitPost(() =>
{
mapSystem.CreateMap(out var mapId);
try
{
#pragma warning disable NUnit2045
Assert.That(mapLoader.TryLoad(mapId, mapFile, out var roots));
Assert.That(roots.Where(uid => entManager.HasComponent<MapGridComponent>(uid)), Is.Not.Empty);
#pragma warning restore NUnit2045
Assert.That(mapLoader.TryLoadGrid(mapId, path, out var grid));
}
catch (Exception ex)
{
throw new Exception($"Failed to load map {mapFile}, was it saved as a map instead of a grid?", ex);
}
try
mapSystem.DeleteMap(mapId);
});
await server.WaitRunTicks(1);
await pair.CleanReturnAsync();
}
/// <summary>
/// Asserts that shuttles are loadable and have been saved as grids and not maps.
/// </summary>
[Test]
public async Task ShuttlesLoadableTest()
{
await using var pair = await PoolManager.GetServerClient();
var server = pair.Server;
var entManager = server.ResolveDependency<IEntityManager>();
var resMan = server.ResolveDependency<IResourceManager>();
var mapLoader = entManager.System<MapLoaderSystem>();
var mapSystem = entManager.System<SharedMapSystem>();
var cfg = server.ResolveDependency<IConfigurationManager>();
Assert.That(cfg.GetCVar(CCVars.GridFill), Is.False);
var shuttleFolder = new ResPath("/Maps/Shuttles");
var shuttles = resMan
.ContentFindFiles(shuttleFolder)
.Where(filePath =>
filePath.Extension == "yml" && !filePath.Filename.StartsWith(".", StringComparison.Ordinal))
.ToArray();
await server.WaitPost(() =>
{
Assert.Multiple(() =>
{
mapManager.DeleteMap(mapId);
}
catch (Exception ex)
{
throw new Exception($"Failed to delete map {mapFile}", ex);
}
foreach (var path in shuttles)
{
mapSystem.CreateMap(out var mapId);
try
{
Assert.That(mapLoader.TryLoadGrid(mapId, path, out _),
$"Failed to load shuttle {path}, was it saved as a map instead of a grid?");
}
catch (Exception ex)
{
throw new Exception($"Failed to load shuttle {path}, was it saved as a map instead of a grid?",
ex);
}
mapSystem.DeleteMap(mapId);
}
});
});
await server.WaitRunTicks(1);
@@ -128,12 +165,15 @@ namespace Content.IntegrationTests.Tests
var resourceManager = server.ResolveDependency<IResourceManager>();
var protoManager = server.ResolveDependency<IPrototypeManager>();
var loader = server.System<MapLoaderSystem>();
var mapFolder = new ResPath("/Maps");
var maps = resourceManager
.ContentFindFiles(mapFolder)
.Where(filePath => filePath.Extension == "yml" && !filePath.Filename.StartsWith(".", StringComparison.Ordinal))
.ToArray();
var v7Maps = new List<ResPath>();
foreach (var map in maps)
{
var rootedPath = map.ToRootedPath();
@@ -156,8 +196,15 @@ namespace Content.IntegrationTests.Tests
var root = yamlStream.Documents[0].RootNode;
var meta = root["meta"];
var postMapInit = meta["postmapinit"].AsBool();
var version = meta["format"].AsInt();
if (version >= 7)
{
v7Maps.Add(map);
continue;
}
var postMapInit = meta["postmapinit"].AsBool();
Assert.That(postMapInit, Is.False, $"Map {map.Filename} was saved postmapinit");
// testing that maps have nothing with the DoNotMap entity category
@@ -177,9 +224,58 @@ namespace Content.IntegrationTests.Tests
}
}
}
var deps = server.ResolveDependency<IEntitySystemManager>().DependencyCollection;
foreach (var map in v7Maps)
{
Assert.That(IsPreInit(map, loader, deps));
}
// Check that the test actually does manage to catch post-init maps and isn't just blindly passing everything.
// To that end, create a new post-init map and try verify it.
var mapSys = server.System<SharedMapSystem>();
MapId id = default;
await server.WaitPost(() => mapSys.CreateMap(out id, runMapInit: false));
await server.WaitPost(() => server.EntMan.Spawn(null, new MapCoordinates(0, 0, id)));
// First check that a pre-init version passes
var path = new ResPath($"{nameof(NoSavedPostMapInitTest)}.yml");
Assert.That(loader.TrySaveMap(id, path));
Assert.That(IsPreInit(path, loader, deps));
// and the post-init version fails.
await server.WaitPost(() => mapSys.InitializeMap(id));
Assert.That(loader.TrySaveMap(id, path));
Assert.That(IsPreInit(path, loader, deps), Is.False);
await pair.CleanReturnAsync();
}
private bool IsPreInit(ResPath map, MapLoaderSystem loader, IDependencyCollection deps)
{
if (!loader.TryReadFile(map, out var data))
{
Assert.Fail($"Failed to read {map}");
return false;
}
var reader = new EntityDeserializer(deps, data, DeserializationOptions.Default);
if (!reader.TryProcessData())
{
Assert.Fail($"Failed to process {map}");
return false;
}
foreach (var mapId in reader.MapYamlIds)
{
var mapData = reader.YamlEntities[mapId];
if (mapData.PostInit)
return false;
}
return true;
}
[Test, TestCaseSource(nameof(GameMaps))]
public async Task GameMapsLoadableTest(string mapProto)
{
@@ -196,16 +292,16 @@ namespace Content.IntegrationTests.Tests
var protoManager = server.ResolveDependency<IPrototypeManager>();
var ticker = entManager.EntitySysManager.GetEntitySystem<GameTicker>();
var shuttleSystem = entManager.EntitySysManager.GetEntitySystem<ShuttleSystem>();
var xformQuery = entManager.GetEntityQuery<TransformComponent>();
var cfg = server.ResolveDependency<IConfigurationManager>();
Assert.That(cfg.GetCVar(CCVars.GridFill), Is.False);
await server.WaitPost(() =>
{
mapSystem.CreateMap(out var mapId);
MapId mapId;
try
{
ticker.LoadGameMap(protoManager.Index<GameMapPrototype>(mapProto), mapId, null);
var opts = DeserializationOptions.Default with {InitializeMaps = true};
ticker.LoadGameMap(protoManager.Index<GameMapPrototype>(mapProto), out mapId, opts);
}
catch (Exception ex)
{
@@ -242,21 +338,17 @@ namespace Content.IntegrationTests.Tests
if (entManager.TryGetComponent<StationEmergencyShuttleComponent>(station, out var stationEvac))
{
var shuttlePath = stationEvac.EmergencyShuttlePath;
#pragma warning disable NUnit2045
Assert.That(mapLoader.TryLoad(shuttleMap, shuttlePath.ToString(), out var roots));
EntityUid shuttle = default!;
Assert.DoesNotThrow(() =>
{
shuttle = roots.First(uid => entManager.HasComponent<MapGridComponent>(uid));
}, $"Failed to load {shuttlePath}");
Assert.That(mapLoader.TryLoadGrid(shuttleMap, shuttlePath, out var shuttle),
$"Failed to load {shuttlePath}");
Assert.That(
shuttleSystem.TryFTLDock(shuttle,
entManager.GetComponent<ShuttleComponent>(shuttle), targetGrid.Value),
shuttleSystem.TryFTLDock(shuttle!.Value.Owner,
entManager.GetComponent<ShuttleComponent>(shuttle!.Value.Owner),
targetGrid.Value),
$"Unable to dock {shuttlePath} to {mapProto}");
#pragma warning restore NUnit2045
}
mapManager.DeleteMap(shuttleMap);
mapSystem.DeleteMap(shuttleMap);
if (entManager.HasComponent<StationJobsComponent>(station))
{
@@ -293,7 +385,7 @@ namespace Content.IntegrationTests.Tests
try
{
mapManager.DeleteMap(mapId);
mapSystem.DeleteMap(mapId);
}
catch (Exception ex)
{
@@ -357,11 +449,9 @@ namespace Content.IntegrationTests.Tests
var server = pair.Server;
var mapLoader = server.ResolveDependency<IEntitySystemManager>().GetEntitySystem<MapLoaderSystem>();
var mapManager = server.ResolveDependency<IMapManager>();
var resourceManager = server.ResolveDependency<IResourceManager>();
var protoManager = server.ResolveDependency<IPrototypeManager>();
var cfg = server.ResolveDependency<IConfigurationManager>();
var mapSystem = server.System<SharedMapSystem>();
Assert.That(cfg.GetCVar(CCVars.GridFill), Is.False);
var gameMaps = protoManager.EnumeratePrototypes<GameMapPrototype>().Select(o => o.MapPath).ToHashSet();
@@ -372,7 +462,7 @@ namespace Content.IntegrationTests.Tests
.Where(filePath => filePath.Extension == "yml" && !filePath.Filename.StartsWith(".", StringComparison.Ordinal))
.ToArray();
var mapNames = new List<string>();
var mapPaths = new List<ResPath>();
foreach (var map in maps)
{
if (gameMaps.Contains(map))
@@ -383,32 +473,46 @@ namespace Content.IntegrationTests.Tests
{
continue;
}
mapNames.Add(rootedPath.ToString());
mapPaths.Add(rootedPath);
}
await server.WaitPost(() =>
{
Assert.Multiple(() =>
{
foreach (var mapName in mapNames)
// This bunch of files contains a random mixture of both map and grid files.
// TODO MAPPING organize files
var opts = MapLoadOptions.Default with
{
DeserializationOptions = DeserializationOptions.Default with
{
InitializeMaps = true,
LogOrphanedGrids = false
}
};
HashSet<Entity<MapComponent>> maps;
foreach (var path in mapPaths)
{
mapSystem.CreateMap(out var mapId);
try
{
Assert.That(mapLoader.TryLoad(mapId, mapName, out _));
Assert.That(mapLoader.TryLoadGeneric(path, out maps, out _, opts));
}
catch (Exception ex)
{
throw new Exception($"Failed to load map {mapName}", ex);
throw new Exception($"Failed to load map {path}", ex);
}
try
{
mapManager.DeleteMap(mapId);
foreach (var map in maps)
{
server.EntMan.DeleteEntity(map);
}
}
catch (Exception ex)
{
throw new Exception($"Failed to delete map {mapName}", ex);
throw new Exception($"Failed to delete map {path}", ex);
}
}
});