Files
VOREStation/code/modules/media/mediamanager.dm
T
84dc5535dc var/global/list -> GLOB. conversion (#17928)
* These two are easy

* !!!runlevel_flags

the fact it was global.runlevel_flags.len has me a bit...iffy on this.

* !!!json_cache

Same as above. used global.

* player_list & observer_mob_list

* mechas_list

* this wasn't even used

* surgery_steps

* event_triggers

* landmarks_list

* dead_mob_list

* living_mob_list

* ai_list

* cable_list

* cleanbot_reserved_turfs

* listening_objects

* silicon_mob_list

* human_mob_list

* Update global_lists.dm

* joblist

* mob_list

* Update global_lists.dm

* holomap_markers

* mapping_units

* mapping_beacons

* hair_styles_list

* facial_hair_styles_list

* Update global_lists.dm

* facial_hair_styles_male_list

* facial_hair_styles_female_list

* body_marking_styles_list

* body_marking_nopersist_list

* ear_styles_list

* hair_styles_male_list

* tail_styles_list

* wing_styles_list

* escape_list & rune_list & endgame_exits

these were all really small

* endgame_safespawns

* stool_cache

* emotes_by_key

* random_maps & map_count

* item_tf_spawnpoints

* narsie_list

* active_radio_jammers

* unused

* paikeys

* pai_software_by_key & default_pai_software

* plant_seed_sprites

* magazine_icondata_keys  & magazine_icondata_states

* unused

* ashtray_cache

* light_type_cache

* HOLIDAY!!!

this one was annoying

* faction stuff (red?!)

* Update preferences_factions.dm

* vs edit removal

* backbaglist, pdachoicelist, exclude_jobs

* item_digestion_blacklist, edible_tech, blacklisted_artifact_effect, selectable_footstep, hexNums, syndicate_access

* string_slot_flags and hexdigits->hexNums

* possible_changeling_IDs

* vr_mob_tf_options

* vr_mob_spawner_options

* pipe_colors

* vr_mob_spawner_options

* common_tools

* newscaster_standard_feeds

* Update periodic_news.dm

* changeling_fabricated_clothing

* semirandom_mob_spawner_decisions

* id_card_states

* Update syndicate_ids.dm

* overlay_cache & gear_distributed_to

* more

* radio_channels_by_freq

* Update global_lists.dm

* proper

* default_medbay_channels & default_internal_channels

default_internal_channels is weird as it has a mapbased proc() but that proc is never called...

* valid_ringtones

* move this

* possible_plants

* more

* separate these

moves xeno2chemlist from a hook to a new global list.

* tube_dir_list

* valid_bloodreagents & monitor_states

* Junk

* valid_bloodtypes

* breach_burn_descriptors & burn

* more!!

appliance_available_recipes seems uber cursed, re-look at later

* Appliance code is cursed

* wide_chassis & flying_chassis

* allows_eye_color

* all_tooltip_styles

* direction_table

* gun_choices

* severity_to_string

* old event_viruses

* description_icons

* MOVE_KEY_MAPPINGS

* more more

* pai & robot modules

* Update global_lists.dm

* GEOSAMPLES

Also swaps a .len to LAZYLEN()

* shieldgens

* reagent recipies

* global ammo types

* rad collector

* old file and unused global

* nif_look_messages

* FESH

* nifsoft

* chamelion

* the death of sortAtom

* globulins

* lazylen that

* Update global_lists.dm

* LAZY

* Theese too

* quick fix

---------

Co-authored-by: Kashargul <144968721+Kashargul@users.noreply.github.com>
2025-07-14 20:14:31 +02:00

182 lines
6.0 KiB
Plaintext

/**********************
* AWW SHIT IT'S TIME FOR RADIO
*
* Concept stolen from D2K5
* Rewritten by N3X15 for vgstation
* Adapted by Leshana for VOREStation
***********************/
// Uncomment to test the mediaplayer
// #define DEBUG_MEDIAPLAYER
#ifdef DEBUG_MEDIAPLAYER
#define MP_DEBUG(x) to_chat(owner,x)
#warn Please comment out #define DEBUG_MEDIAPLAYER before committing.
#else
#define MP_DEBUG(x)
#endif
// Set up player on login.
/client/New()
. = ..()
media = new /datum/media_manager(src)
media.open()
media.update_music()
// Stop media when the round ends. I guess so it doesn't play forever or something (for some reason?)
/hook/roundend/proc/stop_all_media()
log_debug("Stopping all playing media...")
// Stop all music.
for(var/mob/M in GLOB.mob_list)
if(M && M.client)
M.stop_all_music()
// SHITTY HACK TO AVOID RACE CONDITION WITH SERVER REBOOT.
sleep(10) // TODO - Leshana - see if this is needed
// Update when moving between areas.
// TODO - While this direct override might technically be faster, probably better code to use observer or hooks ~Leshana
/area/Entered(var/mob/M)
// Note, we cannot call ..() first, because it would update lastarea.
if(!istype(M) || isEye(M))
return ..()
// Optimization, no need to call update_music() if both are null (or same instance, strange as that would be)
if(M.lastarea?.media_source == src.media_source)
return ..()
if(M.client?.media && !M.client.media.forced)
M.update_music()
return ..()
//
// ### Media variable on /client ###
/client
// Set on Login
var/datum/media_manager/media = null
/client/verb/change_volume()
set name = "Set Volume"
set category = "OOC.Client Settings"
set desc = "Set jukebox volume"
set_new_volume(usr)
/client/proc/set_new_volume(var/mob/user)
if(QDELETED(src.media) || !istype(src.media))
to_chat(user, span_warning("You have no media datum to change, if you're not in the lobby tell an admin."))
return
var/value = tgui_input_number(user, "Choose your Jukebox volume.", "Jukebox volume", media.volume, 100, 0)
value = round(max(0, min(100, value)))
media.update_volume(value)
//
// ### Media procs on mobs ###
// These are all convenience functions, simple delegations to the media datum on mob.
// But their presense and null checks make other coder's life much easier.
//
/mob/proc/update_music()
if (client?.media && !client.media.forced)
client.media.update_music()
/mob/proc/stop_all_music()
client?.media.stop_music()
/mob/proc/force_music(var/url, var/start, var/volume=1)
if (client?.media)
if(url == "")
client.media.forced = 0
client.media.update_music()
else
client.media.forced = 1
client.media.push_music(url, start, volume)
return
//
// ### Define media source to areas ###
// Each area may have at most one media source that plays songs into that area.
// We keep track of that source so any mob entering the area can lookup what to play.
//
/area
// For now, only one media source per area allowed
// Possible Future: turn into a list, then only play the first one that's playing.
var/obj/machinery/media/media_source = null
//
// ### Media Manager Datum
//
/datum/media_manager
var/url = "" // URL of currently playing media
var/start_time = 0 // world.time when it started playing *in the source* (Not when started playing for us)
var/source_volume = 1 // Volume as set by source. Actual volume = "volume * source_volume"
var/rate = 1 // Playback speed. For Fun(tm)
var/volume = 50 // Client's volume modifier. Actual volume = "volume * source_volume"
var/client/owner // Client this is actually running in
var/forced=0 // If true, current url overrides area media sources
var/playerstyle // Choice of which player plugin to use
var/const/WINDOW_ID = "rpane.mediapanel" // Which elem in skin.dmf to use
/datum/media_manager/New(var/client/C)
ASSERT(istype(C))
src.owner = C
// Actually pop open the player in the background.
/datum/media_manager/proc/open()
if(!owner.prefs)
return
if(isnum(owner.prefs.read_preference(/datum/preference/numeric/living/jukebox_volume)))
volume = owner.prefs.read_preference(/datum/preference/numeric/living/jukebox_volume) / 100
playerstyle = PLAYER_HTML5_HTML // we're in the 516 era baby
owner << browse(null, "window=[WINDOW_ID]")
owner << browse(playerstyle, "window=[WINDOW_ID]")
send_update()
// Tell the player to play something via JS.
/datum/media_manager/proc/send_update()
if(!owner.prefs)
return
if(!owner.prefs.read_preference(/datum/preference/toggle/play_jukebox) && url != "")
return // Don't send anything other than a cancel to people with SOUND_STREAMING pref disabled
MP_DEBUG(span_good("Sending update to mediapanel ([url], [(world.time - start_time) / 10], [volume * source_volume])..."))
owner << output(list2params(list(url, (world.time - start_time) / 10, volume * source_volume)), "[WINDOW_ID]:SetMusic")
/datum/media_manager/proc/push_music(var/targetURL, var/targetStartTime, var/targetVolume)
if (url != targetURL || abs(targetStartTime - start_time) > 1 || abs(targetVolume - source_volume) > 0.1 /* 10% */)
url = targetURL
start_time = targetStartTime
source_volume = CLAMP(targetVolume, 0, 1)
send_update()
/datum/media_manager/proc/stop_music()
push_music("", 0, 1)
/datum/media_manager/proc/update_volume(var/value)
volume = value
send_update()
// Scan for media sources and use them.
/datum/media_manager/proc/update_music()
var/targetURL = ""
var/targetStartTime = 0
var/targetVolume = 0
if (forced || !owner || !owner.mob)
return
var/area/A = get_area(owner.mob)
if(!A)
MP_DEBUG("client=[owner], mob=[owner.mob] not in an area! loc=[owner.mob.loc]. Aborting.")
stop_music()
return
var/obj/machinery/media/M = A.media_source
if(M && M.playing)
targetURL = M.media_url
targetStartTime = M.media_start_time
targetVolume = M.volume
//MP_DEBUG("Found audio source: [M.media_url] @ [(world.time - start_time) / 10]s.")
push_music(targetURL, targetStartTime, targetVolume)
#ifdef DEBUG_MEDIAPLAYER
#undef DEBUG_MEDIAPLAYER
#undef MP_DEBUG
#endif