]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Make... sloths... speak... slowly... (#38142)
authorTayrtahn <tayrtahn@gmail.com>
Sat, 21 Jun 2025 06:32:30 +0000 (02:32 -0400)
committerGitHub <noreply@github.com>
Sat, 21 Jun 2025 06:32:30 +0000 (23:32 -0700)
* Add SlowAccent

* Apply SlowAccent to sloths

* xmldocs

Content.Server/Speech/Components/SlowAccentComponent.cs [new file with mode: 0644]
Content.Server/Speech/EntitySystems/SlowAccentSystem.cs [new file with mode: 0644]
Resources/Prototypes/Entities/Mobs/NPCs/animals.yml

diff --git a/Content.Server/Speech/Components/SlowAccentComponent.cs b/Content.Server/Speech/Components/SlowAccentComponent.cs
new file mode 100644 (file)
index 0000000..1222475
--- /dev/null
@@ -0,0 +1,7 @@
+namespace Content.Server.Speech.Components;
+
+/// <summary>
+/// Makes... the... entity... talk... like... this...
+/// </summary>
+[RegisterComponent]
+public sealed partial class SlowAccentComponent : Component;
diff --git a/Content.Server/Speech/EntitySystems/SlowAccentSystem.cs b/Content.Server/Speech/EntitySystems/SlowAccentSystem.cs
new file mode 100644 (file)
index 0000000..5a94b0a
--- /dev/null
@@ -0,0 +1,41 @@
+using System.Text.RegularExpressions;
+using Content.Server.Speech.Components;
+
+namespace Content.Server.Speech.EntitySystems;
+
+public sealed partial class SlowAccentSystem : EntitySystem
+{
+    /// <summary>
+    /// Matches whitespace characters or commas (with or without a space after them).
+    /// </summary>
+    private static readonly Regex WordEndings = new("\\s|, |,");
+
+    /// <summary>
+    /// Matches the end of the string only if the last character is a "word" character.
+    /// </summary>
+    private static readonly Regex NoFinalPunctuation = new("\\w\\z");
+
+    public override void Initialize()
+    {
+        base.Initialize();
+
+        SubscribeLocalEvent<SlowAccentComponent, AccentGetEvent>(OnAccentGet);
+    }
+
+    private void OnAccentGet(Entity<SlowAccentComponent> ent, ref AccentGetEvent args)
+    {
+        args.Message = Accentuate(ent, args.Message);
+    }
+
+    public string Accentuate(Entity<SlowAccentComponent> ent, string message)
+    {
+        // Add... some... delay... between... each... word
+        message = WordEndings.Replace(message, "... ");
+
+        // Add "..." to the end, if the last character is part of a word...
+        if (NoFinalPunctuation.IsMatch(message))
+            message += "...";
+
+        return message;
+    }
+}
index f57d87ed2fde6eadbbc35a2e247c8827ca72c9c5..967dda00db04811a10242ca66ad6e1fa5efed344 100644 (file)
   - type: Grammar
     attributes:
       gender: epicene
+  - type: SlowAccent
   - type: Tag
     tags:
     - VimPilot