mirror of
https://github.com/ParadiseSS13/Paradise.git
synced 2026-07-11 15:14:27 +01:00
Headphones, fix unreachable dropoff threshold, etc.
This commit is contained in:
@@ -27,12 +27,6 @@
|
||||
user.visible_message("<span class='suicide'>[user] begins to play 'Gloomy Sunday'! It looks like [user.p_theyre()] trying to commit suicide!</span>")
|
||||
return BRUTELOSS
|
||||
|
||||
/obj/item/instrument/attack_self(mob/user)
|
||||
if(!user.IsAdvancedToolUser())
|
||||
to_chat(user, "<span class='warning'>You don't have the dexterity to do this!</span>")
|
||||
return TRUE
|
||||
interact(user)
|
||||
|
||||
/obj/item/instrument/attack_self(mob/user)
|
||||
tgui_interact(user)
|
||||
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
/obj/item/clothing/ears/headphones
|
||||
name = "headphones"
|
||||
desc = "Unce unce unce unce."
|
||||
icon_state = "headphones0"
|
||||
item_state = "headphones0"
|
||||
actions_types = list(/datum/action/item_action/change_headphones_song)
|
||||
var/datum/song/headphones/song
|
||||
|
||||
/obj/item/clothing/ears/headphones/Initialize(mapload)
|
||||
. = ..()
|
||||
song = new(src, "piano") // Piano is the default instrument but all instruments are allowed
|
||||
song.instrument_range = 0
|
||||
song.allowed_instrument_ids = SSinstruments.synthesizer_instrument_ids
|
||||
// To update the icon
|
||||
RegisterSignal(src, COMSIG_SONG_START, .proc/start_playing)
|
||||
RegisterSignal(src, COMSIG_SONG_END, .proc/stop_playing)
|
||||
|
||||
/obj/item/clothing/ears/headphones/Destroy()
|
||||
QDEL_NULL(song)
|
||||
return ..()
|
||||
|
||||
/obj/item/clothing/ears/headphones/attack_self(mob/user)
|
||||
tgui_interact(user)
|
||||
|
||||
/obj/item/clothing/ears/headphones/tgui_data(mob/user)
|
||||
return song.tgui_data(user)
|
||||
|
||||
/obj/item/clothing/ears/headphones/tgui_interact(mob/user)
|
||||
if(should_stop_playing(user) || user.incapacitated())
|
||||
return
|
||||
song.tgui_interact(user)
|
||||
|
||||
/obj/item/clothing/ears/headphones/tgui_act(action, params)
|
||||
if(..())
|
||||
return
|
||||
return song.tgui_act(action, params)
|
||||
|
||||
/obj/item/clothing/ears/headphones/update_icon()
|
||||
var/mob/living/carbon/human/user = loc
|
||||
if(istype(user))
|
||||
user.update_action_buttons_icon()
|
||||
user.update_inv_ears()
|
||||
..()
|
||||
|
||||
/obj/item/clothing/ears/headphones/item_action_slot_check(slot)
|
||||
if(slot == slot_l_ear || slot == slot_r_ear)
|
||||
return TRUE
|
||||
|
||||
/**
|
||||
* Called by a component signal when our song starts playing.
|
||||
*/
|
||||
/obj/item/clothing/ears/headphones/proc/start_playing()
|
||||
icon_state = item_state = "headphones1"
|
||||
update_icon()
|
||||
|
||||
/**
|
||||
* Called by a component signal when our song stops playing.
|
||||
*/
|
||||
/obj/item/clothing/ears/headphones/proc/stop_playing()
|
||||
icon_state = item_state = "headphones0"
|
||||
update_icon()
|
||||
|
||||
/**
|
||||
* Whether the headphone's song should stop playing
|
||||
*
|
||||
* Arguments:
|
||||
* * user - The user
|
||||
*/
|
||||
/obj/item/clothing/ears/headphones/proc/should_stop_playing(mob/living/carbon/human/user)
|
||||
return !(src in user) || !istype(user) || !((src == user.l_ear) || (src == user.r_ear))
|
||||
|
||||
// special subtype so it uses the correct item type
|
||||
/datum/song/headphones
|
||||
|
||||
/datum/song/headphones/should_stop_playing(mob/user)
|
||||
. = ..()
|
||||
if(.)
|
||||
return TRUE
|
||||
var/obj/item/clothing/ears/headphones/I = parent
|
||||
return I.should_stop_playing(user)
|
||||
@@ -39,7 +39,7 @@
|
||||
icon_state = "guitar"
|
||||
item_state = "guitar"
|
||||
attack_verb = list("played metal on", "serenaded", "crashed", "smashed")
|
||||
hitsound = 'sound/weapons/stringsmash.ogg'
|
||||
hitsound = 'sound/weapons/guitarslam.ogg'
|
||||
allowed_instrument_ids = "guitar"
|
||||
|
||||
/obj/item/instrument/eguitar
|
||||
|
||||
@@ -115,7 +115,7 @@
|
||||
/// The kind of sustain we're using
|
||||
var/sustain_mode = SUSTAIN_LINEAR
|
||||
/// When a note is considered dead if it is below this in volume
|
||||
var/sustain_dropoff_volume = 0
|
||||
var/sustain_dropoff_volume = INSTRUMENT_MIN_SUSTAIN_DROPOFF
|
||||
/// Total duration of linear sustain for 100 volume note to get to SUSTAIN_DROPOFF
|
||||
var/sustain_linear_duration = 5
|
||||
/// Exponential sustain dropoff rate per decisecond
|
||||
@@ -168,7 +168,9 @@
|
||||
var/turf/source = get_turf(parent)
|
||||
for(var/mob/M in GLOB.player_list)
|
||||
var/dist = get_dist(M, source)
|
||||
if(dist > instrument_range)
|
||||
if(dist > instrument_range) // Distance check
|
||||
continue
|
||||
if(!isInSight(M, source)) // Visibility check (direct line of sight)
|
||||
continue
|
||||
hearing_mobs[M] = dist
|
||||
var/list/exited = old - hearing_mobs
|
||||
@@ -251,7 +253,7 @@
|
||||
* Processes our song.
|
||||
*/
|
||||
/datum/song/proc/process_song(wait)
|
||||
if(!length(compiled_chords) || should_stop_playing(user_playing))
|
||||
if(!length(compiled_chords) || current_chord > length(compiled_chords) || should_stop_playing(user_playing))
|
||||
stop_playing()
|
||||
return
|
||||
var/list/chord = compiled_chords[current_chord]
|
||||
@@ -349,26 +351,29 @@
|
||||
/**
|
||||
* Setter for setting how low the volume has to get before a note is considered "dead" and dropped
|
||||
*/
|
||||
/datum/song/proc/set_dropoff_volume(volume)
|
||||
/datum/song/proc/set_dropoff_volume(volume, no_refresh = FALSE)
|
||||
sustain_dropoff_volume = clamp(volume, INSTRUMENT_MIN_SUSTAIN_DROPOFF, 100)
|
||||
update_sustain()
|
||||
SStgui.update_uis(parent)
|
||||
if(!no_refresh)
|
||||
SStgui.update_uis(parent)
|
||||
|
||||
/**
|
||||
* Setter for setting exponential falloff factor.
|
||||
*/
|
||||
/datum/song/proc/set_exponential_drop_rate(drop)
|
||||
/datum/song/proc/set_exponential_drop_rate(drop, no_refresh = FALSE)
|
||||
sustain_exponential_dropoff = clamp(drop, INSTRUMENT_EXP_FALLOFF_MIN, INSTRUMENT_EXP_FALLOFF_MAX)
|
||||
update_sustain()
|
||||
SStgui.update_uis(parent)
|
||||
if(!no_refresh)
|
||||
SStgui.update_uis(parent)
|
||||
|
||||
/**
|
||||
* Setter for setting linear falloff duration.
|
||||
*/
|
||||
/datum/song/proc/set_linear_falloff_duration(duration)
|
||||
/datum/song/proc/set_linear_falloff_duration(duration, no_refresh = FALSE)
|
||||
sustain_linear_duration = clamp(duration, 0.1, INSTRUMENT_MAX_TOTAL_SUSTAIN)
|
||||
update_sustain()
|
||||
SStgui.update_uis(parent)
|
||||
if(!no_refresh)
|
||||
SStgui.update_uis(parent)
|
||||
|
||||
/datum/song/vv_edit_var(var_name, var_value)
|
||||
. = ..()
|
||||
|
||||
@@ -52,12 +52,12 @@
|
||||
ui.set_autoupdate(FALSE) // NO!!! Don't auto-update this!!
|
||||
|
||||
/datum/song/tgui_act(action, params)
|
||||
. = TRUE
|
||||
switch(action)
|
||||
if("newsong")
|
||||
lines = new()
|
||||
tempo = sanitize_tempo(5) // default 120 BPM
|
||||
name = ""
|
||||
return TRUE
|
||||
if("import")
|
||||
var/t = ""
|
||||
do
|
||||
@@ -71,20 +71,17 @@
|
||||
break
|
||||
while(length_char(t) > MUSIC_MAXLINES * MUSIC_MAXLINECHARS)
|
||||
parse_song(t)
|
||||
return FALSE
|
||||
if("help")
|
||||
help = !help
|
||||
return TRUE
|
||||
if("edit")
|
||||
editing = !editing
|
||||
return TRUE
|
||||
if("repeat") //Changing this from a toggle to a number of repeats to avoid infinite loops.
|
||||
if(playing)
|
||||
return //So that people cant keep adding to repeat. If the do it intentionally, it could result in the server crashing.
|
||||
repeat = clamp(round(text2num(params["new"])), 0, max_repeats)
|
||||
return TRUE
|
||||
if("tempo")
|
||||
tempo = sanitize_tempo(text2num(params["new"]))
|
||||
return TRUE
|
||||
if("play")
|
||||
INVOKE_ASYNC(src, .proc/start_playing, usr)
|
||||
if("newline")
|
||||
@@ -96,13 +93,11 @@
|
||||
if(length(newline) > MUSIC_MAXLINECHARS)
|
||||
newline = copytext(newline, 1, MUSIC_MAXLINECHARS)
|
||||
lines.Add(newline)
|
||||
return TRUE
|
||||
if("deleteline")
|
||||
var/num = round(text2num(params["line"]))
|
||||
if(num > length(lines) || num < 1)
|
||||
return
|
||||
lines.Cut(num, num + 1)
|
||||
return TRUE
|
||||
if("modifyline")
|
||||
var/num = round(text2num(params["line"]))
|
||||
var/content = stripped_input(usr, "Enter your line: ", parent.name, lines[num], MUSIC_MAXLINECHARS)
|
||||
@@ -111,20 +106,16 @@
|
||||
if(num > length(lines) || num < 1)
|
||||
return
|
||||
lines[num] = content
|
||||
return TRUE
|
||||
if("stop")
|
||||
stop_playing()
|
||||
if("setlinearfalloff")
|
||||
set_linear_falloff_duration(round(text2num(params["new"]) * 10, world.tick_lag))
|
||||
return TRUE
|
||||
set_linear_falloff_duration(round(text2num(params["new"]) * 10, world.tick_lag), TRUE)
|
||||
if("setexpfalloff")
|
||||
set_exponential_drop_rate(round(text2num(params["new"]), 0.00001))
|
||||
return TRUE
|
||||
set_exponential_drop_rate(round(text2num(params["new"]), 0.00001), TRUE)
|
||||
if("setvolume")
|
||||
set_volume(round(text2num(params["new"]), 1))
|
||||
if("setdropoffvolume")
|
||||
set_dropoff_volume(round(text2num(params["new"]), 0.01))
|
||||
return TRUE
|
||||
set_dropoff_volume(round(text2num(params["new"]), 0.01), TRUE)
|
||||
if("switchinstrument")
|
||||
if(!length(allowed_instrument_ids))
|
||||
return
|
||||
@@ -136,20 +127,25 @@
|
||||
var/datum/instrument/I = SSinstruments.get_instrument(i)
|
||||
if(I && I.name == choice)
|
||||
set_instrument(I)
|
||||
return TRUE
|
||||
if("setnoteshift")
|
||||
note_shift = clamp(round(text2num(params["new"])), note_shift_min, note_shift_max)
|
||||
return TRUE
|
||||
if("setsustainmode")
|
||||
var/static/list/sustain_modes
|
||||
if(!length(sustain_modes))
|
||||
sustain_modes = list("Linear" = SUSTAIN_LINEAR, "Exponential" = SUSTAIN_EXPONENTIAL)
|
||||
var/choice = params["new"]
|
||||
sustain_mode = sustain_modes[choice] || sustain_mode
|
||||
return TRUE
|
||||
if("togglesustainhold")
|
||||
full_sustain_held_note = !full_sustain_held_note
|
||||
return TRUE
|
||||
if("reset")
|
||||
var/default_instrument = allowed_instrument_ids[1]
|
||||
if(using_instrument != SSinstruments.instrument_data[default_instrument])
|
||||
set_instrument(default_instrument)
|
||||
note_shift = initial(note_shift)
|
||||
sustain_mode = initial(sustain_mode)
|
||||
set_linear_falloff_duration(initial(sustain_linear_duration), TRUE)
|
||||
set_exponential_drop_rate(initial(sustain_exponential_dropoff), TRUE)
|
||||
set_dropoff_volume(initial(sustain_dropoff_volume), TRUE)
|
||||
else
|
||||
return FALSE
|
||||
parent.add_fingerprint(usr)
|
||||
@@ -160,6 +156,7 @@
|
||||
/datum/song/proc/parse_song(text)
|
||||
set waitfor = FALSE
|
||||
//split into lines
|
||||
stop_playing()
|
||||
lines = splittext(text, "\n")
|
||||
if(length(lines))
|
||||
var/bpm_string = "BPM: "
|
||||
|
||||
Reference in New Issue
Block a user