]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Fix votes using an audio entity (#27871)
authormetalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Sat, 11 May 2024 01:21:06 +0000 (11:21 +1000)
committerGitHub <noreply@github.com>
Sat, 11 May 2024 01:21:06 +0000 (21:21 -0400)
* Fix votes using an audio entity

Just retains a source around and uses that. I think the audio limit is like 256 sources on the lower end so this is like whatever to persist.

* Restart

* weh

Content.Client/Voting/VoteManager.cs

index 63c706c86b3c5d295477adab9454086cfc71175f..a7c799b58feb6e2d6e831b4bf072efffe3b8fc1b 100644 (file)
@@ -6,12 +6,15 @@ using Robust.Client;
 using Robust.Client.Audio;
 using Robust.Client.Console;
 using Robust.Client.GameObjects;
+using Robust.Client.ResourceManagement;
 using Robust.Client.UserInterface;
 using Robust.Shared.IoC;
 using Robust.Shared.Network;
 using Robust.Shared.Timing;
 using Robust.Shared.Player;
 using Robust.Shared.Audio;
+using Robust.Shared.Audio.Sources;
+using Robust.Shared.ContentPack;
 
 
 namespace Content.Client.Voting
@@ -31,16 +34,20 @@ namespace Content.Client.Voting
 
     public sealed class VoteManager : IVoteManager
     {
+        [Dependency] private readonly IAudioManager _audio = default!;
+        [Dependency] private readonly IBaseClient _client = default!;
+        [Dependency] private readonly IClientConsoleHost _console = default!;
         [Dependency] private readonly IClientNetManager _netManager = default!;
         [Dependency] private readonly IGameTiming _gameTiming = default!;
-        [Dependency] private readonly IClientConsoleHost _console = default!;
-        [Dependency] private readonly IBaseClient _client = default!;
+        [Dependency] private readonly IResourceCache _res = default!;
 
         private readonly Dictionary<StandardVoteType, TimeSpan> _standardVoteTimeouts = new();
         private readonly Dictionary<int, ActiveVote> _votes = new();
         private readonly Dictionary<int, UI.VotePopup> _votePopups = new();
         private Control? _popupContainer;
 
+        private IAudioSource? _voteSource;
+
         public bool CanCallVote { get; private set; }
 
         public event Action<bool>? CanCallVoteChanged;
@@ -49,6 +56,14 @@ namespace Content.Client.Voting
 
         public void Initialize()
         {
+            const string sound = "/Audio/Effects/voteding.ogg";
+            _voteSource = _audio.CreateAudioSource(_res.GetResource<AudioResource>(sound));
+
+            if (_voteSource != null)
+            {
+                _voteSource.Global = true;
+            }
+
             _netManager.RegisterNetMessage<MsgVoteData>(ReceiveVoteData);
             _netManager.RegisterNetMessage<MsgVoteCanCall>(ReceiveVoteCanCall);
 
@@ -125,9 +140,8 @@ namespace Content.Client.Voting
                     return;
                 }
 
+                _voteSource?.Restart();
                 @new = true;
-                IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<AudioSystem>()
-                    .PlayGlobal("/Audio/Effects/voteding.ogg", Filter.Local(), false);
 
                 // Refresh
                 var container = _popupContainer;