tgui backend
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
* # Concatenate Component
|
||||
*
|
||||
* General string concatenation component. Puts strings together.
|
||||
*/
|
||||
/obj/item/circuit_component/concat
|
||||
display_name = "Concatenate"
|
||||
desc = "A component that combines strings."
|
||||
|
||||
/// The amount of input ports to have
|
||||
var/input_port_amount = 4
|
||||
|
||||
/// 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/Initialize()
|
||||
. = ..()
|
||||
for(var/port_id in 1 to input_port_amount)
|
||||
var/letter = ascii2text(text2ascii("A") + (port_id-1))
|
||||
add_input_port(letter, PORT_TYPE_STRING)
|
||||
|
||||
output = add_output_port("Output", PORT_TYPE_STRING)
|
||||
|
||||
/obj/item/circuit_component/concat/input_received(datum/port/input/port)
|
||||
. = ..()
|
||||
if(.)
|
||||
return
|
||||
|
||||
var/result = ""
|
||||
var/list/ports = input_ports.Copy()
|
||||
ports -= trigger_input
|
||||
|
||||
for(var/datum/port/input/input_port as anything in ports)
|
||||
var/value = input_port.value
|
||||
if(isnull(value))
|
||||
continue
|
||||
|
||||
result += "[value]"
|
||||
|
||||
output.set_output(result)
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
/**
|
||||
* # String Contains Component
|
||||
*
|
||||
* Checks if a string contains a word/letter
|
||||
*/
|
||||
/obj/item/circuit_component/compare/contains
|
||||
display_name = "String Contains"
|
||||
desc = "Checks if a string contains a word/letter"
|
||||
|
||||
input_port_amount = 0
|
||||
|
||||
var/datum/port/input/needle
|
||||
var/datum/port/input/haystack
|
||||
|
||||
/obj/item/circuit_component/compare/contains/load_custom_ports()
|
||||
needle = add_input_port("Needle", PORT_TYPE_STRING)
|
||||
haystack = add_input_port("Haystack", PORT_TYPE_STRING)
|
||||
|
||||
/obj/item/circuit_component/compare/contains/Destroy()
|
||||
needle = null
|
||||
haystack = null
|
||||
return ..()
|
||||
|
||||
|
||||
/obj/item/circuit_component/compare/contains/do_comparisons(list/ports)
|
||||
if(length(ports) < input_port_amount)
|
||||
return
|
||||
|
||||
var/to_find = needle.value
|
||||
var/to_search = haystack.value
|
||||
|
||||
if(!to_find || !to_search)
|
||||
return
|
||||
|
||||
return findtext(to_search, to_find)
|
||||
@@ -0,0 +1,54 @@
|
||||
#define COMP_TEXT_LOWER "To Lower"
|
||||
#define COMP_TEXT_UPPER "To Upper"
|
||||
|
||||
/**
|
||||
* # Text Component
|
||||
*
|
||||
* Either makes the text upper case or lower case.
|
||||
*/
|
||||
/obj/item/circuit_component/textcase
|
||||
display_name = "Text Case"
|
||||
desc = "A component that makes its input uppercase or lowercase."
|
||||
|
||||
var/datum/port/input/option/textcase_options
|
||||
|
||||
/// The input port
|
||||
var/datum/port/input/input_port
|
||||
|
||||
/// The result of the text operation
|
||||
var/datum/port/output/output
|
||||
|
||||
circuit_flags = CIRCUIT_FLAG_INPUT_SIGNAL|CIRCUIT_FLAG_OUTPUT_SIGNAL
|
||||
|
||||
/obj/item/circuit_component/textcase/populate_options()
|
||||
var/static/component_options = list(
|
||||
COMP_TEXT_LOWER,
|
||||
COMP_TEXT_UPPER,
|
||||
)
|
||||
textcase_options = add_option_port("Textcase Options", component_options)
|
||||
|
||||
/obj/item/circuit_component/textcase/Initialize()
|
||||
. = ..()
|
||||
input_port = add_input_port("Input", PORT_TYPE_STRING)
|
||||
output = add_output_port("Output", PORT_TYPE_STRING)
|
||||
|
||||
/obj/item/circuit_component/textcase/input_received(datum/port/input/port)
|
||||
. = ..()
|
||||
if(.)
|
||||
return
|
||||
|
||||
var/value = input_port.value
|
||||
if(isnull(value))
|
||||
return
|
||||
|
||||
var/result
|
||||
switch(textcase_options.value)
|
||||
if(COMP_TEXT_LOWER)
|
||||
result = lowertext(value)
|
||||
if(COMP_TEXT_UPPER)
|
||||
result = uppertext(value)
|
||||
|
||||
output.set_output(result)
|
||||
|
||||
#undef COMP_TEXT_LOWER
|
||||
#undef COMP_TEXT_UPPER
|
||||
@@ -0,0 +1,29 @@
|
||||
/**
|
||||
* #To Number Component
|
||||
*
|
||||
* Converts a string into a Number
|
||||
*/
|
||||
/obj/item/circuit_component/tonumber
|
||||
display_name = "To Number"
|
||||
desc = "A component that converts its input (a string) to a number. If there's text in the input, it'll only consider it if it starts with a number. It will take that number and ignore the rest."
|
||||
|
||||
/// The input port
|
||||
var/datum/port/input/input_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/tonumber/Initialize()
|
||||
. = ..()
|
||||
input_port = add_input_port("Input", PORT_TYPE_STRING)
|
||||
|
||||
output = add_output_port("Output", PORT_TYPE_NUMBER)
|
||||
|
||||
/obj/item/circuit_component/tonumber/input_received(datum/port/input/port)
|
||||
. = ..()
|
||||
if(.)
|
||||
return
|
||||
|
||||
output.set_output(text2num(input_port.value))
|
||||
@@ -0,0 +1,40 @@
|
||||
/**
|
||||
* # To String Component
|
||||
*
|
||||
* Converts any value into a string
|
||||
*/
|
||||
/obj/item/circuit_component/tostring
|
||||
display_name = "To String"
|
||||
desc = "A component that converts its input to text."
|
||||
|
||||
/// The input port
|
||||
var/datum/port/input/input_port
|
||||
|
||||
/// The result from the output
|
||||
var/datum/port/output/output
|
||||
|
||||
circuit_flags = CIRCUIT_FLAG_INPUT_SIGNAL|CIRCUIT_FLAG_OUTPUT_SIGNAL
|
||||
|
||||
var/max_range = 5
|
||||
|
||||
/obj/item/circuit_component/tostring/Initialize()
|
||||
. = ..()
|
||||
input_port = add_input_port("Input", PORT_TYPE_ANY)
|
||||
|
||||
output = add_output_port("Output", PORT_TYPE_STRING)
|
||||
|
||||
/obj/item/circuit_component/tostring/input_received(datum/port/input/port)
|
||||
. = ..()
|
||||
if(.)
|
||||
return
|
||||
|
||||
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)
|
||||
output.set_output(PORT_TYPE_ATOM)
|
||||
return
|
||||
|
||||
output.set_output("[value]")
|
||||
|
||||
Reference in New Issue
Block a user