]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
improve job special (#30753)
authordeltanedas <39013340+deltanedas@users.noreply.github.com>
Fri, 9 Aug 2024 07:43:57 +0000 (07:43 +0000)
committerGitHub <noreply@github.com>
Fri, 9 Aug 2024 07:43:57 +0000 (17:43 +1000)
* cleanup of AddComponentSpecial

* add RemoveComponentSpecial

* require

---------

Co-authored-by: deltanedas <@deltanedas:kde.org>
Content.Server/Jobs/AddComponentSpecial.cs
Content.Server/Jobs/RemoveComponentSpecial.cs [new file with mode: 0644]

index 6489068d1fb7cff5dad568577c905a07e01068ca..3bac923656c113a61aacd3fb28b386e12fc11a57 100644 (file)
@@ -1,34 +1,22 @@
 using Content.Shared.Roles;
-using JetBrains.Annotations;
 using Robust.Shared.Prototypes;
-using Robust.Shared.Serialization.Manager;
 
-namespace Content.Server.Jobs
-{
-    [UsedImplicitly]
-    public sealed partial class AddComponentSpecial : JobSpecial
-    {
-        [DataField("components")]
-        [AlwaysPushInheritance]
-        public ComponentRegistry Components { get; private set; } = new();
+namespace Content.Server.Jobs;
 
-        public override void AfterEquip(EntityUid mob)
-        {
-            // now its a registry of components, still throws i bet.
-            // TODO: This is hot garbage and probably needs an engine change to not be a POS.
-            var factory = IoCManager.Resolve<IComponentFactory>();
-            var entityManager = IoCManager.Resolve<IEntityManager>();
-            var serializationManager = IoCManager.Resolve<ISerializationManager>();
+public sealed partial class AddComponentSpecial : JobSpecial
+{
+    [DataField(required: true)]
+    public ComponentRegistry Components { get; private set; } = new();
 
-            foreach (var (name, data) in Components)
-            {
-                var component = (Component) factory.GetComponent(name);
+    /// <summary>
+    /// If this is true then existing components will be removed and replaced with these ones.
+    /// </summary>
+    [DataField]
+    public bool RemoveExisting = true;
 
-                var temp = (object)component;
-                serializationManager.CopyTo(data.Component, ref temp);
-                entityManager.RemoveComponent(mob, temp!.GetType());
-                entityManager.AddComponent(mob, (Component)temp);
-            }
-        }
+    public override void AfterEquip(EntityUid mob)
+    {
+        var entMan = IoCManager.Resolve<IEntityManager>();
+        entMan.AddComponents(mob, Components, removeExisting: RemoveExisting);
     }
 }
diff --git a/Content.Server/Jobs/RemoveComponentSpecial.cs b/Content.Server/Jobs/RemoveComponentSpecial.cs
new file mode 100644 (file)
index 0000000..7a9b03b
--- /dev/null
@@ -0,0 +1,16 @@
+using Content.Shared.Roles;
+using Robust.Shared.Prototypes;
+
+namespace Content.Server.Jobs;
+
+public sealed partial class RemoveComponentSpecial : JobSpecial
+{
+    [DataField(required: true)]
+    public ComponentRegistry Components { get; private set; } = new();
+
+    public override void AfterEquip(EntityUid mob)
+    {
+        var entMan = IoCManager.Resolve<IEntityManager>();
+        entMan.RemoveComponents(mob, Components);
+    }
+}