Files
Bubberstation/code/modules/wiremod/components/atom/reagentscanner.dm
SkyratBot aa4f9a13db [MIRROR] Reagents scanner circuit component [MDB IGNORE] (#9377)
* Reagents scanner circuit component (#62704)

It allows people to make circuits objects that interface with reagents.

* Reagents scanner circuit component

Co-authored-by: Ghom <42542238+Ghommie@users.noreply.github.com>
2021-11-10 14:56:39 -05:00

38 lines
1.2 KiB
Plaintext

/**
* # Reagents Scanner
*
* Returns the reagentss of an atom
*/
/obj/item/circuit_component/reagentscanner
display_name = "Reagents Scanner"
desc = "Outputs the reagents found inside the inputted entity."
category = "Entity"
circuit_flags = CIRCUIT_FLAG_INPUT_SIGNAL|CIRCUIT_FLAG_OUTPUT_SIGNAL
// The entity to scan
var/datum/port/input/input_port
/// The result from the output
var/datum/port/output/result
var/max_range = 5
/obj/item/circuit_component/reagentscanner/get_ui_notices()
. = ..()
. += create_ui_notice("Maximum Range: [max_range] tiles", "orange", "info")
/obj/item/circuit_component/reagentscanner/populate_ports()
input_port = add_input_port("Entity", PORT_TYPE_ATOM)
result = add_output_port("Reagents", PORT_TYPE_ASSOC_LIST(PORT_TYPE_STRING, PORT_TYPE_NUMBER))
/obj/item/circuit_component/reagentscanner/input_received(datum/port/input/port)
var/atom/entity = input_port.value
var/turf/location = get_location()
if(!istype(entity) || !IN_GIVEN_RANGE(location, entity, max_range))
result.set_output(null)
return
var/list/output_list = list()
for(var/datum/reagent/reagent as anything in entity.reagents?.reagent_list)
output_list[reagent.name] += reagent.volume
result.set_output(output_list)