Make... sloths... speak... slowly... (#38142)

* Add SlowAccent

* Apply SlowAccent to sloths

* xmldocs
This commit is contained in:
Tayrtahn
2025-06-21 02:32:30 -04:00
committed by GitHub
parent 357763c55e
commit 640c984ab2
3 changed files with 49 additions and 0 deletions

View File

@@ -0,0 +1,7 @@
namespace Content.Server.Speech.Components;
/// <summary>
/// Makes... the... entity... talk... like... this...
/// </summary>
[RegisterComponent]
public sealed partial class SlowAccentComponent : Component;

View File

@@ -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;
}
}

View File

@@ -3266,6 +3266,7 @@
- type: Grammar - type: Grammar
attributes: attributes:
gender: epicene gender: epicene
- type: SlowAccent
- type: Tag - type: Tag
tags: tags:
- VimPilot - VimPilot