From 5c31725557193872a57123c6ce3c6d42f74179da Mon Sep 17 00:00:00 2001 From: Kapu1178 <75460809+Kapu1178@users.noreply.github.com> Date: Sun, 21 Jan 2024 20:51:15 -0500 Subject: [PATCH 1/3] seamless title music --- code/controllers/subsystem/ticker.dm | 38 ++++++++++++------- code/game/sound.dm | 14 ------- code/modules/client/client_defines.dm | 3 ++ code/modules/client/client_procs.dm | 33 ++++++++++++++++ .../preferences/middleware/legacy_toggles.dm | 2 +- .../modules/mob/dead/new_player/new_player.dm | 4 +- code/modules/mob/transform_procs.dm | 2 +- 7 files changed, 65 insertions(+), 31 deletions(-) diff --git a/code/controllers/subsystem/ticker.dm b/code/controllers/subsystem/ticker.dm index 8684fbb6de1c..e16ccf0c508e 100755 --- a/code/controllers/subsystem/ticker.dm +++ b/code/controllers/subsystem/ticker.dm @@ -20,7 +20,7 @@ SUBSYSTEM_DEF(ticker) var/datum/game_mode/mode = null ///Media track for the music played in the lobby - var/datum/media/login_music + var/list/datum/media/login_music = list() ///Media track for the round end music. var/datum/media/credits_music @@ -701,14 +701,18 @@ SUBSYSTEM_DEF(ticker) if(!istype(track)) CRASH("Non-datum/media given to set_login_music()!") - if(credits_music == login_music) - credits_music = track - login_music = track + var/index = login_music.Find(track) + if(index) + login_music.Swap(1, index) + else + login_music.Insert(1, track) + var/sound/S = sound(channel = CHANNEL_LOBBYMUSIC) for(var/mob/dead/new_player/player as anything in GLOB.new_player_list) if(!player.client) continue - player.client.playtitlemusic() + player.client.next_in_line = track + SEND_SOUND(player.client, S) //triggers the client's callback /datum/controller/subsystem/ticker/proc/pick_login_music() var/list/title_music_data = SSmedia.get_track_pool(MEDIA_TAG_LOBBYMUSIC_COMMON) @@ -720,6 +724,7 @@ SUBSYSTEM_DEF(ticker) if(rustg_file_exists("data/last_round_lobby_music.txt")) //The define isn't truthy old_login_music_t = rustg_file_read("data/last_round_lobby_music.txt") + var/list/music_tracks = title_music_data + rare_music_data //Filter map-specific tracks for(var/datum/media/music_filtered as anything in music_tracks) @@ -728,6 +733,7 @@ SUBSYSTEM_DEF(ticker) if(music_filtered.map && music_filtered.map != SSmapping.config.map_name) rare_music_data -= music_filtered title_music_data -= music_filtered + //Remove the previous song if(old_login_music) //Remove the old login music from the current pool if it wouldn't empty the pool. @@ -736,22 +742,23 @@ SUBSYSTEM_DEF(ticker) else if(length(title_music_data) > 1) title_music_data -= old_login_music + if(length(title_music_data)) + login_music += shuffle(title_music_data) + //Try to set a song json var/use_rare_music = prob(10) if(use_rare_music && length(rare_music_data)) - login_music = pick(rare_music_data) - if(!login_music && length(title_music_data)) - login_music = pick(title_music_data) + login_music.Insert(1, pick(rare_music_data)) //If there's no valid jsons, fallback to the classic ROUND_START_MUSIC_LIST. - if(!login_music) - var/music = pick(world.file2list(ROUND_START_MUSIC_LIST, "\n")) - var/list/split_path = splittext(music, "/") + if(!length(login_music)) //Construct a minimal music track to satisfy the system. - login_music = new(name = split_path[length(split_path)], path = music) + for(var/music in shuffle(world.file2list(ROUND_START_MUSIC_LIST))) + var/list/split_path = splittext(music, "/") + login_music += new /datum/media(name = split_path[length(split_path)], path = music) //Write the last round file to our current choice - rustg_file_write(login_music.path, "data/last_round_lobby_music.txt") + rustg_file_write(login_music[1].path, "data/last_round_lobby_music.txt") /datum/controller/subsystem/ticker/proc/pick_credits_music() var/list/music_data = SSmedia.get_track_pool(MEDIA_TAG_ROUNDEND_COMMON) @@ -766,3 +773,8 @@ SUBSYSTEM_DEF(ticker) if(!credits_music) credits_music = login_music + +/datum/controller/subsystem/ticker/proc/get_login_song(idx) + RETURN_TYPE(/datum/media) + idx = (idx %% (length(login_music) + 1)) || 1 + return login_music[idx] diff --git a/code/game/sound.dm b/code/game/sound.dm index 758e81b044c9..ddbbdab24a00 100644 --- a/code/game/sound.dm +++ b/code/game/sound.dm @@ -171,20 +171,6 @@ S.status = SOUND_UPDATE SEND_SOUND(src, S) -/client/proc/playtitlemusic(vol = 85) - set waitfor = FALSE - UNTIL(SSticker.login_music) //wait for SSticker init to set the login music - - if(prefs && (prefs.toggles & SOUND_LOBBY)) - SEND_SOUND(src, sound(SSticker.login_music.path, repeat = 0, wait = 0, volume = vol, channel = CHANNEL_LOBBYMUSIC)) // MAD JAMS - - UNTIL(SSticker.current_state >= GAME_STATE_PREGAME) - to_chat(src, span_greenannounce("Now Playing: [SSticker.login_music.name][SSticker.login_music.author ? " by [SSticker.login_music.author]" : ""]")) - -/client/proc/playcreditsmusic(vol = 85) - SEND_SOUND(src, sound(SSticker.credits_music.path, repeat = 0, wait = 0, volume = vol, channel = CHANNEL_LOBBYMUSIC)) - to_chat(src, span_greenannounce("Now Playing: [SSticker.credits_music.name][SSticker.credits_music.author ? " by [SSticker.credits_music.author]" : ""]")) - /proc/get_rand_frequency() return rand(32000, 55000) //Frequency stuff only works with 45kbps oggs. diff --git a/code/modules/client/client_defines.dm b/code/modules/client/client_defines.dm index 5cfe95c833a7..03aea0d9500c 100644 --- a/code/modules/client/client_defines.dm +++ b/code/modules/client/client_defines.dm @@ -271,3 +271,6 @@ //screen_text vars ///lazylist of screen_texts for this client, first in this list is the one playing var/list/atom/movable/screen/text/screen_text/screen_texts + + /// The next in line media datum to play for lobby music + var/datum/media/next_in_line diff --git a/code/modules/client/client_procs.dm b/code/modules/client/client_procs.dm index 5c557caa7467..8e4d32c1694b 100644 --- a/code/modules/client/client_procs.dm +++ b/code/modules/client/client_procs.dm @@ -1319,3 +1319,36 @@ GLOBAL_LIST_INIT(blacklisted_builds, list( hints.Insert(1, "