Files
Bubberstation/code/modules/wiremod/components/utility/router.dm
SkyratBot 9e74cd4a03 [MIRROR] Input ports now connect to multiple output ports. Remove combiner. (#7505)
* Input ports now connect to multiple output ports. Remove combiner. (#60494)

* tgui bsod

* debug disconnections

* prelim

* recomment

* set_value -> put ._.

* DAMN IT

* reinsert subsystem

* prepare

* unditch signals

* remove combiner

* remove combiner some more

* how did router.dm get here? deleting.

* These two COMSIGS should be one.

* critical typo

* inline cast

* have your signals

* Have your set_input & set_output.

* make compile

* upgrade save/load to n-to-n-wires

* have your documentation

* have your unsafe proc

* pay no attention to the compile errors

* unlist the ref

* paste my for block back in ._.

* fix manual input

* oops pushed too soon

* Have your !port.connected_to?.length

Co-authored-by: Watermelon914 <37270891+Watermelon914@ users.noreply.github.com>

Co-authored-by: Watermelon914 <37270891+Watermelon914@ users.noreply.github.com>

* Input ports now connect to multiple output ports. Remove combiner.

Co-authored-by: Gurkenglas <gurkenglas@hotmail.de>
Co-authored-by: Watermelon914 <37270891+Watermelon914@ users.noreply.github.com>
2021-08-11 20:27:29 +01:00

83 lines
2.6 KiB
Plaintext

/**
* # Router Component
*
* Writes one of multiple inputs to one of multiple outputs.
*/
/obj/item/circuit_component/router
display_name = "Router"
desc = "Copies the input chosen by \"Input Selector\" to the output chosen by \"Output Selector\"."
circuit_flags = CIRCUIT_FLAG_INPUT_SIGNAL|CIRCUIT_FLAG_OUTPUT_SIGNAL
var/datum/port/input/option/router_options
/// Which ports to connect.
var/datum/port/input/input_selector
var/datum/port/input/output_selector
/// How many ports to have.
var/input_port_amount = 4
var/output_port_amount = 4
/// Current type of the ports
var/current_type
/// The ports to route.
var/list/datum/port/input/ins
var/list/datum/port/output/outs
/obj/item/circuit_component/router/populate_options()
var/static/component_options = list(
PORT_TYPE_ANY,
PORT_TYPE_STRING,
PORT_TYPE_NUMBER,
PORT_TYPE_LIST,
PORT_TYPE_ATOM,
)
router_options = add_option_port("Router Options", component_options)
/obj/item/circuit_component/router/Initialize()
. = ..()
current_type = router_options.value
if(input_port_amount > 1)
input_selector = add_input_port("Input Selector", PORT_TYPE_NUMBER, default = 1)
if(output_port_amount > 1)
output_selector = add_input_port("Output Selector", PORT_TYPE_NUMBER, default = 1)
ins = list()
for(var/port_id in 1 to input_port_amount)
ins += add_input_port(input_port_amount > 1 ? "Input [port_id]" : "Input", current_type)
outs = list()
for(var/port_id in 1 to output_port_amount)
outs += add_output_port(output_port_amount > 1 ? "Output [port_id]" : "Output", current_type)
/obj/item/circuit_component/router/Destroy()
input_selector = null
output_selector = null
ins.Cut()
ins = null
outs.Cut()
outs = null
return ..()
// If I is in range, L[I]. If I is out of range, wrap around.
#define WRAPACCESS(L, I) L[(((I||1)-1)%length(L)+length(L))%length(L)+1]
/obj/item/circuit_component/router/input_received(datum/port/input/port)
. = ..()
var/current_option = router_options.value
if(current_type != current_option)
current_type = current_option
for(var/datum/port/input/input as anything in ins)
input.set_datatype(current_type)
for(var/datum/port/output/output as anything in outs)
output.set_datatype(current_type)
if(.)
return
var/datum/port/input/input = WRAPACCESS(ins, input_selector ? input_selector.value : 1)
var/datum/port/output/output = WRAPACCESS(outs, output_selector ? output_selector.value : 1)
output.set_output(input.value)
/obj/item/circuit_component/router/multiplexer
display_name = "Multiplexer"
desc = "Copies the input chosen by \"Input Selector\" to the output."
output_port_amount = 1