[MIRROR] Adds the "To Number" circuit component (#7027)

* Adds the "To Number" circuit component (#60202)

Co-authored-by: Mothblocks <35135081+Mothblocks@ users.noreply.github.com>

* Adds the "To Number" circuit component

Co-authored-by: TheSmallBlue <ilanmori@hotmail.com>
Co-authored-by: Mothblocks <35135081+Mothblocks@ users.noreply.github.com>
This commit is contained in:
SkyratBot
2021-07-20 14:42:29 +02:00
committed by GitHub
parent 1c20e3d97e
commit 353ee480da
4 changed files with 41 additions and 0 deletions
@@ -0,0 +1,34 @@
/**
* #To Number Component
*
* Converts a string into a Number
*/
/obj/item/circuit_component/tonumber
display_name = "To Number"
display_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/Destroy()
input_port = null
output = null
return ..()
/obj/item/circuit_component/tonumber/input_received(datum/port/input/port)
. = ..()
if(.)
return
output.set_output(text2num(input_port.input_value))