diff --git a/Content.Server/Chat/Managers/ChatManager.cs b/Content.Server/Chat/Managers/ChatManager.cs index 0ae06fac45..542ff0321d 100644 --- a/Content.Server/Chat/Managers/ChatManager.cs +++ b/Content.Server/Chat/Managers/ChatManager.cs @@ -375,6 +375,7 @@ namespace Content.Server.Chat.Managers public void RegisterChatTransform(TransformChat handler) { + // TODO: Literally just make this an event... _chatTransformHandlers.Add(handler); } } diff --git a/Content.Server/Entry/EntryPoint.cs b/Content.Server/Entry/EntryPoint.cs index dfc51731c4..766a3b8f7f 100644 --- a/Content.Server/Entry/EntryPoint.cs +++ b/Content.Server/Entry/EntryPoint.cs @@ -72,7 +72,6 @@ namespace Content.Server.Entry IoCManager.Resolve().Init(); IoCManager.Resolve().Init(); IoCManager.Resolve().Initialize(); - IoCManager.Resolve().Initialize(); _voteManager.Initialize(); } diff --git a/Content.Server/IoC/ServerContentIoC.cs b/Content.Server/IoC/ServerContentIoC.cs index b8df84bb02..a9de3aa77a 100644 --- a/Content.Server/IoC/ServerContentIoC.cs +++ b/Content.Server/IoC/ServerContentIoC.cs @@ -44,7 +44,6 @@ namespace Content.Server.IoC IoCManager.Register(); IoCManager.Register(); IoCManager.Register(); - IoCManager.Register(); IoCManager.Register(); IoCManager.Register(); IoCManager.Register(); diff --git a/Content.Server/Speech/AccentManager.cs b/Content.Server/Speech/AccentManager.cs deleted file mode 100644 index c75f0548d0..0000000000 --- a/Content.Server/Speech/AccentManager.cs +++ /dev/null @@ -1,39 +0,0 @@ -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 interface IAccentManager - { - public void Initialize(); - } - - public class AccentManager : IAccentManager - { - [Dependency] private readonly IChatManager _chatManager = default!; - [Dependency] private readonly IEntityManager _entityManager = default!; - - public static readonly Regex SentenceRegex = new(@"(?<=[\.!\?])"); - - public void Initialize() - { - IoCManager.InjectDependencies(this); - - _chatManager.RegisterChatTransform(AccentHandler); - } - - public string AccentHandler(IEntity player, string message) - { - //TODO: give accents a prio? - var accents = _entityManager.GetComponents(player.Uid); - foreach (var accent in accents) - { - message = accent.Accentuate(message); - } - return message; - } - } -} diff --git a/Content.Server/Speech/AccentSystem.cs b/Content.Server/Speech/AccentSystem.cs new file mode 100644 index 0000000000..591d40c183 --- /dev/null +++ b/Content.Server/Speech/AccentSystem.cs @@ -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 + { + /// + /// The entity to apply the accent to. + /// + public EntityUid Entity { get; } + + /// + /// The message to apply the accent transformation to. + /// Modify this to apply the accent. + /// + public string Message { get; set; } + + public AccentGetEvent(EntityUid entity, string message) + { + Entity = entity; + Message = message; + } + } +} diff --git a/Content.Server/Speech/AddAccent.cs b/Content.Server/Speech/AddAccent.cs deleted file mode 100644 index 4d448cc4f9..0000000000 --- a/Content.Server/Speech/AddAccent.cs +++ /dev/null @@ -1,80 +0,0 @@ -using System.Linq; -using System.Text; -using Content.Server.Administration; -using Content.Server.Speech.Components; -using Content.Shared.Administration; -using Robust.Server.Player; -using Robust.Shared.Console; -using Robust.Shared.GameObjects; -using Robust.Shared.IoC; - -namespace Content.Server.Speech -{ - [AdminCommand(AdminFlags.Fun)] - public class AddAccent : IConsoleCommand - { - public string Command => "addaccent"; - public string Description => "Add a speech component to the current player"; - public string Help => $"{Command} /?"; - - public void Execute(IConsoleShell shell, string argStr, string[] args) - { - var player = shell.Player as IPlayerSession; - if (player?.AttachedEntity == null) - { - shell.WriteLine("You don't have an entity!"); - return; - } - - if (args.Length == 0) - { - shell.WriteLine(Help); - return; - } - - var compFactory = IoCManager.Resolve(); - - if (args[0] == "?") - { - // Get all components that implement the ISpeechComponent except - var speeches = compFactory.GetAllRefTypes() - .Where(c => typeof(IAccentComponent).IsAssignableFrom(c) && c.IsClass); - var msg = new StringBuilder(); - - foreach(var s in speeches) - { - msg.Append($"{compFactory.GetRegistration(s).Name}\n"); - } - - shell.WriteLine(msg.ToString()); - } - else - { - var name = args[0]; - - // Try to get the Component - if (!compFactory.TryGetRegistration(name, out var registration, true)) - { - shell.WriteLine($"Accent {name} not found. Try {Command} ? to get a list of all applicable accents."); - return; - } - - var type = registration.Type; - - // Check if that already exists - if (player.AttachedEntity.HasComponent(type)) - { - shell.WriteLine("You already have this accent!"); - return; - } - - // Generic fuckery - var ensure = typeof(IEntity).GetMethod("AddComponent"); - if (ensure == null) - return; - var method = ensure.MakeGenericMethod(type); - method.Invoke(player.AttachedEntity, null); - } - } - } -} diff --git a/Content.Server/Speech/Components/BackwardsAccentComponent.cs b/Content.Server/Speech/Components/BackwardsAccentComponent.cs index 1ce172e50d..19d79be50c 100644 --- a/Content.Server/Speech/Components/BackwardsAccentComponent.cs +++ b/Content.Server/Speech/Components/BackwardsAccentComponent.cs @@ -1,18 +1,10 @@ -using System; -using Robust.Shared.GameObjects; +using Robust.Shared.GameObjects; namespace Content.Server.Speech.Components { [RegisterComponent] - public class BackwardsAccentComponent : Component, IAccentComponent + public class BackwardsAccentComponent : Component { public override string Name => "BackwardsAccent"; - - public string Accentuate(string message) - { - var arr = message.ToCharArray(); - Array.Reverse(arr); - return new string(arr); - } } } diff --git a/Content.Server/Speech/Components/IAccentComponent.cs b/Content.Server/Speech/Components/IAccentComponent.cs deleted file mode 100644 index 8db4d7b1da..0000000000 --- a/Content.Server/Speech/Components/IAccentComponent.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace Content.Server.Speech.Components -{ - internal interface IAccentComponent - { - /// - /// Transforms a message with the given Accent - /// - /// The spoken message - /// The message after the transformation - public string Accentuate(string message); - } -} diff --git a/Content.Server/Speech/Components/MouseAccentComponent.cs b/Content.Server/Speech/Components/MouseAccentComponent.cs index 03f4b8d915..a22719a301 100644 --- a/Content.Server/Speech/Components/MouseAccentComponent.cs +++ b/Content.Server/Speech/Components/MouseAccentComponent.cs @@ -1,23 +1,10 @@ -using System.Collections.Generic; using Robust.Shared.GameObjects; -using Robust.Shared.IoC; -using Robust.Shared.Random; namespace Content.Server.Speech.Components { [RegisterComponent] - public class MouseAccentComponent : Component, IAccentComponent + public class MouseAccentComponent : Component { - [Dependency] private readonly IRobustRandom _random = default!; public override string Name => "MouseAccent"; - - private static readonly IReadOnlyList Squeek = new List{ - "Squeak!", "Piep!", "Chuu!" - }.AsReadOnly(); - - public string Accentuate(string message) - { - return _random.Pick(Squeek); - } } } diff --git a/Content.Server/Speech/Components/OwOAccentComponent.cs b/Content.Server/Speech/Components/OwOAccentComponent.cs index 3c97c3ef18..39e9111b14 100644 --- a/Content.Server/Speech/Components/OwOAccentComponent.cs +++ b/Content.Server/Speech/Components/OwOAccentComponent.cs @@ -1,37 +1,10 @@ -using System.Collections.Generic; -using Robust.Shared.GameObjects; -using Robust.Shared.IoC; -using Robust.Shared.Random; +using Robust.Shared.GameObjects; namespace Content.Server.Speech.Components { [RegisterComponent] - public class OwOAccentComponent : Component, IAccentComponent + public class OwOAccentComponent : Component { - [Dependency] private readonly IRobustRandom _random = default!; - public override string Name => "OwOAccent"; - - private static readonly IReadOnlyList Faces = new List{ - " (・`ω´・)", " ;;w;;", " owo", " UwU", " >w<", " ^w^" - }.AsReadOnly(); - private string RandomFace => _random.Pick(Faces); - - private static readonly Dictionary SpecialWords = new() - { - { "you", "wu" }, - }; - - 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"); - } } } diff --git a/Content.Server/Speech/Components/SpanishAccentComponent.cs b/Content.Server/Speech/Components/SpanishAccentComponent.cs index 73272bd3d0..413ed120e0 100644 --- a/Content.Server/Speech/Components/SpanishAccentComponent.cs +++ b/Content.Server/Speech/Components/SpanishAccentComponent.cs @@ -3,55 +3,8 @@ namespace Content.Server.Speech.Components { [RegisterComponent] - public class SpanishAccentComponent : Component, IAccentComponent + public class SpanishAccentComponent : Component { public override string Name => "SpanishAccent"; - - 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 = AccentManager.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; - } } } diff --git a/Content.Server/Speech/EntitySystems/BackwardsAccentSystem.cs b/Content.Server/Speech/EntitySystems/BackwardsAccentSystem.cs new file mode 100644 index 0000000000..1de42822ef --- /dev/null +++ b/Content.Server/Speech/EntitySystems/BackwardsAccentSystem.cs @@ -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(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); + } + } +} diff --git a/Content.Server/Speech/EntitySystems/MouseAccentSystem.cs b/Content.Server/Speech/EntitySystems/MouseAccentSystem.cs new file mode 100644 index 0000000000..9e25ef7982 --- /dev/null +++ b/Content.Server/Speech/EntitySystems/MouseAccentSystem.cs @@ -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 Squeek = new List{ "Squeak!", "Piep!", "Chuu!" }; + + public override void Initialize() + { + SubscribeLocalEvent(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); + } + } +} diff --git a/Content.Server/Speech/EntitySystems/OwOAccentSystem.cs b/Content.Server/Speech/EntitySystems/OwOAccentSystem.cs new file mode 100644 index 0000000000..5b7cf5499f --- /dev/null +++ b/Content.Server/Speech/EntitySystems/OwOAccentSystem.cs @@ -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 Faces = new List{ + " (・`ω´・)", " ;;w;;", " owo", " UwU", " >w<", " ^w^" + }.AsReadOnly(); + + private static readonly IReadOnlyDictionary SpecialWords = new Dictionary() + { + { "you", "wu" }, + }; + + private string RandomFace => _random.Pick(Faces); + + public override void Initialize() + { + SubscribeLocalEvent(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); + } + } +} diff --git a/Content.Server/Speech/EntitySystems/SpanishAccentSystem.cs b/Content.Server/Speech/EntitySystems/SpanishAccentSystem.cs new file mode 100644 index 0000000000..902919bce6 --- /dev/null +++ b/Content.Server/Speech/EntitySystems/SpanishAccentSystem.cs @@ -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(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); + } + } +} diff --git a/SpaceStation14.sln.DotSettings b/SpaceStation14.sln.DotSettings index 11609fb2da..ba042ba865 100644 --- a/SpaceStation14.sln.DotSettings +++ b/SpaceStation14.sln.DotSettings @@ -266,6 +266,7 @@ True True True + True True True True