mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-04-17 05:27:38 +03:00
Ports Russian and German languages from Wizden and adds traits for them. Also adds traits for Italian, French and Spanish since they already exist. Not tested because the game didn't want to build locally. # Changelog <!-- You can add an author after the `🆑` to change the name that appears in the changelog (ex: `🆑 Death`) Leaving it blank will default to your GitHub display name This includes all available types for the changelog --> 🆑 - add: Added traits for accents: Russian, German, French, Italian and Spanish --------- Signed-off-by: Peptide90 <78795277+Peptide90@users.noreply.github.com> (cherry picked from commit 91eb7bff09e7c61896b92fde70ac7c4d47e96a6d)
86 lines
2.9 KiB
C#
86 lines
2.9 KiB
C#
using System.Text;
|
|
using Content.Server.Speech.Components;
|
|
using Robust.Shared.Random;
|
|
using System.Text.RegularExpressions;
|
|
|
|
namespace Content.Server.Speech.EntitySystems;
|
|
|
|
public sealed class GermanAccentSystem : EntitySystem
|
|
{
|
|
[Dependency] private readonly IRobustRandom _random = default!;
|
|
[Dependency] private readonly ReplacementAccentSystem _replacement = default!;
|
|
|
|
private static readonly Regex RegexTh = new(@"(?<=\s|^)th", RegexOptions.IgnoreCase);
|
|
private static readonly Regex RegexThe = new(@"(?<=\s|^)the(?=\s|$)", RegexOptions.IgnoreCase);
|
|
|
|
public override void Initialize()
|
|
{
|
|
SubscribeLocalEvent<GermanAccentComponent, AccentGetEvent>(OnAccent);
|
|
}
|
|
|
|
public string Accentuate(string message)
|
|
{
|
|
var msg = message;
|
|
|
|
// rarely, "the" should become "das" instead of "ze"
|
|
// TODO: The ReplacementAccentSystem should have random replacements this built-in.
|
|
foreach (Match match in RegexThe.Matches(msg))
|
|
{
|
|
if (_random.Prob(0.3f))
|
|
{
|
|
// just shift T, H and E over to D, A and S to preserve capitalization
|
|
msg = msg.Substring(0, match.Index) +
|
|
(char)(msg[match.Index] - 16) +
|
|
(char)(msg[match.Index + 1] - 7) +
|
|
(char)(msg[match.Index + 2] + 14) +
|
|
msg.Substring(match.Index + 3);
|
|
}
|
|
}
|
|
|
|
// now, apply word replacements
|
|
msg = _replacement.ApplyReplacements(msg, "german");
|
|
|
|
// replace th with zh (for zhis, zhat, etc. the => ze is handled by replacements already)
|
|
var msgBuilder = new StringBuilder(msg);
|
|
foreach (Match match in RegexTh.Matches(msg))
|
|
{
|
|
// just shift the T over to a Z to preserve capitalization
|
|
msgBuilder[match.Index] = (char) (msgBuilder[match.Index] + 6);
|
|
}
|
|
|
|
// Random Umlaut Time! (The joke outweighs the emotional damage this inflicts on actual Germans)
|
|
var umlautCooldown = 0;
|
|
for (var i = 0; i < msgBuilder.Length; i++)
|
|
{
|
|
if (umlautCooldown == 0)
|
|
{
|
|
if (_random.Prob(0.1f)) // 10% of all eligible vowels become umlauts)
|
|
{
|
|
msgBuilder[i] = msgBuilder[i] switch
|
|
{
|
|
'A' => 'Ä',
|
|
'a' => 'ä',
|
|
'O' => 'Ö',
|
|
'o' => 'ö',
|
|
'U' => 'Ü',
|
|
'u' => 'ü',
|
|
_ => msgBuilder[i]
|
|
};
|
|
umlautCooldown = 4;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
umlautCooldown--;
|
|
}
|
|
}
|
|
|
|
return msgBuilder.ToString();
|
|
}
|
|
|
|
private void OnAccent(Entity<GermanAccentComponent> ent, ref AccentGetEvent args)
|
|
{
|
|
args.Message = Accentuate(args.Message);
|
|
}
|
|
}
|