Skip to content

Commit

Permalink
[MIRROR] tiny cleanup pass on jukebox datum, audio singleton (#2863)
Browse files Browse the repository at this point in the history
Co-authored-by: Spookerton <[email protected]>
Co-authored-by: Lexanx <[email protected]>
  • Loading branch information
3 people authored Nov 26, 2024
1 parent 0fb5a09 commit 3a0065b
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 56 deletions.
41 changes: 26 additions & 15 deletions code/datums/audio/_audio.dm
Original file line number Diff line number Diff line change
@@ -1,39 +1,50 @@
/singleton/audio
var/source //Path to file source
var/display //A display title we use in the game
var/volume //If present, a `normal` volume
var/title //The real title
/// Path to file source
var/source

/// The real (ie, artist's) audio title
var/title

/// The display title to use in game, if different
var/display

/// The normal volume to play the audio at, if set
var/volume

/// The artist's name
var/author

/// The collection (eg album) the audio belongs to
var/collection
var/singleton/license/license
var/url

/// The license under which the audio was made available
var/singleton/license/license

//Repository scopes
/singleton/audio/effect
/singleton/audio/track
/// A link to the audio's source, if available
var/url


/singleton/audio/New()
/singleton/audio/Initialize()
. = ..()
license = GET_SINGLETON(license)


/singleton/audio/VV_static()
return ..() + vars


/singleton/audio/proc/get_info(with_meta = TRUE)
. = SPAN_GOOD("[title][!author?"":" by [author]"][!collection?"":" ([collection])"]")
if (with_meta)
. = "[.][!url?"":"\[<a href='[url]'>link</a>\]"]\[<a href='[license.url]'>license</a>\]"


/singleton/audio/proc/get_sound(channel)
var/sound/S = sound(source, FALSE, FALSE, channel, volume || 100)
return S
var/sound/sound = sound(source, FALSE, FALSE, channel, volume || 100)
return sound


/singleton/audio/track/get_sound(channel = GLOB.lobby_sound_channel)
var/sound/S = ..()
S.repeat = TRUE
return S
var/sound/sound = ..()
sound.repeat = TRUE
return sound
62 changes: 34 additions & 28 deletions code/datums/audio/jukebox.dm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/jukebox //abstraction of music player behavior for jukeboxes, headphones, etc
/datum/jukebox
var/atom/owner
var/sound_id
var/datum/sound_token/token
Expand All @@ -17,7 +17,7 @@
var/playing


/jukebox/New(atom/_owner, _template, _ui_title, _ui_width, _ui_height)
/datum/jukebox/New(atom/_owner, _template, _ui_title, _ui_width, _ui_height)
. = ..()
if (QDELETED(_owner) || !isatom(_owner))
qdel(src)
Expand All @@ -27,46 +27,46 @@
for (var/path in GLOB.jukebox_tracks)
var/singleton/audio/track/track = GET_SINGLETON(path)
AddTrack(track.display || track.title, track.source)
sound_id = "[/jukebox]_[sequential_id(/jukebox)]"
sound_id = "[/datum/jukebox]_[sequential_id(/datum/jukebox)]"
template = _template
ui_title = _ui_title
ui_width = _ui_width
ui_height = _ui_height


/jukebox/Destroy()
/datum/jukebox/Destroy()
QDEL_NULL_LIST(tracks)
QDEL_NULL(token)
owner = null
. = ..()
return ..()


/jukebox/proc/AddTrack(title = "Track [length(tracks) + 1]", source)
tracks += new /jukebox_track (title, source)
/datum/jukebox/proc/AddTrack(title = "Track [length(tracks) + 1]", source)
tracks += new /datum/jukebox_track (title, source)


/jukebox/proc/ClearTracks()
/datum/jukebox/proc/ClearTracks()
QDEL_NULL_LIST(tracks)
tracks = list()


/jukebox/proc/Next()
/datum/jukebox/proc/Next()
if (++index > length(tracks))
index = 1
if (playing)
Stop()
Play()


/jukebox/proc/Last()
/datum/jukebox/proc/Last()
if (--index < 1)
index = length(tracks)
if (playing)
Stop()
Play()


/jukebox/proc/Track(_index)
/datum/jukebox/proc/Track(_index)
_index = text2num(_index)
if (!IsInteger(_index))
return
Expand All @@ -76,16 +76,16 @@
Play()


/jukebox/proc/Stop()
/datum/jukebox/proc/Stop()
playing = FALSE
QDEL_NULL(token)
owner.queue_icon_update()


/jukebox/proc/Play()
/datum/jukebox/proc/Play()
if (playing)
return
var/jukebox_track/track = tracks[index]
var/datum/jukebox_track/track = tracks[index]
if (!track.source)
return
playing = TRUE
Expand All @@ -94,7 +94,7 @@
owner.queue_icon_update()


/jukebox/proc/Volume(_volume)
/datum/jukebox/proc/Volume(_volume)
_volume = text2num(_volume)
if (!isfinite(_volume))
return
Expand All @@ -108,16 +108,16 @@
token.SetVolume(volume)


/jukebox/nano_host()
/datum/jukebox/nano_host()
return owner


/jukebox/ui_interact(mob/user, ui_key = "main", datum/nanoui/ui, force_open = TRUE, datum/topic_state/state = GLOB.default_state)//, datum/topic_state/state = GLOB.jukebox_state)
/datum/jukebox/ui_interact(mob/user, ui_key = "main", datum/nanoui/ui, force_open = TRUE, datum/topic_state/state = GLOB.default_state)
var/list/data_tracks = list()
for (var/i = 1 to length(tracks))
var/jukebox_track/track = tracks[i]
var/datum/jukebox_track/track = tracks[i]
data_tracks += list(list("track" = track.title, "index" = i))
var/jukebox_track/track = tracks[index]
var/datum/jukebox_track/track = tracks[index]
var/list/data = list(
"track" = track.title,
"playing" = playing,
Expand All @@ -131,24 +131,30 @@
ui.open()


/jukebox/Topic(href, href_list)
/datum/jukebox/Topic(href, href_list)
switch ("[href_list["act"]]")
if ("next") Next()
if ("last") Last()
if ("stop") Stop()
if ("play") Play()
if ("volume") Volume("[href_list["dat"]]")
if ("track") Track("[href_list["dat"]]")
if ("next")
Next()
if ("last")
Last()
if ("stop")
Stop()
if ("play")
Play()
if ("volume")
Volume("[href_list["dat"]]")
if ("track")
Track("[href_list["dat"]]")
return TOPIC_REFRESH



/jukebox_track
/datum/jukebox_track
var/title
var/source


/jukebox_track/New(_title, _source, _volume)
/datum/jukebox_track/New(_title, _source)
title = _title
source = _source

Expand Down
2 changes: 1 addition & 1 deletion code/game/machinery/jukebox.dm
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
obj_flags = OBJ_FLAG_ANCHORABLE
layer = ABOVE_WINDOW_LAYER

var/jukebox/jukebox
var/datum/jukebox/jukebox


/obj/machinery/jukebox/Initialize()
Expand Down
2 changes: 1 addition & 1 deletion code/game/objects/items/devices/boombox.dm
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
w_class = ITEM_SIZE_HUGE //forbid putting something that emits loud sounds forever into a backpack
origin_tech = list(TECH_MAGNET = 2, TECH_COMBAT = 1)

var/jukebox/jukebox
var/datum/jukebox/jukebox
var/boombox_flags


Expand Down
2 changes: 1 addition & 1 deletion code/modules/clothing/ears/headphones.dm
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
item_state = "headphones_off"
slot_flags = SLOT_EARS | SLOT_TWOEARS
volume_multiplier = 0.5
var/jukebox/jukebox
var/datum/jukebox/jukebox


/obj/item/clothing/ears/headphones/Initialize()
Expand Down
4 changes: 2 additions & 2 deletions code/unit_tests/music_test.dm
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@

/datum/unit_test/jukebox_validate/start_test()
var/list/failed = list()
for (var/jukebox/jukebox)
for (var/datum/jukebox/jukebox)
for (var/entry in jukebox.tracks)
var/jukebox_track/track = entry
var/datum/jukebox_track/track = entry
if (!track.title || !isfile(track.source))
log_bad("Invalid Jukebox Track: [log_info_line(jukebox)]")
failed += jukebox
Expand Down
10 changes: 5 additions & 5 deletions mods/jukebox_tapes/code/jukebox.dm
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

if(tape)
jukebox.Stop()
for(var/jukebox_track/T in jukebox.tracks)
for(var/datum/jukebox_track/T in jukebox.tracks)
if(T == tape.track)
jukebox.tracks -= T
jukebox.Last()
Expand Down Expand Up @@ -104,12 +104,12 @@


// SIERRA TODO: Move to corecode or override
/jukebox/ui_interact(mob/user, ui_key = "main", datum/nanoui/ui, force_open = TRUE, datum/topic_state/state = GLOB.default_state)//, datum/topic_state/state = GLOB.jukebox_state)
/datum/jukebox/ui_interact(mob/user, ui_key = "main", datum/nanoui/ui, force_open = TRUE, datum/topic_state/state = GLOB.default_state)//, datum/topic_state/state = GLOB.jukebox_state)
var/list/data_tracks = list()
for (var/i = 1 to length(tracks))
var/jukebox_track/track = tracks[i]
var/datum/jukebox_track/track = tracks[i]
data_tracks += list(list("track" = track.title, "index" = i))
var/jukebox_track/track = tracks[index]
var/datum/jukebox_track/track = tracks[index]
var/list/data = list(
"track" = track.title,
"playing" = playing,
Expand All @@ -125,7 +125,7 @@
ui.set_initial_data(data)
ui.open()

/jukebox/Topic(href, href_list)
/datum/jukebox/Topic(href, href_list)
switch ("[href_list["act"]]")
if ("next") Next()
if ("last") Last()
Expand Down
2 changes: 1 addition & 1 deletion mods/music_player/code/music_tape.dm
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
var/ruined = 0
var/rewrites_left = 2

var/jukebox_track/track
var/datum/jukebox_track/track
var/uploader_ckey

/obj/item/music_tape/Initialize()
Expand Down
2 changes: 1 addition & 1 deletion mods/music_player/code/music_writer.dm
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@
if(disk.track) //Removing old datum disk if there one
qdel(disk.track)

var/jukebox_track/T = new(new_name, new_sound_file)
var/datum/jukebox_track/T = new(new_name, new_sound_file)

if(T)
disk.track = T
Expand Down
2 changes: 1 addition & 1 deletion mods/music_player/code/subtypes_tape.dm
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@
SetName("tape - \"[new_name]\"")

if(new_sound && new_name && !track)
track = new /jukebox_track(new_name, new_sound)
track = new /datum/jukebox_track(new_name, new_sound)
return TRUE
return FALSE

0 comments on commit 3a0065b

Please sign in to comment.