Fix capitalization for pirates and rats (#26644)

* Fix capitalization for pirates and rats

* Deal with replacements better

* Be smarter about caps

* Do last word properly

* Variables named a bit better

* Fix Consistency

* Undo change that's not needed anymore

* Fix up pirate since it doesn't need to check early either

* Make mobster replacin' a bit better anyway

* Remove extra space

* Use capture groups for mobster in', add comments for first and last words

* Slightly more clarification with comments
This commit is contained in:
Verm
2024-04-17 05:04:24 -05:00
committed by GitHub
parent 5b8468c9d8
commit 432e6ec45d
2 changed files with 37 additions and 13 deletions

View File

@@ -1,3 +1,4 @@
using System.Linq;
using Content.Server.Speech.Components;
using Robust.Shared.Random;
using System.Text.RegularExpressions;
@@ -19,17 +20,22 @@ public sealed class PirateAccentSystem : EntitySystem
// converts left word when typed into the right word. For example typing you becomes ye.
public string Accentuate(string message, PirateAccentComponent component)
{
var msg = message;
msg = _replacement.ApplyReplacements(msg, "pirate");
var msg = _replacement.ApplyReplacements(message, "pirate");
if (!_random.Prob(component.YarrChance))
return msg;
//Checks if the first word of the sentence is all caps
//So the prefix can be allcapped and to not resanitize the captial
var firstWordAllCaps = !Regex.Match(msg, @"^(\S+)").Value.Any(char.IsLower);
var pick = _random.Pick(component.PirateWords);
var pirateWord = Loc.GetString(pick);
// Reverse sanitize capital
msg = msg[0].ToString().ToLower() + msg.Remove(0, 1);
msg = Loc.GetString(pick) + " " + msg;
if (!firstWordAllCaps)
msg = msg[0].ToString().ToLower() + msg.Remove(0, 1);
else
pirateWord = pirateWord.ToUpper();
msg = pirateWord + " " + msg;
return msg;
}