]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Expeditions audio tweaks (#27524)
authormetalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Mon, 6 May 2024 00:19:43 +0000 (10:19 +1000)
committerGitHub <noreply@github.com>
Mon, 6 May 2024 00:19:43 +0000 (10:19 +1000)
- Now uses a SoundCollection.
- Now properly handles going between maps (audio rework mucho wow).
- GetAudioLength used so it can properly countdown ANY song (wow audio rework wow wow).

Content.Server/Salvage/Expeditions/SalvageExpeditionComponent.cs
Content.Server/Salvage/SalvageSystem.Expeditions.cs
Content.Server/Salvage/SalvageSystem.Runner.cs
Resources/Prototypes/SoundCollections/expeditions.yml [new file with mode: 0644]

index 6a58c209cfafe7b318bc2c907ad58e53ad108913..ff3c8176fd0747b9c61e045cf0ac22620481002f 100644 (file)
@@ -40,14 +40,21 @@ public sealed partial class SalvageExpeditionComponent : SharedSalvageExpedition
     /// <summary>
     /// Countdown audio stream.
     /// </summary>
+    [DataField, AutoNetworkedField]
     public EntityUid? Stream = null;
 
     /// <summary>
     /// Sound that plays when the mission end is imminent.
     /// </summary>
-    [ViewVariables(VVAccess.ReadWrite), DataField("sound")]
-    public SoundSpecifier Sound = new SoundPathSpecifier("/Audio/Misc/tension_session.ogg")
+    [ViewVariables(VVAccess.ReadWrite), DataField]
+    public SoundSpecifier Sound = new SoundCollectionSpecifier("ExpeditionEnd")
     {
         Params = AudioParams.Default.WithVolume(-5),
     };
+
+    /// <summary>
+    /// Song selected on MapInit so we can predict the audio countdown properly.
+    /// </summary>
+    [DataField]
+    public SoundPathSpecifier SelectedSong;
 }
index 4d5d569dabd45f8dd55c11794966a3c36bf9d994..923880169d5d5baaad0eec101ee30ad7e12222ed 100644 (file)
@@ -4,7 +4,9 @@ using Content.Server.Salvage.Expeditions;
 using Content.Server.Salvage.Expeditions.Structure;
 using Content.Shared.CCVar;
 using Content.Shared.Examine;
+using Content.Shared.Random.Helpers;
 using Content.Shared.Salvage.Expeditions;
+using Robust.Shared.Audio;
 using Robust.Shared.CPUJob.JobQueues;
 using Robust.Shared.CPUJob.JobQueues.Queues;
 using Robust.Shared.GameStates;
@@ -32,6 +34,7 @@ public sealed partial class SalvageSystem
         SubscribeLocalEvent<SalvageExpeditionConsoleComponent, EntParentChangedMessage>(OnSalvageConsoleParent);
         SubscribeLocalEvent<SalvageExpeditionConsoleComponent, ClaimSalvageMessage>(OnSalvageClaimMessage);
 
+        SubscribeLocalEvent<SalvageExpeditionComponent, MapInitEvent>(OnExpeditionMapInit);
         SubscribeLocalEvent<SalvageExpeditionComponent, ComponentShutdown>(OnExpeditionShutdown);
         SubscribeLocalEvent<SalvageExpeditionComponent, ComponentGetState>(OnExpeditionGetState);
 
@@ -64,6 +67,12 @@ public sealed partial class SalvageSystem
         _cooldown = obj;
     }
 
+    private void OnExpeditionMapInit(EntityUid uid, SalvageExpeditionComponent component, MapInitEvent args)
+    {
+        var selectedFile = _audio.GetSound(component.Sound);
+        component.SelectedSong = new SoundPathSpecifier(selectedFile, component.Sound.Params);
+    }
+
     private void OnExpeditionShutdown(EntityUid uid, SalvageExpeditionComponent component, ComponentShutdown args)
     {
         component.Stream = _audio.Stop(component.Stream);
index 8a1498cbe96865ac628aaf0ac4b7229f8c76bcce..e6e29eb577500134032c08b27022f775fe39d65d 100644 (file)
@@ -144,6 +144,7 @@ public sealed partial class SalvageSystem
         while (query.MoveNext(out var uid, out var comp))
         {
             var remaining = comp.EndTime - _timing.CurTime;
+            var audioLength = _audio.GetAudioLength(comp.SelectedSong.Path.ToString());
 
             if (comp.Stage < ExpeditionStage.FinalCountdown && remaining < TimeSpan.FromSeconds(45))
             {
@@ -151,13 +152,14 @@ public sealed partial class SalvageSystem
                 Dirty(uid, comp);
                 Announce(uid, Loc.GetString("salvage-expedition-announcement-countdown-seconds", ("duration", TimeSpan.FromSeconds(45).Seconds)));
             }
-            else if (comp.Stage < ExpeditionStage.MusicCountdown && remaining < TimeSpan.FromMinutes(2))
+            else if (comp.Stream == null && remaining < audioLength)
             {
-                // TODO: Some way to play audio attached to a map for players.
-                comp.Stream = _audio.PlayGlobal(comp.Sound, Filter.BroadcastMap(Comp<MapComponent>(uid).MapId), true).Value.Entity;
+                var audio = _audio.PlayPvs(comp.Sound, uid).Value;
+                comp.Stream = audio.Entity;
+                _audio.SetMapAudio(audio);
                 comp.Stage = ExpeditionStage.MusicCountdown;
                 Dirty(uid, comp);
-                Announce(uid, Loc.GetString("salvage-expedition-announcement-countdown-minutes", ("duration", TimeSpan.FromMinutes(2).Minutes)));
+                Announce(uid, Loc.GetString("salvage-expedition-announcement-countdown-minutes", ("duration", audioLength.Minutes)));
             }
             else if (comp.Stage < ExpeditionStage.Countdown && remaining < TimeSpan.FromMinutes(4))
             {
diff --git a/Resources/Prototypes/SoundCollections/expeditions.yml b/Resources/Prototypes/SoundCollections/expeditions.yml
new file mode 100644 (file)
index 0000000..665ac12
--- /dev/null
@@ -0,0 +1,4 @@
+- type: soundCollection
+  id: ExpeditionEnd
+  files:
+  - /Audio/Misc/tension_session.ogg