From 28b714a3181f1a0dbc7129a405aeae8b29596cb4 Mon Sep 17 00:00:00 2001 From: Remuchi Date: Sat, 20 Apr 2024 12:38:13 +0700 Subject: [PATCH] =?UTF-8?q?fix:=20=D1=82=D0=B5=D0=BF=D0=B5=D1=80=D1=8C=20?= =?UTF-8?q?=D0=B2=20=D0=BB=D0=BE=D0=B1=D0=B1=D0=B8=20=D0=BC=D0=BE=D0=B6?= =?UTF-8?q?=D0=BD=D0=BE=20=D0=BF=D1=80=D0=BE=D1=81=D0=BB=D1=83=D1=88=D0=B0?= =?UTF-8?q?=D1=82=D1=8C=20=D0=B3=D0=BE=D0=BB=D0=BE=D1=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Preferences/UI/HumanoidProfileEditor.xaml | 2 +- .../UI/HumanoidProfileEditor.xaml.cs | 2 +- .../_White/TTS/HumanoidProfileEditor.TTS.cs | 6 ++- Content.Client/_White/TTS/TTSManager.cs | 6 ++- Content.Client/_White/TTS/TTSSystem.cs | 50 +++++++++---------- Content.Server/_White/TTS/TTSSystem.cs | 40 ++++++--------- Content.Shared/_White/TTS/MsgRequestTTS.cs | 4 +- 7 files changed, 51 insertions(+), 59 deletions(-) diff --git a/Content.Client/Preferences/UI/HumanoidProfileEditor.xaml b/Content.Client/Preferences/UI/HumanoidProfileEditor.xaml index ce8e4c1fcc..ff774bd132 100644 --- a/Content.Client/Preferences/UI/HumanoidProfileEditor.xaml +++ b/Content.Client/Preferences/UI/HumanoidProfileEditor.xaml @@ -126,8 +126,8 @@ diff --git a/Content.Client/Preferences/UI/HumanoidProfileEditor.xaml.cs b/Content.Client/Preferences/UI/HumanoidProfileEditor.xaml.cs index 2de8239dba..a0335eff31 100644 --- a/Content.Client/Preferences/UI/HumanoidProfileEditor.xaml.cs +++ b/Content.Client/Preferences/UI/HumanoidProfileEditor.xaml.cs @@ -76,7 +76,7 @@ namespace Content.Client.Preferences.UI private Button _nameRandomButton => CNameRandomize; private Button _nameClownRandomButton => CClownNameRandomize; private Button _nameMimeRandomButton => CMimeNameRandomize; - private Button _nameBorgRandomButton => CBorgNameRandomize; + private Button _nameBorgRandomButton => CBorgNameRandomize; private Button _randomizeEverythingButton => CRandomizeEverything; private RichTextLabel _warningLabel => CWarningLabel; private Button _saveButton => CSaveButton; diff --git a/Content.Client/_White/TTS/HumanoidProfileEditor.TTS.cs b/Content.Client/_White/TTS/HumanoidProfileEditor.TTS.cs index aae1b130c3..b60ec12d0f 100644 --- a/Content.Client/_White/TTS/HumanoidProfileEditor.TTS.cs +++ b/Content.Client/_White/TTS/HumanoidProfileEditor.TTS.cs @@ -5,6 +5,8 @@ using Content.Shared.Preferences; using Content.Shared._White.TTS; using Robust.Shared.Random; +// ReSharper disable InconsistentNaming + namespace Content.Client.Preferences.UI; public sealed partial class HumanoidProfileEditor @@ -12,6 +14,7 @@ public sealed partial class HumanoidProfileEditor private TTSManager _ttsMgr = default!; private TTSSystem _ttsSys = default!; private List _voiceList = default!; + private readonly List _sampleText = new() { "Помогите, клоун насилует в технических тоннелях!", @@ -35,7 +38,6 @@ public sealed partial class HumanoidProfileEditor }; _voicePlayButton.OnPressed += _ => { PlayTTS(); }; - } private void UpdateTTSVoicesControls() @@ -88,4 +90,4 @@ public sealed partial class HumanoidProfileEditor _ttsSys.StopAllStreams(); _ttsMgr.RequestTTS(_previewDummy.Value, IoCManager.Resolve().Pick(_sampleText), Profile.Voice); } -} +} \ No newline at end of file diff --git a/Content.Client/_White/TTS/TTSManager.cs b/Content.Client/_White/TTS/TTSManager.cs index b07452fe2a..246c420b68 100644 --- a/Content.Client/_White/TTS/TTSManager.cs +++ b/Content.Client/_White/TTS/TTSManager.cs @@ -7,6 +7,7 @@ namespace Content.Client._White.TTS; public sealed class TTSManager { [Dependency] private readonly IClientNetManager _netMgr = default!; + [Dependency] private readonly EntityManager _entityManager = default!; public void Initialize() { @@ -16,7 +17,8 @@ public sealed class TTSManager // ReSharper disable once InconsistentNaming public void RequestTTS(EntityUid uid, string text, string voiceId) { - var msg = new MsgRequestTTS() { Text = text, Uid = uid, VoiceId = voiceId }; + var netEntity = _entityManager.GetNetEntity(uid); + var msg = new MsgRequestTTS() { Text = text, Uid = netEntity, VoiceId = voiceId }; _netMgr.ClientSendMessage(msg); } -} +} \ No newline at end of file diff --git a/Content.Client/_White/TTS/TTSSystem.cs b/Content.Client/_White/TTS/TTSSystem.cs index 5e801a4734..ce533e1e63 100644 --- a/Content.Client/_White/TTS/TTSSystem.cs +++ b/Content.Client/_White/TTS/TTSSystem.cs @@ -5,6 +5,7 @@ using Content.Shared.Physics; using Content.Shared._White; using Content.Shared._White.TTS; using Robust.Client.Audio; +using Robust.Client.GameObjects; using Robust.Client.Graphics; using Robust.Shared.Audio.Sources; using Robust.Shared.Configuration; @@ -25,16 +26,16 @@ public sealed class TTSSystem : EntitySystem [Dependency] private readonly IEyeManager _eye = default!; [Dependency] private readonly IConfigurationManager _cfg = default!; [Dependency] private readonly SharedPhysicsSystem _broadPhase = default!; + [Dependency] private readonly TransformSystem _transform = default!; - private ISawmill _sawmill = default!; - private float _volume = 0.0f; + private float _volume; + private const int TTSCollisionMask = (int)CollisionGroup.Impassable; private readonly HashSet _currentStreams = new(); private readonly Dictionary> _entityQueues = new(); public override void Initialize() { - _sawmill = Logger.GetSawmill("tts"); _cfg.OnValueChanged(WhiteCVars.TtsVolume, OnTtsVolumeChanged, true); SubscribeNetworkEvent(OnPlayTTS); } @@ -64,26 +65,27 @@ public sealed class TTSSystem : EntitySystem continue; } - var mapPos = xform.MapPosition; + var mapPos = _transform.GetMapCoordinates(xform); if (mapPos.MapId != MapId.Nullspace) { stream.Source.Position = mapPos.Position; } - if (mapPos.MapId == _eye.CurrentMap) + if (mapPos.MapId != _eye.CurrentMap) { - var collisionMask = (int) CollisionGroup.Impassable; - var sourceRelative = ourPos - mapPos.Position; - var occlusion = 0f; - if (sourceRelative.Length() > 0) - { - occlusion = _broadPhase.IntersectRayPenetration(mapPos.MapId, - new CollisionRay(mapPos.Position, sourceRelative.Normalized(), collisionMask), - sourceRelative.Length(), stream.Uid); - } - - stream.Source.Occlusion = occlusion; + continue; } + + var sourceRelative = ourPos - mapPos.Position; + var occlusion = 0f; + if (sourceRelative.Length() > 0) + { + occlusion = _broadPhase.IntersectRayPenetration(mapPos.MapId, + new CollisionRay(mapPos.Position, sourceRelative.Normalized(), TTSCollisionMask), + sourceRelative.Length(), stream.Uid); + } + + stream.Source.Occlusion = occlusion; } foreach (var audioStream in streamToRemove) @@ -178,7 +180,7 @@ public sealed class TTSSystem : EntitySystem if (!_entity.TryGetComponent(stream.Uid, out var xform)) return; - stream.Source.Position = xform.WorldPosition; + stream.Source.Position = _transform.GetWorldPosition(xform); stream.Source.StartPlaying(); _currentStreams.Add(stream); } @@ -204,16 +206,10 @@ public sealed class TTSSystem : EntitySystem } // ReSharper disable once InconsistentNaming - private sealed class AudioStream + private sealed class AudioStream(EntityUid uid, IAudioSource source) { - public EntityUid Uid { get; } + public EntityUid Uid { get; } = uid; - public IAudioSource Source { get; } - - public AudioStream(EntityUid uid, IAudioSource source) - { - Uid = uid; - Source = source; - } + public IAudioSource Source { get; } = source; } -} +} \ No newline at end of file diff --git a/Content.Server/_White/TTS/TTSSystem.cs b/Content.Server/_White/TTS/TTSSystem.cs index 70f4517ba2..b1ec1082ea 100644 --- a/Content.Server/_White/TTS/TTSSystem.cs +++ b/Content.Server/_White/TTS/TTSSystem.cs @@ -33,7 +33,7 @@ public sealed partial class TTSSystem : EntitySystem [Dependency] private readonly EntityLookupSystem _lookup = default!; private const int MaxMessageChars = 100 * 2; // same as SingleBubbleCharLimit * 2 - private bool _isEnabled = false; + private bool _isEnabled; private string _apiUrl = string.Empty; public override void Initialize() @@ -122,9 +122,12 @@ public sealed partial class TTSSystem : EntitySystem !_prototypeManager.TryIndex(ev.VoiceId, out var protoVoice)) return; - var soundData = await GenerateTTS(ev.Uid, ev.Text, protoVoice.Speaker); + var soundData = await GenerateTTS(GetEntity(ev.Uid), ev.Text, protoVoice.Speaker); if (soundData != null) - RaiseNetworkEvent(new PlayTTSEvent(GetNetEntity(ev.Uid), soundData, false), Filter.SinglePlayer(session), false); + { + RaiseNetworkEvent(new PlayTTSEvent(ev.Uid, soundData, false), Filter.SinglePlayer(session), + false); + } } private async void OnEntitySpoke(EntityUid uid, SharedTTSComponent component, EntitySpokeEvent args) @@ -189,16 +192,9 @@ public sealed partial class TTSSystem : EntitySystem if (distance > (ChatSystem.VoiceRange * ChatSystem.VoiceRange)) continue; - EntityEventArgs actualEvent; - - if (distance > ChatSystem.WhisperClearRange) - { - actualEvent = obfTtsEvent; - } - else - { - actualEvent = ttsEvent; - } + EntityEventArgs actualEvent = distance > ChatSystem.WhisperClearRange + ? obfTtsEvent + : ttsEvent; RaiseNetworkEvent(actualEvent, Filter.SinglePlayer(session), false); } @@ -209,7 +205,9 @@ public sealed partial class TTSSystem : EntitySystem _ttsManager.ResetCache(); } - private async Task GenerateTTS(EntityUid? uid, string text, string speaker, string? speechPitch = null, string? speechRate = null, string? effect = null) + // ReSharper disable once InconsistentNaming + private async Task GenerateTTS(EntityUid? uid, string text, string speaker, string? speechPitch = null, + string? speechRate = null, string? effect = null) { var textSanitized = Sanitize(text); if (textSanitized == "") @@ -240,14 +238,8 @@ public sealed partial class TTSSystem : EntitySystem } } -public sealed class TransformSpeakerVoiceEvent : EntityEventArgs +public sealed class TransformSpeakerVoiceEvent(EntityUid sender, string voiceId) : EntityEventArgs { - public EntityUid Sender; - public string VoiceId; - - public TransformSpeakerVoiceEvent(EntityUid sender, string voiceId) - { - Sender = sender; - VoiceId = voiceId; - } -} + public EntityUid Sender = sender; + public string VoiceId = voiceId; +} \ No newline at end of file diff --git a/Content.Shared/_White/TTS/MsgRequestTTS.cs b/Content.Shared/_White/TTS/MsgRequestTTS.cs index fb60189ee3..0bd5161b8e 100644 --- a/Content.Shared/_White/TTS/MsgRequestTTS.cs +++ b/Content.Shared/_White/TTS/MsgRequestTTS.cs @@ -10,13 +10,13 @@ public sealed class MsgRequestTTS : NetMessage { public override MsgGroups MsgGroup => MsgGroups.Command; - public EntityUid Uid { get; set; } = EntityUid.Invalid; + public NetEntity Uid { get; set; } = NetEntity.Invalid; public string Text { get; set; } = string.Empty; public ProtoId VoiceId { get; set; } = string.Empty; public override void ReadFromBuffer(NetIncomingMessage buffer, IRobustSerializer serializer) { - Uid = new EntityUid(buffer.ReadInt32()); + Uid = new NetEntity(buffer.ReadInt32()); Text = buffer.ReadString(); VoiceId = buffer.ReadString(); }