Files
OldThink/Content.Shared/PDA/SharedPdaSystem.cs

71 lines
2.7 KiB
C#
Raw Normal View History

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
{
public abstract class SharedPdaSystem : EntitySystem
2021-12-16 23:42:02 +13:00
{
[Dependency] protected readonly ItemSlotsSystem ItemSlotsSystem = default!;
[Dependency] protected readonly SharedAppearanceSystem Appearance = default!;
2021-12-16 23:42:02 +13:00
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<PdaComponent, ComponentInit>(OnComponentInit);
SubscribeLocalEvent<PdaComponent, ComponentRemove>(OnComponentRemove);
2021-12-16 23:42:02 +13:00
SubscribeLocalEvent<PdaComponent, EntInsertedIntoContainerMessage>(OnItemInserted);
SubscribeLocalEvent<PdaComponent, EntRemovedFromContainerMessage>(OnItemRemoved);
2021-12-16 23:42:02 +13:00
SubscribeLocalEvent<PdaComponent, GetAdditionalAccessEvent>(OnGetAdditionalAccess);
}
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;
ItemSlotsSystem.AddItemSlot(uid, PdaComponent.PdaIdSlotId, pda.IdSlot);
ItemSlotsSystem.AddItemSlot(uid, PdaComponent.PdaPenSlotId, pda.PenSlot);
ItemSlotsSystem.AddItemSlot(uid, PdaComponent.PdaPaiSlotId, pda.PaiSlot);
2021-12-16 23:42:02 +13:00
UpdatePdaAppearance(uid, pda);
2021-12-16 23:42:02 +13: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);
ItemSlotsSystem.RemoveItemSlot(uid, pda.PaiSlot);
2021-12-16 23:42:02 +13:00
}
protected virtual void OnItemInserted(EntityUid uid, PdaComponent pda, EntInsertedIntoContainerMessage args)
2021-12-16 23:42:02 +13:00
{
if (args.Container.ID == PdaComponent.PdaIdSlotId)
pda.ContainedId = args.Entity;
2021-12-16 23:42:02 +13:00
UpdatePdaAppearance(uid, pda);
2021-12-16 23:42:02 +13: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)
pda.ContainedId = null;
2021-12-16 23:42:02 +13:00
UpdatePdaAppearance(uid, pda);
2021-12-16 23:42:02 +13:00
}
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)
2021-12-16 23:42:02 +13:00
{
Appearance.SetData(uid, PdaVisuals.IdCardInserted, pda.ContainedId != null);
2021-12-16 23:42:02 +13:00
}
}
}