Skip to content

Commit

Permalink
[MIRROR] Give more control over conveyor switch circuits (#2269) (#3140)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
Co-authored-by: Echriser <[email protected]>
  • Loading branch information
3 people authored May 2, 2024
1 parent 48749d3 commit 8736e28
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions code/modules/recycling/conveyor.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 8736e28

Please sign in to comment.