using Content.Shared.Access.Components; using Content.Shared.Containers.ItemSlots; using Robust.Shared.Containers; namespace Content.Shared.PDA { public abstract class SharedPdaSystem : EntitySystem { [Dependency] protected readonly ItemSlotsSystem ItemSlotsSystem = default!; [Dependency] protected readonly SharedAppearanceSystem Appearance = default!; public override void Initialize() { base.Initialize(); SubscribeLocalEvent(OnComponentInit); SubscribeLocalEvent(OnComponentRemove); SubscribeLocalEvent(OnItemInserted); SubscribeLocalEvent(OnItemRemoved); } protected virtual void OnComponentInit(EntityUid uid, PdaComponent pda, ComponentInit args) { if (pda.IdCard != null) pda.IdSlot.StartingItem = pda.IdCard; ItemSlotsSystem.AddItemSlot(uid, PdaComponent.PdaIdSlotId, pda.IdSlot); ItemSlotsSystem.AddItemSlot(uid, PdaComponent.PdaPenSlotId, pda.PenSlot); UpdatePdaAppearance(uid, pda); } private void OnComponentRemove(EntityUid uid, PdaComponent pda, ComponentRemove args) { ItemSlotsSystem.RemoveItemSlot(uid, pda.IdSlot); ItemSlotsSystem.RemoveItemSlot(uid, pda.PenSlot); } protected virtual void OnItemInserted(EntityUid uid, PdaComponent pda, EntInsertedIntoContainerMessage args) { if (args.Container.ID == PdaComponent.PdaIdSlotId) pda.ContainedId = CompOrNull(args.Entity); UpdatePdaAppearance(uid, pda); } protected virtual void OnItemRemoved(EntityUid uid, PdaComponent pda, EntRemovedFromContainerMessage args) { if (args.Container.ID == pda.IdSlot.ID) pda.ContainedId = null; UpdatePdaAppearance(uid, pda); } private void UpdatePdaAppearance(EntityUid uid, PdaComponent pda) { Appearance.SetData(uid, PdaVisuals.IdCardInserted, pda.ContainedId != null); } } }