Files
tbd-station-14/Content.Shared/PDA/SharedPdaSystem.cs
VMSolidus 84a2356831 Adding PAI Slot to PDA (#21086)
* Adding PAI Slot to PDA

* Update PdaComponent.cs

* Update pda.yml

* Update tags.yml

Sorting it alphabetically

* Adding PDA UI Elements.

* Addressing reviews

* Update PdaComponent.cs

* Update Content.Shared/PDA/SharedPdaSystem.cs

Co-authored-by: faint <46868845+ficcialfaint@users.noreply.github.com>

* Update Content.Shared/PDA/SharedPdaSystem.cs

Co-authored-by: faint <46868845+ficcialfaint@users.noreply.github.com>

* Update Resources/Prototypes/Entities/Objects/Devices/pda.yml

Co-authored-by: faint <46868845+ficcialfaint@users.noreply.github.com>

* Update PdaComponent.cs

* Update PdaComponent.cs

---------

Co-authored-by: faint <46868845+ficcialfaint@users.noreply.github.com>
2024-01-04 05:56:14 -07:00

71 lines
2.7 KiB
C#

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<PdaComponent, ComponentInit>(OnComponentInit);
SubscribeLocalEvent<PdaComponent, ComponentRemove>(OnComponentRemove);
SubscribeLocalEvent<PdaComponent, EntInsertedIntoContainerMessage>(OnItemInserted);
SubscribeLocalEvent<PdaComponent, EntRemovedFromContainerMessage>(OnItemRemoved);
SubscribeLocalEvent<PdaComponent, GetAdditionalAccessEvent>(OnGetAdditionalAccess);
}
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);
ItemSlotsSystem.AddItemSlot(uid, PdaComponent.PdaPaiSlotId, pda.PaiSlot);
UpdatePdaAppearance(uid, pda);
}
private void OnComponentRemove(EntityUid uid, PdaComponent pda, ComponentRemove args)
{
ItemSlotsSystem.RemoveItemSlot(uid, pda.IdSlot);
ItemSlotsSystem.RemoveItemSlot(uid, pda.PenSlot);
ItemSlotsSystem.RemoveItemSlot(uid, pda.PaiSlot);
}
protected virtual void OnItemInserted(EntityUid uid, PdaComponent pda, EntInsertedIntoContainerMessage args)
{
if (args.Container.ID == PdaComponent.PdaIdSlotId)
pda.ContainedId = 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 OnGetAdditionalAccess(EntityUid uid, PdaComponent component, ref GetAdditionalAccessEvent args)
{
if (component.ContainedId is { } id)
args.Entities.Add(id);
}
private void UpdatePdaAppearance(EntityUid uid, PdaComponent pda)
{
Appearance.SetData(uid, PdaVisuals.IdCardInserted, pda.ContainedId != null);
}
}
}