Refactors the list datatype to support composite lists. Adapts a lot of circuits to be able to properly use composite lists. Adds the dispenser shell (#61856)

Co-authored-by: Watermelon914 <3052169-Watermelon914@users.noreply.gitlab.com>
Co-authored-by: Colovorat <35225170+Colovorat@users.noreply.github.com>
This commit is contained in:
Watermelon914
2021-10-07 06:51:36 +01:00
committed by GitHub
parent 001315f214
commit d15b305527
52 changed files with 966 additions and 300 deletions
@@ -1,63 +1,53 @@
/**
* # Getter Component
* # Variable Component
*
* Gets the current value from a variable.
* Abstract component for handling variables
*/
/obj/item/circuit_component/getter
/obj/item/circuit_component/variable
display_name = "Variable Getter"
desc = "A component that gets a variable globally on the circuit."
/// Variable name
var/datum/port/input/option/variable_name
/// The value of the variable
var/datum/port/output/value
var/datum/circuit_variable/current_variable
circuit_size = 0
/obj/item/circuit_component/getter/populate_options()
/obj/item/circuit_component/variable/populate_options()
variable_name = add_option_port("Variable", null)
/obj/item/circuit_component/getter/add_to(obj/item/integrated_circuit/added_to)
/obj/item/circuit_component/variable/add_to(obj/item/integrated_circuit/added_to)
. = ..()
variable_name.possible_options = added_to.circuit_variables
/obj/item/circuit_component/getter/removed_from(obj/item/integrated_circuit/removed_from)
/obj/item/circuit_component/variable/removed_from(obj/item/integrated_circuit/removed_from)
variable_name.possible_options = null
return ..()
/obj/item/circuit_component/getter/populate_ports()
value = add_output_port("Value", PORT_TYPE_ANY)
/obj/item/circuit_component/getter/pre_input_received(datum/port/input/port)
/obj/item/circuit_component/variable/pre_input_received(datum/port/input/port)
if(!parent)
return
var/variable_string = variable_name.value
if(!variable_string)
remove_current_variable()
value.set_output(null)
return
var/datum/circuit_variable/variable = parent.circuit_variables[variable_string]
if(!variable)
remove_current_variable()
value.set_output(null)
return
set_current_variable(variable)
value.set_output(variable.value)
/obj/item/circuit_component/getter/proc/remove_current_variable()
/obj/item/circuit_component/variable/proc/remove_current_variable()
SIGNAL_HANDLER
if(current_variable)
current_variable.remove_listener(src)
UnregisterSignal(current_variable, COMSIG_PARENT_QDELETING)
current_variable = null
/obj/item/circuit_component/getter/proc/set_current_variable(datum/circuit_variable/variable)
/obj/item/circuit_component/variable/proc/set_current_variable(datum/circuit_variable/variable)
if(variable == current_variable)
return
@@ -65,4 +55,3 @@
current_variable = variable
current_variable.add_listener(src)
RegisterSignal(current_variable, COMSIG_PARENT_QDELETING, .proc/remove_current_variable)
value.set_datatype(variable.datatype)
@@ -74,7 +74,7 @@
atom_or_filter = add_option_port("Target", component_options)
/obj/item/circuit_component/animation_step/populate_ports()
animation_variables = add_input_port("Variables", PORT_TYPE_ASSOC_LIST, order = 1.66)
animation_variables = add_input_port("Variables", PORT_TYPE_ASSOC_LIST(PORT_TYPE_STRING, PORT_TYPE_ANY), order = 1.66)
animation_time = add_input_port("Time", PORT_TYPE_NUMBER, order = 1.66)
animation_easing = add_input_port("Easing", PORT_TYPE_NUMBER, order = 1.66)
animation_flags = add_input_port("Flags", PORT_TYPE_NUMBER, order = 1.66)
@@ -12,7 +12,7 @@ GLOBAL_LIST_INIT(wiremod_filter_info, list(
"size" = PORT_TYPE_NUMBER,
),
"color" = list(
"color" = PORT_TYPE_LIST,
"color" = PORT_TYPE_LIST(PORT_TYPE_ANY),
"space" = PORT_TYPE_NUMBER,
),
"displace" = list(
@@ -39,7 +39,7 @@ GLOBAL_LIST_INIT(wiremod_filter_info, list(
"render_source" = PORT_TYPE_STRING,
"flags" = PORT_TYPE_NUMBER,
"color" = PORT_TYPE_STRING,
"transform" = PORT_TYPE_LIST,
"transform" = PORT_TYPE_LIST(PORT_TYPE_ANY),
"blend_mode" = PORT_TYPE_NUMBER,
),
"motion_blur" = list(
@@ -162,7 +162,7 @@ GLOBAL_LIST_INIT(wiremod_flag_info, list(
/obj/item/circuit_component/filter_helper/populate_ports()
current_filter_type = filter_type_port.value
output_params = add_output_port("Parameters", PORT_TYPE_ASSOC_LIST)
output_params = add_output_port("Parameters", PORT_TYPE_ASSOC_LIST(PORT_TYPE_STRING, PORT_TYPE_ANY))
handle_filter_type_changed()
/obj/item/circuit_component/filter_helper/pre_input_received(datum/port/input/port)
@@ -93,7 +93,7 @@
if(COMP_INPUT_NUMBER)
input_response.set_datatype(PORT_TYPE_NUMBER)
if(COMP_INPUT_LIST)
parameter = add_input_port("Options List", PORT_TYPE_LIST)
parameter = add_input_port("Options List", PORT_TYPE_LIST(PORT_TYPE_ANY))
input_response.set_datatype(PORT_TYPE_STRING)
#undef COMP_INPUT_STRING
@@ -42,7 +42,7 @@
/obj/item/circuit_component/proccall/populate_ports()
entity = add_input_port("Target", PORT_TYPE_DATUM)
proc_name = add_input_port("Proc Name", PORT_TYPE_STRING)
arguments = add_input_port("Arguments", PORT_TYPE_LIST)
arguments = add_input_port("Arguments", PORT_TYPE_LIST(PORT_TYPE_ANY))
output_value = add_output_port("Output Value", PORT_TYPE_ANY)
@@ -16,7 +16,7 @@
/obj/item/circuit_component/sdql_operation/populate_ports()
sdql_operation = add_input_port("SDQL String", PORT_TYPE_STRING)
results = add_output_port("Result", PORT_TYPE_LIST)
results = add_output_port("Result", PORT_TYPE_LIST(PORT_TYPE_STRING))
/obj/item/circuit_component/sdql_operation/input_received(datum/port/input/port)
if(GLOB.AdminProcCaller)
@@ -23,7 +23,7 @@
/obj/item/circuit_component/spawn_atom/populate_ports()
input_path = add_input_port("Type", PORT_TYPE_ANY)
spawn_at = add_input_port("Spawn At", PORT_TYPE_ATOM)
parameters = add_input_port("Parameters", PORT_TYPE_LIST)
parameters = add_input_port("Parameters", PORT_TYPE_LIST(PORT_TYPE_ANY))
spawned_atom = add_output_port("Spawned Atom", PORT_TYPE_ATOM)
@@ -3,87 +3,57 @@
*
* Return an associative list literal.
*/
/obj/item/circuit_component/assoc_literal
/obj/item/circuit_component/list_literal/assoc_literal
display_name = "Associative List Literal"
desc = "A component that returns an associative list consisting of the inputs. Attack in hand to increase list size, right click to decrease table size."
desc = "A component that returns an associative list consisting of the inputs."
circuit_flags = CIRCUIT_FLAG_INPUT_SIGNAL|CIRCUIT_FLAG_OUTPUT_SIGNAL
/// The inputs used to create the list
var/list/datum/port/input/key_ports = list()
var/list/datum/port/input/value_ports = list()
/// The result from the output
var/datum/port/output/list_output
var/length = 0
/obj/item/circuit_component/list_literal/assoc_literal/clear_lists()
for(var/datum/port/input/port as anything in key_ports)
remove_input_port(port)
for(var/datum/port/input/port as anything in entry_ports)
remove_input_port(port)
key_ports = list()
entry_ports = list()
length = 0
var/default_list_size = 2
/obj/item/circuit_component/list_literal/assoc_literal/remove_one_entry()
var/index = length(entry_ports)
var/key_port = key_ports[index]
key_ports -= key_port
remove_input_port(key_port)
var/value_port = entry_ports[index]
entry_ports -= value_port
remove_input_port(value_port)
length--
var/min_size = 1
var/max_size = 20
/obj/item/circuit_component/list_literal/assoc_literal/pre_input_received(datum/port/input/port)
if(port == list_options)
var/new_datatype = list_options.value
list_output.set_datatype(PORT_TYPE_ASSOC_LIST(PORT_TYPE_STRING, new_datatype))
for(var/datum/port/input/port_to_set as anything in entry_ports)
port_to_set.set_datatype(new_datatype)
ui_buttons = list(
"plus" = "increase",
"minus" = "decrease"
)
/obj/item/circuit_component/list_literal/assoc_literal/add_one_entry()
length++
key_ports += add_input_port("Key [length]", PORT_TYPE_STRING)
entry_ports += add_input_port("Index [length]", PORT_TYPE_ANY)
/obj/item/circuit_component/assoc_literal/save_data_to_list(list/component_data)
. = ..()
component_data["length"] = length
/obj/item/circuit_component/assoc_literal/load_data_from_list(list/component_data)
set_list_size(component_data["length"])
return ..()
/obj/item/circuit_component/assoc_literal/proc/set_list_size(new_size)
if(new_size <= 0)
for(var/datum/port/input/port as anything in key_ports)
remove_input_port(port)
for(var/datum/port/input/port as anything in value_ports)
remove_input_port(port)
key_ports = list()
value_ports = list()
length = 0
return
while(length > new_size)
var/index = length(value_ports)
var/key_port = key_ports[index]
key_ports -= key_port
remove_input_port(key_port)
var/value_port = value_ports[index]
value_ports -= value_port
remove_input_port(value_port)
length--
while(length < new_size)
length++
var/index = length(input_ports)
if(trigger_input)
index -= 1
key_ports += add_input_port("Key [index+1]", PORT_TYPE_STRING)
value_ports += add_input_port("Index [index+1]", PORT_TYPE_ANY)
/obj/item/circuit_component/assoc_literal/populate_ports()
/obj/item/circuit_component/list_literal/assoc_literal/populate_ports()
set_list_size(default_list_size)
list_output = add_output_port("Value", PORT_TYPE_ASSOC_LIST)
/obj/item/circuit_component/assoc_literal/Destroy()
list_output = null
return ..()
/obj/item/circuit_component/assoc_literal/ui_perform_action(mob/user, action)
switch(action)
if("increase")
set_list_size(min(length + 1, max_size))
if("decrease")
set_list_size(max(length - 1, min_size))
/obj/item/circuit_component/assoc_literal/input_received(datum/port/input/port)
list_output = add_output_port("Value", PORT_TYPE_ASSOC_LIST(PORT_TYPE_STRING, PORT_TYPE_ANY))
/obj/item/circuit_component/list_literal/assoc_literal/input_received(datum/port/input/port)
var/list/new_literal = list()
for(var/index in 1 to length)
new_literal += list(key_ports[index].value = value_ports[index].value)
// To prevent people from infinitely making lists to crash the server
if(islist(entry_ports[index].value) && get_list_count(entry_ports[index].value, max_list_count) >= max_list_count)
visible_message("[src] begins to overheat!")
return
new_literal += list(key_ports[index].value = entry_ports[index].value)
list_output.set_output(new_literal)
@@ -18,7 +18,7 @@
circuit_flags = CIRCUIT_FLAG_INPUT_SIGNAL|CIRCUIT_FLAG_OUTPUT_SIGNAL
/obj/item/circuit_component/concat_list/populate_ports()
list_port = add_input_port("List", PORT_TYPE_LIST)
list_port = add_input_port("List", PORT_TYPE_LIST(PORT_TYPE_ANY))
separator = add_input_port("Seperator", PORT_TYPE_STRING)
output = add_output_port("Output", PORT_TYPE_STRING)
@@ -0,0 +1,85 @@
/**
* # For Each Component
*
* Filters
*/
/obj/item/circuit_component/filter_list
display_name = "Filter"
desc = "A component that loops through each element in a list and filters them."
circuit_flags = CIRCUIT_FLAG_INPUT_SIGNAL|CIRCUIT_FLAG_INSTANT
/// The list type
var/datum/port/input/option/list_options
/// Adds the list to the result
var/datum/port/input/accept_entry
/// The list to filter over
var/datum/port/input/list_to_filter
/// The current element from the list
var/datum/port/output/element
/// The current index from the list
var/datum/port/output/current_index
/// A signal that is sent when the list has moved onto the next index.
var/datum/port/output/on_next_index
/// The finished list
var/datum/port/output/finished_list
/// A signal that is sent when the filtering has finished
var/datum/port/output/on_finished
/// A signal that is sent when the filtering has failed
var/datum/port/output/on_failed
ui_buttons = list(
"plus" = "increase",
)
/// The limit of iterations before it breaks. Used to prevent from someone iterating a massive list constantly
var/limit = 300
/obj/item/circuit_component/filter_list/populate_options()
list_options = add_option_port("List Type", GLOB.wiremod_basic_types)
/obj/item/circuit_component/filter_list/pre_input_received(datum/port/input/port)
if(port == list_options)
var/new_datatype = list_options.value
list_to_filter.set_datatype(PORT_TYPE_LIST(new_datatype))
finished_list.set_datatype(PORT_TYPE_LIST(new_datatype))
element.set_datatype(new_datatype)
/obj/item/circuit_component/filter_list/populate_ports()
list_to_filter = add_input_port("List Input", PORT_TYPE_LIST(PORT_TYPE_ANY))
accept_entry = add_input_port("Accept Entry", PORT_TYPE_SIGNAL, trigger = .proc/accept_entry_port)
element = add_output_port("Element", PORT_TYPE_ANY)
current_index = add_output_port("Index", PORT_TYPE_NUMBER)
on_next_index = add_output_port("Next Index", PORT_TYPE_SIGNAL)
finished_list = add_output_port("Filtered List", PORT_TYPE_LIST(PORT_TYPE_ANY))
on_finished = add_output_port("On Finished", PORT_TYPE_SIGNAL)
on_failed = add_output_port("On Failed", PORT_TYPE_SIGNAL)
/obj/item/circuit_component/filter_list/proc/accept_entry_port(datum/port/input/port, list/return_values)
CIRCUIT_TRIGGER
if(return_values)
return_values["accept_entry"] = TRUE
/obj/item/circuit_component/filter_list/input_received(datum/port/input/port)
var/index = 1
var/start_tick_usage = TICK_USAGE
var/list/filtered_list = list()
for(var/element_in_list in list_to_filter.value)
if(index > limit && !parent.admin_only)
break
SScircuit_component.queue_instant_run(start_tick_usage)
element.set_output(element_in_list)
current_index.set_output(index)
on_next_index.set_output(COMPONENT_SIGNAL)
index += 1
var/list/result = SScircuit_component.execute_instant_run()
if(!result)
visible_message("[src] starts to overheat!")
on_failed.set_output(COMPONENT_SIGNAL)
return
if(result["accept_entry"])
filtered_list += list(element_in_list)
finished_list.set_output(filtered_list)
on_finished.set_output(COMPONENT_SIGNAL)
@@ -0,0 +1,55 @@
/**
* # For Each Component
*
* Sends a signal for each item in a list
*/
/obj/item/circuit_component/foreach
display_name = "For Each"
desc = "A component that loops through each element in a list."
circuit_flags = CIRCUIT_FLAG_INPUT_SIGNAL
/// The list type
var/datum/port/input/option/list_options
/// The list to iterate over
var/datum/port/input/list_to_iterate
/// The current element from the list
var/datum/port/output/element
/// The current index from the list
var/datum/port/output/current_index
/// A signal that is sent when the list has moved onto the next index.
var/datum/port/output/on_next_index
/// A signal that is sent when the list has finished iterating
var/datum/port/output/on_finished
/// The limit of iterations before it breaks. Used to prevent from someone iterating a massive list constantly
var/limit = 300
/obj/item/circuit_component/foreach/populate_options()
list_options = add_option_port("List Type", GLOB.wiremod_basic_types)
/obj/item/circuit_component/foreach/pre_input_received(datum/port/input/port)
if(port == list_options)
var/new_datatype = list_options.value
list_to_iterate.set_datatype(PORT_TYPE_LIST(new_datatype))
element.set_datatype(new_datatype)
/obj/item/circuit_component/foreach/populate_ports()
list_to_iterate = add_input_port("List Input", PORT_TYPE_LIST(PORT_TYPE_ANY))
element = add_output_port("Element", PORT_TYPE_ANY)
current_index = add_output_port("Index", PORT_TYPE_NUMBER)
on_next_index = add_output_port("Next Index", PORT_TYPE_SIGNAL)
on_finished = add_output_port("On Finished", PORT_TYPE_SIGNAL)
/obj/item/circuit_component/foreach/input_received(datum/port/input/port)
var/index = 1
for(var/element_in_list in list_to_iterate.value)
if(index > limit && !parent.admin_only)
break
element.set_output(element_in_list)
current_index.set_output(index)
on_next_index.set_output(COMPONENT_SIGNAL)
index += 1
on_finished.set_output(COMPONENT_SIGNAL)
@@ -20,7 +20,7 @@
/obj/item/circuit_component/get_column/populate_ports()
received_table = add_input_port("Input", PORT_TYPE_TABLE)
column_name = add_input_port("Column Name", PORT_TYPE_STRING)
output_list = add_output_port("Output", PORT_TYPE_LIST)
output_list = add_output_port("Output", PORT_TYPE_LIST(PORT_TYPE_ANY))
/obj/item/circuit_component/get_column/input_received(datum/port/input/port)
+33 -2
View File
@@ -7,6 +7,9 @@
display_name = "Index List"
desc = "A component that returns the value of a list at a given index."
/// The list type
var/datum/port/input/option/list_options
/// The input port
var/datum/port/input/list_port
var/datum/port/input/index_port
@@ -15,12 +18,26 @@
var/datum/port/output/output
circuit_flags = CIRCUIT_FLAG_INPUT_SIGNAL|CIRCUIT_FLAG_OUTPUT_SIGNAL
var/index_type = PORT_TYPE_NUMBER
/obj/item/circuit_component/index/populate_options()
list_options = add_option_port("List Type", GLOB.wiremod_basic_types)
/obj/item/circuit_component/index/proc/make_list_port()
list_port = add_input_port("List", PORT_TYPE_LIST(PORT_TYPE_ANY))
/obj/item/circuit_component/index/populate_ports()
index_port = add_input_port("Index", PORT_TYPE_ANY)
list_port = add_input_port("List", PORT_TYPE_LIST)
index_port = add_input_port("Index", index_type)
make_list_port()
output = add_output_port("Value", PORT_TYPE_ANY)
/obj/item/circuit_component/index/pre_input_received(datum/port/input/port)
if(port == list_options)
var/new_type = list_options.value
list_port.set_datatype(PORT_TYPE_LIST(new_type))
output.set_datatype(new_type)
/obj/item/circuit_component/index/input_received(datum/port/input/port)
var/index = index_port.value
@@ -36,3 +53,17 @@
output.set_output(list_input[index])
/obj/item/circuit_component/index/assoc_string
display_name = "Index Associative List"
desc = "A component that is commonly used to access a row from a table. Accesses data from a key, value list."
index_type = PORT_TYPE_STRING
/obj/item/circuit_component/index/assoc_string/make_list_port()
list_port = add_input_port("List", PORT_TYPE_ASSOC_LIST(PORT_TYPE_STRING, PORT_TYPE_ANY))
/obj/item/circuit_component/index/assoc_string/pre_input_received(datum/port/input/port)
if(port == list_options)
var/new_type = list_options.value
list_port.set_datatype(PORT_TYPE_ASSOC_LIST(PORT_TYPE_STRING, new_type))
output.set_datatype(new_type)
@@ -21,7 +21,7 @@
received_table = add_input_port("Input", PORT_TYPE_TABLE)
target_index = add_input_port("Index", PORT_TYPE_NUMBER)
output_list = add_output_port("Output", PORT_TYPE_LIST)
output_list = add_output_port("Output", PORT_TYPE_ASSOC_LIST(PORT_TYPE_STRING, PORT_TYPE_ANY))
/obj/item/circuit_component/index_table/input_received(datum/port/input/port)
@@ -5,9 +5,12 @@
*/
/obj/item/circuit_component/list_literal
display_name = "List Literal"
desc = "A component that returns the value of a list at a given index. Attack in hand to increase list size, right click to decrease list size."
desc = "A component that creates a list from whatever input you give it."
circuit_flags = CIRCUIT_FLAG_INPUT_SIGNAL|CIRCUIT_FLAG_OUTPUT_SIGNAL
/// The list type
var/datum/port/input/option/list_options
/// The inputs used to create the list
var/list/datum/port/input/entry_ports = list()
/// The result from the output
@@ -25,6 +28,11 @@
"minus" = "decrease"
)
var/max_list_count = 100
/obj/item/circuit_component/list_literal/populate_options()
list_options = add_option_port("List Type", GLOB.wiremod_basic_types)
/obj/item/circuit_component/list_literal/save_data_to_list(list/component_data)
. = ..()
component_data["length"] = length
@@ -34,31 +42,44 @@
return ..()
/obj/item/circuit_component/list_literal/proc/clear_lists()
for(var/datum/port/input/port as anything in entry_ports)
remove_input_port(port)
entry_ports.Cut()
length = 0
/obj/item/circuit_component/list_literal/proc/remove_one_entry()
var/index = length(entry_ports)
var/entry_port = entry_ports[index]
entry_ports -= entry_port
remove_input_port(entry_port)
length--
/obj/item/circuit_component/list_literal/proc/add_one_entry()
length++
entry_ports += add_input_port("Index [length]", list_options.value || PORT_TYPE_ANY)
/obj/item/circuit_component/list_literal/proc/set_list_size(new_size)
if(new_size <= 0)
for(var/datum/port/input/port in entry_ports)
remove_input_port(port)
entry_ports = list()
length = 0
clear_lists()
return
while(length > new_size)
var/index = length(entry_ports)
var/entry_port = entry_ports[index]
entry_ports -= entry_port
remove_input_port(entry_port)
length--
remove_one_entry()
while(length < new_size)
length++
var/index = length(input_ports)
if(trigger_input)
index -= 1
entry_ports += add_input_port("Index [index+1]", PORT_TYPE_ANY)
add_one_entry()
/obj/item/circuit_component/list_literal/pre_input_received(datum/port/input/port)
if(port == list_options)
var/new_datatype = list_options.value
list_output.set_datatype(PORT_TYPE_LIST(new_datatype))
for(var/datum/port/input/port_to_set as anything in entry_ports)
port_to_set.set_datatype(new_datatype)
/obj/item/circuit_component/list_literal/populate_ports()
set_list_size(default_list_size)
list_output = add_output_port("Value", PORT_TYPE_LIST)
list_output = add_output_port("Value", PORT_TYPE_LIST(PORT_TYPE_ANY))
/obj/item/circuit_component/list_literal/Destroy()
list_output = null
@@ -76,8 +97,25 @@
var/list/new_literal = list()
for(var/datum/port/input/entry_port as anything in entry_ports)
// Prevents lists from merging together
new_literal += list(entry_port.value)
var/value = entry_port.value
// To prevent people from infinitely making lists to crash the server
if(islist(value) && get_list_count(value, max_list_count) >= max_list_count)
visible_message("[src] begins to overheat!")
return
new_literal += list(value)
list_output.set_output(new_literal)
/proc/get_list_count(list/value, max_list_count)
var/list/lists_to_check = list()
lists_to_check += list(value)
var/lists = 1
while(length(lists_to_check))
var/list/list_to_iterate = lists_to_check[length(lists_to_check)]
for(var/list/list_data in list_to_iterate)
lists_to_check += list(list_data)
lists += 1
lists_to_check.len--
if(lists > max_list_count)
return lists
return lists
@@ -21,7 +21,7 @@
/obj/item/circuit_component/split/populate_ports()
input_port = add_input_port("Input", PORT_TYPE_STRING)
separator = add_input_port("Seperator", PORT_TYPE_STRING)
output = add_output_port("Output", PORT_TYPE_LIST)
output = add_output_port("Output", PORT_TYPE_LIST(PORT_TYPE_STRING))
/obj/item/circuit_component/split/input_received(datum/port/input/port)
@@ -11,22 +11,43 @@
network_id = __NETWORK_CIRCUITS
/// The list type
var/datum/port/input/option/list_options
/// Data being received
var/datum/port/output/data_package
/// Encryption key
var/datum/port/input/enc_key
/obj/item/circuit_component/ntnet_receive/populate_options()
list_options = add_option_port("List Type", GLOB.wiremod_basic_types)
/obj/item/circuit_component/ntnet_receive/populate_ports()
data_package = add_output_port("Data Package", PORT_TYPE_ANY)
data_package = add_output_port("Data Package", PORT_TYPE_LIST(PORT_TYPE_ANY))
enc_key = add_input_port("Encryption Key", PORT_TYPE_STRING)
RegisterSignal(src, COMSIG_COMPONENT_NTNET_RECEIVE, .proc/ntnet_receive)
/obj/item/circuit_component/ntnet_receive/pre_input_received(datum/port/input/port)
if(port == list_options)
var/new_datatype = list_options.value
data_package.set_datatype(PORT_TYPE_LIST(new_datatype))
/obj/item/circuit_component/ntnet_receive/proc/ntnet_receive(datum/source, datum/netdata/data)
SIGNAL_HANDLER
if(data.data["enc_key"] != enc_key.value)
return
var/datum/weakref/ref = data.data["port"]
var/datum/port/input/port = ref?.resolve()
if(!port)
return
var/datum/circuit_datatype/datatype_handler = data_package.datatype_handler
if(!datatype_handler?.can_receive_from_datatype(port.datatype))
return
data_package.set_output(data.data["data"])
trigger_output.set_output(COMPONENT_SIGNAL)
@@ -12,15 +12,26 @@
network_id = __NETWORK_CIRCUITS
/// The list type
var/datum/port/input/option/list_options
/// Data being sent
var/datum/port/input/data_package
/// Encryption key
var/datum/port/input/enc_key
/obj/item/circuit_component/ntnet_send/populate_options()
list_options = add_option_port("List Type", GLOB.wiremod_basic_types)
/obj/item/circuit_component/ntnet_send/populate_ports()
data_package = add_input_port("Data Package", PORT_TYPE_ANY)
data_package = add_input_port("Data Package", PORT_TYPE_LIST(PORT_TYPE_ANY))
enc_key = add_input_port("Encryption Key", PORT_TYPE_STRING)
/obj/item/circuit_component/ntnet_send/pre_input_received(datum/port/input/port)
if(port == list_options)
var/new_datatype = list_options.value
data_package.set_datatype(PORT_TYPE_LIST(new_datatype))
/obj/item/circuit_component/ntnet_send/input_received(datum/port/input/port)
ntnet_send(list("data" = data_package.value, "enc_key" = enc_key.value))
ntnet_send(list("data" = data_package.value, "enc_key" = enc_key.value, "port" = WEAKREF(data_package)))
@@ -26,8 +26,8 @@
var/value = input_port.value
if(isatom(value))
var/turf/location = get_turf(src)
var/atom/object = value
if(object.z != location.z || get_dist(location, object) > max_range)
var/turf/target_location = get_turf(value)
if(target_location.z != location.z || get_dist(location, target_location) > max_range)
output.set_output(PORT_TYPE_ATOM)
return
@@ -26,14 +26,7 @@
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)
router_options = add_option_port("Router Options", GLOB.wiremod_basic_types)
/obj/item/circuit_component/router/populate_ports()
current_type = router_options.value
@@ -1,70 +0,0 @@
/**
* # Setter Component
*
* Stores the current input when triggered into a variable.
*/
/obj/item/circuit_component/setter
display_name = "Variable Setter"
desc = "A component that sets a variable globally on the circuit."
circuit_flags = CIRCUIT_FLAG_OUTPUT_SIGNAL
/// Variable name
var/datum/port/input/option/variable_name
/// The input to store
var/datum/port/input/input_port
/// The trigger to store the current value of the input
var/datum/port/input/trigger
var/current_type
circuit_size = 0
/obj/item/circuit_component/setter/populate_options()
variable_name = add_option_port("Variable", null)
/obj/item/circuit_component/setter/add_to(obj/item/integrated_circuit/added_to)
. = ..()
variable_name.possible_options = added_to.circuit_variables
/obj/item/circuit_component/setter/removed_from(obj/item/integrated_circuit/removed_from)
variable_name.possible_options = null
return ..()
/obj/item/circuit_component/setter/populate_ports()
input_port = add_input_port("Input", PORT_TYPE_ANY)
trigger = add_input_port("Store", PORT_TYPE_SIGNAL)
/obj/item/circuit_component/setter/pre_input_received(datum/port/input/port)
var/datum/circuit_variable/variable = get_variable()
if(!variable)
return
if(variable.datatype != current_type)
current_type = variable.datatype
input_port.set_datatype(current_type)
/obj/item/circuit_component/setter/should_receive_input(datum/port/input/port)
if(!COMPONENT_TRIGGERED_BY(trigger, port))
return FALSE
return ..()
/obj/item/circuit_component/setter/input_received(datum/port/input/port)
var/datum/circuit_variable/variable = get_variable()
if(!variable)
return
variable.set_value(input_port.value)
/obj/item/circuit_component/setter/proc/get_variable()
var/variable_string = variable_name.value
if(!variable_string)
return
var/datum/circuit_variable/variable = parent.circuit_variables[variable_string]
if(!variable)
return
return variable
@@ -25,7 +25,7 @@
var/static/list/component_options = list(
PORT_TYPE_STRING,
PORT_TYPE_NUMBER,
PORT_TYPE_LIST,
PORT_COMPOSITE_TYPE_LIST,
PORT_TYPE_ATOM,
)
typecast_options = add_option_port("Typecast Options", component_options)
@@ -48,7 +48,7 @@
if(PORT_TYPE_NUMBER)
if(isnum(value))
value_to_set = value
if(PORT_TYPE_LIST)
if(PORT_COMPOSITE_TYPE_LIST)
if(islist(value))
value_to_set = value
if(PORT_TYPE_ATOM)
@@ -17,7 +17,7 @@
var/static/component_options = list(
PORT_TYPE_STRING,
PORT_TYPE_NUMBER,
PORT_TYPE_LIST,
PORT_COMPOSITE_TYPE_LIST,
PORT_TYPE_ATOM,
COMP_TYPECHECK_MOB,
COMP_TYPECHECK_HUMAN,
@@ -37,7 +37,7 @@
return istext(input_val)
if(PORT_TYPE_NUMBER)
return isnum(input_val)
if(PORT_TYPE_LIST)
if(PORT_COMPOSITE_TYPE_LIST)
return islist(input_val)
if(PORT_TYPE_ATOM)
return isatom(input_val)
@@ -0,0 +1,22 @@
/**
* # Getter Component
*
* Gets the current value from a variable.
*/
/obj/item/circuit_component/variable/getter
display_name = "Variable Getter"
desc = "A component that gets a variable globally on the circuit."
/// The value of the variable
var/datum/port/output/value
circuit_size = 0
/obj/item/circuit_component/variable/getter/populate_ports()
value = add_output_port("Value", PORT_TYPE_ANY)
/obj/item/circuit_component/variable/getter/pre_input_received(datum/port/input/port)
. = ..()
if(current_variable)
value.set_datatype(current_variable.datatype)
value.set_value(current_variable.value)
@@ -0,0 +1,30 @@
/**
* # Setter Component
*
* Stores the current input when triggered into a variable.
*/
/obj/item/circuit_component/variable/setter
display_name = "Variable Setter"
desc = "A component that sets a variable globally on the circuit."
circuit_flags = CIRCUIT_FLAG_INPUT_SIGNAL|CIRCUIT_FLAG_OUTPUT_SIGNAL
/// The input to store
var/datum/port/input/input_port
circuit_size = 0
/obj/item/circuit_component/variable/setter/populate_ports()
input_port = add_input_port("Input", PORT_TYPE_ANY)
trigger_input = add_input_port("Store", PORT_TYPE_SIGNAL)
/obj/item/circuit_component/variable/setter/pre_input_received(datum/port/input/port)
. = ..()
if(port == variable_name)
input_port.set_datatype(current_variable.datatype)
/obj/item/circuit_component/variable/setter/input_received(datum/port/input/port)
if(!current_variable)
return
current_variable.set_value(input_port.value)