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-06 22:51:36 -07:00
committed by GitHub
co-authored by Watermelon914 Colovorat
parent 001315f214
commit d15b305527
52 changed files with 966 additions and 300 deletions
@@ -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)