Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add codeword highlighting #30092

Merged
merged 8 commits into from
Aug 23, 2024
11 changes: 11 additions & 0 deletions Content.Client/Roles/RoleCodewordComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace Content.Client.Roles;

/// <summary>
///
/// </summary>
SlamBamActionman marked this conversation as resolved.
Show resolved Hide resolved
[RegisterComponent]
public sealed partial class RoleCodewordComponent : Component
{
[DataField("codewords"), ViewVariables(VVAccess.ReadWrite)]
SlamBamActionman marked this conversation as resolved.
Show resolved Hide resolved
public List<string> Codewords;
}
20 changes: 20 additions & 0 deletions Content.Client/Roles/RoleCodewordSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Content.Shared.Roles;

namespace Content.Client.Roles;
public sealed class RoleCodewordSystem : EntitySystem
{
public override void Initialize()
{
base.Initialize();

SubscribeNetworkEvent<RoleCodewordEvent>(SetRoleCodewords);
}

private void SetRoleCodewords(RoleCodewordEvent args)
{
EntityUid uid = GetEntity(args.Entity);

RoleCodewordComponent comp = EnsureComp<RoleCodewordComponent>(uid);
SlamBamActionman marked this conversation as resolved.
Show resolved Hide resolved
comp.Codewords = args.Codewords;
}
}
15 changes: 15 additions & 0 deletions Content.Client/UserInterface/Systems/Chat/ChatUIController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Content.Client.Examine;
using Content.Client.Gameplay;
using Content.Client.Ghost;
using Content.Client.Roles;
using Content.Client.Stylesheets;
using Content.Client.UserInterface.Screens;
using Content.Client.UserInterface.Systems.Chat.Widgets;
Expand Down Expand Up @@ -819,6 +820,20 @@ public void ProcessChatMessage(ChatMessage msg, bool speechBubble = true)
msg.WrappedMessage = SharedChatSystem.InjectTagInsideTag(msg, "Name", "color", GetNameColor(SharedChatSystem.GetStringInsideTag(msg, "Name")));
}

// Color any codewords for roles that use them
var player = _player.LocalEntity;
if (_ent.TryGetComponent(player, out RoleCodewordComponent? codewordComp))
{
var color = Color.FromHex("#8f4a4b"); // Falls back to a dark red Syndicate color if a prototype is not found
if (_prototypeManager.TryIndex("Syndicate", out RadioChannelPrototype? syndieChannel))
SlamBamActionman marked this conversation as resolved.
Show resolved Hide resolved
{
color = syndieChannel.Color;
}

foreach (string codeword in codewordComp.Codewords)
msg.WrappedMessage = SharedChatSystem.InjectTagAroundString(msg, codeword, "color", color.ToHex());
}

// Log all incoming chat to repopulate when filter is un-toggled
if (!msg.HideChat)
{
Expand Down
3 changes: 3 additions & 0 deletions Content.Server/GameTicking/Rules/TraitorRuleSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ public bool MakeTraitor(EntityUid traitor, TraitorRuleComponent component, bool

_antag.SendBriefing(traitor, GenerateBriefing(component.Codewords, code, issuer), null, component.GreetSoundNotification);

// Send codewords to only the traitor client
RaiseNetworkEvent(new RoleCodewordEvent(GetNetEntity(traitor), component.Codewords.ToList()), traitor);
SlamBamActionman marked this conversation as resolved.
Show resolved Hide resolved

component.TraitorMinds.Add(mindId);

// Assign briefing
Expand Down
12 changes: 12 additions & 0 deletions Content.Shared/Chat/SharedChatSystem.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Frozen;
using System.Text.RegularExpressions;
using Content.Shared.Popups;
using Content.Shared.Radio;
using Content.Shared.Speech;
Expand Down Expand Up @@ -237,6 +238,17 @@ public static string InjectTagInsideTag(ChatMessage message, string outerTag, st

return rawmsg;
}

/// <summary>
/// Injects a tag around all found instances of a specific string in a ChatMessage.
/// </summary>
public static string InjectTagAroundString(ChatMessage message, string targetString, string tag, string? tagParameter)
{
var rawmsg = message.WrappedMessage;
rawmsg = Regex.Replace(rawmsg, "(?i)(" + targetString + ")(?-i)", $"[{tag}={tagParameter}]$1[/{tag}]");
return rawmsg;
}

public static string GetStringInsideTag(ChatMessage message, string tag)
{
var rawmsg = message.WrappedMessage;
Expand Down
19 changes: 19 additions & 0 deletions Content.Shared/Roles/RoleCodewordEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Robust.Shared.Serialization;

namespace Content.Shared.Roles;

/// <summary>
/// Raised on the server and sent to a client to record traitor codewords without exposing them to other clients.
/// </summary>
[Serializable, NetSerializable]
public sealed class RoleCodewordEvent : EntityEventArgs
{
public NetEntity Entity;
public List<string> Codewords;

public RoleCodewordEvent(NetEntity entity, List<string> codewords)
{
Codewords = codewords;
Entity = entity;
}
}
Tayrtahn marked this conversation as resolved.
Show resolved Hide resolved
6 changes: 1 addition & 5 deletions Resources/Prototypes/Datasets/verbs.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
- type: dataset
- type: dataset
id: verbs
values:
- accept
Expand Down Expand Up @@ -97,9 +97,7 @@
- coach
- coil
- collect
- colour
- comb
SlamBamActionman marked this conversation as resolved.
Show resolved Hide resolved
- command
- communicate
- compare
- compete
Expand Down Expand Up @@ -544,7 +542,6 @@
- suffer
- suggest
- suit
- supply
- support
- suppose
- surprise
Expand Down Expand Up @@ -616,7 +613,6 @@
- whine
- whip
- whirl
- whisper
- whistle
- wink
- wipe
Expand Down
Loading