Lawyer badge changes typing indicator (#13445)

This commit is contained in:
Morb
2023-01-12 15:33:57 +03:00
committed by GitHub
parent ab073d9571
commit 76f8a7e91e
7 changed files with 67 additions and 32 deletions

View File

@@ -1,9 +1,42 @@
namespace Content.Shared.Chat.TypingIndicator;
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;
}
}

View File

@@ -0,0 +1,13 @@
using Robust.Shared.GameStates;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
namespace Content.Shared.Chat.TypingIndicator;
[RegisterComponent, NetworkedComponent]
[Access(typeof(SharedTypingIndicatorSystem))]
public sealed class TypingIndicatorClothingComponent : Component
{
[ViewVariables(VVAccess.ReadWrite)]
[DataField("proto", required: true, customTypeSerializer: typeof(PrototypeIdSerializer<TypingIndicatorPrototype>))]
public string Prototype = default!;
}

View File

@@ -14,7 +14,7 @@ public sealed class TypingIndicatorComponent : Component
/// <summary>
/// Prototype id that store all visual info about typing indicator.
/// </summary>
[ViewVariables(VVAccess.ReadOnly)]
[ViewVariables(VVAccess.ReadWrite)]
[DataField("proto", customTypeSerializer: typeof(PrototypeIdSerializer<TypingIndicatorPrototype>))]
public string Prototype = "default";
public string Prototype = SharedTypingIndicatorSystem.InitialIndicatorId;
}