diff --git a/Content.Client/Audio/BackgroundAudioSystem.cs b/Content.Client/Audio/BackgroundAudioSystem.cs index 100ee7458e..0b31db2463 100644 --- a/Content.Client/Audio/BackgroundAudioSystem.cs +++ b/Content.Client/Audio/BackgroundAudioSystem.cs @@ -34,7 +34,7 @@ public sealed class BackgroundAudioSystem : EntitySystem _client.PlayerLeaveServer += OnLeave; - _gameTicker.LobbyStatusUpdated += LobbySongReceived; + _gameTicker.LobbySongUpdated += LobbySongUpdated; } public override void Shutdown() @@ -48,7 +48,7 @@ public sealed class BackgroundAudioSystem : EntitySystem _client.PlayerLeaveServer -= OnLeave; - _gameTicker.LobbyStatusUpdated -= LobbySongReceived; + _gameTicker.LobbySongUpdated -= LobbySongUpdated; EndLobbyMusic(); } @@ -95,17 +95,9 @@ public sealed class BackgroundAudioSystem : EntitySystem } } - private void LobbySongReceived() + private void LobbySongUpdated() { - if (_lobbyStream != null) //Toggling Ready status fires this method. This check ensures we only start the lobby music if it's not playing. - { - return; - } - - if (_stateManager.CurrentState is LobbyState) - { - StartLobbyMusic(); - } + RestartLobbyMusic(); } public void RestartLobbyMusic() diff --git a/Content.Client/GameTicking/Managers/ClientGameTicker.cs b/Content.Client/GameTicking/Managers/ClientGameTicker.cs index 5c255cd193..7c94a60aad 100644 --- a/Content.Client/GameTicking/Managers/ClientGameTicker.cs +++ b/Content.Client/GameTicking/Managers/ClientGameTicker.cs @@ -1,4 +1,3 @@ -using Content.Client.Audio; using Content.Client.Gameplay; using Content.Client.Lobby; using Content.Client.RoundEnd; @@ -8,7 +7,6 @@ using Content.Shared.GameWindow; using JetBrains.Annotations; using Robust.Client.Graphics; using Robust.Client.State; -using Robust.Shared.Audio; using Robust.Shared.Configuration; using Robust.Shared.Player; using Robust.Shared.Utility; @@ -21,7 +19,6 @@ namespace Content.Client.GameTicking.Managers [Dependency] private readonly IStateManager _stateManager = default!; [Dependency] private readonly IEntityManager _entityManager = default!; [Dependency] private readonly IConfigurationManager _configManager = default!; - [Dependency] private readonly BackgroundAudioSystem _backgroundAudio = default!; [Dependency] private readonly SharedAudioSystem _audio = default!; [ViewVariables] private bool _initialized; @@ -49,6 +46,7 @@ namespace Content.Client.GameTicking.Managers public event Action? InfoBlobUpdated; public event Action? LobbyStatusUpdated; + public event Action? LobbySongUpdated; public event Action? LobbyLateJoinStatusUpdated; public event Action>>? LobbyJobsAvailableUpdated; @@ -73,6 +71,16 @@ namespace Content.Client.GameTicking.Managers _initialized = true; } + public void SetLobbySong(string? song, bool forceUpdate = false) + { + var updated = song != LobbySong; + + LobbySong = song; + + if (updated || forceUpdate) + LobbySongUpdated?.Invoke(); + } + private void LateJoinStatus(TickerLateJoinStatusEvent message) { DisallowedLateJoin = message.Disallowed; @@ -97,7 +105,7 @@ namespace Content.Client.GameTicking.Managers RoundStartTimeSpan = message.RoundStartTimeSpan; IsGameStarted = message.IsRoundStarted; AreWeReady = message.YouAreReady; - LobbySong = message.LobbySong; + SetLobbySong(message.LobbySong); LobbyBackground = message.LobbyBackground; Paused = message.Paused; @@ -124,12 +132,8 @@ namespace Content.Client.GameTicking.Managers private void RoundEnd(RoundEndMessageEvent message) { - if (message.LobbySong != null) - { - LobbySong = message.LobbySong; - _backgroundAudio.StartLobbyMusic(); - } - + // Force an update in the event of this song being the same as the last. + SetLobbySong(message.LobbySong, true); RestartSound = message.RestartSound; // Don't open duplicate windows (mainly for replays). diff --git a/Content.Server/GameTicking/GameTicker.RoundFlow.cs b/Content.Server/GameTicking/GameTicker.RoundFlow.cs index 47fded14c9..98794c9926 100644 --- a/Content.Server/GameTicking/GameTicker.RoundFlow.cs +++ b/Content.Server/GameTicking/GameTicker.RoundFlow.cs @@ -323,6 +323,12 @@ namespace Content.Server.GameTicking RunLevel = GameRunLevel.PostRound; + // The lobby song is set here instead of in RestartRound, + // because ShowRoundEndScoreboard triggers the start of the music playing + // at the end of a round, and this needs to be set before RestartRound + // in order for the lobby song status display to be accurate. + LobbySong = _robustRandom.Pick(_lobbyMusicCollection.PickFiles).ToString(); + ShowRoundEndScoreboard(text); } @@ -453,7 +459,6 @@ namespace Content.Server.GameTicking PlayersJoinedRoundNormally = 0; RunLevel = GameRunLevel.PreRoundLobby; - LobbySong = _robustRandom.Pick(_lobbyMusicCollection.PickFiles).ToString(); RandomizeLobbyBackground(); ResettingCleanup(); IncrementRoundNumber();