Files
Bubberstation/code/modules/wiremod/components/variables/setter.dm
SkyratBot f8196cd6a8 [MIRROR] Adds a trigger version of the variable setter circuit component [MDB IGNORE] (#11443)
* Adds a trigger version of the variable setter component (#64820)

See title. Lets you use input and output signals to set variables instead of automatically setting them.

Gives more control, additionally there may be cases where you don't want this, and the normal component still exists.
They're two separate components so that the first one can be a lot more compact

* Adds a trigger version of the variable setter circuit component

Co-authored-by: Watermelon914 <37270891+Watermelon914@users.noreply.github.com>
2022-02-11 10:26:59 +00:00

36 lines
1.2 KiB
Plaintext

/**
* # Setter Component
*
* Stores the current input when triggered into a variable.
*/
/obj/item/circuit_component/variable/setter
display_name = "Variable Setter"
desc = "A component that sets a variable globally on the circuit."
/// The input to store
var/datum/port/input/input_port
circuit_size = 0
/obj/item/circuit_component/variable/setter/trigger
display_name = "Trigger Variable Setter"
desc = "A component that sets a variable globally on the circuit. This one requires input signals and also provides an output signal"
circuit_flags = CIRCUIT_FLAG_INPUT_SIGNAL|CIRCUIT_FLAG_OUTPUT_SIGNAL
/obj/item/circuit_component/variable/setter/get_variable_list(obj/item/integrated_circuit/integrated_circuit)
return integrated_circuit.modifiable_circuit_variables
/obj/item/circuit_component/variable/setter/populate_ports()
input_port = add_input_port("Input", PORT_TYPE_ANY)
/obj/item/circuit_component/variable/setter/pre_input_received(datum/port/input/port)
. = ..()
if(port == variable_name)
input_port.set_datatype(current_variable.datatype)
/obj/item/circuit_component/variable/setter/input_received(datum/port/input/port)
if(!current_variable)
return
current_variable.set_value(input_port.value)