]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Add RequiresGrid component (#23394)
authorHoofedEar <HoofedEar@users.noreply.github.com>
Thu, 22 Feb 2024 11:26:02 +0000 (03:26 -0800)
committerGitHub <noreply@github.com>
Thu, 22 Feb 2024 11:26:02 +0000 (22:26 +1100)
* saving working code

* add checks for deletion

Content.Server/RequiresGrid/RequiresGridComponent.cs [new file with mode: 0644]
Content.Server/RequiresGrid/RequiresGridSystem.cs [new file with mode: 0644]

diff --git a/Content.Server/RequiresGrid/RequiresGridComponent.cs b/Content.Server/RequiresGrid/RequiresGridComponent.cs
new file mode 100644 (file)
index 0000000..0e956c9
--- /dev/null
@@ -0,0 +1,11 @@
+namespace Content.Server.RequiresGrid;
+
+/// <summary>
+/// Destroys an entity when they no longer are part of a Grid
+/// </summary>
+[RegisterComponent]
+[Access(typeof(RequiresGridSystem))]
+public sealed partial class RequiresGridComponent : Component
+{
+
+}
diff --git a/Content.Server/RequiresGrid/RequiresGridSystem.cs b/Content.Server/RequiresGrid/RequiresGridSystem.cs
new file mode 100644 (file)
index 0000000..16a20c9
--- /dev/null
@@ -0,0 +1,29 @@
+using Content.Server.Destructible;
+
+namespace Content.Server.RequiresGrid;
+
+public sealed class RequiresGridSystem : EntitySystem
+{
+    [Dependency] private readonly DestructibleSystem _destructible = default!;
+
+    public override void Initialize()
+    {
+        base.Initialize();
+
+        SubscribeLocalEvent<RequiresGridComponent, EntParentChangedMessage>(OnEntParentChanged);
+    }
+
+    private void OnEntParentChanged(EntityUid owner, RequiresGridComponent component, EntParentChangedMessage args)
+    {
+        if (args.OldParent == null)
+            return;
+
+        if (args.Transform.GridUid != null)
+            return;
+
+        if (TerminatingOrDeleted(owner))
+            return;
+
+        _destructible.DestroyEntity(owner);
+    }
+}