]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Change Polymorph Actions to use Polymorph Proto Id (#26419)
authorkeronshb <54602815+keronshb@users.noreply.github.com>
Fri, 29 Mar 2024 06:41:09 +0000 (02:41 -0400)
committerGitHub <noreply@github.com>
Fri, 29 Mar 2024 06:41:09 +0000 (17:41 +1100)
* polymorph changes

Adds poly proto ids to polymorph action event and checks for proto id when performing

* nullable proto id

* Replaces instances of Polymorph prototype with a proto id and tryindex

* birdup

---------

Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
Content.Server/Polymorph/Systems/PolymorphSystem.cs
Content.Server/Polymorph/Toolshed/PolymorphCommand.cs
Content.Shared/Polymorph/PolymorphActions.cs

index 5fe29dcd30e28c441afb7d3fb71cd558fd68238e..b7640ff984358f01c50dbd9db4aaabfa7f7b1de6 100644 (file)
@@ -118,7 +118,10 @@ public sealed partial class PolymorphSystem : EntitySystem
 
     private void OnPolymorphActionEvent(Entity<PolymorphableComponent> ent, ref PolymorphActionEvent args)
     {
-        PolymorphEntity(ent, args.Prototype.Configuration);
+        if (!_proto.TryIndex(args.ProtoId, out var prototype))
+            return;
+
+        PolymorphEntity(ent, prototype.Configuration);
     }
 
     private void OnRevertPolymorphActionEvent(Entity<PolymorphedEntityComponent> ent,
@@ -348,7 +351,9 @@ public sealed partial class PolymorphSystem : EntitySystem
         if (target.Comp.PolymorphActions.ContainsKey(id))
             return;
 
-        var polyProto = _proto.Index(id);
+        if (!_proto.TryIndex(id, out var polyProto))
+            return;
+
         var entProto = _proto.Index(polyProto.Configuration.Entity);
 
         EntityUid? actionId = default!;
@@ -366,7 +371,7 @@ public sealed partial class PolymorphSystem : EntitySystem
 
         baseAction.Icon = new SpriteSpecifier.EntityPrototype(polyProto.Configuration.Entity);
         if (baseAction is InstantActionComponent action)
-            action.Event = new PolymorphActionEvent(prototype: polyProto);
+            action.Event = new PolymorphActionEvent(id);
     }
 
     public void RemovePolymorphAction(ProtoId<PolymorphPrototype> id, Entity<PolymorphableComponent> target)
index f741c24571e54c2bbdaecb908da1b4cf6e128bc9..5654c84722f7a3b27f89e1e0a55a4ce2d6a148af 100644 (file)
@@ -3,8 +3,8 @@ using Content.Server.Administration;
 using Content.Server.Polymorph.Systems;
 using Content.Shared.Administration;
 using Content.Shared.Polymorph;
+using Robust.Shared.Prototypes;
 using Robust.Shared.Toolshed;
-using Robust.Shared.Toolshed.TypeParsers;
 
 namespace Content.Server.Polymorph.Toolshed;
 
@@ -15,22 +15,26 @@ namespace Content.Server.Polymorph.Toolshed;
 public sealed class PolymorphCommand : ToolshedCommand
 {
     private PolymorphSystem? _system;
+    [Dependency] private IPrototypeManager _proto = default!;
 
     [CommandImplementation]
     public EntityUid? Polymorph(
             [PipedArgument] EntityUid input,
-            [CommandArgument] Prototype<PolymorphPrototype> prototype
+            [CommandArgument] ProtoId<PolymorphPrototype> protoId
         )
     {
         _system ??= GetSys<PolymorphSystem>();
 
-        return _system.PolymorphEntity(input, prototype.Value.Configuration);
+        if (!_proto.TryIndex(protoId, out var prototype))
+            return null;
+
+        return _system.PolymorphEntity(input, prototype.Configuration);
     }
 
     [CommandImplementation]
     public IEnumerable<EntityUid> Polymorph(
             [PipedArgument] IEnumerable<EntityUid> input,
-            [CommandArgument] Prototype<PolymorphPrototype> prototype
+            [CommandArgument] ProtoId<PolymorphPrototype> protoId
         )
-        => input.Select(x => Polymorph(x, prototype)).Where(x => x is not null).Select(x => (EntityUid)x!);
+        => input.Select(x => Polymorph(x, protoId)).Where(x => x is not null).Select(x => (EntityUid)x!);
 }
index 0f230868f03fb38f1662f4f8248626d83bac91f0..13e00f55e2bb8c97dbec9136bb67c67eaa518421 100644 (file)
@@ -1,18 +1,20 @@
 using Content.Shared.Actions;
+using Robust.Shared.Prototypes;
 
 namespace Content.Shared.Polymorph;
 
 public sealed partial class PolymorphActionEvent : InstantActionEvent
 {
     /// <summary>
-    /// The polymorph prototype containing all the information about
-    /// the specific polymorph.
+    ///     The polymorph proto id, containing all the information about
+    ///     the specific polymorph.
     /// </summary>
-    public PolymorphPrototype Prototype = default!;
+    [DataField]
+    public ProtoId<PolymorphPrototype>? ProtoId;
 
-    public PolymorphActionEvent(PolymorphPrototype prototype) : this()
+    public PolymorphActionEvent(ProtoId<PolymorphPrototype> protoId) : this()
     {
-        Prototype = prototype;
+        ProtoId = protoId;
     }
 }