Add some tests and fix some miscellaneous bugs (#22836)
* Add some tests and fix some bugs * Add more helper methods * remove submodule * fix merge * also fix DirtyAll() * poke
This commit is contained in:
@@ -134,9 +134,9 @@ public abstract partial class InteractionTest
|
||||
/// <remarks>
|
||||
/// Automatically enables welders.
|
||||
/// </remarks>
|
||||
protected async Task<EntityUid?> PlaceInHands(string? id, int quantity = 1, bool enableWelder = true)
|
||||
protected async Task<NetEntity> PlaceInHands(string id, int quantity = 1, bool enableWelder = true)
|
||||
{
|
||||
return await PlaceInHands(id == null ? null : (id, quantity), enableWelder);
|
||||
return await PlaceInHands((id, quantity), enableWelder);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -145,7 +145,7 @@ public abstract partial class InteractionTest
|
||||
/// <remarks>
|
||||
/// Automatically enables welders.
|
||||
/// </remarks>
|
||||
protected async Task<EntityUid?> PlaceInHands(EntitySpecifier? entity, bool enableWelder = true)
|
||||
protected async Task<NetEntity> PlaceInHands(EntitySpecifier entity, bool enableWelder = true)
|
||||
{
|
||||
if (Hands.ActiveHand == null)
|
||||
{
|
||||
@@ -153,15 +153,9 @@ public abstract partial class InteractionTest
|
||||
return default;
|
||||
}
|
||||
|
||||
Assert.That(!string.IsNullOrWhiteSpace(entity.Prototype));
|
||||
await DeleteHeldEntity();
|
||||
|
||||
if (entity == null || string.IsNullOrWhiteSpace(entity.Prototype))
|
||||
{
|
||||
await RunTicks(1);
|
||||
Assert.That(Hands.ActiveHandEntity, Is.Null);
|
||||
return null;
|
||||
}
|
||||
|
||||
// spawn and pick up the new item
|
||||
var item = await SpawnEntity(entity, SEntMan.GetCoordinates(PlayerCoords));
|
||||
ItemToggleComponent? itemToggle = null;
|
||||
@@ -184,7 +178,7 @@ public abstract partial class InteractionTest
|
||||
if (enableWelder && itemToggle != null)
|
||||
Assert.That(itemToggle.Activated);
|
||||
|
||||
return item;
|
||||
return SEntMan.GetNetEntity(item);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -330,6 +324,17 @@ public abstract partial class InteractionTest
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throw the currently held entity. Defaults to targeting the current <see cref="TargetCoords"/>
|
||||
/// </summary>
|
||||
protected async Task<bool> ThrowItem(NetCoordinates? target = null, float minDistance = 4)
|
||||
{
|
||||
var actualTarget = SEntMan.GetCoordinates(target ?? TargetCoords);
|
||||
var result = false;
|
||||
await Server.WaitPost(() => result = HandSys.ThrowHeldItem(SEntMan.GetEntity(Player), actualTarget, minDistance));
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
@@ -483,7 +488,7 @@ public abstract partial class InteractionTest
|
||||
});
|
||||
}
|
||||
|
||||
protected void AssertDeleted(bool deleted = true, NetEntity? target = null)
|
||||
protected void AssertDeleted(NetEntity? target = null)
|
||||
{
|
||||
target ??= Target;
|
||||
if (target == null)
|
||||
@@ -494,8 +499,24 @@ public abstract partial class InteractionTest
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(SEntMan.Deleted(SEntMan.GetEntity(target)), Is.EqualTo(deleted));
|
||||
Assert.That(CEntMan.Deleted(CEntMan.GetEntity(target)), Is.EqualTo(deleted));
|
||||
Assert.That(SEntMan.Deleted(SEntMan.GetEntity(target)));
|
||||
Assert.That(CEntMan.Deleted(CEntMan.GetEntity(target)));
|
||||
});
|
||||
}
|
||||
|
||||
protected void AssertExists(NetEntity? target = null)
|
||||
{
|
||||
target ??= Target;
|
||||
if (target == null)
|
||||
{
|
||||
Assert.Fail("No target specified");
|
||||
return;
|
||||
}
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(SEntMan.EntityExists(SEntMan.GetEntity(target)));
|
||||
Assert.That(CEntMan.EntityExists(CEntMan.GetEntity(target)));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -733,6 +754,11 @@ public abstract partial class InteractionTest
|
||||
await RunTicks(5);
|
||||
}
|
||||
|
||||
protected Task Delete(NetEntity nuid)
|
||||
{
|
||||
return Delete(SEntMan.GetEntity(nuid));
|
||||
}
|
||||
|
||||
#region Time/Tick managment
|
||||
|
||||
protected async Task RunTicks(int ticks)
|
||||
@@ -1064,4 +1090,35 @@ public abstract partial class InteractionTest
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Networking
|
||||
|
||||
protected EntityUid ToServer(NetEntity nent) => SEntMan.GetEntity(nent);
|
||||
protected EntityUid ToClient(NetEntity nent) => CEntMan.GetEntity(nent);
|
||||
protected EntityUid? ToServer(NetEntity? nent) => SEntMan.GetEntity(nent);
|
||||
protected EntityUid? ToClient(NetEntity? nent) => CEntMan.GetEntity(nent);
|
||||
protected EntityUid ToServer(EntityUid cuid) => SEntMan.GetEntity(CEntMan.GetNetEntity(cuid));
|
||||
protected EntityUid ToClient(EntityUid cuid) => CEntMan.GetEntity(SEntMan.GetNetEntity(cuid));
|
||||
protected EntityUid? ToServer(EntityUid? cuid) => SEntMan.GetEntity(CEntMan.GetNetEntity(cuid));
|
||||
protected EntityUid? ToClient(EntityUid? cuid) => CEntMan.GetEntity(SEntMan.GetNetEntity(cuid));
|
||||
|
||||
protected EntityCoordinates ToServer(NetCoordinates coords) => SEntMan.GetCoordinates(coords);
|
||||
protected EntityCoordinates ToClient(NetCoordinates coords) => CEntMan.GetCoordinates(coords);
|
||||
protected EntityCoordinates? ToServer(NetCoordinates? coords) => SEntMan.GetCoordinates(coords);
|
||||
protected EntityCoordinates? ToClient(NetCoordinates? coords) => CEntMan.GetCoordinates(coords);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Metadata & Transforms
|
||||
|
||||
protected MetaDataComponent Meta(NetEntity uid) => Meta(ToServer(uid));
|
||||
protected MetaDataComponent Meta(EntityUid uid) => SEntMan.GetComponent<MetaDataComponent>(uid);
|
||||
|
||||
protected TransformComponent Xform(NetEntity uid) => Xform(ToServer(uid));
|
||||
protected TransformComponent Xform(EntityUid uid) => SEntMan.GetComponent<TransformComponent>(uid);
|
||||
|
||||
protected EntityCoordinates Position(NetEntity uid) => Position(ToServer(uid));
|
||||
protected EntityCoordinates Position(EntityUid uid) => Xform(uid).Coordinates;
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
@@ -5,12 +5,12 @@ using Content.Client.Construction;
|
||||
using Content.Client.Examine;
|
||||
using Content.IntegrationTests.Pair;
|
||||
using Content.Server.Body.Systems;
|
||||
using Content.Server.Hands.Systems;
|
||||
using Content.Server.Stack;
|
||||
using Content.Server.Tools;
|
||||
using Content.Shared.Body.Part;
|
||||
using Content.Shared.DoAfter;
|
||||
using Content.Shared.Hands.Components;
|
||||
using Content.Shared.Hands.EntitySystems;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Server.Item;
|
||||
using Content.Shared.Mind;
|
||||
@@ -66,6 +66,9 @@ public abstract partial class InteractionTest
|
||||
/// </summary>
|
||||
protected NetEntity Player;
|
||||
|
||||
protected EntityUid SPlayer => ToServer(Player);
|
||||
protected EntityUid CPlayer => ToClient(Player);
|
||||
|
||||
protected ICommonSession ClientSession = default!;
|
||||
protected ICommonSession ServerSession = default!;
|
||||
|
||||
@@ -81,6 +84,9 @@ public abstract partial class InteractionTest
|
||||
/// </remarks>
|
||||
protected NetEntity? Target;
|
||||
|
||||
protected EntityUid? STarget => ToServer(Target);
|
||||
protected EntityUid? CTarget => ToClient(Target);
|
||||
|
||||
/// <summary>
|
||||
/// When attempting to start construction, this is the client-side ID of the construction ghost.
|
||||
/// </summary>
|
||||
@@ -93,7 +99,7 @@ public abstract partial class InteractionTest
|
||||
protected IPrototypeManager ProtoMan = default!;
|
||||
protected IGameTiming STiming = default!;
|
||||
protected IComponentFactory Factory = default!;
|
||||
protected SharedHandsSystem HandSys = default!;
|
||||
protected HandsSystem HandSys = default!;
|
||||
protected StackSystem Stack = default!;
|
||||
protected SharedInteractionSystem InteractSys = default!;
|
||||
protected Content.Server.Construction.ConstructionSystem SConstruction = default!;
|
||||
@@ -152,7 +158,7 @@ public abstract partial class InteractionTest
|
||||
ProtoMan = Server.ResolveDependency<IPrototypeManager>();
|
||||
Factory = Server.ResolveDependency<IComponentFactory>();
|
||||
STiming = Server.ResolveDependency<IGameTiming>();
|
||||
HandSys = SEntMan.System<SharedHandsSystem>();
|
||||
HandSys = SEntMan.System<HandsSystem>();
|
||||
InteractSys = SEntMan.System<SharedInteractionSystem>();
|
||||
ToolSys = SEntMan.System<ToolSystem>();
|
||||
ItemToggleSys = SEntMan.System<SharedItemToggleSystem>();
|
||||
|
||||
Reference in New Issue
Block a user