]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Add public methods to relay inventory events (#22165)
authorDrSmugleaf <DrSmugleaf@users.noreply.github.com>
Wed, 6 Dec 2023 07:01:31 +0000 (00:01 -0700)
committerGitHub <noreply@github.com>
Wed, 6 Dec 2023 07:01:31 +0000 (18:01 +1100)
Content.Shared/Inventory/InventorySystem.Relay.cs

index 20a98dc12444411b195dff36eaa4793043845907..f6863c74e0f2154748067150a495a2217e3504af 100644 (file)
@@ -49,14 +49,26 @@ public partial class InventorySystem
 
     protected void RefRelayInventoryEvent<T>(EntityUid uid, InventoryComponent component, ref T args) where T : IInventoryRelayEvent
     {
-        var containerEnumerator = new ContainerSlotEnumerator(uid, component.TemplateId, _prototypeManager, this, args.TargetSlots);
+        RelayEvent((uid, component), args);
+    }
+
+    protected void RelayInventoryEvent<T>(EntityUid uid, InventoryComponent component, T args) where T : IInventoryRelayEvent
+    {
+        RelayEvent((uid, component), args);
+    }
+
+    public void RelayEvent<T>(Entity<InventoryComponent> inventory, ref T args) where T : IInventoryRelayEvent
+    {
+        var containerEnumerator = new ContainerSlotEnumerator(inventory, inventory.Comp.TemplateId, _prototypeManager, this, args.TargetSlots);
 
-        // this copies the by-ref event
+        // this copies the by-ref event if it is a struct
         var ev = new InventoryRelayedEvent<T>(args);
 
         while (containerEnumerator.MoveNext(out var container))
         {
-            if (!container.ContainedEntity.HasValue) continue;
+            if (!container.ContainedEntity.HasValue)
+                continue;
+
             RaiseLocalEvent(container.ContainedEntity.Value, ev);
         }
 
@@ -64,16 +76,18 @@ public partial class InventorySystem
         args = ev.Args;
     }
 
-    protected void RelayInventoryEvent<T>(EntityUid uid, InventoryComponent component, T args) where T : IInventoryRelayEvent
+    public void RelayEvent<T>(Entity<InventoryComponent> inventory, T args) where T : IInventoryRelayEvent
     {
         if (args.TargetSlots == SlotFlags.NONE)
             return;
 
-        var containerEnumerator = new ContainerSlotEnumerator(uid, component.TemplateId, _prototypeManager, this, args.TargetSlots);
+        var containerEnumerator = new ContainerSlotEnumerator(inventory, inventory.Comp.TemplateId, _prototypeManager, this, args.TargetSlots);
         var ev = new InventoryRelayedEvent<T>(args);
         while (containerEnumerator.MoveNext(out var container))
         {
-            if (!container.ContainedEntity.HasValue) continue;
+            if (!container.ContainedEntity.HasValue)
+                continue;
+
             RaiseLocalEvent(container.ContainedEntity.Value, ev);
         }
     }