mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-08-27 23:27:34 +01:00
[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>
This commit is contained in:
co-authored by
Watermelon914
parent
30424992e7
commit
d4df0f5ee2
@@ -16,7 +16,7 @@
|
||||
|
||||
/obj/item/circuit_component/combiner/populate_options()
|
||||
var/static/component_options = list(
|
||||
COMP_TYPE_ANY,
|
||||
PORT_TYPE_ANY,
|
||||
PORT_TYPE_STRING,
|
||||
PORT_TYPE_NUMBER,
|
||||
PORT_TYPE_LIST,
|
||||
@@ -27,12 +27,11 @@
|
||||
|
||||
/obj/item/circuit_component/combiner/Initialize()
|
||||
. = ..()
|
||||
current_option = COMP_TYPE_ANY
|
||||
current_type = COMP_TYPE_ANY
|
||||
current_type = current_option
|
||||
for(var/port_id in 1 to input_port_amount)
|
||||
var/letter = ascii2text(text2ascii("A") + (port_id-1))
|
||||
add_input_port(letter, PORT_TYPE_ANY)
|
||||
output_port = add_output_port("Output", PORT_TYPE_ANY)
|
||||
add_input_port(letter, current_option)
|
||||
output_port = add_output_port("Output", current_option)
|
||||
|
||||
/obj/item/circuit_component/combiner/Destroy()
|
||||
output_port = null
|
||||
@@ -40,10 +39,8 @@
|
||||
|
||||
/obj/item/circuit_component/combiner/input_received(datum/port/input/port)
|
||||
. = ..()
|
||||
if(current_type != current_option && (current_option != COMP_TYPE_ANY || current_type != PORT_TYPE_ANY))
|
||||
if(current_type != current_option)
|
||||
current_type = current_option
|
||||
if(current_type == COMP_TYPE_ANY)
|
||||
current_type = PORT_TYPE_ANY
|
||||
for(var/datum/port/input/input_port as anything in input_ports)
|
||||
input_port.set_datatype(current_type)
|
||||
output_port.set_datatype(current_type)
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
/obj/item/circuit_component/multiplexer/populate_options()
|
||||
var/static/component_options = list(
|
||||
COMP_TYPE_ANY,
|
||||
PORT_TYPE_ANY,
|
||||
PORT_TYPE_STRING,
|
||||
PORT_TYPE_NUMBER,
|
||||
PORT_TYPE_LIST,
|
||||
@@ -34,13 +34,12 @@
|
||||
|
||||
/obj/item/circuit_component/multiplexer/Initialize()
|
||||
. = ..()
|
||||
current_option = COMP_TYPE_ANY
|
||||
current_type = COMP_TYPE_ANY
|
||||
current_type = current_option
|
||||
input_port = add_input_port("Selector", PORT_TYPE_NUMBER, default = 1)
|
||||
multiplexer_inputs = list()
|
||||
for(var/port_id in 1 to input_port_amount)
|
||||
multiplexer_inputs += add_input_port("Port [port_id]", PORT_TYPE_ANY)
|
||||
output_port = add_output_port("Output", PORT_TYPE_ANY)
|
||||
multiplexer_inputs += add_input_port("Port [port_id]", current_type)
|
||||
output_port = add_output_port("Output", current_type)
|
||||
|
||||
/obj/item/circuit_component/multiplexer/Destroy()
|
||||
output_port = null
|
||||
@@ -51,16 +50,14 @@
|
||||
|
||||
/obj/item/circuit_component/multiplexer/input_received(datum/port/input/port)
|
||||
. = ..()
|
||||
if(current_type != current_option && (current_option != COMP_TYPE_ANY || current_type != PORT_TYPE_ANY))
|
||||
if(current_type != current_option)
|
||||
current_type = current_option
|
||||
if(current_type == COMP_TYPE_ANY)
|
||||
current_type = PORT_TYPE_ANY
|
||||
for(var/datum/port/input/input_port as anything in multiplexer_inputs)
|
||||
input_port.set_datatype(current_type)
|
||||
output_port.set_datatype(current_type)
|
||||
|
||||
input_port.set_input(clamp(input_port.input_value || 1, 1, input_port_amount), FALSE)
|
||||
if(.)
|
||||
return TRUE
|
||||
return
|
||||
output_port.set_output(multiplexer_inputs[input_port.input_value].input_value)
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
/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
|
||||
@@ -19,13 +20,27 @@
|
||||
/// 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()
|
||||
. = ..()
|
||||
input_port = add_input_port("Input", PORT_TYPE_ANY)
|
||||
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", PORT_TYPE_ANY)
|
||||
output = add_output_port("Stored Value", current_type)
|
||||
|
||||
/obj/item/circuit_component/ram/Destroy()
|
||||
input_port = null
|
||||
@@ -36,7 +51,11 @@
|
||||
|
||||
/obj/item/circuit_component/ram/input_received(datum/port/input/port)
|
||||
. = ..()
|
||||
match_port_datatype(input_port, output)
|
||||
if(current_type != current_option)
|
||||
current_type = current_option
|
||||
input_port.set_datatype(current_type)
|
||||
output.set_datatype(current_type)
|
||||
|
||||
if(.)
|
||||
return
|
||||
|
||||
@@ -45,7 +64,7 @@
|
||||
return
|
||||
|
||||
if(!COMPONENT_TRIGGERED_BY(trigger, port))
|
||||
return
|
||||
return TRUE
|
||||
|
||||
var/input_val = input_port.input_value
|
||||
|
||||
|
||||
Reference in New Issue
Block a user