]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Add a debug command for global audio (#22018)
authormetalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Thu, 30 Nov 2023 13:24:48 +0000 (00:24 +1100)
committerGitHub <noreply@github.com>
Thu, 30 Nov 2023 13:24:48 +0000 (00:24 +1100)
Content.Server/Administration/Commands/PlayGlobalSoundCommand.cs

index fdf067181dba7859918d0532eebeec8d6dd54716..e282c1d7da51cab31a2d945a8c230c9c875ab84f 100644 (file)
@@ -1,6 +1,8 @@
+using System.IO;
 using System.Linq;
 using Content.Server.Audio;
 using Content.Shared.Administration;
+using Robust.Server.Audio;
 using Robust.Server.Player;
 using Robust.Shared.Audio;
 using Robust.Shared.Console;
@@ -10,6 +12,50 @@ using Robust.Shared.Prototypes;
 
 namespace Content.Server.Administration.Commands;
 
+// This is for debugging nothing more.
+[AdminCommand(AdminFlags.Debug)]
+public sealed class PlayGlobalAudioCommand : IConsoleCommand
+{
+    public string Command => "playaudio";
+    public string Description => "Plays audio globally for debugging";
+    public string Help => $"{Command}";
+    public void Execute(IConsoleShell shell, string argStr, string[] args)
+    {
+        var entManager = IoCManager.Resolve<IEntityManager>();
+        var protoManager = IoCManager.Resolve<IPrototypeManager>();
+        var resourceManager = IoCManager.Resolve<IResourceManager>();
+        var audioSystem = entManager.System<AudioSystem>();
+        var fileName = args[0];
+
+        shell.WriteLine($"Checking {fileName} global audio");
+
+        var audioLength = audioSystem.GetAudioLength(fileName);
+
+        shell.WriteLine($"Cached audio length is: {audioLength}");
+
+        // Copied code to get the actual length determination
+        // Check shipped metadata from packaging.
+        if (protoManager.TryIndex(fileName, out AudioMetadataPrototype? metadata))
+        {
+            shell.WriteLine($"Used prototype, length is: {metadata.Length}");
+        }
+        else if (!resourceManager.TryContentFileRead(fileName, out var stream))
+        {
+            throw new FileNotFoundException($"Unable to find metadata for audio file {fileName}");
+        }
+        else
+        {
+            shell.WriteLine("Looks like audio stream used and cached.");
+        }
+
+        var broadcastFilter = Filter.Broadcast();
+
+        shell.WriteLine($"Playing filter to {broadcastFilter.Count} players");
+
+        audioSystem.PlayGlobal(fileName, broadcastFilter, true);
+    }
+}
+
 [AdminCommand(AdminFlags.Fun)]
 public sealed class PlayGlobalSoundCommand : IConsoleCommand
 {