]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Move PlaceableSurfaceComponent usages to PlaceableSurfaceSystem (#28384)
authorShadowCommander <10494922+ShadowCommander@users.noreply.github.com>
Thu, 19 Sep 2024 07:42:49 +0000 (00:42 -0700)
committerGitHub <noreply@github.com>
Thu, 19 Sep 2024 07:42:49 +0000 (17:42 +1000)
* Move placeable check to PlaceableSurfaceSystem

This check stops entities from being inserted into a storage entity
when it has a PlaceableSurfaceComponent.

The entity is instead placed on top of the entity like a table.

* Move SetPlaceable to PlaceableSurfaceSystem

* Update to transform system and consolidate code

* Fix interaction with storage that has a placeable component

* deadlock

---------

Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
Content.Shared/Placeable/PlaceableSurfaceSystem.cs
Content.Shared/Storage/EntitySystems/SharedEntityStorageSystem.cs
Content.Shared/Storage/EntitySystems/SharedStorageSystem.cs
Content.Shared/Storage/StorageComponent.cs

index a9a9390a6e0e9838ad9d3d01ac4b62ab721b1e52..c332064ea38eae767f8d35a11b7b89a820b40524 100644 (file)
@@ -1,6 +1,7 @@
 using System.Numerics;
 using Content.Shared.Hands.EntitySystems;
 using Content.Shared.Interaction;
+using Content.Shared.Storage;
 using Content.Shared.Storage.Components;
 
 namespace Content.Shared.Placeable;
@@ -8,12 +9,16 @@ namespace Content.Shared.Placeable;
 public sealed class PlaceableSurfaceSystem : EntitySystem
 {
     [Dependency] private readonly SharedHandsSystem _handsSystem = default!;
+    [Dependency] private readonly SharedTransformSystem _transformSystem = default!;
 
     public override void Initialize()
     {
         base.Initialize();
 
         SubscribeLocalEvent<PlaceableSurfaceComponent, AfterInteractUsingEvent>(OnAfterInteractUsing);
+        SubscribeLocalEvent<PlaceableSurfaceComponent, StorageInteractUsingAttemptEvent>(OnStorageInteractUsingAttempt);
+        SubscribeLocalEvent<PlaceableSurfaceComponent, StorageAfterOpenEvent>(OnStorageAfterOpen);
+        SubscribeLocalEvent<PlaceableSurfaceComponent, StorageAfterCloseEvent>(OnStorageAfterClose);
     }
 
     public void SetPlaceable(EntityUid uid, bool isPlaceable, PlaceableSurfaceComponent? surface = null)
@@ -21,6 +26,9 @@ public sealed class PlaceableSurfaceSystem : EntitySystem
         if (!Resolve(uid, ref surface, false))
             return;
 
+        if (surface.IsPlaceable == isPlaceable)
+            return;
+
         surface.IsPlaceable = isPlaceable;
         Dirty(uid, surface);
     }
@@ -59,11 +67,24 @@ public sealed class PlaceableSurfaceSystem : EntitySystem
         if (!_handsSystem.TryDrop(args.User, args.Used))
             return;
 
-        if (surface.PlaceCentered)
-            Transform(args.Used).LocalPosition = Transform(uid).LocalPosition + surface.PositionOffset;
-        else
-            Transform(args.Used).Coordinates = args.ClickLocation;
+        _transformSystem.SetCoordinates(args.Used,
+            surface.PlaceCentered ? Transform(uid).Coordinates.Offset(surface.PositionOffset) : args.ClickLocation);
 
         args.Handled = true;
     }
+
+    private void OnStorageInteractUsingAttempt(Entity<PlaceableSurfaceComponent> ent, ref StorageInteractUsingAttemptEvent args)
+    {
+        args.Cancelled = true;
+    }
+
+    private void OnStorageAfterOpen(Entity<PlaceableSurfaceComponent> ent, ref StorageAfterOpenEvent args)
+    {
+        SetPlaceable(ent.Owner, true, ent.Comp);
+    }
+
+    private void OnStorageAfterClose(Entity<PlaceableSurfaceComponent> ent, ref StorageAfterCloseEvent args)
+    {
+        SetPlaceable(ent.Owner, false, ent.Comp);
+    }
 }
index 4932613d0e640dad56b042a9a75f95f62dbea662..309ac0a2e09358717dc3062f4bcec4b7e5ca9014 100644 (file)
@@ -487,9 +487,6 @@ public abstract class SharedEntityStorageSystem : EntitySystem
             }
         }
 
-        if (TryComp<PlaceableSurfaceComponent>(uid, out var surface))
-            _placeableSurface.SetPlaceable(uid, component.Open, surface);
-
         _appearance.SetData(uid, StorageVisuals.Open, component.Open);
         _appearance.SetData(uid, StorageVisuals.HasContents, component.Contents.ContainedEntities.Count > 0);
     }
index def9d797c4833c0f259c7be40fe673ce22c0d702..d6fde292a14786f9338df044ad1ea3c8021cc5b0 100644 (file)
@@ -364,7 +364,9 @@ public abstract class SharedStorageSystem : EntitySystem
         if (args.Handled || !CanInteract(args.User, (uid, storageComp), storageComp.ClickInsert, false))
             return;
 
-        if (HasComp<PlaceableSurfaceComponent>(uid))
+        var attemptEv = new StorageInteractUsingAttemptEvent();
+        RaiseLocalEvent(uid, ref attemptEv);
+        if (attemptEv.Cancelled)
             return;
 
         PlayerInsertHeldEntity((uid, storageComp), args.User);
index a666169f529481a1a6296e60849f4b24d7b2c73d..d2c607e57f765636a808ac5d41e3c5e9736e14c5 100644 (file)
@@ -238,6 +238,9 @@ namespace Content.Shared.Storage
     [ByRefEvent]
     public record struct StorageInteractAttemptEvent(bool Silent, bool Cancelled = false);
 
+    [ByRefEvent]
+    public record struct StorageInteractUsingAttemptEvent(bool Cancelled = false);
+
     [NetSerializable]
     [Serializable]
     public enum StorageVisuals : byte