From 560f59a5d9de2a53b264a62bce138f1d68d15843 Mon Sep 17 00:00:00 2001
From: Janet Blackquill <uhhadd@gmail.com>
Date: Fri, 29 Nov 2024 22:25:24 -0500
Subject: [PATCH] start hacking in some level of BC

---
 Robust.Client/Audio/AudioSystem.cs            |  2 +-
 Robust.Shared/Audio/ResolvedSoundSpecifier.cs |  2 +-
 .../Audio/Systems/SharedAudioSystem.cs        | 88 +++++++++++++++----
 3 files changed, 75 insertions(+), 17 deletions(-)

diff --git a/Robust.Client/Audio/AudioSystem.cs b/Robust.Client/Audio/AudioSystem.cs
index 314ff30a275f..e36422a249bf 100644
--- a/Robust.Client/Audio/AudioSystem.cs
+++ b/Robust.Client/Audio/AudioSystem.cs
@@ -417,7 +417,7 @@ public float GetOcclusion(MapCoordinates listener, Vector2 delta, float distance
 
     private bool TryGetAudio(ResolvedSoundSpecifier specifier, [NotNullWhen(true)] out AudioResource? audio)
     {
-        var filename = GetAudioPath(specifier) ?? string.Empty;
+        var filename = GetSoundPath(specifier) ?? string.Empty;
         if (_resourceCache.TryGetResource(new ResPath(filename), out audio))
             return true;
 
diff --git a/Robust.Shared/Audio/ResolvedSoundSpecifier.cs b/Robust.Shared/Audio/ResolvedSoundSpecifier.cs
index db5c8b39cebf..ff9162baa1fe 100644
--- a/Robust.Shared/Audio/ResolvedSoundSpecifier.cs
+++ b/Robust.Shared/Audio/ResolvedSoundSpecifier.cs
@@ -14,7 +14,7 @@ namespace Robust.Shared.Audio;
 [Serializable, NetSerializable]
 public abstract partial class ResolvedSoundSpecifier {
     [Obsolete("String literals for sounds are deprecated, use a SoundSpecifier or ResolvedSoundSpecifier as appropriate instead")]
-    public static implicit operator ResolvedSoundSpecifier(string s) => new ResolvedPathSpecifier(s);
+    public static implicit operator ResolvedSoundSpecifier(string? s) => s is string path ? new ResolvedPathSpecifier(path) : null!;
     [Obsolete("String literals for sounds are deprecated, use a SoundSpecifier or ResolvedSoundSpecifier as appropriate instead")]
     public static implicit operator ResolvedSoundSpecifier(ResPath s) => new ResolvedPathSpecifier(s);
 
diff --git a/Robust.Shared/Audio/Systems/SharedAudioSystem.cs b/Robust.Shared/Audio/Systems/SharedAudioSystem.cs
index 7d753134564e..602d5ba75881 100644
--- a/Robust.Shared/Audio/Systems/SharedAudioSystem.cs
+++ b/Robust.Shared/Audio/Systems/SharedAudioSystem.cs
@@ -273,7 +273,7 @@ public float GetAudioDistance(float length)
     /// <summary>
     /// Resolves the filepath to a sound file.
     /// </summary>
-    public ResolvedSoundSpecifier GetSound(SoundSpecifier specifier)
+    public ResolvedSoundSpecifier ResolveSound(SoundSpecifier specifier)
     {
         switch (specifier)
         {
@@ -294,9 +294,67 @@ public ResolvedSoundSpecifier GetSound(SoundSpecifier specifier)
         return new ResolvedPathSpecifier(string.Empty);
     }
 
+    [Obsolete("Use ResolvedSound instead")]
+    public string GetSound(SoundSpecifier specifier)
+    {
+        switch (specifier)
+        {
+            case SoundPathSpecifier path:
+                return path.Path == default ? string.Empty : path.Path.ToString();
+
+            case SoundCollectionSpecifier collection:
+            {
+                if (collection.Collection == null)
+                    return string.Empty;
+
+                var soundCollection = ProtoMan.Index<SoundCollectionPrototype>(collection.Collection);
+                return RandMan.Pick(soundCollection.PickFiles).ToString();
+            }
+        }
+
+        return string.Empty;
+    }
+
+    [Obsolete("Use the ResolvedSoundSpecifier overload instead")]
+    public (EntityUid Entity, Components.AudioComponent Component)? PlayGlobal(string? filename, Filter playerFilter, bool recordReplay, AudioParams? audioParams = null) =>
+        PlayGlobal((ResolvedSoundSpecifier)filename, playerFilter, recordReplay, audioParams);
+    [Obsolete("Use the ResolvedSoundSpecifier overload instead")]
+    public (EntityUid Entity, Components.AudioComponent Component)? PlayGlobal(string? filename, ICommonSession recipient, AudioParams? audioParams = null) =>
+        PlayGlobal((ResolvedSoundSpecifier)filename, recipient, audioParams);
+    [Obsolete("Use the ResolvedSoundSpecifier overload instead")]
+    public (EntityUid Entity, Components.AudioComponent Component)? PlayGlobal(string? filename, EntityUid recipient, AudioParams? audioParams = null) =>
+        PlayGlobal((ResolvedSoundSpecifier)filename, recipient, audioParams);
+
+    [Obsolete("Use the ResolvedSoundSpecifier overload instead")]
+    public (EntityUid Entity, Components.AudioComponent Component)? PlayEntity(string? filename, Filter playerFilter, EntityUid uid, bool recordReplay, AudioParams? audioParams = null) =>
+        PlayEntity((ResolvedSoundSpecifier)filename, playerFilter, uid, recordReplay, audioParams);
+    [Obsolete("Use the ResolvedSoundSpecifier overload instead")]
+    public (EntityUid Entity, Components.AudioComponent Component)? PlayEntity(string? filename, ICommonSession recipient, EntityUid uid, AudioParams? audioParams = null) =>
+        PlayEntity((ResolvedSoundSpecifier)filename, recipient, uid, audioParams);
+    [Obsolete("Use the ResolvedSoundSpecifier overload instead")]
+    public (EntityUid Entity, Components.AudioComponent Component)? PlayEntity(string? filename, EntityUid recipient, EntityUid uid, AudioParams? audioParams = null) =>
+        PlayEntity((ResolvedSoundSpecifier)filename, recipient, uid, audioParams);
+
+    [Obsolete("Use the ResolvedSoundSpecifier overload instead")]
+    public (EntityUid Entity, Components.AudioComponent Component)? PlayPvs(string? filename, EntityCoordinates coordinates, AudioParams? audioParams = null) =>
+        PlayPvs((ResolvedSoundSpecifier)filename, coordinates, audioParams);
+    [Obsolete("Use the ResolvedSoundSpecifier overload instead")]
+    public (EntityUid Entity, Components.AudioComponent Component)? PlayPvs(string? filename, EntityUid uid, AudioParams? audioParams = null) =>
+        PlayPvs((ResolvedSoundSpecifier)filename, uid, audioParams);
+
+    [Obsolete("Use the ResolvedSoundSpecifier overload instead")]
+    public (EntityUid Entity, Components.AudioComponent Component)? PlayStatic(string? filename, Filter playerFilter, EntityCoordinates coordinates, bool recordReplay, AudioParams? audioParams = null) =>
+        PlayStatic((ResolvedSoundSpecifier)filename, playerFilter, coordinates, recordReplay, audioParams);
+    [Obsolete("Use the ResolvedSoundSpecifier overload instead")]
+    public (EntityUid Entity, Components.AudioComponent Component)? PlayStatic(string? filename, ICommonSession recipient, EntityCoordinates coordinates, AudioParams? audioParams = null) =>
+        PlayStatic((ResolvedSoundSpecifier)filename, recipient, coordinates, audioParams);
+    [Obsolete("Use the ResolvedSoundSpecifier overload instead")]
+    public (EntityUid Entity, Components.AudioComponent Component)? PlayStatic(string? filename, EntityUid recipient, EntityCoordinates coordinates, AudioParams? audioParams = null) =>
+        PlayStatic((ResolvedSoundSpecifier)filename, recipient, coordinates, audioParams);
+
     #region AudioParams
 
-    public string? GetAudioPath(ResolvedSoundSpecifier? specifier)
+    public string? GetSoundPath(ResolvedSoundSpecifier? specifier)
     {
         return specifier switch {
             ResolvedPathSpecifier path =>
@@ -312,7 +370,7 @@ collection.Collection is null ?
     protected Entity<AudioComponent> SetupAudio(ResolvedSoundSpecifier? specifier, AudioParams? audioParams, bool initialize = true, TimeSpan? length = null)
     {
         var uid = EntityManager.CreateEntityUninitialized("Audio", MapCoordinates.Nullspace);
-        var fileName = GetAudioPath(specifier);
+        var fileName = GetSoundPath(specifier);
         DebugTools.Assert(!string.IsNullOrEmpty(fileName) || length is not null);
         MetadataSys.SetEntityName(uid, $"Audio ({fileName})", raiseEvents: false);
         audioParams ??= AudioParams.Default;
@@ -400,7 +458,7 @@ public void SetVolume(EntityUid? entity, float value, AudioComponent? component
     /// </summary>
     public TimeSpan GetAudioLength(ResolvedSoundSpecifier specifier)
     {
-        var filename = GetAudioPath(specifier) ?? string.Empty;
+        var filename = GetSoundPath(specifier) ?? string.Empty;
         if (!filename.StartsWith("/"))
             throw new ArgumentException("Path must be rooted");
 
@@ -442,7 +500,7 @@ public TimeSpan GetAudioLength(ResolvedSoundSpecifier specifier)
     /// <param name="playerFilter">The set of players that will hear the sound.</param>
     public (EntityUid Entity, Components.AudioComponent Component)? PlayGlobal(SoundSpecifier? sound, Filter playerFilter, bool recordReplay, AudioParams? audioParams = null)
     {
-        return sound == null ? null : PlayGlobal(GetSound(sound), playerFilter, recordReplay, audioParams ?? sound.Params);
+        return sound == null ? null : PlayGlobal(ResolveSound(sound), playerFilter, recordReplay, audioParams ?? sound.Params);
     }
 
     /// <summary>
@@ -459,7 +517,7 @@ public TimeSpan GetAudioLength(ResolvedSoundSpecifier specifier)
     /// <param name="recipient">The player that will hear the sound.</param>
     public (EntityUid Entity, Components.AudioComponent Component)? PlayGlobal(SoundSpecifier? sound, ICommonSession recipient, AudioParams? audioParams = null)
     {
-        return sound == null ? null : PlayGlobal(GetSound(sound), recipient, audioParams ?? sound.Params);
+        return sound == null ? null : PlayGlobal(ResolveSound(sound), recipient, audioParams ?? sound.Params);
     }
 
     public abstract void LoadStream<T>(Entity<AudioComponent> entity, T stream);
@@ -478,7 +536,7 @@ public TimeSpan GetAudioLength(ResolvedSoundSpecifier specifier)
     /// <param name="recipient">The player that will hear the sound.</param>
     public (EntityUid Entity, Components.AudioComponent Component)? PlayGlobal(SoundSpecifier? sound, EntityUid recipient, AudioParams? audioParams = null)
     {
-        return sound == null ? null : PlayGlobal(GetSound(sound), recipient, audioParams ?? sound.Params);
+        return sound == null ? null : PlayGlobal(ResolveSound(sound), recipient, audioParams ?? sound.Params);
     }
 
     /// <summary>
@@ -513,7 +571,7 @@ public TimeSpan GetAudioLength(ResolvedSoundSpecifier specifier)
     /// <param name="uid">The UID of the entity "emitting" the audio.</param>
     public (EntityUid Entity, Components.AudioComponent Component)? PlayEntity(SoundSpecifier? sound, Filter playerFilter, EntityUid uid, bool recordReplay, AudioParams? audioParams = null)
     {
-        return sound == null ? null : PlayEntity(GetSound(sound), playerFilter, uid, recordReplay, audioParams ?? sound.Params);
+        return sound == null ? null : PlayEntity(ResolveSound(sound), playerFilter, uid, recordReplay, audioParams ?? sound.Params);
     }
 
     /// <summary>
@@ -524,7 +582,7 @@ public TimeSpan GetAudioLength(ResolvedSoundSpecifier specifier)
     /// <param name="uid">The UID of the entity "emitting" the audio.</param>
     public (EntityUid Entity, Components.AudioComponent Component)? PlayEntity(SoundSpecifier? sound, ICommonSession recipient, EntityUid uid, AudioParams? audioParams = null)
     {
-        return sound == null ? null : PlayEntity(GetSound(sound), recipient, uid, audioParams ?? sound.Params);
+        return sound == null ? null : PlayEntity(ResolveSound(sound), recipient, uid, audioParams ?? sound.Params);
     }
 
     /// <summary>
@@ -535,7 +593,7 @@ public TimeSpan GetAudioLength(ResolvedSoundSpecifier specifier)
     /// <param name="uid">The UID of the entity "emitting" the audio.</param>
     public (EntityUid Entity, Components.AudioComponent Component)? PlayEntity(SoundSpecifier? sound, EntityUid recipient, EntityUid uid, AudioParams? audioParams = null)
     {
-        return sound == null ? null : PlayEntity(GetSound(sound), recipient, uid, audioParams ?? sound.Params);
+        return sound == null ? null : PlayEntity(ResolveSound(sound), recipient, uid, audioParams ?? sound.Params);
     }
 
     /// <summary>
@@ -545,7 +603,7 @@ public TimeSpan GetAudioLength(ResolvedSoundSpecifier specifier)
     /// <param name="uid">The UID of the entity "emitting" the audio.</param>
     public (EntityUid Entity, Components.AudioComponent Component)? PlayPvs(SoundSpecifier? sound, EntityUid uid, AudioParams? audioParams = null)
     {
-        return sound == null ? null : PlayPvs(GetSound(sound), uid, audioParams ?? sound.Params);
+        return sound == null ? null : PlayPvs(ResolveSound(sound), uid, audioParams ?? sound.Params);
     }
 
     /// <summary>
@@ -555,7 +613,7 @@ public TimeSpan GetAudioLength(ResolvedSoundSpecifier specifier)
     /// <param name="coordinates">The EntityCoordinates to attach the audio source to.</param>
     public (EntityUid Entity, Components.AudioComponent Component)? PlayPvs(SoundSpecifier? sound, EntityCoordinates coordinates, AudioParams? audioParams = null)
     {
-        return sound == null ? null : PlayPvs(GetSound(sound), coordinates, audioParams ?? sound.Params);
+        return sound == null ? null : PlayPvs(ResolveSound(sound), coordinates, audioParams ?? sound.Params);
     }
 
     /// <summary>
@@ -634,7 +692,7 @@ public abstract (EntityUid Entity, Components.AudioComponent Component)? PlayPvs
     /// <param name="coordinates">The coordinates at which to play the audio.</param>
     public (EntityUid Entity, Components.AudioComponent Component)? PlayStatic(SoundSpecifier? sound, Filter playerFilter, EntityCoordinates coordinates, bool recordReplay, AudioParams? audioParams = null)
     {
-        return sound == null ? null : PlayStatic(GetSound(sound), playerFilter, coordinates, recordReplay, audioParams);
+        return sound == null ? null : PlayStatic(ResolveSound(sound), playerFilter, coordinates, recordReplay, audioParams);
     }
 
     /// <summary>
@@ -645,7 +703,7 @@ public abstract (EntityUid Entity, Components.AudioComponent Component)? PlayPvs
     /// <param name="coordinates">The coordinates at which to play the audio.</param>
     public (EntityUid Entity, Components.AudioComponent Component)? PlayStatic(SoundSpecifier? sound, ICommonSession recipient, EntityCoordinates coordinates, AudioParams? audioParams = null)
     {
-        return sound == null ? null : PlayStatic(GetSound(sound), recipient, coordinates, audioParams ?? sound.Params);
+        return sound == null ? null : PlayStatic(ResolveSound(sound), recipient, coordinates, audioParams ?? sound.Params);
     }
 
     /// <summary>
@@ -656,7 +714,7 @@ public abstract (EntityUid Entity, Components.AudioComponent Component)? PlayPvs
     /// <param name="coordinates">The coordinates at which to play the audio.</param>
     public (EntityUid Entity, Components.AudioComponent Component)? PlayStatic(SoundSpecifier? sound, EntityUid recipient, EntityCoordinates coordinates, AudioParams? audioParams = null)
     {
-        return sound == null ? null : PlayStatic(GetSound(sound), recipient, coordinates, audioParams ?? sound.Params);
+        return sound == null ? null : PlayStatic(ResolveSound(sound), recipient, coordinates, audioParams ?? sound.Params);
     }
 
     // These are just here for replays now.