Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
SandPoot committed May 18, 2024
2 parents 7abab8a + 22a0ad4 commit 6083aeb
Showing 1 changed file with 67 additions and 11 deletions.
78 changes: 67 additions & 11 deletions code/controllers/subsystem/jukeboxes.dm
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@
#define JUKE_FALLOFF 4
#define JUKE_SOUND 5

// Track data
/// Name of the track
#define TRACK_NAME 1
/// Length of the track (in deciseconds)
#define TRACK_LENGTH 2
/// BPM of the track (in deciseconds)
#define TRACK_BEAT 3
/// Unique code-facing identifier for this track
#define TRACK_ID 4


SUBSYSTEM_DEF(jukeboxes)
name = "Jukeboxes"
Expand Down Expand Up @@ -66,7 +76,7 @@ SUBSYSTEM_DEF(jukeboxes)


//Updates jukebox by transferring to different object or modifying falloff.
/datum/controller/subsystem/jukeboxes/proc/updatejukebox(IDtoupdate, obj/jukebox, jukefalloff)
/datum/controller/subsystem/jukeboxes/proc/updatejukebox(IDtoupdate, obj/jukebox, jukefalloff)
if(islist(activejukeboxes[IDtoupdate]))
if(istype(jukebox))
activejukeboxes[IDtoupdate][JUKE_BOX] = jukebox
Expand Down Expand Up @@ -94,19 +104,60 @@ SUBSYSTEM_DEF(jukeboxes)
return FALSE

/datum/controller/subsystem/jukeboxes/Initialize()
init_channels()

var/list/tracks = flist("config/jukebox_music/sounds/")
for(var/S in tracks)
var/datum/track/T = new()
T.song_path = file("config/jukebox_music/sounds/[S]")
var/list/L = splittext(S,"+")
T.song_name = L[1]
T.song_length = text2num(L[2])
T.song_beat = text2num(L[3])
T.song_associated_id = L[4]
songs |= T
for(var/track in tracks)
var/datum/track/track_datum = add_track(track)
if(!track_datum)
continue
songs |= track_datum

return ..()

/// Creates audio channels for jukeboxes to use, run first to prevent init failing to fill this
/datum/controller/subsystem/jukeboxes/proc/init_channels()
for(var/i in CHANNEL_JUKEBOX_START to CHANNEL_JUKEBOX)
freejukeboxchannels |= i
return ..()

/datum/controller/subsystem/jukeboxes/proc/add_track(track)
var/datum/track/track_datum = new()
track_datum.song_path = file("config/jukebox_music/sounds/[track]")

var/list/track_data = splittext(track,"+")
if(!LAZYLEN(track_data))
stack_trace("Invalid track: [track]")
return FALSE
var/track_name = LAZYACCESS(track_data, TRACK_NAME)
if(!track_name)
stack_trace("Track [track] lacks name???")
return FALSE
track_datum.song_name = track_name
var/track_length = LAZYACCESS(track_data, TRACK_LENGTH)
if(!track_length)
stack_trace("Track [track] lacks length.")
return FALSE
track_length = text2num(track_length)
if(!isnum(track_length))
stack_trace("Track [track]'s length value is not a number")
return FALSE
track_datum.song_length = track_length
var/track_beat = LAZYACCESS(track_data, TRACK_BEAT)
if(!track_beat)
stack_trace("Track [track] lacks BPM.")
return FALSE
track_beat = text2num(track_beat)
if(!isnum(track_beat))
stack_trace("Track [track]'s beat value is not a number")
return FALSE
track_datum.song_beat = track_beat
var/track_id = LAZYACCESS(track_data, TRACK_ID)
if(!track_id)
stack_trace("Track [track] lacks an unique identifier.")
return FALSE
track_datum.song_associated_id = track_id
return track_datum


/datum/controller/subsystem/jukeboxes/fire()
if(!activejukeboxes.len)
Expand Down Expand Up @@ -181,6 +232,11 @@ SUBSYSTEM_DEF(jukeboxes)
CHECK_TICK
return

#undef TRACK_NAME
#undef TRACK_LENGTH
#undef TRACK_BEAT
#undef TRACK_ID

#undef JUKE_TRACK
#undef JUKE_CHANNEL
#undef JUKE_BOX
Expand Down

0 comments on commit 6083aeb

Please sign in to comment.