Verb predict (#5638)

This commit is contained in:
Leon Friedrich
2021-12-16 23:42:02 +13:00
committed by GitHub
parent 2e141347ed
commit 7e49b22a74
40 changed files with 551 additions and 395 deletions

View File

@@ -0,0 +1,33 @@
using Content.Shared.Access.Components;
using Content.Shared.Containers.ItemSlots;
using Robust.Shared.GameObjects;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
using Robust.Shared.ViewVariables;
namespace Content.Shared.PDA
{
[RegisterComponent]
public class PDAComponent : Component
{
public override string Name => "PDA";
[DataField("idSlot")]
public ItemSlot IdSlot = new();
[DataField("penSlot")]
public ItemSlot PenSlot = new();
// Really this should just be using ItemSlot.StartingItem. However, seeing as we have so many different starting
// PDA's and no nice way to inherit the other fields from the ItemSlot data definition, this makes the yaml much
// nicer to read.
[DataField("idCard", customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>))]
public string? IdCard;
[ViewVariables] public IdCardComponent? ContainedID;
[ViewVariables] public bool FlashlightOn;
[ViewVariables] public string? OwnerName;
}
}

View File

@@ -0,0 +1,65 @@
using Content.Shared.Access.Components;
using Content.Shared.Containers.ItemSlots;
using Robust.Shared.Containers;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
namespace Content.Shared.PDA
{
public abstract class SharedPDASystem : EntitySystem
{
[Dependency] protected readonly ItemSlotsSystem ItemSlotsSystem = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<PDAComponent, ComponentInit>(OnComponentInit);
SubscribeLocalEvent<PDAComponent, ComponentRemove>(OnComponentRemove);
SubscribeLocalEvent<PDAComponent, EntInsertedIntoContainerMessage>(OnItemInserted);
SubscribeLocalEvent<PDAComponent, EntRemovedFromContainerMessage>(OnItemRemoved);
}
protected virtual void OnComponentInit(EntityUid uid, PDAComponent pda, ComponentInit args)
{
if (pda.IdCard != null)
pda.IdSlot.StartingItem = pda.IdCard;
ItemSlotsSystem.AddItemSlot(uid, $"{pda.Name}-id", pda.IdSlot);
ItemSlotsSystem.AddItemSlot(uid, $"{pda.Name}-pen", pda.PenSlot);
UpdatePDAAppearance(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 (!pda.Initialized) return;
if (args.Container.ID == pda.IdSlot.ID)
pda.ContainedID = CompOrNull<IdCardComponent>(args.Entity);
UpdatePDAAppearance(pda);
}
protected virtual void OnItemRemoved(EntityUid uid, PDAComponent pda, EntRemovedFromContainerMessage args)
{
if (args.Container.ID == pda.IdSlot.ID)
pda.ContainedID = null;
UpdatePDAAppearance(pda);
}
private void UpdatePDAAppearance(PDAComponent pda)
{
if (TryComp(pda.Owner, out AppearanceComponent ? appearance))
appearance.SetData(PDAVisuals.IDCardInserted, pda.ContainedID != null);
}
}
}