]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Fix capitalization for pirates and rats (#26644)
authorVerm <32827189+Vermidia@users.noreply.github.com>
Wed, 17 Apr 2024 10:04:24 +0000 (05:04 -0500)
committerGitHub <noreply@github.com>
Wed, 17 Apr 2024 10:04:24 +0000 (20:04 +1000)
* 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

Content.Server/Speech/EntitySystems/MobsterAccentSystem.cs
Content.Server/Speech/EntitySystems/PirateAccentSystem.cs

index dfc3ab7e124ff04c97c09d3fe741d27148ee73c0..d1a6a049d5e0262a3ea35de3f1c684ca44ef85d6 100644 (file)
@@ -1,4 +1,5 @@
-using System.Globalization;
+using System.Globalization;
+using System.Linq;
 using System.Text.RegularExpressions;
 using Content.Server.Speech.Components;
 using Robust.Shared.Random;
@@ -49,20 +50,30 @@ public sealed class MobsterAccentSystem : EntitySystem
 
         // thinking -> thinkin'
         // king -> king
-        msg = Regex.Replace(msg, @"(?<=\w\w)ing(?!\w)", "in'", RegexOptions.IgnoreCase);
+        //Uses captures groups to make sure the captialization of IN is kept
+        msg = Regex.Replace(msg, @"(?<=\w\w)(in)g(?!\w)", "$1'", RegexOptions.IgnoreCase);
 
         // or -> uh and ar -> ah in the middle of words (fuhget, tahget)
-        msg = Regex.Replace(msg, @"(?<=\w)or(?=\w)", "uh", RegexOptions.IgnoreCase);
-        msg = Regex.Replace(msg, @"(?<=\w)ar(?=\w)", "ah", RegexOptions.IgnoreCase);
+        msg = Regex.Replace(msg, @"(?<=\w)o[Rr](?=\w)", "uh");
+        msg = Regex.Replace(msg, @"(?<=\w)O[Rr](?=\w)", "UH");
+        msg = Regex.Replace(msg, @"(?<=\w)a[Rr](?=\w)", "ah");
+        msg = Regex.Replace(msg, @"(?<=\w)A[Rr](?=\w)", "AH");
 
         // Prefix
         if (_random.Prob(0.15f))
         {
+            //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.Next(1, 2);
 
             // Reverse sanitize capital
-            msg = msg[0].ToString().ToLower() + msg.Remove(0, 1);
-            msg = Loc.GetString($"accent-mobster-prefix-{pick}") + " " + msg;
+            var prefix = Loc.GetString($"accent-mobster-prefix-{pick}");
+            if (!firstWordAllCaps)
+                msg = msg[0].ToString().ToLower() + msg.Remove(0, 1);
+            else
+                prefix = prefix.ToUpper();
+            msg = prefix + " " + msg;
         }
 
         // Sanitize capital again, in case we substituted a word that should be capitalized
@@ -71,16 +82,23 @@ public sealed class MobsterAccentSystem : EntitySystem
         // Suffixes
         if (_random.Prob(0.4f))
         {
+            //Checks if the last word of the sentence is all caps
+            //So the suffix can be allcapped
+            var lastWordAllCaps = !Regex.Match(msg, @"(\S+)$").Value.Any(char.IsLower);
+            var suffix = "";
             if (component.IsBoss)
             {
                 var pick = _random.Next(1, 4);
-                msg += Loc.GetString($"accent-mobster-suffix-boss-{pick}");
+                suffix = Loc.GetString($"accent-mobster-suffix-boss-{pick}");
             }
             else
             {
                 var pick = _random.Next(1, 3);
-                msg += Loc.GetString($"accent-mobster-suffix-minion-{pick}");
+                suffix = Loc.GetString($"accent-mobster-suffix-minion-{pick}");                
             }
+            if (lastWordAllCaps)
+                suffix = suffix.ToUpper();
+            msg += suffix;
         }
 
         return msg;
index f1d64ede101a8bab75eb6269a4fc69e4e6671655..9f5f8080b9b1e2f263df229daf9abdf4ffd002b2 100644 (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;
     }