Refactor AccentManager to be an entity system, makes accents ECS. (#4825)
This commit is contained in:
committed by
GitHub
parent
55b4edb895
commit
4c80fb9586
46
Content.Server/Speech/EntitySystems/OwOAccentSystem.cs
Normal file
46
Content.Server/Speech/EntitySystems/OwOAccentSystem.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using System.Collections.Generic;
|
||||
using Content.Server.Speech.Components;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Random;
|
||||
|
||||
namespace Content.Server.Speech.EntitySystems
|
||||
{
|
||||
public class OwOAccentSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly IRobustRandom _random = default!;
|
||||
|
||||
private static readonly IReadOnlyList<string> Faces = new List<string>{
|
||||
" (・`ω´・)", " ;;w;;", " owo", " UwU", " >w<", " ^w^"
|
||||
}.AsReadOnly();
|
||||
|
||||
private static readonly IReadOnlyDictionary<string, string> SpecialWords = new Dictionary<string, string>()
|
||||
{
|
||||
{ "you", "wu" },
|
||||
};
|
||||
|
||||
private string RandomFace => _random.Pick(Faces);
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
SubscribeLocalEvent<OwOAccentComponent, AccentGetEvent>(OnAccent);
|
||||
}
|
||||
|
||||
public string Accentuate(string message)
|
||||
{
|
||||
foreach (var (word, repl) in SpecialWords)
|
||||
{
|
||||
message = message.Replace(word, repl);
|
||||
}
|
||||
|
||||
return message.Replace("!", RandomFace)
|
||||
.Replace("r", "w").Replace("R", "W")
|
||||
.Replace("l", "w").Replace("L", "W");
|
||||
}
|
||||
|
||||
private void OnAccent(EntityUid uid, OwOAccentComponent component, AccentGetEvent args)
|
||||
{
|
||||
args.Message = Accentuate(args.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user