mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-08-22 12:41:09 +01:00
[MIRROR] Adds USB to arrest consoles. Adds list circuit components. (#6593)
* Adds USB to arrest consoles. Adds list circuit components. (#59850) Co-authored-by: Watermelon914 <3052169-Watermelon914@ users.noreply.gitlab.com> Co-authored-by: Mothblocks <35135081+Mothblocks@ users.noreply.github.com> * Adds USB to arrest consoles. Adds list circuit components. Co-authored-by: Watermelon914 <37270891+Watermelon914@users.noreply.github.com> Co-authored-by: Watermelon914 <3052169-Watermelon914@ users.noreply.gitlab.com> Co-authored-by: Mothblocks <35135081+Mothblocks@ users.noreply.github.com>
This commit is contained in:
co-authored by
Watermelon914
Mothblocks
Watermelon914
parent
3eb74acb91
commit
7269bd83ab
@@ -0,0 +1,54 @@
|
||||
/**
|
||||
* # Concat List Component
|
||||
*
|
||||
* Concatenates a list with a separator
|
||||
*/
|
||||
/obj/item/circuit_component/concat_list
|
||||
display_name = "Concatenate List"
|
||||
display_desc = "A component that joins up a list with a separator into a single string."
|
||||
|
||||
/// The input port
|
||||
var/datum/port/input/list_port
|
||||
|
||||
/// The seperator
|
||||
var/datum/port/input/separator
|
||||
|
||||
/// The result from the output
|
||||
var/datum/port/output/output
|
||||
circuit_flags = CIRCUIT_FLAG_INPUT_SIGNAL|CIRCUIT_FLAG_OUTPUT_SIGNAL
|
||||
|
||||
/obj/item/circuit_component/concat_list/Initialize()
|
||||
. = ..()
|
||||
list_port = add_input_port("List", PORT_TYPE_LIST)
|
||||
separator = add_input_port("Seperator", PORT_TYPE_STRING)
|
||||
|
||||
output = add_output_port("Output", PORT_TYPE_STRING)
|
||||
|
||||
/obj/item/circuit_component/concat_list/Destroy()
|
||||
list_port = null
|
||||
separator = null
|
||||
output = null
|
||||
return ..()
|
||||
|
||||
/obj/item/circuit_component/concat_list/input_received(datum/port/input/port)
|
||||
. = ..()
|
||||
if(.)
|
||||
return
|
||||
|
||||
var/seperator = separator.input_value
|
||||
if(!seperator)
|
||||
return
|
||||
|
||||
var/list/list_input = list_port.input_value
|
||||
if(!list_input)
|
||||
return
|
||||
|
||||
var/list/text_list = list()
|
||||
for(var/entry in list_input)
|
||||
if(isatom(entry))
|
||||
text_list += PORT_TYPE_ATOM
|
||||
else
|
||||
text_list += "[entry]"
|
||||
|
||||
output.set_output(text_list.Join(seperator))
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* # Get Column Component
|
||||
*
|
||||
* Gets the column of a table and returns it as a regular list.
|
||||
*/
|
||||
/obj/item/circuit_component/get_column
|
||||
display_name = "Get Column"
|
||||
display_desc = "Gets the column of a table and returns it as a regular list."
|
||||
circuit_flags = CIRCUIT_FLAG_INPUT_SIGNAL|CIRCUIT_FLAG_OUTPUT_SIGNAL
|
||||
|
||||
/// The list to perform the filter on
|
||||
var/datum/port/input/received_table
|
||||
|
||||
/// The name of the column to check
|
||||
var/datum/port/input/column_name
|
||||
|
||||
/// The filtered list
|
||||
var/datum/port/output/output_list
|
||||
|
||||
/obj/item/circuit_component/get_column/Initialize()
|
||||
. = ..()
|
||||
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)
|
||||
|
||||
/obj/item/circuit_component/get_column/Destroy()
|
||||
received_table = null
|
||||
column_name = null
|
||||
output_list = null
|
||||
return ..()
|
||||
|
||||
/obj/item/circuit_component/get_column/input_received(datum/port/input/port)
|
||||
. = ..()
|
||||
if(.)
|
||||
return
|
||||
|
||||
var/list/input_list = received_table.input_value
|
||||
if(!islist(input_list) || isnum(column_name.input_value))
|
||||
return
|
||||
|
||||
var/list/new_list = list()
|
||||
for(var/list/entry in input_list)
|
||||
var/anything = entry[column_name.input_value]
|
||||
if(islist(anything))
|
||||
continue
|
||||
new_list += anything
|
||||
|
||||
output_list.set_output(new_list)
|
||||
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* # Index Component
|
||||
*
|
||||
* Return the index of a list
|
||||
*/
|
||||
/obj/item/circuit_component/index
|
||||
display_name = "Index List"
|
||||
display_desc = "A component that returns the value of a list at a given index."
|
||||
|
||||
/// The input port
|
||||
var/datum/port/input/list_port
|
||||
var/datum/port/input/index_port
|
||||
|
||||
/// The result from the output
|
||||
var/datum/port/output/output
|
||||
circuit_flags = CIRCUIT_FLAG_INPUT_SIGNAL|CIRCUIT_FLAG_OUTPUT_SIGNAL
|
||||
|
||||
/obj/item/circuit_component/index/Initialize()
|
||||
. = ..()
|
||||
index_port = add_input_port("Index", PORT_TYPE_ANY)
|
||||
list_port = add_input_port("List", PORT_TYPE_LIST)
|
||||
|
||||
output = add_output_port("Value", PORT_TYPE_ANY)
|
||||
|
||||
/obj/item/circuit_component/index/Destroy()
|
||||
list_port = null
|
||||
index_port = null
|
||||
output = null
|
||||
return ..()
|
||||
|
||||
/obj/item/circuit_component/index/input_received(datum/port/input/port)
|
||||
. = ..()
|
||||
if(.)
|
||||
return
|
||||
|
||||
var/index = index_port.input_value
|
||||
var/list/list_input = list_port.input_value
|
||||
|
||||
if(!islist(list_input) || !index)
|
||||
output.set_output(null)
|
||||
return
|
||||
|
||||
if(isnum(index) && (index < 1 || index > length(list_input)))
|
||||
output.set_output(null)
|
||||
return
|
||||
|
||||
output.set_output(list_input[index])
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* # Index Table Component
|
||||
*
|
||||
* Gets the row of a table using the index inputted. Will return no value if the index is invalid or a proper table is not returned.
|
||||
*/
|
||||
/obj/item/circuit_component/index_table
|
||||
display_name = "Index Table"
|
||||
display_desc = "Gets the row of a table using the index inputted. Will return no value if the index is invalid or a proper table is not returned."
|
||||
circuit_flags = CIRCUIT_FLAG_INPUT_SIGNAL|CIRCUIT_FLAG_OUTPUT_SIGNAL
|
||||
|
||||
/// The list to perform the filter on
|
||||
var/datum/port/input/received_table
|
||||
|
||||
/// The target index
|
||||
var/datum/port/input/target_index
|
||||
|
||||
/// The filtered list
|
||||
var/datum/port/output/output_list
|
||||
|
||||
/obj/item/circuit_component/index_table/Initialize()
|
||||
. = ..()
|
||||
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_TABLE)
|
||||
|
||||
/obj/item/circuit_component/index_table/Destroy()
|
||||
received_table = null
|
||||
target_index = null
|
||||
output_list = null
|
||||
return ..()
|
||||
|
||||
/obj/item/circuit_component/index_table/input_received(datum/port/input/port)
|
||||
. = ..()
|
||||
if(.)
|
||||
return
|
||||
|
||||
var/list/target_list = received_table.input_value
|
||||
if(!islist(target_list) || !length(target_list))
|
||||
output_list.set_output(null)
|
||||
return
|
||||
|
||||
var/index = target_index.input_value
|
||||
if(index < 1 || index > length(target_list))
|
||||
output_list.set_output(null)
|
||||
return
|
||||
|
||||
output_list.set_output(target_list[index])
|
||||
@@ -0,0 +1,96 @@
|
||||
/**
|
||||
* # Select Component
|
||||
*
|
||||
* Selects a list from a list of lists by a specific column. Used only by USBs for communications to and from computers with lists of varying sizes.
|
||||
*/
|
||||
/obj/item/circuit_component/select
|
||||
display_name = "Select Query"
|
||||
display_desc = "A component used with USB cables that can perform select queries on a list based on the column name selected. The values are then compared with the comparison input."
|
||||
circuit_flags = CIRCUIT_FLAG_INPUT_SIGNAL|CIRCUIT_FLAG_OUTPUT_SIGNAL
|
||||
|
||||
/// The list to perform the filter on
|
||||
var/datum/port/input/received_table
|
||||
|
||||
/// The name of the column to check
|
||||
var/datum/port/input/column_name
|
||||
|
||||
/// The input to compare with
|
||||
var/datum/port/input/comparison_input
|
||||
|
||||
/// The filtered list
|
||||
var/datum/port/output/filtered_table
|
||||
|
||||
var/current_type = PORT_TYPE_ANY
|
||||
|
||||
/obj/item/circuit_component/select/populate_options()
|
||||
var/static/component_options = list(
|
||||
COMP_COMPARISON_EQUAL,
|
||||
COMP_COMPARISON_NOT_EQUAL,
|
||||
COMP_COMPARISON_GREATER_THAN,
|
||||
COMP_COMPARISON_LESS_THAN,
|
||||
COMP_COMPARISON_GREATER_THAN_OR_EQUAL,
|
||||
COMP_COMPARISON_LESS_THAN_OR_EQUAL,
|
||||
)
|
||||
options = component_options
|
||||
|
||||
/obj/item/circuit_component/select/Initialize()
|
||||
. = ..()
|
||||
received_table = add_input_port("Input", PORT_TYPE_TABLE)
|
||||
column_name = add_input_port("Column Name", PORT_TYPE_STRING)
|
||||
comparison_input = add_input_port("Comparison Input", PORT_TYPE_ANY)
|
||||
|
||||
filtered_table = add_output_port("Output", PORT_TYPE_TABLE)
|
||||
|
||||
/obj/item/circuit_component/select/Destroy()
|
||||
received_table = null
|
||||
column_name = null
|
||||
comparison_input = null
|
||||
filtered_table = null
|
||||
return ..()
|
||||
|
||||
/obj/item/circuit_component/select/input_received(datum/port/input/port)
|
||||
. = ..()
|
||||
switch(current_option)
|
||||
if(COMP_COMPARISON_EQUAL, COMP_COMPARISON_NOT_EQUAL)
|
||||
if(current_type != PORT_TYPE_ANY)
|
||||
current_type = PORT_TYPE_ANY
|
||||
comparison_input.set_datatype(PORT_TYPE_ANY)
|
||||
else
|
||||
if(current_type != PORT_TYPE_NUMBER)
|
||||
current_type = PORT_TYPE_NUMBER
|
||||
comparison_input.set_datatype(PORT_TYPE_NUMBER)
|
||||
|
||||
if(.)
|
||||
return
|
||||
|
||||
var/list/input_list = received_table.input_value
|
||||
if(!islist(input_list) || isnum(column_name.input_value))
|
||||
return
|
||||
|
||||
var/comparison_value = comparison_input.input_value
|
||||
var/list/new_list = list()
|
||||
for(var/list/entry in input_list)
|
||||
var/anything = entry[column_name.input_value]
|
||||
if(islist(anything))
|
||||
continue
|
||||
if(current_option != COMP_COMPARISON_EQUAL && current_option != COMP_COMPARISON_NOT_EQUAL && !isnum(anything))
|
||||
continue
|
||||
var/add_to_list = FALSE
|
||||
switch(current_option)
|
||||
if(COMP_COMPARISON_EQUAL)
|
||||
add_to_list = anything == comparison_value
|
||||
if(COMP_COMPARISON_NOT_EQUAL)
|
||||
add_to_list = anything != comparison_value
|
||||
if(COMP_COMPARISON_GREATER_THAN)
|
||||
add_to_list = anything > comparison_value
|
||||
if(COMP_COMPARISON_GREATER_THAN_OR_EQUAL)
|
||||
add_to_list = anything >= comparison_value
|
||||
if(COMP_COMPARISON_LESS_THAN)
|
||||
add_to_list = anything < comparison_value
|
||||
if(COMP_COMPARISON_LESS_THAN_OR_EQUAL)
|
||||
add_to_list = anything <= comparison_value
|
||||
|
||||
if(add_to_list)
|
||||
new_list += list(entry)
|
||||
|
||||
filtered_table.set_output(new_list)
|
||||
Reference in New Issue
Block a user