2021-12-16 23:42:02 +13:00
|
|
|
using Content.Shared.Access.Components;
|
|
|
|
|
using Content.Shared.Containers.ItemSlots;
|
|
|
|
|
using Robust.Shared.Containers;
|
|
|
|
|
|
|
|
|
|
namespace Content.Shared.PDA
|
|
|
|
|
{
|
2023-06-15 03:44:28 +02:00
|
|
|
public abstract class SharedPdaSystem : EntitySystem
|
2021-12-16 23:42:02 +13:00
|
|
|
{
|
|
|
|
|
[Dependency] protected readonly ItemSlotsSystem ItemSlotsSystem = default!;
|
2023-06-07 07:22:19 -07:00
|
|
|
[Dependency] protected readonly SharedAppearanceSystem Appearance = default!;
|
2021-12-16 23:42:02 +13:00
|
|
|
|
|
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
|
2023-06-15 03:44:28 +02:00
|
|
|
SubscribeLocalEvent<PdaComponent, ComponentInit>(OnComponentInit);
|
|
|
|
|
SubscribeLocalEvent<PdaComponent, ComponentRemove>(OnComponentRemove);
|
2021-12-16 23:42:02 +13:00
|
|
|
|
2023-06-15 03:44:28 +02:00
|
|
|
SubscribeLocalEvent<PdaComponent, EntInsertedIntoContainerMessage>(OnItemInserted);
|
|
|
|
|
SubscribeLocalEvent<PdaComponent, EntRemovedFromContainerMessage>(OnItemRemoved);
|
2021-12-16 23:42:02 +13:00
|
|
|
|
2023-08-14 19:34:23 -04:00
|
|
|
SubscribeLocalEvent<PdaComponent, GetAdditionalAccessEvent>(OnGetAdditionalAccess);
|
|
|
|
|
}
|
2023-06-15 03:44:28 +02:00
|
|
|
protected virtual void OnComponentInit(EntityUid uid, PdaComponent pda, ComponentInit args)
|
2021-12-16 23:42:02 +13:00
|
|
|
{
|
|
|
|
|
if (pda.IdCard != null)
|
|
|
|
|
pda.IdSlot.StartingItem = pda.IdCard;
|
|
|
|
|
|
2023-06-15 03:44:28 +02:00
|
|
|
ItemSlotsSystem.AddItemSlot(uid, PdaComponent.PdaIdSlotId, pda.IdSlot);
|
|
|
|
|
ItemSlotsSystem.AddItemSlot(uid, PdaComponent.PdaPenSlotId, pda.PenSlot);
|
2024-01-04 07:56:14 -05:00
|
|
|
ItemSlotsSystem.AddItemSlot(uid, PdaComponent.PdaPaiSlotId, pda.PaiSlot);
|
2021-12-16 23:42:02 +13:00
|
|
|
|
2023-02-02 17:34:53 +01:00
|
|
|
UpdatePdaAppearance(uid, pda);
|
2021-12-16 23:42:02 +13:00
|
|
|
}
|
|
|
|
|
|
2023-06-15 03:44:28 +02:00
|
|
|
private void OnComponentRemove(EntityUid uid, PdaComponent pda, ComponentRemove args)
|
2021-12-16 23:42:02 +13:00
|
|
|
{
|
|
|
|
|
ItemSlotsSystem.RemoveItemSlot(uid, pda.IdSlot);
|
|
|
|
|
ItemSlotsSystem.RemoveItemSlot(uid, pda.PenSlot);
|
2024-01-04 07:56:14 -05:00
|
|
|
ItemSlotsSystem.RemoveItemSlot(uid, pda.PaiSlot);
|
2021-12-16 23:42:02 +13:00
|
|
|
}
|
|
|
|
|
|
2023-06-15 03:44:28 +02:00
|
|
|
protected virtual void OnItemInserted(EntityUid uid, PdaComponent pda, EntInsertedIntoContainerMessage args)
|
2021-12-16 23:42:02 +13:00
|
|
|
{
|
2023-06-15 03:44:28 +02:00
|
|
|
if (args.Container.ID == PdaComponent.PdaIdSlotId)
|
2023-07-22 21:19:51 -07:00
|
|
|
pda.ContainedId = args.Entity;
|
2021-12-16 23:42:02 +13:00
|
|
|
|
2023-02-02 17:34:53 +01:00
|
|
|
UpdatePdaAppearance(uid, pda);
|
2021-12-16 23:42:02 +13:00
|
|
|
}
|
|
|
|
|
|
2023-06-15 03:44:28 +02:00
|
|
|
protected virtual void OnItemRemoved(EntityUid uid, PdaComponent pda, EntRemovedFromContainerMessage args)
|
2021-12-16 23:42:02 +13:00
|
|
|
{
|
|
|
|
|
if (args.Container.ID == pda.IdSlot.ID)
|
2023-06-15 03:44:28 +02:00
|
|
|
pda.ContainedId = null;
|
2021-12-16 23:42:02 +13:00
|
|
|
|
2023-02-02 17:34:53 +01:00
|
|
|
UpdatePdaAppearance(uid, pda);
|
2021-12-16 23:42:02 +13:00
|
|
|
}
|
|
|
|
|
|
2023-08-14 19:34:23 -04:00
|
|
|
private void OnGetAdditionalAccess(EntityUid uid, PdaComponent component, ref GetAdditionalAccessEvent args)
|
|
|
|
|
{
|
|
|
|
|
if (component.ContainedId is { } id)
|
|
|
|
|
args.Entities.Add(id);
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-15 03:44:28 +02:00
|
|
|
private void UpdatePdaAppearance(EntityUid uid, PdaComponent pda)
|
2021-12-16 23:42:02 +13:00
|
|
|
{
|
2023-06-15 03:44:28 +02:00
|
|
|
Appearance.SetData(uid, PdaVisuals.IdCardInserted, pda.ContainedId != null);
|
2021-12-16 23:42:02 +13:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|