using System.Text.RegularExpressions;
using Content.Server.Speech.Components;
using Content.Shared.Speech;
namespace Content.Server.Speech.EntitySystems;
///
/// System that gives the speaker a faux-French accent.
///
public sealed class FrenchAccentSystem : EntitySystem
{
[Dependency] private readonly ReplacementAccentSystem _replacement = default!;
private static readonly Regex RegexK = new(@"к", RegexOptions.IgnoreCase); // Sunrise-Edit
private static readonly Regex RegexR = new(@"р", RegexOptions.IgnoreCase); // Sunrise-Edit
private static readonly Regex RegexSpacePunctuation = new(@"(?<=\w\w)[!?;:](?!\w)", RegexOptions.IgnoreCase);
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent(OnAccentGet);
}
public string Accentuate(string message, FrenchAccentComponent component)
{
var msg = message;
msg = _replacement.ApplyReplacements(msg, "french");
// replaces к with кх at the start of words.
msg = RegexK.Replace(msg, "кх"); // Sunrise-Edit
// replaces р with х at the start of words.
msg = RegexR.Replace(msg, "х"); // Sunrise-Edit
// spaces out ! ? : and ;.
msg = RegexSpacePunctuation.Replace(msg, " $&");
return msg;
}
private void OnAccentGet(EntityUid uid, FrenchAccentComponent component, AccentGetEvent args)
{
args.Message = Accentuate(args.Message, component);
}
}