Files
Bubberstation/code/modules/wiremod/components/utility/ram.dm
SkyratBot d4df0f5ee2 [MIRROR] RAM now has an option to select between types. Refactored the any type to be more friendly with circuit code. (#6681)
* RAM now has an option to select between types. Refactored the any type to be more friendly with circuit code. (#59953)

RAM now has an option to select between types and an output signal. Refactored the any type to be more friendly with user displays.
Code that includes changing type is no longer hard to read because of snowflake code for the "any" type.
RAM can now more easily act as a constant value component.
RAM also has an output signal because it should and the fact that it doesn't was an oversight when converting everything to use input and output signals.

* RAM now has an option to select between types. Refactored the any type to be more friendly with circuit code.

Co-authored-by: Watermelon914 <37270891+Watermelon914@users.noreply.github.com>
2021-07-03 22:24:30 +01:00

72 lines
1.7 KiB
Plaintext

/**
* # RAM Component
*
* Stores the current input when triggered.
* Players will need to think logically when using the RAM component
* as there can be race conditions due to the delays of transferring signals
*/
/obj/item/circuit_component/ram
display_name = "RAM"
display_desc = "A component that retains a variable."
circuit_flags = CIRCUIT_FLAG_OUTPUT_SIGNAL
/// The input to store
var/datum/port/input/input_port
/// The trigger to store the current value of the input
var/datum/port/input/trigger
/// Clears the current input
var/datum/port/input/clear
/// The current set value
var/datum/port/output/output
var/current_type
/obj/item/circuit_component/ram/populate_options()
var/static/component_options = list(
PORT_TYPE_ANY,
PORT_TYPE_STRING,
PORT_TYPE_NUMBER,
PORT_TYPE_LIST,
PORT_TYPE_ATOM,
PORT_TYPE_SIGNAL,
)
options = component_options
/obj/item/circuit_component/ram/Initialize()
. = ..()
current_type = current_option
input_port = add_input_port("Input", current_type)
trigger = add_input_port("Store", PORT_TYPE_SIGNAL)
clear = add_input_port("Clear", PORT_TYPE_SIGNAL)
output = add_output_port("Stored Value", current_type)
/obj/item/circuit_component/ram/Destroy()
input_port = null
trigger = null
clear = null
output = null
return ..()
/obj/item/circuit_component/ram/input_received(datum/port/input/port)
. = ..()
if(current_type != current_option)
current_type = current_option
input_port.set_datatype(current_type)
output.set_datatype(current_type)
if(.)
return
if(COMPONENT_TRIGGERED_BY(clear, port))
output.set_output(null)
return
if(!COMPONENT_TRIGGERED_BY(trigger, port))
return TRUE
var/input_val = input_port.input_value
output.set_output(input_val)