]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Remove server-side sprite references from chem master (#15888)
authorLeon Friedrich <60421075+ElectroJr@users.noreply.github.com>
Sat, 29 Apr 2023 09:27:14 +0000 (21:27 +1200)
committerGitHub <noreply@github.com>
Sat, 29 Apr 2023 09:27:14 +0000 (19:27 +1000)
Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
Content.Client/Chemistry/EntitySystems/PillSystem.cs [new file with mode: 0644]
Content.Server/Chemistry/EntitySystems/ChemMasterSystem.cs
Content.Shared/Chemistry/Components/PillComponent.cs [new file with mode: 0644]
Resources/Prototypes/Entities/Objects/Specific/chemistry.yml

diff --git a/Content.Client/Chemistry/EntitySystems/PillSystem.cs b/Content.Client/Chemistry/EntitySystems/PillSystem.cs
new file mode 100644 (file)
index 0000000..390a485
--- /dev/null
@@ -0,0 +1,24 @@
+using Content.Shared.Chemistry.Components;
+using Robust.Client.GameObjects;
+
+namespace Content.Client.Chemistry.EntitySystems;
+
+public sealed class PillSystem : EntitySystem
+{
+    public override void Initialize()
+    {
+        base.Initialize();
+        SubscribeLocalEvent<PillComponent, AfterAutoHandleStateEvent>(OnHandleState);
+    }
+
+    private void OnHandleState(EntityUid uid, PillComponent component, ref AfterAutoHandleStateEvent args)
+    {
+        if (!TryComp(uid, out SpriteComponent? sprite))
+            return;
+
+        if (!sprite.TryGetLayer(0, out var layer))
+            return;
+
+        layer.SetState($"pill{component.PillType + 1}");
+    }
+}
index 535efd6070efbcb1b29191f997ffe51df75d7b3a..f1d164b2bd9025a4ccdfef7e417e91727f454921 100644 (file)
@@ -34,6 +34,7 @@ namespace Content.Server.Chemistry.EntitySystems
         [Dependency] private readonly StorageSystem _storageSystem = default!;
         [Dependency] private readonly LabelSystem _labelSystem = default!;
         [Dependency] private readonly ISharedAdminLogManager _adminLogger = default!;
+        [Dependency] private readonly AppearanceSystem _appearance = default!;
 
         private const string PillPrototypeId = "Pill";
 
@@ -206,8 +207,9 @@ namespace Content.Server.Chemistry.EntitySystems
                 _solutionContainerSystem.TryAddSolution(
                     item, itemSolution, withdrawal.SplitSolution(message.Dosage));
 
-                if (TryComp<SpriteComponent>(item, out var spriteComp))
-                    spriteComp.LayerSetState(0, "pill" + (chemMaster.PillType + 1));
+                var pill = EnsureComp<PillComponent>(item);
+                pill.PillType = chemMaster.PillType;
+                Dirty(pill);
 
                 if (user.HasValue)
                 {
diff --git a/Content.Shared/Chemistry/Components/PillComponent.cs b/Content.Shared/Chemistry/Components/PillComponent.cs
new file mode 100644 (file)
index 0000000..ad32aa7
--- /dev/null
@@ -0,0 +1,15 @@
+using Robust.Shared.GameStates;
+
+namespace Content.Shared.Chemistry.Components;
+
+[RegisterComponent, NetworkedComponent, AutoGenerateComponentState(true)]
+public sealed partial class PillComponent : Component
+{
+    /// <summary>
+    /// The pill id. Used for networking & serializing pill visuals.
+    /// </summary>
+    [AutoNetworkedField]
+    [DataField("pillType")]
+    [ViewVariables(VVAccess.ReadWrite)]
+    public uint PillType;
+}
index 010a29269164319350ebc589e8e6cd5374185f2a..0f1f81e74e10ea86c7536cd8c83499d8d663b80c 100644 (file)
   - type: Item
     size: 1
     sprite: Objects/Specific/Chemistry/pills.rsi
+  - type: Pill
+  # TODO remove pill tag?
   - type: Tag
     tags:
       - Pill