Add interaction tests (#15251)

This commit is contained in:
Leon Friedrich
2023-04-15 07:41:25 +12:00
committed by GitHub
parent ffe946729f
commit 489660a6bb
36 changed files with 2354 additions and 32 deletions

View File

@@ -1,3 +1,4 @@
using System.Diagnostics.CodeAnalysis;
using Content.Shared.Construction;
using Content.Shared.Construction.Prototypes;
using Content.Shared.Examine;
@@ -151,33 +152,45 @@ namespace Content.Client.Construction
/// Creates a construction ghost at the given location.
/// </summary>
public void SpawnGhost(ConstructionPrototype prototype, EntityCoordinates loc, Direction dir)
=> TrySpawnGhost(prototype, loc, dir, out _);
/// <summary>
/// Creates a construction ghost at the given location.
/// </summary>
public bool TrySpawnGhost(
ConstructionPrototype prototype,
EntityCoordinates loc,
Direction dir,
[NotNullWhen(true)] out EntityUid? ghost)
{
ghost = null;
if (_playerManager.LocalPlayer?.ControlledEntity is not { } user ||
!user.IsValid())
{
return;
return false;
}
if (GhostPresent(loc)) return;
if (GhostPresent(loc))
return false;
// This InRangeUnobstructed should probably be replaced with "is there something blocking us in that tile?"
var predicate = GetPredicate(prototype.CanBuildInImpassable, loc.ToMap(EntityManager));
if (!_interactionSystem.InRangeUnobstructed(user, loc, 20f, predicate: predicate))
return;
return false;
foreach (var condition in prototype.Conditions)
{
if (!condition.Condition(user, loc, dir))
return;
return false;
}
var ghost = EntityManager.SpawnEntity("constructionghost", loc);
var comp = EntityManager.GetComponent<ConstructionGhostComponent>(ghost);
ghost = EntityManager.SpawnEntity("constructionghost", loc);
var comp = EntityManager.GetComponent<ConstructionGhostComponent>(ghost.Value);
comp.Prototype = prototype;
comp.GhostId = _nextId++;
EntityManager.GetComponent<TransformComponent>(ghost).LocalRotation = dir.ToAngle();
EntityManager.GetComponent<TransformComponent>(ghost.Value).LocalRotation = dir.ToAngle();
_ghosts.Add(comp.GhostId, comp);
var sprite = EntityManager.GetComponent<SpriteComponent>(ghost);
var sprite = EntityManager.GetComponent<SpriteComponent>(ghost.Value);
sprite.Color = new Color(48, 255, 48, 128);
for (int i = 0; i < prototype.Layers.Count; i++)
@@ -189,7 +202,9 @@ namespace Content.Client.Construction
}
if (prototype.CanBuildInImpassable)
EnsureComp<WallMountComponent>(ghost).Arc = new(Math.Tau);
EnsureComp<WallMountComponent>(ghost.Value).Arc = new(Math.Tau);
return true;
}
/// <summary>
@@ -205,7 +220,7 @@ namespace Content.Client.Construction
return false;
}
private void TryStartConstruction(int ghostId)
public void TryStartConstruction(int ghostId)
{
var ghost = _ghosts[ghostId];