using Content.Server.Preferences.Managers;
using Content.Shared.Preferences;
using Content.Shared.Roles;
+using Robust.Shared.EntitySerialization;
+using Robust.Shared.EntitySerialization.Systems;
+using Robust.Shared.GameObjects;
+using Robust.Shared.Map;
using Robust.Shared.Network;
using Robust.Shared.Prototypes;
+using Robust.Shared.Utility;
namespace Content.IntegrationTests.Pair;
public Task<TestMapData> CreateTestMap(bool initialized = true)
=> CreateTestMap(initialized, "Plating");
+ /// <summary>
+ /// Loads a test map and returns a <see cref="TestMapData"/> representing it.
+ /// </summary>
+ /// <param name="testMapPath">The <see cref="ResPath"/> to the test map to load.</param>
+ /// <param name="initialized">Whether to initialize the map on load.</param>
+ /// <returns>A <see cref="TestMapData"/> representing the loaded map.</returns>
+ public async Task<TestMapData> LoadTestMap(ResPath testMapPath, bool initialized = true)
+ {
+ TestMapData mapData = new();
+ var deserializationOptions = DeserializationOptions.Default with { InitializeMaps = initialized };
+ var mapLoaderSys = Server.EntMan.System<MapLoaderSystem>();
+ var mapSys = Server.System<SharedMapSystem>();
+
+ // Load our test map in and assert that it exists.
+ await Server.WaitAssertion(() =>
+ {
+ Assert.That(mapLoaderSys.TryLoadMap(testMapPath, out var map, out var gridSet, deserializationOptions),
+ $"Failed to load map {testMapPath}.");
+ Assert.That(gridSet, Is.Not.Empty, "There were no grids loaded from the map!");
+
+ mapData.MapUid = map!.Value.Owner;
+ mapData.MapId = map!.Value.Comp.MapId;
+ mapData.Grid = gridSet!.First();
+ mapData.GridCoords = new EntityCoordinates(mapData.Grid, 0, 0);
+ mapData.MapCoords = new MapCoordinates(0, 0, mapData.MapId);
+ mapData.Tile = mapSys.GetAllTiles(mapData.Grid.Owner, mapData.Grid.Comp).First();
+ });
+
+ await RunTicksSync(10);
+ mapData.CMapUid = ToClientUid(mapData.MapUid);
+ mapData.CGridUid = ToClientUid(mapData.Grid);
+ mapData.CGridCoords = new EntityCoordinates(mapData.CGridUid, 0, 0);
+
+ return mapData;
+ }
+
/// <summary>
/// Set a user's antag preferences. Modified preferences are automatically reset at the end of the test.
/// </summary>
public async Task SetAntagPreference(ProtoId<AntagPrototype> id, bool value, NetUserId? user = null)
{
user ??= Client.User!.Value;
- if (user is not {} userId)
+ if (user is not { } userId)
return;
var prefMan = Server.ResolveDependency<IServerPreferencesManager>();
// Automatic preference resetting only resets slot 0.
Assert.That(prefs.SelectedCharacterIndex, Is.EqualTo(0));
- var profile = (HumanoidCharacterProfile) prefs.Characters[0];
+ var profile = (HumanoidCharacterProfile)prefs.Characters[0];
var newProfile = profile.WithAntagPreference(id, value);
_modifiedProfiles.Add(userId);
await Server.WaitPost(() => prefMan.SetProfile(userId, 0, newProfile).Wait());
var prefMan = Server.ResolveDependency<IServerPreferencesManager>();
var prefs = prefMan.GetPreferences(user);
- var profile = (HumanoidCharacterProfile) prefs.Characters[0];
+ var profile = (HumanoidCharacterProfile)prefs.Characters[0];
var dictionary = new Dictionary<ProtoId<JobPrototype>, JobPriority>(profile.JobPriorities);
// Automatic preference resetting only resets slot 0.
using Robust.Shared.Player;
using Robust.Shared.Prototypes;
using Robust.Shared.Timing;
+using Robust.Shared.Utility;
using Robust.UnitTesting;
namespace Content.IntegrationTests.Tests.Interaction;
[FixtureLifeCycle(LifeCycle.InstancePerTestCase)]
public abstract partial class InteractionTest
{
+ /// <summary>
+ /// The prototype that will be spawned for the player entity at <see cref="PlayerCoords"/>.
+ /// This is not a full humanoid and only has one hand by default.
+ /// </summary>
protected virtual string PlayerPrototype => "InteractionTestMob";
+ /// <summary>
+ /// The map path to load for the integration test.
+ /// If null an empty map with a single 1x1 plating grid will be generated.
+ /// </summary>
+ protected virtual ResPath? TestMapPath => null;
+
protected TestPair Pair = default!;
- protected TestMapData MapData => Pair.TestMap!;
+ protected TestMapData MapData = default!;
protected RobustIntegrationTest.ServerIntegrationInstance Server => Pair.Server;
protected RobustIntegrationTest.ClientIntegrationInstance Client => Pair.Client;
CUiSys = CEntMan.System<SharedUserInterfaceSystem>();
// Setup map.
- await Pair.CreateTestMap();
+ if (TestMapPath == null)
+ MapData = await Pair.CreateTestMap();
+ else
+ MapData = await Pair.LoadTestMap(TestMapPath.Value);
PlayerCoords = SEntMan.GetNetCoordinates(Transform.WithEntityId(MapData.GridCoords.Offset(new Vector2(0.5f, 0.5f)), MapData.MapUid));
TargetCoords = SEntMan.GetNetCoordinates(Transform.WithEntityId(MapData.GridCoords.Offset(new Vector2(1.5f, 0.5f)), MapData.MapUid));
--- /dev/null
+using System.Linq;
+using Robust.Shared.GameObjects;
+using Robust.Shared.Map.Components;
+using Robust.Shared.Utility;
+
+namespace Content.IntegrationTests.Tests.Interaction;
+
+/// <summary>
+/// Makes sure that interaction test helper methods are working as intended.
+/// </summary>
+public sealed class InteractionTestTests : InteractionTest
+{
+ protected override ResPath? TestMapPath => new("Maps/Test/empty.yml");
+
+ /// <summary>
+ /// Tests that map loading is working correctly.
+ /// </summary>
+ [Test]
+ public void MapLoadingTest()
+ {
+ // Make sure that there is only one grid.
+ var grids = SEntMan.AllEntities<MapGridComponent>().ToList();
+ Assert.That(grids, Has.Count.EqualTo(1), "Test map did not have exactly one grid.");
+ Assert.That(grids, Does.Contain(MapData.Grid), "MapData did not contain the loaded grid.");
+
+ // Make sure we loaded the right map.
+ // This name is defined in empty.yml
+ Assert.That(SEntMan.GetComponent<MetaDataComponent>(MapData.MapUid).EntityName, Is.EqualTo("Empty Debug Map"));
+ }
+}
+