From 8736e28925098fb3dd842f2fa81ec00b711f086b Mon Sep 17 00:00:00 2001 From: Iajret Creature <122297233+Steals-The-PRs@users.noreply.github.com> Date: Thu, 2 May 2024 09:46:14 +0300 Subject: [PATCH] [MIRROR] Give more control over conveyor switch circuits (#2269) (#3140) * Give more control over conveyor switch circuits (#82857) ## About The Pull Request This adds more signals to the conveyor switch circuits, specifically for going forward, stopping, or reversing. One-way conveyor switches will not get the reverse signal (as shown by the bottom right switch in the video). https://github.com/tgstation/tgstation/assets/16826524/66f287de-8413-41df-a69c-51b9ab8d7a02 ## Why It's Good For The Game This makes it far easier to make contraptions such as sorting mechanisms using circuits without the need to toggle multiple times just to get the conveyor direction into the state you need it in. ## Changelog :cl: qol: conveyor switches now have direction-specific input signals /:cl: * Give more control over conveyor switch circuits --------- Co-authored-by: NovaBot <154629622+NovaBot13@users.noreply.github.com> Co-authored-by: Echriser --- code/modules/recycling/conveyor.dm | 34 ++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/code/modules/recycling/conveyor.dm b/code/modules/recycling/conveyor.dm index 8271298a0e6..36d73552159 100644 --- a/code/modules/recycling/conveyor.dm +++ b/code/modules/recycling/conveyor.dm @@ -590,12 +590,18 @@ GLOBAL_LIST_EMPTY(conveyors_by_id) desc = "Allows to control connected conveyor belts." circuit_flags = CIRCUIT_FLAG_INPUT_SIGNAL + /// Direction input ports. + var/datum/port/input/stop + var/datum/port/input/active + var/datum/port/input/reverse /// The current direction of the conveyor attached to the component. var/datum/port/output/direction /// The switch this conveyor switch component is attached to. var/obj/machinery/conveyor_switch/attached_switch /obj/item/circuit_component/conveyor_switch/populate_ports() + active = add_input_port("Activate", PORT_TYPE_SIGNAL, trigger = PROC_REF(activate)) + stop = add_input_port("Stop", PORT_TYPE_SIGNAL, trigger = PROC_REF(stop)) direction = add_output_port("Conveyor Direction", PORT_TYPE_NUMBER) /obj/item/circuit_component/conveyor_switch/get_ui_notices() @@ -606,6 +612,8 @@ GLOBAL_LIST_EMPTY(conveyors_by_id) . = ..() if(istype(shell, /obj/machinery/conveyor_switch)) attached_switch = shell + if(!attached_switch.oneway) + reverse = add_input_port("Reverse", PORT_TYPE_SIGNAL, trigger = PROC_REF(reverse)) /obj/item/circuit_component/conveyor_switch/unregister_usb_parent(atom/movable/shell) attached_switch = null @@ -617,15 +625,33 @@ GLOBAL_LIST_EMPTY(conveyors_by_id) INVOKE_ASYNC(src, PROC_REF(update_conveyors), port) +/obj/item/circuit_component/conveyor_switch/proc/on_switch_changed() + attached_switch.update_appearance() + attached_switch.update_linked_conveyors() + attached_switch.update_linked_switches() + direction.set_output(attached_switch.position) + +/obj/item/circuit_component/conveyor_switch/proc/activate() + SIGNAL_HANDLER + attached_switch.position = CONVEYOR_FORWARD + INVOKE_ASYNC(src, PROC_REF(on_switch_changed)) + +/obj/item/circuit_component/conveyor_switch/proc/stop() + SIGNAL_HANDLER + attached_switch.position = CONVEYOR_OFF + INVOKE_ASYNC(src, PROC_REF(on_switch_changed)) + +/obj/item/circuit_component/conveyor_switch/proc/reverse() + SIGNAL_HANDLER + attached_switch.position = CONVEYOR_BACKWARDS + INVOKE_ASYNC(src, PROC_REF(on_switch_changed)) + /obj/item/circuit_component/conveyor_switch/proc/update_conveyors(datum/port/input/port) if(!attached_switch) return attached_switch.update_position() - attached_switch.update_appearance() - attached_switch.update_linked_conveyors() - attached_switch.update_linked_switches() - direction.set_output(attached_switch.position) + INVOKE_ASYNC(src, PROC_REF(on_switch_changed)) #undef CONVEYOR_BACKWARDS #undef CONVEYOR_OFF