AccentSystem.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using System.Text.RegularExpressions;
  2. using Content.Server.Chat;
  3. using Content.Server.Chat.Systems;
  4. namespace Content.Server.Speech
  5. {
  6. public sealed class AccentSystem : EntitySystem
  7. {
  8. public static readonly Regex SentenceRegex = new(@"(?<=[\.!\?‽])(?![\.!\?‽])", RegexOptions.Compiled);
  9. public override void Initialize()
  10. {
  11. SubscribeLocalEvent<TransformSpeechEvent>(AccentHandler);
  12. }
  13. private void AccentHandler(TransformSpeechEvent args)
  14. {
  15. var accentEvent = new AccentGetEvent(args.Sender, args.Message);
  16. RaiseLocalEvent(args.Sender, accentEvent, true);
  17. args.Message = accentEvent.Message;
  18. }
  19. }
  20. public sealed class AccentGetEvent : EntityEventArgs
  21. {
  22. /// <summary>
  23. /// The entity to apply the accent to.
  24. /// </summary>
  25. public EntityUid Entity { get; }
  26. /// <summary>
  27. /// The message to apply the accent transformation to.
  28. /// Modify this to apply the accent.
  29. /// </summary>
  30. public string Message { get; set; }
  31. public AccentGetEvent(EntityUid entity, string message)
  32. {
  33. Entity = entity;
  34. Message = message;
  35. }
  36. }
  37. }