[MIRROR] [NO GBP] Fixing issues with modular computer and circuits. (#26247)

* [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.
/🆑

* [NO GBP] Fixing issues with modular computer and circuits.

---------

Co-authored-by: Ghom <42542238+Ghommie@users.noreply.github.com>
This commit is contained in:
SkyratBot
2024-01-25 23:08:34 -05:00
committed by GitHub
co-authored by Ghom
parent 309da5fd76
commit f768fab6c9
16 changed files with 210 additions and 85 deletions
@@ -277,7 +277,6 @@
if(computer_id_slot)
return FALSE
computer_id_slot = inserting_id
if(user)
if(!user.transferItemToLoc(inserting_id, src))
return FALSE
@@ -285,6 +284,8 @@
else
inserting_id.forceMove(src)
computer_id_slot = inserting_id
playsound(src, 'sound/machines/terminal_insert_disc.ogg', 50, FALSE)
if(ishuman(loc))
var/mob/living/carbon/human/human_wearer = loc
@@ -292,6 +293,7 @@
human_wearer.sec_hud_set_ID()
update_appearance()
update_slot_icon()
SEND_SIGNAL(src, COMSIG_MODULAR_COMPUTER_INSERTED_ID, inserting_id, user)
return TRUE
/**
@@ -488,6 +490,7 @@
to_chat(user, span_notice("You press the power button and start up \the [src]."))
if(open_ui)
update_tablet_open_uis(user)
SEND_SIGNAL(src, COMSIG_MODULAR_COMPUTER_TURNED_ON, user)
return TRUE
else // Unpowered
if(user)
@@ -692,6 +695,7 @@
physical.visible_message(span_notice("\The [src] shuts down."))
enabled = FALSE
update_appearance()
SEND_SIGNAL(src, COMSIG_MODULAR_COMPUTER_SHUT_DOWN, loud)
///Imprints name and job into the modular computer, and calls back to necessary functions.
///Acts as a replacement to directly setting the imprints fields. All fields are optional, the proc will try to fill in missing gaps.
@@ -8,6 +8,11 @@
///When set, will print a piece of paper with the value as text.
var/datum/port/input/print
///Sent when turned on
var/datum/port/output/is_on
///Sent when shut down
var/datum/port/output/is_off
///Toggles lights on and off. Also RGB.
var/datum/port/input/lights
var/datum/port/input/red
@@ -22,25 +27,36 @@
var/obj/machinery/modular_computer/console = shell
computer = console.cpu
if(isnull(computer))
return
RegisterSignal(computer, COMSIG_MODULAR_COMPUTER_TURNED_ON, PROC_REF(computer_on))
RegisterSignal(computer, COMSIG_MODULAR_COMPUTER_SHUT_DOWN, PROC_REF(computer_off))
/**
* Some mod pc have lights while some don't, but populate_ports()
* is called before we get to know which object this has attahed to,
* I hope you're cool with me doing it here.
*/
if(computer?.has_light)
if(computer.has_light && isnull(lights))
lights = add_input_port("Toggle Lights", PORT_TYPE_SIGNAL)
red = add_input_port("Red", PORT_TYPE_NUMBER)
green = add_input_port("Green", PORT_TYPE_NUMBER)
blue = add_input_port("Blue", PORT_TYPE_NUMBER)
/obj/item/circuit_component/modpc/unregister_shell(atom/movable/shell)
computer = null
if(computer)
UnregisterSignal(computer, list(COMSIG_MODULAR_COMPUTER_TURNED_ON, COMSIG_MODULAR_COMPUTER_SHUT_DOWN))
computer = null
return ..()
/obj/item/circuit_component/modpc/populate_ports()
on_off = add_input_port("Turn On/Off", PORT_TYPE_SIGNAL)
print = add_input_port("Print Text", PORT_TYPE_STRING)
is_on = add_output_port("Turned On", PORT_TYPE_SIGNAL)
is_on = add_output_port("Shut Down", PORT_TYPE_SIGNAL)
/obj/item/circuit_component/modpc/pre_input_received(datum/port/input/port)
if(isnull(computer))
return
@@ -74,3 +90,11 @@
computer.toggle_flashlight()
if(COMPONENT_TRIGGERED_BY(red, port) || COMPONENT_TRIGGERED_BY(green, port) || COMPONENT_TRIGGERED_BY(blue, port))
computer.set_flashlight_color(rgb(red.value || 0, green.value || 0, blue.value || 0))
/obj/item/circuit_component/modpc/proc/computer_on(datum/source, mob/user)
SIGNAL_HANDLER
is_on.set_output(COMPONENT_SIGNAL)
/obj/item/circuit_component/modpc/proc/computer_off(datum/source, loud)
SIGNAL_HANDLER
is_off.set_output(COMPONENT_SIGNAL)