Refactor AccentManager to be an entity system, makes accents ECS. (#4825)
This commit is contained in:
committed by
GitHub
parent
55b4edb895
commit
4c80fb9586
49
Content.Server/Speech/AccentSystem.cs
Normal file
49
Content.Server/Speech/AccentSystem.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using System.Text.RegularExpressions;
|
||||
using Content.Server.Chat.Managers;
|
||||
using Content.Server.Speech.Components;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
|
||||
namespace Content.Server.Speech
|
||||
{
|
||||
public class AccentSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly IChatManager _chatManager = default!;
|
||||
|
||||
public static readonly Regex SentenceRegex = new(@"(?<=[\.!\?])");
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
_chatManager.RegisterChatTransform(AccentHandler);
|
||||
}
|
||||
|
||||
public string AccentHandler(IEntity player, string message)
|
||||
{
|
||||
var accentEvent = new AccentGetEvent(player.Uid, message);
|
||||
|
||||
RaiseLocalEvent(player.Uid, accentEvent);
|
||||
|
||||
return accentEvent.Message;
|
||||
}
|
||||
}
|
||||
|
||||
public class AccentGetEvent : EntityEventArgs
|
||||
{
|
||||
/// <summary>
|
||||
/// The entity to apply the accent to.
|
||||
/// </summary>
|
||||
public EntityUid Entity { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The message to apply the accent transformation to.
|
||||
/// Modify this to apply the accent.
|
||||
/// </summary>
|
||||
public string Message { get; set; }
|
||||
|
||||
public AccentGetEvent(EntityUid entity, string message)
|
||||
{
|
||||
Entity = entity;
|
||||
Message = message;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user