]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Prevent certain foldable items from being unfolded on structures (#36687)
authorSlamBamActionman <83650252+SlamBamActionman@users.noreply.github.com>
Sat, 19 Apr 2025 02:17:13 +0000 (04:17 +0200)
committerGitHub <noreply@github.com>
Sat, 19 Apr 2025 02:17:13 +0000 (12:17 +1000)
initial commit

Content.Shared/Construction/EntitySystems/AnchorableSystem.cs
Content.Shared/Foldable/DeployFoldableSystem.cs
Content.Shared/Foldable/FoldableSystem.cs
Content.Shared/Interaction/SharedInteractionSystem.cs
Resources/Locale/en-US/foldable/components/foldable-component.ftl

index a291473b30d885c7c0ec5618ca831758de00aa1d..ec8edea474108f96bcd0bbc87f72c895846279c9 100644 (file)
@@ -277,7 +277,10 @@ public sealed partial class AnchorableSystem : EntitySystem
         return !attempt.Cancelled;
     }
 
-    private bool TileFree(EntityCoordinates coordinates, PhysicsComponent anchorBody)
+    /// <summary>
+    /// Returns true if no hard anchored entities exist on the coordinate tile that would collide with the provided physics body.
+    /// </summary>
+    public bool TileFree(EntityCoordinates coordinates, PhysicsComponent anchorBody)
     {
         // Probably ignore CanCollide on the anchoring body?
         var gridUid = _transformSystem.GetGrid(coordinates);
index 16315cde69963c3bcbc04989e0777ce4b975699d..a83518dfa338c218b37275e85cbc343b598c7776 100644 (file)
@@ -1,7 +1,10 @@
+using Content.Shared.Construction.EntitySystems;
 using Content.Shared.DragDrop;
 using Content.Shared.Hands.Components;
 using Content.Shared.Hands.EntitySystems;
 using Content.Shared.Interaction;
+using Content.Shared.Popups;
+using Robust.Shared.Physics.Components;
 
 namespace Content.Shared.Foldable;
 
@@ -9,6 +12,8 @@ public sealed class DeployFoldableSystem : EntitySystem
 {
     [Dependency] private readonly SharedHandsSystem _hands = default!;
     [Dependency] private readonly FoldableSystem _foldable = default!;
+    [Dependency] private readonly AnchorableSystem _anchorable = default!;
+    [Dependency] private readonly SharedPopupSystem _popup = default!;
 
     public override void Initialize()
     {
@@ -57,6 +62,13 @@ public sealed class DeployFoldableSystem : EntitySystem
         if (!TryComp<FoldableComponent>(ent, out var foldable))
             return;
 
+        if (!TryComp(ent.Owner, out PhysicsComponent? anchorBody)
+            || !_anchorable.TileFree(args.ClickLocation, anchorBody))
+        {
+            _popup.PopupPredicted(Loc.GetString("foldable-deploy-fail", ("object", ent)), ent, args.User);
+            return;
+        }
+
         if (!TryComp(args.User, out HandsComponent? hands)
             || !_hands.TryDrop(args.User, args.Used, targetDropLocation: args.ClickLocation, handsComp: hands))
             return;
index 3ba4201e79524d4251757b4c34b449982049ae86..73916f1c154e17e53ec86b72d9c8548008c9f46e 100644 (file)
@@ -1,9 +1,11 @@
-using Content.Shared.Body.Components;
 using Content.Shared.Buckle;
 using Content.Shared.Buckle.Components;
+using Content.Shared.Construction.EntitySystems;
+using Content.Shared.Popups;
 using Content.Shared.Storage.Components;
 using Content.Shared.Verbs;
 using Robust.Shared.Containers;
+using Robust.Shared.Physics.Components;
 using Robust.Shared.Serialization;
 using Robust.Shared.Utility;
 
@@ -15,6 +17,8 @@ public sealed class FoldableSystem : EntitySystem
     [Dependency] private readonly SharedAppearanceSystem _appearance = default!;
     [Dependency] private readonly SharedBuckleSystem _buckle = default!;
     [Dependency] private readonly SharedContainerSystem _container = default!;
+    [Dependency] private readonly AnchorableSystem _anchorable = default!;
+    [Dependency] private readonly SharedPopupSystem _popup = default!;
 
     public override void Initialize()
     {
@@ -83,9 +87,17 @@ public sealed class FoldableSystem : EntitySystem
             args.Cancel();
     }
 
-    public bool TryToggleFold(EntityUid uid, FoldableComponent comp)
+    public bool TryToggleFold(EntityUid uid, FoldableComponent comp, EntityUid? folder = null)
     {
-        return TrySetFolded(uid, comp, !comp.IsFolded);
+        var result = TrySetFolded(uid, comp, !comp.IsFolded);
+        if (!result && folder != null)
+        {
+            if (comp.IsFolded)
+                _popup.PopupPredicted(Loc.GetString("foldable-unfold-fail", ("object", uid)), uid, folder.Value);
+            else
+                _popup.PopupPredicted(Loc.GetString("foldable-fold-fail", ("object", uid)), uid, folder.Value);
+        }
+        return result;
     }
 
     public bool CanToggleFold(EntityUid uid, FoldableComponent? fold = null)
@@ -97,6 +109,10 @@ public sealed class FoldableSystem : EntitySystem
         if (_container.IsEntityInContainer(uid) && !fold.CanFoldInsideContainer)
             return false;
 
+        if (!TryComp(uid, out PhysicsComponent? body) ||
+            !_anchorable.TileFree(Transform(uid).Coordinates, body))
+            return false;
+
         var ev = new FoldAttemptEvent(fold);
         RaiseLocalEvent(uid, ref ev);
         return !ev.Cancelled;
@@ -121,12 +137,12 @@ public sealed class FoldableSystem : EntitySystem
 
     private void AddFoldVerb(EntityUid uid, FoldableComponent component, GetVerbsEvent<AlternativeVerb> args)
     {
-        if (!args.CanAccess || !args.CanInteract || args.Hands == null || !CanToggleFold(uid, component))
+        if (!args.CanAccess || !args.CanInteract || args.Hands == null)
             return;
 
         AlternativeVerb verb = new()
         {
-            Act = () => TryToggleFold(uid, component),
+            Act = () => TryToggleFold(uid, component, args.User),
             Text = component.IsFolded ? Loc.GetString(component.UnfoldVerbText) : Loc.GetString(component.FoldVerbText),
             Icon = new SpriteSpecifier.Texture(new ("/Textures/Interface/VerbIcons/fold.svg.192dpi.png")),
 
index 00246bafcd915c33bfea0092c8858ecb1aca2a31..eeb961537b7137cb822701fb40a92578c4321314 100644 (file)
@@ -855,7 +855,7 @@ namespace Content.Shared.Interaction
             {
                 // If the target is an item, we ignore any colliding entities. Currently done so that if items get stuck
                 // inside of walls, users can still pick them up.
-                ignored.UnionWith(_broadphase.GetEntitiesIntersectingBody(target, (int) collisionMask, false, physics));
+                ignored.UnionWith(_broadphase.GetEntitiesIntersectingBody(target, (int) collisionMask, false, physics)); // Note: This also bypasses items underneath doors, which may be problematic if it'd cause undesirable behavior.
             }
             else if (_wallMountQuery.TryComp(target, out var wallMount))
             {
index 525820920bdc3ef15bce834e4b739bff7bbb2892..1221efbdf059d601be942faacb0e1e94c70b0961 100644 (file)
@@ -1,5 +1,8 @@
 # Foldable
 
+foldable-fold-fail = You can't fold the {$object} here.
+foldable-unfold-fail = You can't unfold the {$object} here.
+
 foldable-deploy-fail = You can't deploy the {$object} here.
 fold-verb = Fold
 unfold-verb = Unfold