]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Strip drag drop test (#30754)
authorShadowCommander <10494922+ShadowCommander@users.noreply.github.com>
Thu, 8 Aug 2024 02:12:01 +0000 (19:12 -0700)
committerGitHub <noreply@github.com>
Thu, 8 Aug 2024 02:12:01 +0000 (12:12 +1000)
* Add test for drag drop to open strip menu

* Make screencoords change based on deadzone

Content.Client/Interaction/DragDropSystem.cs
Content.IntegrationTests/Tests/Interaction/InteractionTest.Helpers.cs
Content.IntegrationTests/Tests/Strip/StrippableTest.cs [new file with mode: 0644]

index a34cd0f5b11ede7f1b2aabc3f7285030686a4f08..41459995796e9fc7b63ae299aa8ffa8ff8e749cf 100644 (file)
@@ -90,7 +90,7 @@ public sealed class DragDropSystem : SharedDragDropSystem
     /// </summary>
     private bool _isReplaying;
 
-    private float _deadzone;
+    public float Deadzone;
 
     private DragState _state = DragState.NotDragging;
 
@@ -122,7 +122,7 @@ public sealed class DragDropSystem : SharedDragDropSystem
 
     private void SetDeadZone(float deadZone)
     {
-        _deadzone = deadZone;
+        Deadzone = deadZone;
     }
 
     public override void Shutdown()
@@ -212,7 +212,7 @@ public sealed class DragDropSystem : SharedDragDropSystem
 
         _draggedEntity = entity;
         _state = DragState.MouseDown;
-        _mouseDownScreenPos = _inputManager.MouseScreenPosition;
+        _mouseDownScreenPos = args.ScreenCoordinates;
         _mouseDownTime = 0;
 
         // don't want anything else to process the click,
@@ -240,8 +240,13 @@ public sealed class DragDropSystem : SharedDragDropSystem
 
         if (TryComp<SpriteComponent>(_draggedEntity, out var draggedSprite))
         {
+            var screenPos = _inputManager.MouseScreenPosition;
+            // No _draggedEntity in null window (Happens in tests)
+            if (!screenPos.IsValid)
+                return;
+
             // pop up drag shadow under mouse
-            var mousePos = _eyeManager.PixelToMap(_inputManager.MouseScreenPosition);
+            var mousePos = _eyeManager.PixelToMap(screenPos);
             _dragShadow = EntityManager.SpawnEntity("dragshadow", mousePos);
             var dragSprite = Comp<SpriteComponent>(_dragShadow.Value);
             dragSprite.CopyFrom(draggedSprite);
@@ -534,7 +539,7 @@ public sealed class DragDropSystem : SharedDragDropSystem
             case DragState.MouseDown:
             {
                 var screenPos = _inputManager.MouseScreenPosition;
-                if ((_mouseDownScreenPos!.Value.Position - screenPos.Position).Length() > _deadzone)
+                if ((_mouseDownScreenPos!.Value.Position - screenPos.Position).Length() > Deadzone)
                 {
                     StartDrag();
                 }
index 0f2c314ed01e845557897a2fe5de3edbd8cd57ea..d431c440a2e7cbcb82b93a8dfc7d0247bb01f149 100644 (file)
@@ -1207,11 +1207,12 @@ public abstract partial class InteractionTest
         BoundKeyFunction key,
         BoundKeyState state,
         NetCoordinates? coordinates = null,
-        NetEntity? cursorEntity = null)
+        NetEntity? cursorEntity = null,
+        ScreenCoordinates? screenCoordinates = null)
     {
         var coords = coordinates ?? TargetCoords;
         var target = cursorEntity ?? Target ?? default;
-        ScreenCoordinates screen = default;
+        var screen = screenCoordinates ?? default;
 
         var funcId = InputManager.NetworkBindMap.KeyFunctionID(key);
         var message = new ClientFullInputCmdMessage(CTiming.CurTick, CTiming.TickFraction, funcId)
diff --git a/Content.IntegrationTests/Tests/Strip/StrippableTest.cs b/Content.IntegrationTests/Tests/Strip/StrippableTest.cs
new file mode 100644 (file)
index 0000000..f65bab1
--- /dev/null
@@ -0,0 +1,46 @@
+using Content.Client.Interaction;
+using Content.IntegrationTests.Tests.Interaction;
+using Robust.Shared.GameObjects;
+using Robust.Shared.Input;
+using Robust.Shared.Map;
+
+namespace Content.IntegrationTests.Tests.Strip;
+
+public sealed class StrippableTest : InteractionTest
+{
+    protected override string PlayerPrototype => "MobHuman";
+
+    [Test]
+    public async Task DragDropOpensStrip()
+    {
+        // Spawn one tile away
+        TargetCoords = SEntMan.GetNetCoordinates(new EntityCoordinates(MapData.MapUid, 1, 0));
+        await SpawnTarget("MobHuman");
+
+        var userInterface = Comp<UserInterfaceComponent>(Target);
+        Assert.That(userInterface.Actors.Count == 0);
+
+        // screenCoordinates diff needs to be larger than DragDropSystem._deadzone
+        var screenX = CEntMan.System<DragDropSystem>().Deadzone + 1f;
+
+        // Start drag
+        await SetKey(EngineKeyFunctions.Use,
+            BoundKeyState.Down,
+            TargetCoords,
+            Target,
+            screenCoordinates: new ScreenCoordinates(screenX, 0f, WindowId.Main));
+
+        await RunTicks(5);
+
+        // End drag
+        await SetKey(EngineKeyFunctions.Use,
+            BoundKeyState.Up,
+            PlayerCoords,
+            Player,
+            screenCoordinates: new ScreenCoordinates(0f, 0f, WindowId.Main));
+
+        await RunTicks(5);
+
+        Assert.That(userInterface.Actors.Count > 0);
+    }
+}