Files
OldThink/Content.IntegrationTests/Tests/ClickableTest.cs

94 lines
5.2 KiB
C#
Raw Normal View History

2021-02-22 00:46:27 +01:00
using System;
using System.Threading.Tasks;
2021-06-09 22:19:39 +02:00
using Content.Client.Clickable;
2021-02-22 00:46:27 +01:00
using NUnit.Framework;
2022-02-09 15:11:06 +13:00
using Robust.Client.Graphics;
2021-02-22 00:46:27 +01:00
using Robust.Server.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.Map;
namespace Content.IntegrationTests.Tests
{
[TestFixture]
public sealed class ClickableTest
2021-02-22 00:46:27 +01:00
{
private const double DirSouth = 0;
private const double DirNorth = Math.PI;
private const double DirEast = Math.PI / 2;
private const double DirSouthEast = Math.PI / 4;
private const double DirSouthEastJustShy = Math.PI / 4 - 0.1;
[Test]
[TestCase("ClickTestRotatingCornerVisible", 0.25f, 0.25f, DirSouth, 1, ExpectedResult = true)]
[TestCase("ClickTestRotatingCornerVisible", 0.35f, 0.5f, DirSouth, 2, ExpectedResult = true)]
[TestCase("ClickTestRotatingCornerVisible", -0.25f, -0.25f, DirSouth, 1, ExpectedResult = false)]
[TestCase("ClickTestRotatingCornerVisible", 0.25f, 0.25f, DirNorth, 1, ExpectedResult = false)]
[TestCase("ClickTestRotatingCornerVisible", -0.25f, -0.25f, DirNorth, 1, ExpectedResult = true)]
[TestCase("ClickTestRotatingCornerVisible", -0.25f, 0.25f, DirEast, 1, ExpectedResult = true)]
[TestCase("ClickTestRotatingCornerVisible", 0, 0.25f, DirSouthEast, 1, ExpectedResult = true)]
[TestCase("ClickTestRotatingCornerVisibleNoRot", 0.25f, 0.25f, DirSouth, 1, ExpectedResult = true)]
[TestCase("ClickTestRotatingCornerVisibleNoRot", -0.25f, -0.25f, DirSouth, 1, ExpectedResult = false)]
[TestCase("ClickTestRotatingCornerVisibleNoRot", 0.25f, 0.25f, DirNorth, 1, ExpectedResult = false)]
[TestCase("ClickTestRotatingCornerVisibleNoRot", -0.25f, -0.25f, DirNorth, 1, ExpectedResult = true)]
[TestCase("ClickTestRotatingCornerVisibleNoRot", 0, 0.35f, DirSouthEastJustShy, 1, ExpectedResult = false)]
[TestCase("ClickTestRotatingCornerVisibleNoRot", 0.25f, 0.25f, DirSouthEastJustShy, 1, ExpectedResult = true)]
[TestCase("ClickTestRotatingCornerInvisible", 0.25f, 0.25f, DirSouth, 1, ExpectedResult = true)]
[TestCase("ClickTestRotatingCornerInvisible", 0.35f, 0.5f, DirSouth, 2, ExpectedResult = true)]
[TestCase("ClickTestRotatingCornerInvisible", -0.25f, -0.25f, DirSouth, 1, ExpectedResult = false)]
[TestCase("ClickTestRotatingCornerInvisible", 0.25f, 0.25f, DirNorth, 1, ExpectedResult = false)]
[TestCase("ClickTestRotatingCornerInvisible", -0.25f, -0.25f, DirNorth, 1, ExpectedResult = true)]
[TestCase("ClickTestRotatingCornerInvisible", -0.25f, 0.25f, DirEast, 1, ExpectedResult = true)]
[TestCase("ClickTestRotatingCornerInvisible", 0, 0.25f, DirSouthEast, 1, ExpectedResult = true)]
[TestCase("ClickTestRotatingCornerInvisibleNoRot", 0.25f, 0.25f, DirSouth, 1, ExpectedResult = true)]
[TestCase("ClickTestRotatingCornerInvisibleNoRot", -0.25f, -0.25f, DirSouth, 1, ExpectedResult = false)]
[TestCase("ClickTestRotatingCornerInvisibleNoRot", 0.25f, 0.25f, DirNorth, 1, ExpectedResult = false)]
[TestCase("ClickTestRotatingCornerInvisibleNoRot", -0.25f, -0.25f, DirNorth, 1, ExpectedResult = true)]
[TestCase("ClickTestRotatingCornerInvisibleNoRot", 0, 0.35f, DirSouthEastJustShy, 1, ExpectedResult = false)]
[TestCase("ClickTestRotatingCornerInvisibleNoRot", 0.25f, 0.25f, DirSouthEastJustShy, 1, ExpectedResult = true)]
public async Task<bool> Test(string prototype, float clickPosX, float clickPosY, double angle, float scale)
{
await using var pairTracker = await PoolManager.GetServerClient();
var server = pairTracker.Pair.Server;
var client = pairTracker.Pair.Client;
2021-02-22 00:46:27 +01:00
EntityUid entity = default;
var clientEntManager = client.ResolveDependency<IEntityManager>();
var serverEntManager = server.ResolveDependency<IEntityManager>();
var eyeManager = client.ResolveDependency<IEyeManager>();
2021-02-22 00:46:27 +01:00
2022-06-21 07:44:19 -07:00
var testMap = await PoolManager.CreateTestMap(pairTracker);
await server.WaitPost(() =>
2021-02-22 00:46:27 +01:00
{
2022-06-21 07:44:19 -07:00
var ent = serverEntManager.SpawnEntity(prototype, testMap.GridCoords);
serverEntManager.GetComponent<TransformComponent>(ent).WorldRotation = angle;
serverEntManager.GetComponent<SpriteComponent>(ent).Scale = (scale, scale);
2021-12-03 15:53:09 +01:00
entity = ent;
2021-02-22 00:46:27 +01:00
});
// Let client sync up.
await PoolManager.RunTicksSync(pairTracker.Pair, 5);
2021-02-22 00:46:27 +01:00
var hit = false;
await client.WaitPost(() =>
2021-02-22 00:46:27 +01:00
{
2022-02-09 15:11:06 +13:00
// these tests currently all assume player eye is 0
eyeManager.CurrentEye.Rotation = 0;
var pos = clientEntManager.GetComponent<TransformComponent>(entity).WorldPosition;
var clickable = clientEntManager.GetComponent<ClickableComponent>(entity);
2021-02-22 00:46:27 +01:00
hit = clickable.CheckClick((clickPosX, clickPosY) + pos, out _, out _);
2021-02-22 00:46:27 +01:00
});
await server.WaitPost(() =>
2021-04-02 21:10:06 +11:00
{
serverEntManager.DeleteEntity(entity);
2021-04-02 21:10:06 +11:00
});
await pairTracker.CleanReturnAsync();
2021-02-22 00:46:27 +01:00
return hit;
}
}
}