Lobby Audio from static to CVar (#38375)
* Changed LobbyMusiccollection over to a Cvar and edited ContentAudioSystem.cs to use Cvar Values * Addedd Ability to modify the lobbyMusiccollection from the command line * Fixed changing lobby music while in the round * Deleted uneeded duplicate line * Removed additional duplicate lobbyplaylist line * Alphabatized imports and refactored to use Subs.CVar * Added error checking and default behaviour to CVar sub. * Refactored to use TryIndex and Allowed for a empty soundcollection when a sound collection is not found. Edited Cvar comment to reflect changes. * Made _lobbyMusicCollection nullable and addedd handling for null case where used. Also Changed LobbyMusicCollection Cvar over to audio rather than ambience. * Update Content.Server/Audio/ContentAudioSystem.cs --------- Co-authored-by: Pieter-Jan Briers <pieterjan.briers@gmail.com>
This commit is contained in:
@@ -3,32 +3,52 @@ using Content.Server.GameTicking;
|
|||||||
using Content.Server.GameTicking.Events;
|
using Content.Server.GameTicking.Events;
|
||||||
using Content.Shared.Audio;
|
using Content.Shared.Audio;
|
||||||
using Content.Shared.Audio.Events;
|
using Content.Shared.Audio.Events;
|
||||||
|
using Content.Shared.CCVar;
|
||||||
using Content.Shared.GameTicking;
|
using Content.Shared.GameTicking;
|
||||||
using Robust.Server.Audio;
|
using Robust.Server.Audio;
|
||||||
using Robust.Shared.Audio;
|
using Robust.Shared.Audio;
|
||||||
|
using Robust.Shared.Configuration;
|
||||||
using Robust.Shared.Prototypes;
|
using Robust.Shared.Prototypes;
|
||||||
using Robust.Shared.Random;
|
using Robust.Shared.Random;
|
||||||
|
|
||||||
|
|
||||||
namespace Content.Server.Audio;
|
namespace Content.Server.Audio;
|
||||||
|
|
||||||
public sealed class ContentAudioSystem : SharedContentAudioSystem
|
public sealed class ContentAudioSystem : SharedContentAudioSystem
|
||||||
{
|
{
|
||||||
[ValidatePrototypeId<SoundCollectionPrototype>]
|
|
||||||
private const string LobbyMusicCollection = "LobbyMusic";
|
|
||||||
|
|
||||||
[Dependency] private readonly AudioSystem _serverAudio = default!;
|
[Dependency] private readonly AudioSystem _serverAudio = default!;
|
||||||
[Dependency] private readonly IRobustRandom _robustRandom = default!;
|
[Dependency] private readonly IRobustRandom _robustRandom = default!;
|
||||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||||
|
[Dependency] private readonly IConfigurationManager _cfg = default!;
|
||||||
|
|
||||||
private SoundCollectionPrototype _lobbyMusicCollection = default!;
|
private SoundCollectionPrototype? _lobbyMusicCollection = default!;
|
||||||
private string[]? _lobbyPlaylist;
|
private string[]? _lobbyPlaylist;
|
||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
base.Initialize();
|
base.Initialize();
|
||||||
|
|
||||||
_lobbyMusicCollection = _prototypeManager.Index<SoundCollectionPrototype>(LobbyMusicCollection);
|
//changes the music collection and reshuffles the playlist to update the lobby music
|
||||||
_lobbyPlaylist = ShuffleLobbyPlaylist();
|
Subs.CVar(
|
||||||
|
_cfg,
|
||||||
|
CCVars.LobbyMusicCollection,
|
||||||
|
x =>
|
||||||
|
{
|
||||||
|
//Checks to see if the sound collection exists. If it does change it if not defaults to null
|
||||||
|
// as the new _lobbyMusicCollection meaning it wont play anything in the lobby.
|
||||||
|
if(_prototypeManager.TryIndex<SoundCollectionPrototype>(x, out var outputSoundCollection))
|
||||||
|
{
|
||||||
|
_lobbyMusicCollection = outputSoundCollection;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Log.Error($"Invalid Lobby Music sound collection specified: {x}");
|
||||||
|
_lobbyMusicCollection = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
_lobbyPlaylist = ShuffleLobbyPlaylist();
|
||||||
|
},
|
||||||
|
true);
|
||||||
|
|
||||||
SubscribeLocalEvent<RoundEndMessageEvent>(OnRoundEnd);
|
SubscribeLocalEvent<RoundEndMessageEvent>(OnRoundEnd);
|
||||||
SubscribeLocalEvent<PlayerJoinedLobbyEvent>(OnPlayerJoinedLobby);
|
SubscribeLocalEvent<PlayerJoinedLobbyEvent>(OnPlayerJoinedLobby);
|
||||||
@@ -76,11 +96,16 @@ public sealed class ContentAudioSystem : SharedContentAudioSystem
|
|||||||
|
|
||||||
private string[] ShuffleLobbyPlaylist()
|
private string[] ShuffleLobbyPlaylist()
|
||||||
{
|
{
|
||||||
|
if (_lobbyMusicCollection == null)
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
var playlist = _lobbyMusicCollection.PickFiles
|
var playlist = _lobbyMusicCollection.PickFiles
|
||||||
.Select(x => x.ToString())
|
.Select(x => x.ToString())
|
||||||
.ToArray();
|
.ToArray();
|
||||||
_robustRandom.Shuffle(playlist);
|
_robustRandom.Shuffle(playlist);
|
||||||
|
|
||||||
return playlist;
|
return playlist;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
using Robust.Shared.Configuration;
|
using Content.Shared.Administration;
|
||||||
|
using Content.Shared.CCVar.CVarAccess;
|
||||||
|
using Robust.Shared.Configuration;
|
||||||
|
|
||||||
namespace Content.Shared.CCVar;
|
namespace Content.Shared.CCVar;
|
||||||
|
|
||||||
@@ -58,4 +60,10 @@ public sealed partial class CCVars
|
|||||||
public static readonly CVarDef<float> InterfaceVolume =
|
public static readonly CVarDef<float> InterfaceVolume =
|
||||||
CVarDef.Create("audio.interface_volume", 0.50f, CVar.ARCHIVE | CVar.CLIENTONLY);
|
CVarDef.Create("audio.interface_volume", 0.50f, CVar.ARCHIVE | CVar.CLIENTONLY);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Lobby music collection string
|
||||||
|
/// </summary>
|
||||||
|
[CVarControl(AdminFlags.VarEdit)]
|
||||||
|
public static readonly CVarDef<string> LobbyMusicCollection =
|
||||||
|
CVarDef.Create("audio.lobby_music_collection", "LobbyMusic", CVar.REPLICATED | CVar.SERVER);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user