diff --git a/Content.Client/Chemistry/EntitySystems/PillSystem.cs b/Content.Client/Chemistry/EntitySystems/PillSystem.cs new file mode 100644 index 0000000000..390a4857a2 --- /dev/null +++ b/Content.Client/Chemistry/EntitySystems/PillSystem.cs @@ -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(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}"); + } +} diff --git a/Content.Server/Chemistry/EntitySystems/ChemMasterSystem.cs b/Content.Server/Chemistry/EntitySystems/ChemMasterSystem.cs index 535efd6070..f1d164b2bd 100644 --- a/Content.Server/Chemistry/EntitySystems/ChemMasterSystem.cs +++ b/Content.Server/Chemistry/EntitySystems/ChemMasterSystem.cs @@ -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(item, out var spriteComp)) - spriteComp.LayerSetState(0, "pill" + (chemMaster.PillType + 1)); + var pill = EnsureComp(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 index 0000000000..ad32aa750a --- /dev/null +++ b/Content.Shared/Chemistry/Components/PillComponent.cs @@ -0,0 +1,15 @@ +using Robust.Shared.GameStates; + +namespace Content.Shared.Chemistry.Components; + +[RegisterComponent, NetworkedComponent, AutoGenerateComponentState(true)] +public sealed partial class PillComponent : Component +{ + /// + /// The pill id. Used for networking & serializing pill visuals. + /// + [AutoNetworkedField] + [DataField("pillType")] + [ViewVariables(VVAccess.ReadWrite)] + public uint PillType; +} diff --git a/Resources/Prototypes/Entities/Objects/Specific/chemistry.yml b/Resources/Prototypes/Entities/Objects/Specific/chemistry.yml index 010a292691..0f1f81e74e 100644 --- a/Resources/Prototypes/Entities/Objects/Specific/chemistry.yml +++ b/Resources/Prototypes/Entities/Objects/Specific/chemistry.yml @@ -283,6 +283,8 @@ - type: Item size: 1 sprite: Objects/Specific/Chemistry/pills.rsi + - type: Pill + # TODO remove pill tag? - type: Tag tags: - Pill