Refactor AccentManager to be an entity system, makes accents ECS. (#4825)
This commit is contained in:
committed by
GitHub
parent
55b4edb895
commit
4c80fb9586
26
Content.Server/Speech/EntitySystems/BackwardsAccentSystem.cs
Normal file
26
Content.Server/Speech/EntitySystems/BackwardsAccentSystem.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using Content.Server.Speech.Components;
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Content.Server.Speech.EntitySystems
|
||||
{
|
||||
public class BackwardsAccentSystem : EntitySystem
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
SubscribeLocalEvent<BackwardsAccentComponent, AccentGetEvent>(OnAccent);
|
||||
}
|
||||
|
||||
public string Accentuate(string message)
|
||||
{
|
||||
var arr = message.ToCharArray();
|
||||
Array.Reverse(arr);
|
||||
return new string(arr);
|
||||
}
|
||||
|
||||
private void OnAccent(EntityUid uid, BackwardsAccentComponent component, AccentGetEvent args)
|
||||
{
|
||||
args.Message = Accentuate(args.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
32
Content.Server/Speech/EntitySystems/MouseAccentSystem.cs
Normal file
32
Content.Server/Speech/EntitySystems/MouseAccentSystem.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
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
|
||||
{
|
||||
// TODO: Code in-game languages and make this a language
|
||||
public class MouseAccentSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly IRobustRandom _random = default!;
|
||||
|
||||
private static readonly IReadOnlyList<string> Squeek = new List<string>{ "Squeak!", "Piep!", "Chuu!" };
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
SubscribeLocalEvent<MouseAccentComponent, AccentGetEvent>(OnAccent);
|
||||
}
|
||||
|
||||
public string Accentuate(string message)
|
||||
{
|
||||
// TODO: Maybe add more than one squeek when there are more words?
|
||||
return _random.Pick(Squeek);
|
||||
}
|
||||
|
||||
private void OnAccent(EntityUid uid, MouseAccentComponent component, AccentGetEvent args)
|
||||
{
|
||||
args.Message = Accentuate(args.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
65
Content.Server/Speech/EntitySystems/SpanishAccentSystem.cs
Normal file
65
Content.Server/Speech/EntitySystems/SpanishAccentSystem.cs
Normal file
@@ -0,0 +1,65 @@
|
||||
using Content.Server.Speech.Components;
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Content.Server.Speech.EntitySystems
|
||||
{
|
||||
public class SpanishAccentSystem : EntitySystem
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
SubscribeLocalEvent<SpanishAccentComponent, AccentGetEvent>(OnAccent);
|
||||
}
|
||||
|
||||
public string Accentuate(string message)
|
||||
{
|
||||
// Insert E before every S
|
||||
message = InsertS(message);
|
||||
// If a sentence ends with ?, insert a reverse ? at the beginning of the sentence
|
||||
message = ReplaceQuestionMark(message);
|
||||
return message;
|
||||
}
|
||||
|
||||
private string InsertS(string message)
|
||||
{
|
||||
// Replace every new Word that starts with s/S
|
||||
var msg = message.Replace(" s", " es").Replace(" S", " Es");
|
||||
|
||||
// Still need to check if the beginning of the message starts
|
||||
if (msg.StartsWith("s"))
|
||||
{
|
||||
return msg.Remove(0, 1).Insert(0, "es");
|
||||
}
|
||||
else if (msg.StartsWith("S"))
|
||||
{
|
||||
return msg.Remove(0, 1).Insert(0, "Es");
|
||||
}
|
||||
|
||||
return msg;
|
||||
}
|
||||
|
||||
private string ReplaceQuestionMark(string message)
|
||||
{
|
||||
var sentences = AccentSystem.SentenceRegex.Split(message);
|
||||
var msg = "";
|
||||
foreach (var s in sentences)
|
||||
{
|
||||
if (s.EndsWith("?")) // We've got a question => add ¿ to the beginning
|
||||
{
|
||||
// Because we don't split by whitespace, we may have some spaces in front of the sentence.
|
||||
// So we add the symbol before the first non space char
|
||||
msg += s.Insert(s.Length - s.TrimStart().Length, "¿");
|
||||
}
|
||||
else
|
||||
{
|
||||
msg += s;
|
||||
}
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
|
||||
private void OnAccent(EntityUid uid, SpanishAccentComponent component, AccentGetEvent args)
|
||||
{
|
||||
args.Message = Accentuate(args.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user