Files
Bubberstation/code/modules/modular_computers/file_system/programs/statusdisplay.dm
Ghom 3f1c159904 [NO GBP] Fixing issues with modular computer and circuits. (#81076)
## About The Pull Request
It turns out the messenger circuit wasn't working as intended, because
list components tend to convert datum keys into weakrefs, creating
incoherence between composite datum/atom and simple datum/atom
datatypes, which at least just spares us from the headache of clearing
the refs on del from lists too.

So, taking the shortest path, I decided to adapt the messenger to the
weak ref usage.

Another thing, instead of refusing altogether to send message that
trigger the pda filter regexes, the messenger circuit will instead
replace the matches with grawlix, since we have no way to inform
whoever's responsible for said message about the filters in an orthodox
way.

Beside that, I've noticed several of the circuits from my PR were
lacking trigger outputs or similar when needed, pretty making them only
as half as functional, at least to a noob like me.

And another small issue with missing ports from the status display
circuit.

One more suggestion from moocow is to add a cooldown to the ringtone
trigger for the messenger circuit, because he said it's pretty spammy
and some admins are fickle.

## Why It's Good For The Game
Bugfixing and improvements.

## Changelog

🆑
fix: Fixed the messenger circuit not sending messages.
fix: Added several ports to modpc circuits that were missing or needing
them.
fix: Fixes ever-expanding ports whenever circuits are re-inserted in a
modular computer.
/🆑
2024-01-25 09:11:45 -05:00

127 lines
4.5 KiB
Plaintext

/datum/computer_file/program/status
filename = "statusdisplay"
filedesc = "Status Display"
program_icon = "signal"
program_open_overlay = "generic"
size = 1
circuit_comp_type = /obj/item/circuit_component/mod_program/status
extended_desc = "An app used to change the message on the station status displays."
tgui_id = "NtosStatus"
can_run_on_flags = PROGRAM_ALL
program_flags = PROGRAM_REQUIRES_NTNET
var/upper_text = ""
var/lower_text = ""
/**
* Post status display radio packet.
* Arguments:
* * command - the status display command
* * data1 - the data1 value, as defined by status displays
* * data2 - the data2 value, as defined by status displays
*/
/datum/computer_file/program/status/proc/post_status(command, data1, data2)
var/datum/radio_frequency/frequency = SSradio.return_frequency(FREQ_STATUS_DISPLAYS)
if(!frequency)
return
var/datum/signal/status_signal = new(list("command" = command))
switch(command)
if("message")
status_signal.data["top_text"] = data1
status_signal.data["bottom_text"] = data2
if("alert")
status_signal.data["picture_state"] = data1
frequency.post_signal(src, status_signal)
/**
* Post a message to status displays
* Arguments:
* * upper - Top text
* * lower - Bottom text
*/
/datum/computer_file/program/status/proc/post_message(upper, lower, log_usr = key_name(usr))
post_status("message", upper, lower)
log_game("[log_usr] has changed the station status display message to \"[upper] [lower]\" [loc_name(usr)]")
/**
* Post a picture to status displays
* Arguments:
* * picture - The picture name
*/
/datum/computer_file/program/status/proc/post_picture(picture, log_usr = key_name(usr))
if (!(picture in GLOB.status_display_approved_pictures))
return
if(picture in GLOB.status_display_state_pictures)
post_status(picture)
else
if(picture == "currentalert") // You cannot set Code Blue display during Code Red and similiar
switch(SSsecurity_level.get_current_level_as_number())
if(SEC_LEVEL_DELTA)
post_status("alert", "deltaalert")
if(SEC_LEVEL_RED)
post_status("alert", "redalert")
if(SEC_LEVEL_BLUE)
post_status("alert", "bluealert")
if(SEC_LEVEL_GREEN)
post_status("alert", "greenalert")
else
post_status("alert", picture)
log_game("[log_usr] has changed the station status display message to \"[picture]\" [loc_name(usr)]")
/datum/computer_file/program/status/ui_act(action, list/params, datum/tgui/ui, datum/ui_state/state)
. = ..()
switch(action)
if("setStatusMessage")
upper_text = reject_bad_text(params["upperText"] || "", MAX_STATUS_LINE_LENGTH)
lower_text = reject_bad_text(params["lowerText"] || "", MAX_STATUS_LINE_LENGTH)
post_message(upper_text, lower_text)
if("setStatusPicture")
post_picture(params["picture"])
/datum/computer_file/program/status/ui_static_data(mob/user)
var/list/data = list()
data["maxStatusLineLength"] = MAX_STATUS_LINE_LENGTH
return data
/datum/computer_file/program/status/ui_data(mob/user)
var/list/data = list()
data["upperText"] = upper_text
data["lowerText"] = lower_text
return data
/obj/item/circuit_component/mod_program/status
associated_program = /datum/computer_file/program/status
circuit_flags = CIRCUIT_FLAG_INPUT_SIGNAL|CIRCUIT_FLAG_OUTPUT_SIGNAL
///When the trigger is signaled, this will be the upper text of status displays.
var/datum/port/input/upper_text
///When the trigger is signaled, this will be the bottom text.
var/datum/port/input/bottom_text
///A list port that, when signaled, will set the status image to one of its values
var/datum/port/input/status_display_pics
/obj/item/circuit_component/mod_program/status/populate_ports()
. = ..()
upper_text = add_input_port("Upper text", PORT_TYPE_STRING)
bottom_text = add_input_port("Bottom text", PORT_TYPE_STRING)
/obj/item/circuit_component/mod_program/status/populate_options()
status_display_pics = add_option_port("Set Status Display Picture", GLOB.status_display_approved_pictures, trigger = PROC_REF(set_picture))
/obj/item/circuit_component/mod_program/status/proc/set_picture(datum/port/port)
var/datum/computer_file/program/status/status = associated_program
INVOKE_ASYNC(status, TYPE_PROC_REF(/datum/computer_file/program/status, post_picture), status_display_pics.value, parent.get_creator())
/obj/item/circuit_component/mod_program/status/input_received(datum/port/port)
var/datum/computer_file/program/status/status = associated_program
INVOKE_ASYNC(status, TYPE_PROC_REF(/datum/computer_file/program/status, post_message), upper_text.value, bottom_text.value, parent.get_creator())