2023-09-13 22:22:21 +10:00
|
|
|
using System.Collections.Generic;
|
2022-05-22 20:31:39 -07:00
|
|
|
using System.IO;
|
2020-09-02 01:16:42 +02:00
|
|
|
using System.Linq;
|
2022-09-14 19:02:59 +10:00
|
|
|
using Content.Server.GameTicking;
|
|
|
|
|
using Content.Server.Maps;
|
|
|
|
|
using Content.Server.Shuttles.Components;
|
2023-10-19 12:34:31 -07:00
|
|
|
using Content.Server.Shuttles.Systems;
|
2022-10-15 22:18:48 +02:00
|
|
|
using Content.Server.Spawners.Components;
|
2022-09-14 19:02:59 +10:00
|
|
|
using Content.Server.Station.Components;
|
2023-04-25 11:48:29 +12:00
|
|
|
using Content.Shared.CCVar;
|
2022-10-15 22:18:48 +02:00
|
|
|
using Content.Shared.Roles;
|
2022-11-13 17:47:48 +11:00
|
|
|
using Robust.Server.GameObjects;
|
2023-04-25 11:48:29 +12:00
|
|
|
using Robust.Shared.Configuration;
|
2021-02-11 01:13:03 -08:00
|
|
|
using Robust.Shared.ContentPack;
|
2022-09-14 19:02:59 +10:00
|
|
|
using Robust.Shared.GameObjects;
|
2021-11-12 02:42:27 +00:00
|
|
|
using Robust.Shared.Map;
|
2023-07-05 21:54:25 -07:00
|
|
|
using Robust.Shared.Map.Components;
|
2022-09-14 19:02:59 +10:00
|
|
|
using Robust.Shared.Prototypes;
|
2023-10-19 12:34:31 -07:00
|
|
|
using Robust.Shared.Utility;
|
2020-09-02 01:16:42 +02:00
|
|
|
using YamlDotNet.RepresentationModel;
|
|
|
|
|
|
|
|
|
|
namespace Content.IntegrationTests.Tests
|
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
2022-06-19 20:22:28 -07:00
|
|
|
public sealed class PostMapInitTest
|
2020-09-02 01:16:42 +02:00
|
|
|
{
|
2022-07-20 14:48:44 +10:00
|
|
|
private const bool SkipTestMaps = true;
|
|
|
|
|
private const string TestMapsPath = "/Maps/Test/";
|
2020-09-02 01:16:42 +02:00
|
|
|
|
2022-10-17 14:24:48 +11:00
|
|
|
private static readonly string[] NoSpawnMaps =
|
|
|
|
|
{
|
|
|
|
|
"CentComm",
|
|
|
|
|
"Dart",
|
Refactor antag rule code (#23445)
* Initial Pass, Rev, Thief
* Zombie initial pass
* Rebase, Traitor
* Nukeops, More overloads
* Revert RevolutionaryRuleComponent
* Use TryRoundStartAttempt, Rewrite nukie spawning
* Comments, Add task scheduler to GameRuleSystem
* Zombie initial testing done
* Sort methods, rework GameRuleTask
* Add CCVar, Initial testing continues
* Might as well get rid of the obsolete logging
* Oops, i dont know how to log apparently
* Suggested formatting fixes
* Suggested changes
* Fix merge issues
* Minor optimisation
* Allowed thief to choose other antags
* Review changes
* Spawn items on floor first, then inserting
* minor tweaks
* Shift as much as possible to ProtoId<>
* Remove unneeded
* Add exclusive antag attribute
* Fix merge issues
* Minor formatting fix
* Convert to struct
* Cleanup
* Review cleanup (need to test a lot)
* Some fixes, (mostly) tested
* oop
* Pass tests (for real)
---------
Co-authored-by: Rainfall <rainfey0+git@gmail.com>
Co-authored-by: AJCM <AJCM@tutanota.com>
2024-02-29 06:25:10 +00:00
|
|
|
"NukieOutpost"
|
2022-10-17 14:24:48 +11:00
|
|
|
};
|
|
|
|
|
|
2023-07-05 21:54:25 -07:00
|
|
|
private static readonly string[] Grids =
|
2022-10-17 03:44:56 +11:00
|
|
|
{
|
|
|
|
|
"/Maps/centcomm.yml",
|
|
|
|
|
"/Maps/Shuttles/cargo.yml",
|
|
|
|
|
"/Maps/Shuttles/emergency.yml",
|
Refactor antag rule code (#23445)
* Initial Pass, Rev, Thief
* Zombie initial pass
* Rebase, Traitor
* Nukeops, More overloads
* Revert RevolutionaryRuleComponent
* Use TryRoundStartAttempt, Rewrite nukie spawning
* Comments, Add task scheduler to GameRuleSystem
* Zombie initial testing done
* Sort methods, rework GameRuleTask
* Add CCVar, Initial testing continues
* Might as well get rid of the obsolete logging
* Oops, i dont know how to log apparently
* Suggested formatting fixes
* Suggested changes
* Fix merge issues
* Minor optimisation
* Allowed thief to choose other antags
* Review changes
* Spawn items on floor first, then inserting
* minor tweaks
* Shift as much as possible to ProtoId<>
* Remove unneeded
* Add exclusive antag attribute
* Fix merge issues
* Minor formatting fix
* Convert to struct
* Cleanup
* Review cleanup (need to test a lot)
* Some fixes, (mostly) tested
* oop
* Pass tests (for real)
---------
Co-authored-by: Rainfall <rainfey0+git@gmail.com>
Co-authored-by: AJCM <AJCM@tutanota.com>
2024-02-29 06:25:10 +00:00
|
|
|
"/Maps/Shuttles/infiltrator.yml",
|
2022-10-17 03:44:56 +11:00
|
|
|
};
|
|
|
|
|
|
2023-08-05 16:16:48 +12:00
|
|
|
private static readonly string[] GameMaps =
|
|
|
|
|
{
|
|
|
|
|
"Dev",
|
2023-08-12 22:41:55 +02:00
|
|
|
"TestTeg",
|
2023-08-05 16:16:48 +12:00
|
|
|
"Fland",
|
|
|
|
|
"Meta",
|
|
|
|
|
"Packed",
|
|
|
|
|
"Cluster",
|
|
|
|
|
"Omega",
|
|
|
|
|
"Bagel",
|
|
|
|
|
"Origin",
|
|
|
|
|
"CentComm",
|
Refactor antag rule code (#23445)
* Initial Pass, Rev, Thief
* Zombie initial pass
* Rebase, Traitor
* Nukeops, More overloads
* Revert RevolutionaryRuleComponent
* Use TryRoundStartAttempt, Rewrite nukie spawning
* Comments, Add task scheduler to GameRuleSystem
* Zombie initial testing done
* Sort methods, rework GameRuleTask
* Add CCVar, Initial testing continues
* Might as well get rid of the obsolete logging
* Oops, i dont know how to log apparently
* Suggested formatting fixes
* Suggested changes
* Fix merge issues
* Minor optimisation
* Allowed thief to choose other antags
* Review changes
* Spawn items on floor first, then inserting
* minor tweaks
* Shift as much as possible to ProtoId<>
* Remove unneeded
* Add exclusive antag attribute
* Fix merge issues
* Minor formatting fix
* Convert to struct
* Cleanup
* Review cleanup (need to test a lot)
* Some fixes, (mostly) tested
* oop
* Pass tests (for real)
---------
Co-authored-by: Rainfall <rainfey0+git@gmail.com>
Co-authored-by: AJCM <AJCM@tutanota.com>
2024-02-29 06:25:10 +00:00
|
|
|
"NukieOutpost",
|
2023-08-05 16:16:48 +12:00
|
|
|
"Box",
|
2023-09-13 22:22:21 +10:00
|
|
|
"Europa",
|
2023-08-05 16:16:48 +12:00
|
|
|
"Saltern",
|
|
|
|
|
"Core",
|
|
|
|
|
"Marathon",
|
2023-11-16 22:35:33 +00:00
|
|
|
"MeteorArena",
|
2023-12-14 22:38:05 -07:00
|
|
|
"Atlas",
|
2024-02-21 01:21:31 +03:00
|
|
|
"Reach",
|
|
|
|
|
"Train"
|
2023-08-05 16:16:48 +12:00
|
|
|
};
|
|
|
|
|
|
2022-10-17 03:44:56 +11:00
|
|
|
/// <summary>
|
|
|
|
|
/// Asserts that specific files have been saved as grids and not maps.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Test, TestCaseSource(nameof(Grids))]
|
|
|
|
|
public async Task GridsLoadableTest(string mapFile)
|
|
|
|
|
{
|
2023-08-25 02:56:51 +02:00
|
|
|
await using var pair = await PoolManager.GetServerClient();
|
|
|
|
|
var server = pair.Server;
|
2022-10-17 03:44:56 +11:00
|
|
|
|
2023-07-05 21:54:25 -07:00
|
|
|
var entManager = server.ResolveDependency<IEntityManager>();
|
|
|
|
|
var mapLoader = entManager.System<MapLoaderSystem>();
|
2022-10-17 03:44:56 +11:00
|
|
|
var mapManager = server.ResolveDependency<IMapManager>();
|
2023-04-25 11:48:29 +12:00
|
|
|
var cfg = server.ResolveDependency<IConfigurationManager>();
|
2023-05-31 11:13:02 +10:00
|
|
|
Assert.That(cfg.GetCVar(CCVars.GridFill), Is.False);
|
2022-10-17 03:44:56 +11:00
|
|
|
|
|
|
|
|
await server.WaitPost(() =>
|
|
|
|
|
{
|
|
|
|
|
var mapId = mapManager.CreateMap();
|
|
|
|
|
try
|
|
|
|
|
{
|
2023-07-05 21:54:25 -07:00
|
|
|
#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
|
2022-10-17 03:44:56 +11:00
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception($"Failed to load map {mapFile}, was it saved as a map instead of a grid?", ex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
mapManager.DeleteMap(mapId);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception($"Failed to delete map {mapFile}", ex);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
await server.WaitRunTicks(1);
|
|
|
|
|
|
2023-08-25 02:56:51 +02:00
|
|
|
await pair.CleanReturnAsync();
|
2022-10-17 03:44:56 +11:00
|
|
|
}
|
|
|
|
|
|
2020-09-02 01:16:42 +02:00
|
|
|
[Test]
|
|
|
|
|
public async Task NoSavedPostMapInitTest()
|
|
|
|
|
{
|
2023-08-25 02:56:51 +02:00
|
|
|
await using var pair = await PoolManager.GetServerClient();
|
|
|
|
|
var server = pair.Server;
|
2020-09-02 01:16:42 +02:00
|
|
|
|
|
|
|
|
var resourceManager = server.ResolveDependency<IResourceManager>();
|
2023-04-20 20:16:01 +10:00
|
|
|
var mapFolder = new ResPath("/Maps");
|
2020-09-02 01:16:42 +02:00
|
|
|
var maps = resourceManager
|
|
|
|
|
.ContentFindFiles(mapFolder)
|
2023-01-19 03:56:45 +01:00
|
|
|
.Where(filePath => filePath.Extension == "yml" && !filePath.Filename.StartsWith(".", StringComparison.Ordinal))
|
2020-09-02 01:16:42 +02:00
|
|
|
.ToArray();
|
|
|
|
|
|
|
|
|
|
foreach (var map in maps)
|
|
|
|
|
{
|
|
|
|
|
var rootedPath = map.ToRootedPath();
|
|
|
|
|
|
2020-09-12 15:47:57 +02:00
|
|
|
// ReSharper disable once RedundantLogicalConditionalExpressionOperand
|
2023-01-19 03:56:45 +01:00
|
|
|
if (SkipTestMaps && rootedPath.ToString().StartsWith(TestMapsPath, StringComparison.Ordinal))
|
2020-09-02 01:16:42 +02:00
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!resourceManager.TryContentFileRead(rootedPath, out var fileStream))
|
|
|
|
|
{
|
|
|
|
|
Assert.Fail($"Map not found: {rootedPath}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
using var reader = new StreamReader(fileStream);
|
|
|
|
|
var yamlStream = new YamlStream();
|
|
|
|
|
|
|
|
|
|
yamlStream.Load(reader);
|
|
|
|
|
|
|
|
|
|
var root = yamlStream.Documents[0].RootNode;
|
|
|
|
|
var meta = root["meta"];
|
|
|
|
|
var postMapInit = meta["postmapinit"].AsBool();
|
|
|
|
|
|
2023-07-05 21:54:25 -07:00
|
|
|
Assert.That(postMapInit, Is.False, $"Map {map.Filename} was saved postmapinit");
|
2020-09-02 01:16:42 +02:00
|
|
|
}
|
2023-08-25 02:56:51 +02:00
|
|
|
await pair.CleanReturnAsync();
|
2020-09-02 01:16:42 +02:00
|
|
|
}
|
2021-11-12 02:42:27 +00:00
|
|
|
|
2023-08-05 16:16:48 +12:00
|
|
|
[Test, TestCaseSource(nameof(GameMaps))]
|
2022-09-14 19:02:59 +10:00
|
|
|
public async Task GameMapsLoadableTest(string mapProto)
|
|
|
|
|
{
|
2023-08-25 02:56:51 +02:00
|
|
|
await using var pair = await PoolManager.GetServerClient();
|
|
|
|
|
var server = pair.Server;
|
2022-09-14 19:02:59 +10:00
|
|
|
|
|
|
|
|
var mapManager = server.ResolveDependency<IMapManager>();
|
|
|
|
|
var entManager = server.ResolveDependency<IEntityManager>();
|
2022-11-13 17:47:48 +11:00
|
|
|
var mapLoader = entManager.System<MapLoaderSystem>();
|
2022-09-14 19:02:59 +10:00
|
|
|
var protoManager = server.ResolveDependency<IPrototypeManager>();
|
|
|
|
|
var ticker = entManager.EntitySysManager.GetEntitySystem<GameTicker>();
|
|
|
|
|
var shuttleSystem = entManager.EntitySysManager.GetEntitySystem<ShuttleSystem>();
|
2022-10-17 14:24:48 +11:00
|
|
|
var xformQuery = entManager.GetEntityQuery<TransformComponent>();
|
2023-04-25 11:48:29 +12:00
|
|
|
var cfg = server.ResolveDependency<IConfigurationManager>();
|
2023-05-31 11:13:02 +10:00
|
|
|
Assert.That(cfg.GetCVar(CCVars.GridFill), Is.False);
|
2022-09-14 19:02:59 +10:00
|
|
|
|
|
|
|
|
await server.WaitPost(() =>
|
|
|
|
|
{
|
|
|
|
|
var mapId = mapManager.CreateMap();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
ticker.LoadGameMap(protoManager.Index<GameMapPrototype>(mapProto), mapId, null);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception($"Failed to load map {mapProto}", ex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var shuttleMap = mapManager.CreateMap();
|
|
|
|
|
var largest = 0f;
|
|
|
|
|
EntityUid? targetGrid = null;
|
|
|
|
|
var memberQuery = entManager.GetEntityQuery<StationMemberComponent>();
|
|
|
|
|
|
2023-10-19 12:34:31 -07:00
|
|
|
var grids = mapManager.GetAllGrids(mapId).ToList();
|
2022-12-12 14:59:02 +11:00
|
|
|
var gridUids = grids.Select(o => o.Owner).ToList();
|
2023-09-13 22:06:15 +10:00
|
|
|
targetGrid = gridUids.First();
|
2022-09-14 19:02:59 +10:00
|
|
|
|
|
|
|
|
foreach (var grid in grids)
|
|
|
|
|
{
|
2023-07-05 21:54:25 -07:00
|
|
|
var gridEnt = grid.Owner;
|
|
|
|
|
if (!memberQuery.HasComponent(gridEnt))
|
2022-09-14 19:02:59 +10:00
|
|
|
continue;
|
|
|
|
|
|
2023-10-19 12:34:31 -07:00
|
|
|
var area = grid.Comp.LocalAABB.Width * grid.Comp.LocalAABB.Height;
|
2022-09-14 19:02:59 +10:00
|
|
|
|
|
|
|
|
if (area > largest)
|
|
|
|
|
{
|
|
|
|
|
largest = area;
|
2023-07-05 21:54:25 -07:00
|
|
|
targetGrid = gridEnt;
|
2022-09-14 19:02:59 +10:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Test shuttle can dock.
|
|
|
|
|
// This is done inside gamemap test because loading the map takes ages and we already have it.
|
|
|
|
|
var station = entManager.GetComponent<StationMemberComponent>(targetGrid!.Value).Station;
|
2023-05-19 15:45:09 -05:00
|
|
|
if (entManager.TryGetComponent<StationEmergencyShuttleComponent>(station, out var stationEvac))
|
|
|
|
|
{
|
|
|
|
|
var shuttlePath = stationEvac.EmergencyShuttlePath;
|
2023-07-05 21:54:25 -07:00
|
|
|
#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}");
|
2023-05-19 15:45:09 -05:00
|
|
|
Assert.That(
|
2023-07-05 21:54:25 -07:00
|
|
|
shuttleSystem.TryFTLDock(shuttle,
|
|
|
|
|
entManager.GetComponent<ShuttleComponent>(shuttle), targetGrid.Value),
|
2023-05-19 15:45:09 -05:00
|
|
|
$"Unable to dock {shuttlePath} to {mapProto}");
|
2023-07-05 21:54:25 -07:00
|
|
|
#pragma warning restore NUnit2045
|
2023-05-19 15:45:09 -05:00
|
|
|
}
|
2022-09-14 19:02:59 +10:00
|
|
|
|
|
|
|
|
mapManager.DeleteMap(shuttleMap);
|
|
|
|
|
|
2023-05-19 15:45:09 -05:00
|
|
|
if (entManager.HasComponent<StationJobsComponent>(station))
|
2022-10-17 14:24:48 +11:00
|
|
|
{
|
2024-02-25 17:54:44 +04:00
|
|
|
// Test that the map has valid latejoin spawn points or container spawn points
|
2023-05-19 15:45:09 -05:00
|
|
|
if (!NoSpawnMaps.Contains(mapProto))
|
2022-10-17 14:24:48 +11:00
|
|
|
{
|
2023-05-19 15:45:09 -05:00
|
|
|
var lateSpawns = 0;
|
|
|
|
|
|
2024-02-25 17:54:44 +04:00
|
|
|
lateSpawns += GetCountLateSpawn<SpawnPointComponent>(gridUids, entManager);
|
|
|
|
|
lateSpawns += GetCountLateSpawn<ContainerSpawnPointComponent>(gridUids, entManager);
|
2022-10-17 14:24:48 +11:00
|
|
|
|
2023-05-19 15:45:09 -05:00
|
|
|
Assert.That(lateSpawns, Is.GreaterThan(0), $"Found no latejoin spawn points on {mapProto}");
|
2022-10-17 14:24:48 +11:00
|
|
|
}
|
|
|
|
|
|
2023-05-19 15:45:09 -05:00
|
|
|
// Test all availableJobs have spawnPoints
|
|
|
|
|
// This is done inside gamemap test because loading the map takes ages and we already have it.
|
|
|
|
|
var jobList = entManager.GetComponent<StationJobsComponent>(station).RoundStartJobList
|
|
|
|
|
.Where(x => x.Value != 0)
|
|
|
|
|
.Select(x => x.Key);
|
|
|
|
|
var spawnPoints = entManager.EntityQuery<SpawnPointComponent>()
|
|
|
|
|
.Where(spawnpoint => spawnpoint.SpawnType == SpawnPointType.Job)
|
|
|
|
|
.Select(spawnpoint => spawnpoint.Job.ID)
|
|
|
|
|
.Distinct();
|
|
|
|
|
List<string> missingSpawnPoints = new();
|
|
|
|
|
foreach (var spawnpoint in jobList.Except(spawnPoints))
|
|
|
|
|
{
|
|
|
|
|
if (protoManager.Index<JobPrototype>(spawnpoint).SetPreference)
|
|
|
|
|
missingSpawnPoints.Add(spawnpoint);
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-05 21:54:25 -07:00
|
|
|
Assert.That(missingSpawnPoints, Has.Count.EqualTo(0),
|
|
|
|
|
$"There is no spawnpoint for {string.Join(", ", missingSpawnPoints)} on {mapProto}.");
|
2022-10-15 22:18:48 +02:00
|
|
|
}
|
|
|
|
|
|
2022-09-14 19:02:59 +10:00
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
mapManager.DeleteMap(mapId);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception($"Failed to delete map {mapProto}", ex);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
await server.WaitRunTicks(1);
|
|
|
|
|
|
2023-08-25 02:56:51 +02:00
|
|
|
await pair.CleanReturnAsync();
|
2022-09-14 19:02:59 +10:00
|
|
|
}
|
|
|
|
|
|
2024-02-25 17:54:44 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
private static int GetCountLateSpawn<T>(List<EntityUid> gridUids, IEntityManager entManager)
|
|
|
|
|
where T : ISpawnPoint, IComponent
|
|
|
|
|
{
|
|
|
|
|
var resultCount = 0;
|
|
|
|
|
var queryPoint = entManager.AllEntityQueryEnumerator<T, TransformComponent>();
|
|
|
|
|
#nullable enable
|
|
|
|
|
while (queryPoint.MoveNext(out T? comp, out var xform))
|
|
|
|
|
{
|
|
|
|
|
var spawner = (ISpawnPoint) comp;
|
|
|
|
|
|
|
|
|
|
if (spawner.SpawnType is not SpawnPointType.LateJoin
|
|
|
|
|
|| xform.GridUid == null
|
|
|
|
|
|| !gridUids.Contains(xform.GridUid.Value))
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
#nullable disable
|
|
|
|
|
resultCount++;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return resultCount;
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-05 16:16:48 +12:00
|
|
|
[Test]
|
|
|
|
|
public async Task AllMapsTested()
|
2022-09-14 19:02:59 +10:00
|
|
|
{
|
2023-08-25 02:56:51 +02:00
|
|
|
await using var pair = await PoolManager.GetServerClient();
|
|
|
|
|
var server = pair.Server;
|
2023-08-05 16:16:48 +12:00
|
|
|
var protoMan = server.ResolveDependency<IPrototypeManager>();
|
2022-06-19 20:22:28 -07:00
|
|
|
|
2023-08-05 16:16:48 +12:00
|
|
|
var gameMaps = protoMan.EnumeratePrototypes<GameMapPrototype>()
|
2023-08-25 02:56:51 +02:00
|
|
|
.Where(x => !pair.IsTestPrototype(x))
|
2023-08-05 16:16:48 +12:00
|
|
|
.Select(x => x.ID)
|
|
|
|
|
.ToHashSet();
|
2022-06-19 20:22:28 -07:00
|
|
|
|
2023-08-05 16:16:48 +12:00
|
|
|
Assert.That(gameMaps.Remove(PoolManager.TestMap));
|
2022-06-19 20:22:28 -07:00
|
|
|
|
2024-01-12 23:22:01 +01:00
|
|
|
Assert.That(gameMaps, Is.EquivalentTo(GameMaps.ToHashSet()), "Game map prototype missing from test cases.");
|
2023-08-05 16:16:48 +12:00
|
|
|
|
2023-08-25 02:56:51 +02:00
|
|
|
await pair.CleanReturnAsync();
|
2022-06-19 20:22:28 -07:00
|
|
|
}
|
2021-11-12 02:42:27 +00:00
|
|
|
|
2023-08-05 16:16:48 +12:00
|
|
|
[Test]
|
|
|
|
|
public async Task NonGameMapsLoadableTest()
|
2022-06-19 20:22:28 -07:00
|
|
|
{
|
2023-08-25 02:56:51 +02:00
|
|
|
await using var pair = await PoolManager.GetServerClient();
|
|
|
|
|
var server = pair.Server;
|
2021-11-12 02:42:27 +00:00
|
|
|
|
2022-11-13 17:47:48 +11:00
|
|
|
var mapLoader = server.ResolveDependency<IEntitySystemManager>().GetEntitySystem<MapLoaderSystem>();
|
2021-11-12 02:42:27 +00:00
|
|
|
var mapManager = server.ResolveDependency<IMapManager>();
|
2023-08-05 16:16:48 +12:00
|
|
|
var resourceManager = server.ResolveDependency<IResourceManager>();
|
|
|
|
|
var protoManager = server.ResolveDependency<IPrototypeManager>();
|
2023-04-25 11:48:29 +12:00
|
|
|
var cfg = server.ResolveDependency<IConfigurationManager>();
|
2023-05-31 11:13:02 +10:00
|
|
|
Assert.That(cfg.GetCVar(CCVars.GridFill), Is.False);
|
2021-11-12 02:42:27 +00:00
|
|
|
|
2023-08-05 16:16:48 +12:00
|
|
|
var gameMaps = protoManager.EnumeratePrototypes<GameMapPrototype>().Select(o => o.MapPath).ToHashSet();
|
|
|
|
|
|
|
|
|
|
var mapFolder = new ResPath("/Maps");
|
|
|
|
|
var maps = resourceManager
|
|
|
|
|
.ContentFindFiles(mapFolder)
|
|
|
|
|
.Where(filePath => filePath.Extension == "yml" && !filePath.Filename.StartsWith(".", StringComparison.Ordinal))
|
|
|
|
|
.ToArray();
|
|
|
|
|
|
|
|
|
|
var mapNames = new List<string>();
|
|
|
|
|
foreach (var map in maps)
|
2021-11-12 02:42:27 +00:00
|
|
|
{
|
2023-08-05 16:16:48 +12:00
|
|
|
if (gameMaps.Contains(map))
|
|
|
|
|
continue;
|
2021-11-12 02:42:27 +00:00
|
|
|
|
2023-08-05 16:16:48 +12:00
|
|
|
var rootedPath = map.ToRootedPath();
|
|
|
|
|
if (SkipTestMaps && rootedPath.ToString().StartsWith(TestMapsPath, StringComparison.Ordinal))
|
2021-11-12 02:42:27 +00:00
|
|
|
{
|
2023-08-05 16:16:48 +12:00
|
|
|
continue;
|
2022-06-19 20:22:28 -07:00
|
|
|
}
|
2023-08-05 16:16:48 +12:00
|
|
|
mapNames.Add(rootedPath.ToString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await server.WaitPost(() =>
|
|
|
|
|
{
|
|
|
|
|
Assert.Multiple(() =>
|
2022-06-19 20:22:28 -07:00
|
|
|
{
|
2023-08-05 16:16:48 +12:00
|
|
|
foreach (var mapName in mapNames)
|
|
|
|
|
{
|
|
|
|
|
var mapId = mapManager.CreateMap();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Assert.That(mapLoader.TryLoad(mapId, mapName, out _));
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception($"Failed to load map {mapName}", ex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
mapManager.DeleteMap(mapId);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception($"Failed to delete map {mapName}", ex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
2022-06-19 20:22:28 -07:00
|
|
|
});
|
|
|
|
|
|
2023-08-05 16:16:48 +12:00
|
|
|
await server.WaitRunTicks(1);
|
2023-08-25 02:56:51 +02:00
|
|
|
await pair.CleanReturnAsync();
|
2021-11-12 02:42:27 +00:00
|
|
|
}
|
2020-09-02 01:16:42 +02:00
|
|
|
}
|
|
|
|
|
}
|