Refactors port types completely and adds the option type. Refactors options to use this new type (#60571)

Co-authored-by: Watermelon914 <3052169-Watermelon914@users.noreply.gitlab.com>
This commit is contained in:
Watermelon914
2021-08-04 09:06:48 -07:00
committed by GitHub
co-authored by Watermelon914
parent 7d1c9d112b
commit 13296f5f74
39 changed files with 487 additions and 271 deletions
@@ -9,9 +9,11 @@
/// The amount of input ports to have
var/input_port_amount = 4
var/datum/port/input/option/combiner_options
var/datum/port/output/output_port
var/list/combiner_ports = list()
var/current_type
/obj/item/circuit_component/combiner/populate_options()
@@ -23,21 +25,21 @@
PORT_TYPE_ATOM,
PORT_TYPE_SIGNAL,
)
options = component_options
combiner_options = add_option_port("Combiner Options", component_options)
/obj/item/circuit_component/combiner/Initialize()
. = ..()
current_type = current_option
current_type = combiner_options.input_value
for(var/port_id in 1 to input_port_amount)
var/letter = ascii2text(text2ascii("A") + (port_id-1))
add_input_port(letter, current_option)
output_port = add_output_port("Output", current_option)
combiner_ports += add_input_port(letter, current_type)
output_port = add_output_port("Output", current_type)
/obj/item/circuit_component/combiner/input_received(datum/port/input/port)
. = ..()
if(current_type != current_option)
current_type = current_option
for(var/datum/port/input/input_port as anything in input_ports)
if(current_type != combiner_options.input_value)
current_type = combiner_options.input_value
for(var/datum/port/input/input_port as anything in combiner_ports)
input_port.set_datatype(current_type)
output_port.set_datatype(current_type)
@@ -10,6 +10,8 @@
desc = "A component that retains a variable."
circuit_flags = CIRCUIT_FLAG_OUTPUT_SIGNAL
var/datum/port/input/option/ram_options
/// The input to store
var/datum/port/input/input_port
/// The trigger to store the current value of the input
@@ -31,16 +33,15 @@
PORT_TYPE_ATOM,
PORT_TYPE_SIGNAL,
)
options = component_options
ram_options = add_option_port("RAM Options", component_options)
/obj/item/circuit_component/ram/Initialize()
. = ..()
current_type = current_option
input_port = add_input_port("Input", current_type)
input_port = add_input_port("Input", PORT_TYPE_ANY)
trigger = add_input_port("Store", PORT_TYPE_SIGNAL)
clear = add_input_port("Clear", PORT_TYPE_SIGNAL)
output = add_output_port("Stored Value", current_type)
output = add_output_port("Stored Value", PORT_TYPE_ANY)
/obj/item/circuit_component/ram/Destroy()
input_port = null
@@ -51,8 +52,8 @@
/obj/item/circuit_component/ram/input_received(datum/port/input/port)
. = ..()
if(current_type != current_option)
current_type = current_option
if(current_type != ram_options.input_value)
current_type = ram_options.input_value
input_port.set_datatype(current_type)
output.set_datatype(current_type)
@@ -8,6 +8,8 @@
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
@@ -31,11 +33,11 @@
PORT_TYPE_LIST,
PORT_TYPE_ATOM,
)
options = component_options
router_options = add_option_port("Router Options", component_options)
/obj/item/circuit_component/router/Initialize()
. = ..()
current_type = current_option
current_type = router_options.input_value
if(input_port_amount > 1)
input_selector = add_input_port("Input Selector", PORT_TYPE_NUMBER, default = 1)
if(output_port_amount > 1)
@@ -61,6 +63,7 @@
#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.input_value
if(current_type != current_option)
current_type = current_option
for(var/datum/port/input/input as anything in ins)
@@ -8,6 +8,8 @@
desc = "A component that casts a value to a type if it matches or outputs null."
circuit_flags = CIRCUIT_FLAG_INPUT_SIGNAL|CIRCUIT_FLAG_OUTPUT_SIGNAL
var/datum/port/input/option/typecast_options
var/datum/port/input/input_value
var/datum/port/output/output_value
@@ -16,21 +18,22 @@
/obj/item/circuit_component/typecast/Initialize()
. = ..()
current_type = current_option
current_type = typecast_options.input_value
input_value = add_input_port("Input", PORT_TYPE_ANY)
output_value = add_output_port("Output", current_option)
output_value = add_output_port("Output", current_type)
/obj/item/circuit_component/typecast/populate_options()
var/static/component_options = list(
var/static/list/component_options = list(
PORT_TYPE_STRING,
PORT_TYPE_NUMBER,
PORT_TYPE_LIST,
PORT_TYPE_ATOM,
)
options = component_options
typecast_options = add_option_port("Typecast Options", component_options)
/obj/item/circuit_component/typecast/input_received(datum/port/input/port)
. = ..()
var/current_option = typecast_options.input_value
if(current_type != current_option)
current_type = current_option
output_value.set_datatype(current_type)
@@ -8,6 +8,7 @@
desc = "A component that checks the type of its input."
input_port_amount = 1
var/datum/port/input/option/typecheck_options
/obj/item/circuit_component/compare/typecheck/populate_options()
var/static/component_options = list(
@@ -18,7 +19,7 @@
COMP_TYPECHECK_MOB,
COMP_TYPECHECK_HUMAN,
)
options = component_options
typecheck_options = add_option_port("Typecheck Options", component_options)
/obj/item/circuit_component/compare/typecheck/do_comparisons(list/ports)
if(!length(ports))
@@ -28,7 +29,7 @@
// We're only comparing the first port/value. There shouldn't be any more.
var/datum/port/input/input_port = ports[1]
var/input_val = input_port.input_value
switch(current_option)
switch(typecheck_options.input_value)
if(PORT_TYPE_STRING)
return istext(input_val)
if(PORT_TYPE_NUMBER)