Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MIRROR] Fixing issues with modular computer and circuits. #1703

Merged
merged 1 commit into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions code/__DEFINES/dcs/signals/signals_modular_computer.dm
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
// Various modular computer signals.

/// From /obj/item/modular_computer/proc/turn_on: (user)
#define COMSIG_MODULAR_COMPUTER_TURNED_ON "comsig_modular_computer_turned_on"
/// From /obj/item/modular_computer/proc/shutdown_computer: (loud)
#define COMSIG_MODULAR_COMPUTER_SHUT_DOWN "comsig_modular_computer_shut_down"

/// From /obj/item/modular_computer/proc/store_file: (datum/computer_file/file_storing)
#define COMSIG_MODULAR_COMPUTER_FILE_STORE "comsig_modular_computer_file_store"
/// From /obj/item/modular_computer/proc/remove_file: (datum/computer_file/file_removing)
Expand All @@ -9,6 +14,9 @@
/// From /obj/item/modular_computer/proc/store_file: ()
#define COMSIG_COMPUTER_FILE_DELETE "comsig_computer_file_delete"

/// From /obj/item/modular_computer/proc/InsertID: (inserting_id, user)
#define COMSIG_MODULAR_COMPUTER_INSERTED_ID "comsig_computer_inserted_id"

/// From /datum/computer_file/program/on_start: (user)
#define COMSIG_COMPUTER_PROGRAM_START "computer_program_start"

Expand Down
3 changes: 3 additions & 0 deletions code/__DEFINES/dcs/signals/signals_object.dm
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,9 @@
///from /obj/item/assembly/proc/pulsed(mob/pulser)
#define COMSIG_ASSEMBLY_PULSED "assembly_pulsed"

///from /datum/computer_file/program/nt_pay/_pay(), sent to every physical card of a bank account: (computer, money_received)
#define COMSIG_ID_CARD_NTPAY_MONEY_RECEIVED "id_card_ntpay_money_received"

///from base of /obj/item/mmi/set_brainmob(): (mob/living/brain/new_brainmob)
#define COMSIG_MMI_SET_BRAINMOB "mmi_set_brainmob"

Expand Down
8 changes: 8 additions & 0 deletions code/__HELPERS/chat_filter.dm
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@

return null

///Given a pda message, will replace any match in the message with grawlixs.
/proc/censor_ic_filter_for_pdas(message)
if(config.ic_outside_pda_filter_regex)
message = config.ic_outside_pda_filter_regex.Replace(message, GLOBAL_PROC_REF(grawlix))
if(config.soft_ic_outside_pda_filter_regex)
message = config.soft_ic_outside_pda_filter_regex.Replace(message, GLOBAL_PROC_REF(grawlix))
return message

/// Logs to the filter log with the given message, match, and scope
/proc/log_filter(scope, message, filter_result)
log_filter_raw("[scope] filter:\n\tMessage: [message]\n\tFilter match: [filter_result[CHAT_FILTER_INDEX_WORD]]")
Expand Down
7 changes: 7 additions & 0 deletions code/__HELPERS/text.dm
Original file line number Diff line number Diff line change
Expand Up @@ -1196,3 +1196,10 @@ GLOBAL_LIST_INIT(binary, list("0","1"))
/proc/endswith(input_text, ending)
var/input_length = LAZYLEN(ending)
return !!findtext(input_text, ending, -input_length)

/// Generate a grawlix string of length of the text argument.
/proc/grawlix(text)
var/grawlix = ""
for(var/iteration in 1 to length_char(text))
grawlix += pick("@", "$", "?", "!", "#", "§", "*", "£", "%", "☠", "★", "☆", "¿", "⚡")
return grawlix
6 changes: 5 additions & 1 deletion code/modules/modular_computers/computers/item/computer.dm
Original file line number Diff line number Diff line change
Expand Up @@ -277,21 +277,23 @@
if(computer_id_slot)
return FALSE

