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, "
Craftables
") to_chat(mob, examine_block("[jointext(hints, "
")]
")) + +/client/proc/playtitlemusic() + set waitfor = FALSE + UNTIL(length(SSticker.login_music)) //wait for SSticker init to set the login music + + if(prefs && (prefs.toggles & SOUND_LOBBY)) + next_in_line = SSticker.login_music[1] + cycle_title_music() + +/client/proc/stoptitlemusic() + next_in_line = null + SEND_SOUND(src, sound(wait = FALSE, channel = CHANNEL_LOBBYMUSIC)) + +/client/proc/playcreditsmusic() + SEND_SOUND(src, sound(SSticker.credits_music.path, repeat = 0, wait = 0, volume = 85, channel = CHANNEL_LOBBYMUSIC)) + to_chat(src, span_greenannounce("Now Playing: [SSticker.credits_music.name][SSticker.credits_music.author ? " by [SSticker.credits_music.author]" : ""]")) + +/client/verb/cycle_title_music() + set name = ".cycle_title_music" + set instant = TRUE + + var/datum/media/song = next_in_line + if(!song) + return + + var/sound/S = sound(song.path, repeat = 0, wait = 0, volume = 85, channel = CHANNEL_LOBBYMUSIC) + S.params = "on-end=.cycle_title_music" + SEND_SOUND(src, S) + + next_in_line = SSticker.get_login_song(SSticker.login_music.Find(song) + 1) + + UNTIL(SSticker.current_state >= GAME_STATE_PREGAME) + to_chat(src, span_greenannounce("Now Playing: [song.name][song.author ? " by [song.author]" : ""]")) diff --git a/code/modules/client/preferences/middleware/legacy_toggles.dm b/code/modules/client/preferences/middleware/legacy_toggles.dm index e35832e54344..83c56c518ba7 100644 --- a/code/modules/client/preferences/middleware/legacy_toggles.dm +++ b/code/modules/client/preferences/middleware/legacy_toggles.dm @@ -116,7 +116,7 @@ if (value && isnewplayer(user)) user.client?.playtitlemusic() else - user.stop_sound_channel(CHANNEL_LOBBYMUSIC) + user.client?.stoptitlemusic() return TRUE diff --git a/code/modules/mob/dead/new_player/new_player.dm b/code/modules/mob/dead/new_player/new_player.dm index 5eee19b92409..adc2adfb3abf 100644 --- a/code/modules/mob/dead/new_player/new_player.dm +++ b/code/modules/mob/dead/new_player/new_player.dm @@ -221,7 +221,7 @@ observer.real_name = observer.client.prefs.read_preference(/datum/preference/name/real_name) observer.name = observer.real_name observer.client.init_verbs() - observer.stop_sound_channel(CHANNEL_LOBBYMUSIC) + observer.client?.stoptitlemusic() deadchat_broadcast(" has observed.", "[observer.real_name]", follow_target = observer, turf_target = get_turf(observer), message_type = DEADCHAT_DEATHRATTLE) QDEL_NULL(mind) qdel(src) @@ -472,7 +472,7 @@ if(!.) return new_character.key = key //Manually transfer the key to log them in, - new_character.stop_sound_channel(CHANNEL_LOBBYMUSIC) + new_character.client?.stoptitlemusic() new_character.client?.show_location_blurb() var/area/joined_area = get_area(new_character.loc) if(joined_area) diff --git a/code/modules/mob/transform_procs.dm b/code/modules/mob/transform_procs.dm index 078f6a546010..fb49dbddb858 100644 --- a/code/modules/mob/transform_procs.dm +++ b/code/modules/mob/transform_procs.dm @@ -83,7 +83,7 @@ landmark_loc += loc if(client) - stop_sound_channel(CHANNEL_LOBBYMUSIC) + client.stoptitlemusic() var/mob/living/silicon/ai/our_AI = new /mob/living/silicon/ai(pick(landmark_loc), null, src) . = our_AI From 78c54eb3a969a1d62877e90309885d935e96e6a6 Mon Sep 17 00:00:00 2001 From: Kapu1178 <75460809+Kapu1178@users.noreply.github.com> Date: Sun, 21 Jan 2024 21:07:58 -0500 Subject: [PATCH 2/3] better admin logic --- code/controllers/subsystem/ticker.dm | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/code/controllers/subsystem/ticker.dm b/code/controllers/subsystem/ticker.dm index e16ccf0c508e..75d1c3ffcb55 100755 --- a/code/controllers/subsystem/ticker.dm +++ b/code/controllers/subsystem/ticker.dm @@ -701,11 +701,8 @@ SUBSYSTEM_DEF(ticker) if(!istype(track)) CRASH("Non-datum/media given to set_login_music()!") - var/index = login_music.Find(track) - if(index) - login_music.Swap(1, index) - else - login_music.Insert(1, track) + login_music -= track + 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) From bb5ce23e73e7ce86012123d0d23a12f971d9b2de Mon Sep 17 00:00:00 2001 From: Kapu1178 <75460809+Kapu1178@users.noreply.github.com> Date: Sun, 12 May 2024 01:17:18 -0400 Subject: [PATCH 3/3] hidden --- code/modules/client/client_procs.dm | 1 + 1 file changed, 1 insertion(+) diff --git a/code/modules/client/client_procs.dm b/code/modules/client/client_procs.dm index d3d1989024b3..582f9f90a81d 100644 --- a/code/modules/client/client_procs.dm +++ b/code/modules/client/client_procs.dm @@ -1344,6 +1344,7 @@ GLOBAL_LIST_INIT(blacklisted_builds, list( /client/verb/cycle_title_music() set name = ".cycle_title_music" set instant = TRUE + set hidden = TRUE var/datum/media/song = next_in_line if(!song)