[MIRROR] Added circuit component UI details, added multiplexer and allowed inserting components directly into shells. (#6479)

* Added circuit component UI details, added multiplexer and allowed inserting components directly into shells. (#59635)

Adds the multiplexer circuit component - en.wikipedia.org/wiki/Multiplexer
Circuit components can now be directly inserted into shells rather than having to take the integrated circuit out.
Special information can be accessed from components now through the "Info" button besides the eject button on a component.

* Added circuit component UI details, added multiplexer and allowed inserting components directly into shells.

Co-authored-by: Watermelon914 <37270891+Watermelon914@users.noreply.github.com>
This commit is contained in:
SkyratBot
2021-06-23 22:50:59 +01:00
committed by GitHub
co-authored by Watermelon914
parent 1a2f4f5d69
commit 5ab9aba9d4
41 changed files with 398 additions and 95 deletions
@@ -5,6 +5,7 @@
*/
/obj/item/circuit_component/clock
display_name = "Clock"
display_desc = "A component that repeatedly fires."
/// Whether the clock is on or not
var/datum/port/input/on
@@ -12,6 +13,14 @@
/// The signal from this clock component
var/datum/port/output/signal
/obj/item/circuit_component/clock/get_ui_notices()
. = ..()
. += list(list(
"icon" = "clock",
"content" = "Clock Interval: [DisplayTimeText(COMP_CLOCK_DELAY)]",
"color" = "orange",
))
/obj/item/circuit_component/clock/Initialize()
. = ..()
on = add_input_port("On", PORT_TYPE_NUMBER)
@@ -5,6 +5,7 @@
*/
/obj/item/circuit_component/combiner
display_name = "Combiner"
display_desc = "A component that combines multiple inputs to provide 1 output."
/// The amount of input ports to have
var/input_port_amount = 4
@@ -13,34 +14,40 @@
var/current_type
GLOBAL_LIST_INIT(comp_combiner_options, list(
COMP_COMBINER_ANY,
PORT_TYPE_STRING,
PORT_TYPE_NUMBER,
PORT_TYPE_LIST,
PORT_TYPE_ATOM,
PORT_TYPE_SIGNAL,
))
/obj/item/circuit_component/combiner/populate_options()
var/static/component_options = list(
COMP_TYPE_ANY,
PORT_TYPE_STRING,
PORT_TYPE_NUMBER,
PORT_TYPE_LIST,
PORT_TYPE_ATOM,
PORT_TYPE_SIGNAL,
)
options = component_options
/obj/item/circuit_component/combiner/Initialize()
options = GLOB.comp_combiner_options
. = ..()
current_type = current_option
current_option = COMP_TYPE_ANY
current_type = COMP_TYPE_ANY
for(var/port_id in 1 to input_port_amount)
var/letter = ascii2text(text2ascii("A") + (port_id-1))
add_input_port(letter, current_type)
output_port = add_output_port("Output", current_type)
add_input_port(letter, PORT_TYPE_ANY)
output_port = add_output_port("Output", PORT_TYPE_ANY)
/obj/item/circuit_component/combiner/Destroy()
output_port = null
return ..()
/obj/item/circuit_component/combiner/input_received(datum/port/input/port)
. = ..()
if(current_type != current_option && (current_option != COMP_COMBINER_ANY || current_type != PORT_TYPE_ANY))
if(current_type != current_option && (current_option != COMP_TYPE_ANY || current_type != PORT_TYPE_ANY))
current_type = current_option
if(current_type == COMP_COMBINER_ANY)
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)
output_port.set_output(port?.input_value)
if(. || !port)
return TRUE
output_port.set_output(port.input_value)
@@ -5,6 +5,7 @@
*/
/obj/item/circuit_component/delay
display_name = "Delay"
display_desc = "A component that delays a signal by a specified duration."
/// Amount to delay by
var/datum/port/input/delay_amount
@@ -0,0 +1,66 @@
/**
* # Combiner Component
*
* Combines multiple inputs into 1 output port.
*/
/obj/item/circuit_component/multiplexer
display_name = "Multiplexer"
display_desc = "A component that allows you to selectively choose which input port provides an output. The first port is the selector and takes a number between 1 and the maximum port amount."
circuit_flags = CIRCUIT_FLAG_INPUT_SIGNAL|CIRCUIT_FLAG_OUTPUT_SIGNAL
/// The port to select from, goes from 1 to input_port_amount
var/datum/port/input/input_port
/// The amount of input ports to have
var/input_port_amount = 4
var/datum/port/output/output_port
/// Current type of the ports
var/current_type
/// The multiplexer inputs. These are what get selected for the output by the input_port.
var/list/datum/port/input/multiplexer_inputs
/obj/item/circuit_component/multiplexer/populate_options()
var/static/component_options = list(
COMP_TYPE_ANY,
PORT_TYPE_STRING,
PORT_TYPE_NUMBER,
PORT_TYPE_LIST,
PORT_TYPE_ATOM,
)
options = component_options
/obj/item/circuit_component/multiplexer/Initialize()
. = ..()
current_option = COMP_TYPE_ANY
current_type = COMP_TYPE_ANY
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)
/obj/item/circuit_component/multiplexer/Destroy()
output_port = null
multiplexer_inputs.Cut()
multiplexer_inputs = null
return ..()
/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))
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
output_port.set_output(multiplexer_inputs[input_port.input_value].input_value)
@@ -7,6 +7,7 @@
*/
/obj/item/circuit_component/ram
display_name = "RAM"
display_desc = "A component that retains a variable."
/// The input to store
var/datum/port/input/input_port
@@ -5,6 +5,7 @@
*/
/obj/item/circuit_component/compare/typecheck
display_name = "Typecheck"
display_desc = "A component that checks the type of its input."
input_port_amount = 1
@@ -17,9 +18,16 @@ GLOBAL_LIST_INIT(comp_typecheck_options, list(
COMP_TYPECHECK_HUMAN,
))
/obj/item/circuit_component/compare/typecheck/Initialize()
options = GLOB.comp_typecheck_options
return ..()
/obj/item/circuit_component/compare/typecheck/populate_options()
var/static/component_options = list(
PORT_TYPE_STRING,
PORT_TYPE_NUMBER,
PORT_TYPE_LIST,
PORT_TYPE_ATOM,
COMP_TYPECHECK_MOB,
COMP_TYPECHECK_HUMAN,
)
options = component_options
/obj/item/circuit_component/compare/typecheck/do_comparisons(list/ports)
if(!length(ports))