CatStation/Content.Shared/Speech/EntitySystems/FrenchAccentSystem.cs
Pok 7a8fab78e3
Move Accents to Shared v2 (#44772)
* move-accents-to-shared

* Update AccentSystem.cs

* Update ListeningSystem.cs

* aaaaaa

* Update AccentSystem.cs

* oh god

* aaooao

* //

* review

* fix

* Update VocalSystem.cs
2026-07-25 22:29:39 +00:00

51 lines
1.8 KiB
C#

using System.Text.RegularExpressions;
using Content.Shared.Speech.Components;
namespace Content.Shared.Speech.EntitySystems;
/// <summary>
/// System that gives the speaker a faux-French accent.
/// </summary>
public sealed partial class FrenchAccentSystem : RelayAccentSystem<FrenchAccentComponent>
{
[Dependency] private ReplacementAccentSystem _replacement = default!;
private static readonly Regex RegexTh = new("th", RegexOptions.IgnoreCase);
private static readonly Regex RegexStartH = new(@"(?<!\w)h", RegexOptions.IgnoreCase);
private static readonly Regex RegexSpacePunctuation = new(@"(?<=\w\w)[!?;:](?!\w)", RegexOptions.IgnoreCase);
public override string Accentuate(string message, Entity<FrenchAccentComponent>? ent = null)
{
var msg = message;
msg = _replacement.ApplyReplacements(msg, "french", ent?.Owner);
// replaces h with ' at the start of words.
msg = RegexStartH.Replace(msg, "'");
// spaces out ! ? : and ;.
msg = RegexSpacePunctuation.Replace(msg, " $&");
// replaces th with 'z or 's depending on the case
foreach (Match match in RegexTh.Matches(msg))
{
var uppercase = msg.Substring(match.Index, 2).Contains("TH");
var z = uppercase ? "Z" : "z";
var s = uppercase ? "S" : "s";
var idxLetter = match.Index + 2;
// If th is alone, just do 'z
if (msg.Length <= idxLetter)
{
msg = msg.Substring(0, match.Index) + "'" + z;
}
else
{
var c = "aeiouy".Contains(msg.Substring(idxLetter, 1).ToLower()) ? z : s;
msg = msg.Substring(0, match.Index) + "'" + c + msg.Substring(idxLetter);
}
}
return msg;
}
}