43 lines
1.5 KiB
C#
43 lines
1.5 KiB
C#
using Content.Shared.Clothing.Components;
|
|
using Content.Shared.Inventory.Events;
|
|
|
|
namespace Content.Shared.Chat.TypingIndicator;
|
|
|
|
/// <summary>
|
|
/// Sync typing indicator icon between client and server.
|
|
/// </summary>
|
|
public abstract class SharedTypingIndicatorSystem : EntitySystem
|
|
{
|
|
/// <summary>
|
|
/// Default ID of <see cref="TypingIndicatorPrototype"/>
|
|
/// </summary>
|
|
public const string InitialIndicatorId = "default";
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
SubscribeLocalEvent<TypingIndicatorClothingComponent, GotEquippedEvent>(OnGotEquipped);
|
|
SubscribeLocalEvent<TypingIndicatorClothingComponent, GotUnequippedEvent>(OnGotUnequipped);
|
|
}
|
|
|
|
private void OnGotEquipped(EntityUid uid, TypingIndicatorClothingComponent component, GotEquippedEvent args)
|
|
{
|
|
if (!TryComp<ClothingComponent>(uid, out var clothing) ||
|
|
!TryComp<TypingIndicatorComponent>(args.Equipee, out var indicator))
|
|
return;
|
|
|
|
var isCorrectSlot = clothing.Slots.HasFlag(args.SlotFlags);
|
|
if (!isCorrectSlot) return;
|
|
|
|
indicator.Prototype = component.Prototype;
|
|
}
|
|
|
|
private void OnGotUnequipped(EntityUid uid, TypingIndicatorClothingComponent component, GotUnequippedEvent args)
|
|
{
|
|
if (!TryComp<TypingIndicatorComponent>(args.Equipee, out var indicator))
|
|
return;
|
|
|
|
indicator.Prototype = SharedTypingIndicatorSystem.InitialIndicatorId;
|
|
}
|
|
}
|