computer_id_slot = inserting_id
if(user)
if(!user.transferItemToLoc(inserting_id, src))
return FALSE
to_chat(user, span_notice("You insert \the [inserting_id] into the card slot."))
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
if(human_wearer.wear_id == src)
human_wearer.sec_hud_set_ID()
update_appearance()
update_slot_icon()
SEND_SIGNAL(src, COMSIG_MODULAR_COMPUTER_INSERTED_ID, inserting_id, user)
return TRUE

/**
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down
28 changes: 26 additions & 2 deletions code/modules/modular_computers/computers/item/computer_circuit.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
8 changes: 5 additions & 3 deletions code/modules/modular_computers/file_system/program_circuit.dm
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@
return FALSE
if(isnull(associated_program))
return FALSE
if(!associated_program.computer.enabled)
return FALSE
if(associated_program.program_flags & PROGRAM_CIRCUITS_RUN_WHEN_CLOSED || COMPONENT_TRIGGERED_BY(start, port))
return TRUE
var/obj/item/modular_computer/computer = associated_program.computer
Expand All @@ -78,16 +80,16 @@

/obj/item/circuit_component/mod_program/proc/on_start(mob/living/user)
SIGNAL_HANDLER
running.set_value(TRUE)
running.set_output(TRUE)

/obj/item/circuit_component/mod_program/proc/kill_prog(datum/port/input/port)
associated_program.kill_program()

/obj/item/circuit_component/mod_program/proc/on_kill(mob/living/user)
SIGNAL_HANDLER
running.set_value(FALSE)
running.set_output(FALSE)

/obj/item/circuit_component/mod_program/get_ui_notices()
. = ..()
if(!(associated_program.program_flags & PROGRAM_CIRCUITS_RUN_WHEN_CLOSED))
. += create_ui_notice("Requires program to be running", "purple")
. += create_ui_notice("Requires open program for inputs", "purple")
Original file line number Diff line number Diff line change
Expand Up @@ -17,48 +17,6 @@
/// How many pictures were taken already, used for the camera's TGUI photo display
var/picture_number = 1

/obj/item/circuit_component/mod_program/camera
associated_program = /datum/computer_file/program/maintenance/camera
circuit_flags = CIRCUIT_FLAG_INPUT_SIGNAL

///A target to take a picture of.
var/datum/port/input/picture_target
///The photographed target
var/datum/port/output/photographed

/obj/item/circuit_component/mod_program/camera/populate_ports()
. = ..()
picture_target = add_input_port("Picture Target", PORT_TYPE_ATOM)
photographed = add_output_port("Photographed Entity", PORT_TYPE_ATOM)

/obj/item/circuit_component/mod_program/camera/register_shell(atom/movable/shell)
. = ..()
var/datum/computer_file/program/maintenance/camera/cam = associated_program
RegisterSignal(cam.internal_camera, COMSIG_CAMERA_IMAGE_CAPTURED, PROC_REF(on_image_captured))

/obj/item/circuit_component/mod_program/camera/unregister_shell()
var/datum/computer_file/program/maintenance/camera/cam = associated_program
UnregisterSignal(cam.internal_camera, COMSIG_CAMERA_IMAGE_CAPTURED)
return ..()

/obj/item/circuit_component/mod_program/camera/input_received(datum/port/input/port)
var/atom/target = picture_target.value
if(!target)
var/turf/our_turf = get_location()
target = locate(our_turf.x, our_turf.y, our_turf.z)
if(!target)
return
var/datum/computer_file/program/maintenance/camera/cam = associated_program
if(!cam.internal_camera.can_target(target))
return
var/pic_size_x = cam.internal_camera.picture_size_x - 1
var/pic_size_y = cam.internal_camera.picture_size_y - 1
INVOKE_ASYNC(cam.internal_camera, TYPE_PROC_REF(/obj/item/camera, captureimage), target, null, pic_size_x, pic_size_y)

/obj/item/circuit_component/mod_program/camera/proc/on_image_captured(obj/item/camera/source, atom/target, mob/user)
SIGNAL_HANDLER
photographed.set_output(target)

/datum/computer_file/program/maintenance/camera/on_install()
. = ..()
internal_camera = new(computer)
Expand Down Expand Up @@ -103,3 +61,53 @@
internal_camera.printpicture(usr, internal_picture)
computer.stored_paper--
computer.visible_message(span_notice("\The [computer] prints out a paper."))

/obj/item/circuit_component/mod_program/camera
associated_program = /datum/computer_file/program/maintenance/camera
circuit_flags = CIRCUIT_FLAG_INPUT_SIGNAL

///A target to take a picture of.
var/datum/port/input/picture_target
///The photographed target
var/datum/port/output/photographed
/**
* Pinged when the image has been captured.
* I'm not using the default trigger output here because the process is asynced,
* even though I'm mostly sure it only sleeps if there's a set user.
*/
var/datum/port/output/photo_taken

