Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Seamless & Per-Client Title Music #775

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 22 additions & 13 deletions code/controllers/subsystem/ticker.dm
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ SUBSYSTEM_DEF(ticker)
var/list/mob/dead/new_player/ready_players

///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

Expand Down Expand Up @@ -715,14 +715,15 @@ 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
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)
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)
Expand All @@ -734,6 +735,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)
Expand All @@ -742,6 +744,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.
Expand All @@ -750,22 +753,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)
Expand All @@ -781,6 +785,11 @@ 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]

///Generate a list of gamemodes we can play.
/datum/controller/subsystem/ticker/proc/draft_gamemodes()
var/list/datum/game_mode/runnable_modes = list()
Expand Down
14 changes: 0 additions & 14 deletions code/game/sound.dm
Original file line number Diff line number Diff line change
Expand Up @@ -176,20 +176,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: <i>[SSticker.login_music.name]</i>[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: <i>[SSticker.credits_music.name]</i>[SSticker.credits_music.author ? " by [SSticker.credits_music.author]" : ""]"))

/proc/get_rand_frequency()
return rand(32000, 55000) //Frequency stuff only works with 45kbps oggs.

Expand Down
3 changes: 3 additions & 0 deletions code/modules/client/client_defines.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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
34 changes: 34 additions & 0 deletions code/modules/client/client_procs.dm
Original file line number Diff line number Diff line change
Expand Up @@ -1324,3 +1324,37 @@ GLOBAL_LIST_INIT(blacklisted_builds, list(
hints.Insert(1, "<div style='text-align: center;font-size: 200%;font-weight: bold'>Craftables<hr></div>")

to_chat(mob, examine_block("<span class='notice'>[jointext(hints, "<br>")]</span>"))

/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: <i>[SSticker.credits_music.name]</i>[SSticker.credits_music.author ? " by [SSticker.credits_music.author]" : ""]"))

/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)
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: <i>[song.name]</i>[song.author ? " by [song.author]" : ""]"))
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
if (value && isnewplayer(user))
user.client?.playtitlemusic()
else
user.stop_sound_channel(CHANNEL_LOBBYMUSIC)
user.client?.stoptitlemusic()

return TRUE

Expand Down
4 changes: 2 additions & 2 deletions code/modules/mob/dead/new_player/new_player.dm
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@
if(observer.client && observer.client.prefs)
observer.set_real_name(observer.client.prefs.read_preference(/datum/preference/name/real_name))
observer.client.init_verbs()
observer.stop_sound_channel(CHANNEL_LOBBYMUSIC)
observer.client?.stoptitlemusic()
deadchat_broadcast(" has observed.", "<b>[observer.real_name]</b>", follow_target = observer, turf_target = get_turf(observer), message_type = DEADCHAT_DEATHRATTLE)
QDEL_NULL(mind)
qdel(src)
Expand Down Expand Up @@ -470,7 +470,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)
Expand Down
2 changes: 1 addition & 1 deletion code/modules/mob/transform_procs.dm
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,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
Expand Down
Loading