Skip to content

Commit

Permalink
music-prefs
Browse files Browse the repository at this point in the history
  • Loading branch information
Builder13 committed Nov 29, 2024
1 parent 4ac01b2 commit 245b1e6
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
1 change: 1 addition & 0 deletions mods/music_player/_music_player.dme
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "_music_player.dm"

#include "code/music_prefs.dm"
#include "code/music_player.dm"
#include "code/music_tape.dm"
#include "code/music_writer.dm"
Expand Down
2 changes: 1 addition & 1 deletion mods/music_player/code/music_player.dm
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ GLOBAL_LIST_INIT(switch_small_sound, list(
sound_token.Unpause()
else
QDEL_NULL(sound_token)
sound_token = GLOB.sound_player.PlayLoopingSound(src, sound_id, tape.track.source, volume = volume, frequency = frequency, range = 9, falloff = 2, prefer_mute = TRUE)
sound_token = GLOB.sound_player.PlayLoopingSound(src, sound_id, tape.track.source, volume = volume, frequency = frequency, range = 9, falloff = 2, prefer_mute = TRUE, preference = /datum/client_preference/play_pmps)

mode = PLAYER_STATE_PLAY
START_PROCESSING(SSobj, src)
Expand Down
60 changes: 60 additions & 0 deletions mods/music_player/code/music_prefs.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/datum/client_preference/play_jukeboxes
description ="Play jukeboxes"
key = "SOUND_JUKEBOXES"

/datum/client_preference/play_pmps
description ="Play music players"
key = "SOUND_PMPS"

/datum/sound_token
var/datum/client_preference/preference

/datum/sound_token/proc/check_preference(atom/listener)
if(preference)
var/mob/M = listener
if(istype(M))
if((M.get_preference_value(preference) != GLOB.PREF_YES))
return FALSE
return TRUE

/singleton/sound_player/PlaySoundDatum(atom/source, sound_id, sound/sound, range, prefer_mute, datum/client_preference/preference)
var/token_type = isnum(sound.environment) ? /datum/sound_token : /datum/sound_token/static_environment
return new token_type(source, sound_id, sound, range, prefer_mute, preference)

/singleton/sound_player/PlayLoopingSound(atom/source, sound_id, sound, volume, range, falloff = 1, echo, frequency, prefer_mute, datum/client_preference/preference)
var/sound/S = istype(sound, /sound) ? sound : new(sound)
S.environment = 0 // Ensures a 3D effect even if x/y offset happens to be 0 the first time it's played
S.volume = volume
S.falloff = falloff
S.echo = echo
S.frequency = frequency
S.repeat = TRUE

return PlaySoundDatum(source, sound_id, S, range, prefer_mute, preference)

/datum/sound_token/New(atom/source, sound_id, sound/sound, range = 4, prefer_mute = FALSE, datum/client_preference/preference)
src.preference = preference
..()

/datum/sound_token/PrivAddListener(atom/listener)
if(!check_preference(listener))
return
..()

/datum/sound_token/PrivUpdateListener(listener, update_sound = TRUE)
if(!check_preference(listener))
PrivRemoveListener(listener)
return
..()


/datum/jukebox/Play()
if (playing)
return
var/datum/jukebox_track/track = tracks[index]
if (!track.source)
return
playing = TRUE
token = GLOB.sound_player.PlayLoopingSound(owner, sound_id, track.source,
volume, range, falloff, frequency = frequency, prefer_mute = TRUE, preference = /datum/client_preference/play_jukeboxes)
owner.queue_icon_update()

0 comments on commit 245b1e6

Please sign in to comment.