From 9441d1f36d4afa6ef189b55314b6788d31e563df Mon Sep 17 00:00:00 2001 From: FaDeOkno <143940725+FaDeOkno@users.noreply.github.com> Date: Fri, 8 Nov 2024 21:20:47 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A4=D0=B8=D0=BA=D1=81=20=D1=82=D1=82=D1=81?= =?UTF-8?q?=D0=B0=20=D0=BD=D0=B0=D0=B2=D0=B5=D1=80=D0=BD=D0=BE=D0=B5=3F=20?= =?UTF-8?q?(#761)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Описание PR Мини-рефактор части кода языков в ChatSystem. Так же, по идее, должен починиться ТТС заменяемых слов. ## Почему / Баланс **Ссылка на публикацию в Discord** - [Баги](https://discord.com/channels/901772674865455115/1304274716223209473) ## Техническая информация ## Медиа ## Требования - [ ] Я прочитал(а) и следую [Руководство по созданию пулл реквестов](https://docs.spacestation14.com/en/general-development/codebase-info/pull-request-guidelines.html). Я понимаю, что в противном случае мой ПР может быть закрыт по усмотрению мейнтейнера. - [ ] Я добавил скриншоты/видео к этому пулл реквесту, демонстрирующие его изменения в игре, **или** этот пулл реквест не требует демонстрации в игре ## Критические изменения **Чейнджлог** :cl: Котя - fix: Поидее должна поправиться работа ттса с автозаменой --- .../ADT/Language/ChatSystem.Language.cs | 54 +++++++++++++++++++ Content.Server/Chat/Systems/ChatSystem.cs | 35 +++--------- 2 files changed, 60 insertions(+), 29 deletions(-) create mode 100644 Content.Server/ADT/Language/ChatSystem.Language.cs diff --git a/Content.Server/ADT/Language/ChatSystem.Language.cs b/Content.Server/ADT/Language/ChatSystem.Language.cs new file mode 100644 index 00000000000..7b1f1f17261 --- /dev/null +++ b/Content.Server/ADT/Language/ChatSystem.Language.cs @@ -0,0 +1,54 @@ +using Robust.Shared.Utility; +using Content.Shared.ADT.Language; + +namespace Content.Server.Chat.Systems; + +public sealed partial class ChatSystem +{ + public (string, string) GetLanguageColoredMessages(EntityUid sender, string message, LanguagePrototype language) + { + string coloredMessage = message; + string coloredLanguageMessage = _language.ObfuscateMessage(sender, message, language); + + if (language.Color != null) + { + coloredMessage = "[color=" + language.Color.Value.ToHex().ToString() + "]" + coloredMessage + "[/color]"; + coloredLanguageMessage = "[color=" + language.Color.Value.ToHex().ToString() + "]" + coloredLanguageMessage + "[/color]"; + } + + return (coloredMessage, coloredLanguageMessage); + } + + public (string, string) GetLanguageICSanitizedMessages(EntityUid sender, string message, LanguagePrototype language) + { + message = SanitizeInGameICMessage(sender, FormattedMessage.EscapeText(message), out _); + string languageMessage = SanitizeInGameICMessage(sender, FormattedMessage.EscapeText(_language.ObfuscateMessage(sender, message, language)), out _); + + return (message, languageMessage); + } + + public (string, string) GetObfuscatedLanguageMessages(EntityUid source, string message, LanguagePrototype language) + { + var obfuscatedMessage = ObfuscateMessageReadability(message, 0.2f); + var obfuscatedLanguageMessage = ObfuscateMessageReadability(_language.ObfuscateMessage(source, message, language), 0.2f); + + return (obfuscatedMessage, obfuscatedLanguageMessage); + } + + public (string, string, string, string) GetColoredObfuscatedLanguageMessages(EntityUid source, string message, LanguagePrototype language) + { + var languageMessage = _language.ObfuscateMessage(source, message, language); + var obfuscatedMessage = ObfuscateMessageReadability(message, 0.2f); + var obfuscatedLanguageMessage = ObfuscateMessageReadability(languageMessage, 0.2f); + + if (language.Color != null) + { + message = "[color=" + language.Color.Value.ToHex().ToString() + "]" + message + "[/color]"; + languageMessage = "[color=" + language.Color.Value.ToHex().ToString() + "]" + languageMessage + "[/color]"; + obfuscatedMessage = "[color=" + language.Color.Value.ToHex().ToString() + "]" + obfuscatedMessage + "[/color]"; + obfuscatedLanguageMessage = "[color=" + language.Color.Value.ToHex().ToString() + "]" + obfuscatedLanguageMessage + "[/color]"; + } + + return (message, languageMessage, obfuscatedMessage, obfuscatedLanguageMessage); + } +} diff --git a/Content.Server/Chat/Systems/ChatSystem.cs b/Content.Server/Chat/Systems/ChatSystem.cs index 22a96111d65..83f762a0a36 100644 --- a/Content.Server/Chat/Systems/ChatSystem.cs +++ b/Content.Server/Chat/Systems/ChatSystem.cs @@ -558,12 +558,8 @@ private void SendEntitySpeak( bool shouldCapitalizeTheWordI = (!CultureInfo.CurrentCulture.IsNeutralCulture && CultureInfo.CurrentCulture.Parent.Name == "en") || (CultureInfo.CurrentCulture.IsNeutralCulture && CultureInfo.CurrentCulture.Name == "en"); - string coloredMessage = SanitizeInGameICMessage(source, FormattedMessage.EscapeText(message), out _, true, shouldPunctuate, shouldCapitalizeTheWordI); - - string coloredLanguageMessage = SanitizeInGameICMessage(source, _language.ObfuscateMessage(source, FormattedMessage.EscapeText(message), language), out _); - - coloredMessage = FormattedMessage.EscapeText(coloredMessage); - coloredLanguageMessage = FormattedMessage.EscapeText(coloredLanguageMessage); + var (sanitizedMessage, sanitizedLanguageMessage) = GetLanguageICSanitizedMessages(source, message, language); + var (coloredMessage, coloredLanguageMessage) = GetLanguageColoredMessages(source, sanitizedMessage, language); if (language.Color != null) { @@ -595,7 +591,7 @@ private void SendEntitySpeak( SendInVoiceRange(ChatChannel.Local, message, wrappedMessage, wrappedLanguageMessage, source, range, language: language); // ADT Languages - var ev = new EntitySpokeEvent(source, message, language, null, null); + var ev = new EntitySpokeEvent(source, sanitizedMessage, language, null, null); // ADT message => sanitizedMessage RaiseLocalEvent(source, ev, true); // To avoid logging any messages sent by entities that are not players, like vendors, cloning, etc. @@ -644,9 +640,6 @@ private void SendEntityWhisper( // ADT Languages start if (language == null) language = _language.GetCurrentLanguage(source); - - var languageMessage = SanitizeInGameICMessage(source, _language.ObfuscateMessage(source, message, language), out _); - var obfuscatedLanguageMessage = ObfuscateMessageReadability(SanitizeInGameICMessage(source, _language.ObfuscateMessage(source, message, language), out _), 0.2f); // ADT Languages end // get the entity's name by visual identity (if no override provided). @@ -670,24 +663,8 @@ private void SendEntityWhisper( bool shouldCapitalizeTheWordI = (!CultureInfo.CurrentCulture.IsNeutralCulture && CultureInfo.CurrentCulture.Parent.Name == "en") || (CultureInfo.CurrentCulture.IsNeutralCulture && CultureInfo.CurrentCulture.Name == "en"); - string coloredMessage = SanitizeInGameICMessage(source, FormattedMessage.EscapeText(message), out _, true, shouldPunctuate, shouldCapitalizeTheWordI); - string coloredObfuscatedMessage = SanitizeInGameICMessage(source, FormattedMessage.EscapeText(obfuscatedMessage), out _, true, shouldPunctuate, shouldCapitalizeTheWordI); - - string coloredObfuscatedLanguageMessage = FormattedMessage.EscapeText(obfuscatedLanguageMessage); - string coloredLanguageMessage = FormattedMessage.EscapeText(languageMessage); - - coloredMessage = FormattedMessage.EscapeText(coloredMessage); - coloredObfuscatedMessage = FormattedMessage.EscapeText(coloredObfuscatedMessage); - coloredObfuscatedLanguageMessage = FormattedMessage.EscapeText(coloredObfuscatedLanguageMessage); - coloredLanguageMessage = FormattedMessage.EscapeText(coloredLanguageMessage); - - if (language.WhisperColor != null) - { - coloredMessage = "[color=" + language.WhisperColor.Value.ToHex().ToString() + "]" + coloredMessage + "[/color]"; - coloredObfuscatedMessage = "[color=" + language.WhisperColor.Value.ToHex().ToString() + "]" + coloredObfuscatedMessage + "[/color]"; - coloredObfuscatedLanguageMessage = "[color=" + language.WhisperColor.Value.ToHex().ToString() + "]" + coloredObfuscatedLanguageMessage + "[/color]"; - coloredLanguageMessage = "[color=" + language.WhisperColor.Value.ToHex().ToString() + "]" + coloredLanguageMessage + "[/color]"; - } + var (sanitizedMessage, sanitizedLanguageMessage) = GetLanguageICSanitizedMessages(source, message, language); + var (coloredMessage, coloredLanguageMessage, coloredObfuscatedMessage, coloredObfuscatedLanguageMessage) = GetColoredObfuscatedLanguageMessages(source, sanitizedMessage, language); name = FormattedMessage.EscapeText(name); @@ -755,7 +732,7 @@ private void SendEntityWhisper( _replay.RecordServerMessage(new ChatMessage(ChatChannel.Whisper, message, wrappedMessage, GetNetEntity(source), null, MessageRangeHideChatForReplay(range))); - var ev = new EntitySpokeEvent(source, message, language, channel, obfuscatedMessage, true); + var ev = new EntitySpokeEvent(source, sanitizedMessage, language, channel, obfuscatedMessage, true); // ADT message => sanitizedMessage RaiseLocalEvent(source, ev, true); if (!hideLog) if (originalMessage == message)