tgui backend
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* # Concat List Component
|
||||
*
|
||||
* Concatenates a list with a separator
|
||||
*/
|
||||
/obj/item/circuit_component/concat_list
|
||||
display_name = "Concatenate List"
|
||||
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/input_received(datum/port/input/port)
|
||||
. = ..()
|
||||
if(.)
|
||||
return
|
||||
|
||||
var/seperator = separator.value
|
||||
if(!seperator)
|
||||
return
|
||||
|
||||
var/list/list_input = list_port.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,42 @@
|
||||
/**
|
||||
* # 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"
|
||||
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/input_received(datum/port/input/port)
|
||||
. = ..()
|
||||
if(.)
|
||||
return
|
||||
|
||||
var/list/input_list = received_table.value
|
||||
if(!islist(input_list) || isnum(column_name.value))
|
||||
return
|
||||
|
||||
var/list/new_list = list()
|
||||
for(var/list/entry in input_list)
|
||||
var/anything = entry[column_name.value]
|
||||
if(islist(anything))
|
||||
continue
|
||||
new_list += anything
|
||||
|
||||
output_list.set_output(new_list)
|
||||
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
* # Index Component
|
||||
*
|
||||
* Return the index of a list
|
||||
*/
|
||||
/obj/item/circuit_component/index
|
||||
display_name = "Index List"
|
||||
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/input_received(datum/port/input/port)
|
||||
. = ..()
|
||||
if(.)
|
||||
return
|
||||
|
||||
var/index = index_port.value
|
||||
var/list/list_input = list_port.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,42 @@
|
||||
/**
|
||||
* # 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"
|
||||
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_LIST)
|
||||
|
||||
/obj/item/circuit_component/index_table/input_received(datum/port/input/port)
|
||||
. = ..()
|
||||
if(.)
|
||||
return
|
||||
|
||||
var/list/target_list = received_table.value
|
||||
if(!islist(target_list) || !length(target_list))
|
||||
output_list.set_output(null)
|
||||
return
|
||||
|
||||
var/index = target_index.value
|
||||
if(index < 1 || index > length(target_list))
|
||||
output_list.set_output(null)
|
||||
return
|
||||
|
||||
output_list.set_output(target_list[index])
|
||||
@@ -0,0 +1,86 @@
|
||||
/**
|
||||
* # List Literal Component
|
||||
*
|
||||
* Return a list literal.
|
||||
*/
|
||||
/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."
|
||||
circuit_flags = CIRCUIT_FLAG_INPUT_SIGNAL|CIRCUIT_FLAG_OUTPUT_SIGNAL
|
||||
|
||||
/// The inputs used to create the list
|
||||
var/list/datum/port/input/entry_ports = list()
|
||||
/// The result from the output
|
||||
var/datum/port/output/list_output
|
||||
|
||||
var/length = 0
|
||||
|
||||
var/default_list_size = 2
|
||||
|
||||
var/min_size = 1
|
||||
var/max_size = 20
|
||||
|
||||
/obj/item/circuit_component/list_literal/save_data_to_list(list/component_data)
|
||||
. = ..()
|
||||
component_data["length"] = length
|
||||
|
||||
/obj/item/circuit_component/list_literal/load_data_from_list(list/component_data)
|
||||
set_list_size(component_data["length"])
|
||||
|
||||
return ..()
|
||||
|
||||
/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
|
||||
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--
|
||||
|
||||
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, index = index+1)
|
||||
|
||||
/obj/item/circuit_component/list_literal/Initialize()
|
||||
. = ..()
|
||||
set_list_size(default_list_size)
|
||||
list_output = add_output_port("Value", PORT_TYPE_LIST)
|
||||
|
||||
/obj/item/circuit_component/list_literal/Destroy()
|
||||
list_output = null
|
||||
return ..()
|
||||
|
||||
// Increases list length
|
||||
/obj/item/circuit_component/list_literal/attack_self(mob/user, list/modifiers)
|
||||
. = ..()
|
||||
set_list_size(min(length + 1, max_size))
|
||||
balloon_alert(user, "new size is now [length]")
|
||||
|
||||
// Decreases list length
|
||||
/obj/item/circuit_component/list_literal/attack_self_secondary(mob/user, list/modifiers)
|
||||
. = ..()
|
||||
set_list_size(max(length - 1, min_size))
|
||||
balloon_alert(user, "new size is now [length]")
|
||||
|
||||
/obj/item/circuit_component/list_literal/input_received(datum/port/input/port)
|
||||
. = ..()
|
||||
if(.)
|
||||
return
|
||||
|
||||
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)
|
||||
|
||||
list_output.set_output(new_literal)
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
/**
|
||||
* # 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"
|
||||
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
|
||||
|
||||
var/datum/port/input/option/comparison_options
|
||||
|
||||
/// 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,
|
||||
)
|
||||
comparison_options = add_option_port("Comparison 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/input_received(datum/port/input/port)
|
||||
. = ..()
|
||||
var/current_option = comparison_options.value
|
||||
|
||||
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.value
|
||||
if(!islist(input_list) || isnum(column_name.value))
|
||||
return
|
||||
|
||||
var/comparison_value = comparison_input.value
|
||||
var/list/new_list = list()
|
||||
for(var/list/entry in input_list)
|
||||
var/anything = entry[column_name.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)
|
||||
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
* # Split component
|
||||
*
|
||||
* Splits a string
|
||||
*/
|
||||
/obj/item/circuit_component/split
|
||||
display_name = "Split"
|
||||
desc = "Splits a string by the separator, turning it into a list"
|
||||
|
||||
/// The input port
|
||||
var/datum/port/input/input_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/split/Initialize()
|
||||
. = ..()
|
||||
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)
|
||||
|
||||
/obj/item/circuit_component/split/input_received(datum/port/input/port)
|
||||
. = ..()
|
||||
if(.)
|
||||
return
|
||||
|
||||
var/separator_value = separator.value
|
||||
if(isnull(separator_value))
|
||||
return
|
||||
|
||||
var/value = input_port.value
|
||||
if(isnull(value))
|
||||
return
|
||||
|
||||
var/list/result = splittext(value,separator_value)
|
||||
|
||||
output.set_output(result)
|
||||
Reference in New Issue
Block a user