Add codeword highlighting (#30092)

* Added codeword highlighting

* Updated to support more codeword roles, color is set serverside

* Review feedback

* Change to a Component-based system using SessionSpecific

* Tidied up CanGetState, set Access restrictions on component

* Clean-up

* Makes the injection ignore brackets, restore some codewords, remove "Taste/Touch" from adjectives
This commit is contained in:
SlamBamActionman
2024-08-23 11:14:38 +02:00
committed by GitHub
parent 7b5c6be674
commit 61a1e89339
9 changed files with 146 additions and 3 deletions

View File

@@ -1,4 +1,5 @@
using System.Collections.Frozen;
using System.Text.RegularExpressions;
using Content.Shared.Popups;
using Content.Shared.Radio;
using Content.Shared.Speech;
@@ -237,6 +238,18 @@ public abstract class SharedChatSystem : EntitySystem
return rawmsg;
}
/// <summary>
/// Injects a tag around all found instances of a specific string in a ChatMessage.
/// Excludes strings inside other tags and brackets.
/// </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;