/obj/item/circuit_component/mod_program/camera/populate_ports()
. = ..()
picture_target = add_input_port("Picture Target", PORT_TYPE_ATOM)
photographed = add_output_port("Photographed Entity", PORT_TYPE_ATOM)
photo_taken = add_output_port("Photo Taken", PORT_TYPE_SIGNAL)

/obj/item/circuit_component/mod_program/camera/register_shell(atom/movable/shell)
. = ..()
var/datum/computer_file/program/maintenance/camera/cam = associated_program
RegisterSignal(cam.internal_camera, COMSIG_CAMERA_IMAGE_CAPTURED, PROC_REF(on_image_captured))

/obj/item/circuit_component/mod_program/camera/unregister_shell()
var/datum/computer_file/program/maintenance/camera/cam = associated_program
UnregisterSignal(cam.internal_camera, COMSIG_CAMERA_IMAGE_CAPTURED)
return ..()

/obj/item/circuit_component/mod_program/camera/input_received(datum/port/input/port)
var/atom/target = picture_target.value
if(!target)
var/turf/our_turf = get_location()
target = locate(our_turf.x, our_turf.y, our_turf.z)
if(!target)
return
var/datum/computer_file/program/maintenance/camera/cam = associated_program
if(!cam.internal_camera.can_target(target))
return
var/pic_size_x = cam.internal_camera.picture_size_x - 1
var/pic_size_y = cam.internal_camera.picture_size_y - 1
INVOKE_ASYNC(cam.internal_camera, TYPE_PROC_REF(/obj/item/camera, captureimage), target, null, pic_size_x, pic_size_y)

/obj/item/circuit_component/mod_program/camera/proc/on_image_captured(obj/item/camera/source, atom/target, mob/user)
SIGNAL_HANDLER
photographed.set_output(target)
photo_taken.set_output(COMPONENT_SIGNAL)
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,13 @@

/// Returns the spookiness of each scan.
var/datum/port/output/scan_results
/// Pinged whenever a scan is done.
var/datum/port/output/scanned

/obj/item/circuit_component/mod_program/spectre_meter/populate_ports()
. = ..()
scan_results = add_output_port("Scan Results", PORT_TYPE_NUMBER)
scanned = add_output_port("Scaned", PORT_TYPE_SIGNAL)

/obj/item/circuit_component/mod_program/spectre_meter/register_shell(atom/movable/shell)
. = ..()
Expand All @@ -166,7 +169,8 @@

/obj/item/circuit_component/mod_program/spectre_meter/proc/on_scan(datum/source, spook_value)
SIGNAL_HANDLER
scan_results.set_value(spook_value)
scan_results.set_output(spook_value)
scanned.set_output(COMPONENT_SIGNAL)

#undef SPOOK_VALUE_SAME_TURF_MULT
#undef SPOOK_VALUE_LIVING_MULT
Expand Down
Loading
Loading