[MIRROR] Refactors port types completely and adds the option type. Refactors options to use this new type (#7386)

* Refactors port types completely and adds the option type. Refactors options to use this new type (#60571)

Co-authored-by: Watermelon914 <3052169-Watermelon914@ users.noreply.gitlab.com>

* Refactors port types completely and adds the option type. Refactors options to use this new type

Co-authored-by: Watermelon914 <37270891+Watermelon914@users.noreply.github.com>
Co-authored-by: Watermelon914 <3052169-Watermelon914@ users.noreply.gitlab.com>
This commit is contained in:
SkyratBot
2021-08-04 19:30:56 +02:00
committed by GitHub
parent 742f11f0d8
commit 3ab1e7ebe2
39 changed files with 487 additions and 271 deletions
@@ -19,11 +19,13 @@
/// The result from the output
var/datum/port/output/result
var/list/datum/port/input/compare_ports = list()
/obj/item/circuit_component/compare/Initialize()
. = ..()
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)
compare_ports += add_input_port(letter, PORT_TYPE_ANY)
load_custom_ports()
compare = add_input_port("Compare", PORT_TYPE_SIGNAL)
@@ -43,11 +45,7 @@
if(.)
return
var/list/ports = input_ports.Copy()
if(input_port_amount)
ports.Cut(input_port_amount+1)
var/logic_result = do_comparisons(ports)
var/logic_result = do_comparisons(compare_ports)
if(COMPONENT_TRIGGERED_BY(compare, port))
if(logic_result)
true.set_output(COMPONENT_SIGNAL)
@@ -7,6 +7,9 @@
display_name = "Radio"
desc = "A component that can listen and send frequencies. If set to private, the component will only receive signals from other components attached to circuitboards with the same owner id."
/// The publicity options. Controls whether it's public or private.
var/datum/port/input/option/public_options
/// Frequency input
var/datum/port/input/freq
/// Signal input
@@ -22,7 +25,7 @@
COMP_RADIO_PUBLIC,
COMP_RADIO_PRIVATE,
)
options = component_options
public_options = add_option_port("Encryption Options", component_options)
/obj/item/circuit_component/radio/Initialize()
. = ..()
@@ -59,7 +62,7 @@
if(signal.data["code"] != round(code.input_value || 0))
return
if(current_option == COMP_RADIO_PRIVATE && parent?.owner_id != signal.data["key"])
if(public_options.input_value == COMP_RADIO_PRIVATE && parent?.owner_id != signal.data["key"])
return
trigger_output.set_output(COMPONENT_SIGNAL)
@@ -8,6 +8,9 @@
desc = "A component that emits a sound when it receives an input. The frequency is a multiplier which determines the speed at which the sound is played"
circuit_flags = CIRCUIT_FLAG_INPUT_SIGNAL|CIRCUIT_FLAG_OUTPUT_SIGNAL
/// Sound to play
var/datum/port/input/option/sound_file
/// Volume of the sound when played
var/datum/port/input/volume
@@ -40,7 +43,7 @@
COMP_SOUND_WARN,
COMP_SOUND_SLOWCLAP,
)
options = component_options
sound_file = add_option_port("Sound Option", component_options)
var/static/options_to_sound = list(
COMP_SOUND_BUZZ = 'sound/machines/buzz-sigh.ogg',
@@ -65,7 +68,7 @@
if(TIMER_COOLDOWN_CHECK(parent, COOLDOWN_CIRCUIT_SOUNDEMITTER))
return
var/sound_to_play = options_map[current_option]
var/sound_to_play = options_map[sound_file.input_value]
if(!sound_to_play)
return
@@ -5,9 +5,11 @@
*/
/obj/item/circuit_component/proccall
display_name = "Proc Call"
desc = "A component that gets a variable on an object."
desc = "A component that calls a proc on an object."
circuit_flags = CIRCUIT_FLAG_INPUT_SIGNAL|CIRCUIT_FLAG_OUTPUT_SIGNAL|CIRCUIT_FLAG_ADMIN
var/datum/port/input/option/proccall_options
/// Entity to proccall on
var/datum/port/input/entity
@@ -26,7 +28,7 @@
COMP_PROC_GLOBAL,
)
options = component_options
proccall_options = add_option_port("Proccall Options", component_options)
/obj/item/circuit_component/proccall/Initialize()
. = ..()
@@ -42,7 +44,7 @@
return
var/called_on
if(current_option == COMP_PROC_OBJECT)
if(proccall_options.input_value == COMP_PROC_OBJECT)
called_on = entity.input_value
else
called_on = GLOBAL_PROC
@@ -5,7 +5,7 @@
*/
/obj/item/circuit_component/spawn_atom
display_name = "Spawn Atom"
desc = "A component that returns the value of a list at a given index."
desc = "Spawns an atom at a desired location"
circuit_flags = CIRCUIT_FLAG_INPUT_SIGNAL|CIRCUIT_FLAG_OUTPUT_SIGNAL|CIRCUIT_FLAG_ADMIN
/// The input path to convert into a typepath
@@ -5,7 +5,7 @@
*/
/obj/item/circuit_component/to_type
display_name = "String To Type"
desc = "A component that returns the value of a list at a given index."
desc = "Converts a string into a typepath. Useful for adding components."
circuit_flags = CIRCUIT_FLAG_INPUT_SIGNAL|CIRCUIT_FLAG_OUTPUT_SIGNAL|CIRCUIT_FLAG_ADMIN
/// The input path to convert into a typepath
@@ -5,42 +5,40 @@
* Requires a BCI shell.
*/
#define BAR_OVERLAY_LIMIT 10
/obj/item/circuit_component/object_overlay/bar
display_name = "Bar Overlay"
desc = "Requires a BCI shell. A component that shows a bar overlay ontop of an object from a range of 0 to 100."
var/datum/port/input/option/bar_overlay_options
var/datum/port/input/bar_number
var/overlay_limit = 10
/obj/item/circuit_component/object_overlay/bar/Initialize()
. = ..()
bar_number = add_input_port("Number", PORT_TYPE_NUMBER)
/obj/item/circuit_component/object_overlay/bar/populate_options()
var/static/component_options_bar = list(
"Vertical",
"Horizontal"
COMP_BAR_OVERLAY_VERTICAL = "barvert",
COMP_BAR_OVERLAY_HORIZONTAL = "barhoriz"
)
options = component_options_bar
var/static/options_to_icons_bar = list(
"Vertical" = "barvert",
"Horizontal" = "barhoriz"
)
options_map = options_to_icons_bar
bar_overlay_options = add_option_port("Bar Overlay Options", component_options_bar)
options_map = component_options_bar
/obj/item/circuit_component/object_overlay/bar/show_to_owner(atom/target_atom, mob/living/owner)
if(LAZYLEN(active_overlays) >= BAR_OVERLAY_LIMIT)
if(LAZYLEN(active_overlays) >= overlay_limit)
return
var/current_option = bar_overlay_options.input_value
if(active_overlays[target_atom])
QDEL_NULL(active_overlays[target_atom])
var/number_clear = clamp(bar_number.input_value, 0, 100)
if(current_option == "Horizontal")
if(current_option == COMP_BAR_OVERLAY_HORIZONTAL)
number_clear = round(number_clear / 6.25) * 6.25
else if(current_option == "Vertical")
else if(current_option == COMP_BAR_OVERLAY_VERTICAL)
number_clear = round(number_clear / 10) * 10
var/image/cool_overlay = image(icon = 'icons/hud/screen_bci.dmi', loc = target_atom, icon_state = "[options_map[current_option]][number_clear]", layer = RIPPLE_LAYER)
@@ -56,5 +54,3 @@
cool_overlay,
owner,
))
#undef BAR_OVERLAY_LIMIT
@@ -13,6 +13,8 @@
required_shells = list(/obj/item/organ/cyberimp/bci)
var/datum/port/input/option/object_overlay_options
/// Target atom
var/datum/port/input/target
@@ -44,20 +46,6 @@
/obj/item/circuit_component/object_overlay/populate_options()
var/static/component_options = list(
"Corners (Blue)",
"Corners (Red)",
"Circle (Blue)",
"Circle (Red)",
"Small Corners (Blue)",
"Small Corners (Red)",
"Triangle (Blue)",
"Triangle (Red)",
"HUD mark (Blue)",
"HUD mark (Red)"
)
options = component_options
var/static/options_to_icons = list(
"Corners (Blue)" = "hud_corners",
"Corners (Red)" = "hud_corners_red",
"Circle (Blue)" = "hud_circle",
@@ -69,7 +57,8 @@
"HUD mark (Blue)" = "hud_mark",
"HUD mark (Red)" = "hud_mark_red"
)
options_map = options_to_icons
object_overlay_options = add_option_port("Object", component_options)
options_map = component_options
/obj/item/circuit_component/object_overlay/register_shell(atom/movable/shell)
if(istype(shell, /obj/item/organ/cyberimp/bci))
@@ -106,7 +95,7 @@
if(active_overlays[target_atom])
QDEL_NULL(active_overlays[target_atom])
var/image/cool_overlay = image(icon = 'icons/hud/screen_bci.dmi', loc = target_atom, icon_state = options_map[current_option], layer = RIPPLE_LAYER)
var/image/cool_overlay = image(icon = 'icons/hud/screen_bci.dmi', loc = target_atom, icon_state = options_map[object_overlay_options.input_value], layer = RIPPLE_LAYER)
if(image_pixel_x.input_value)
cool_overlay.pixel_x = image_pixel_x.input_value
@@ -8,6 +8,8 @@
desc = "A component used with USB cables that can perform select queries on a list based on the column name selected. The values are then compared with the comparison input."
circuit_flags = CIRCUIT_FLAG_INPUT_SIGNAL|CIRCUIT_FLAG_OUTPUT_SIGNAL
var/datum/port/input/option/comparison_options
/// The list to perform the filter on
var/datum/port/input/received_table
@@ -31,7 +33,7 @@
COMP_COMPARISON_GREATER_THAN_OR_EQUAL,
COMP_COMPARISON_LESS_THAN_OR_EQUAL,
)
options = component_options
comparison_options = add_option_port("Comparison Options", component_options)
/obj/item/circuit_component/select/Initialize()
. = ..()
@@ -43,6 +45,8 @@
/obj/item/circuit_component/select/input_received(datum/port/input/port)
. = ..()
var/current_option = comparison_options.input_value
switch(current_option)
if(COMP_COMPARISON_EQUAL, COMP_COMPARISON_NOT_EQUAL)
if(current_type != PORT_TYPE_ANY)
@@ -11,9 +11,12 @@
/// The amount of input ports to have
var/input_port_amount = 4
var/datum/port/input/option/arithmetic_option
/// The result from the output
var/datum/port/output/output
var/list/arithmetic_ports
circuit_flags = CIRCUIT_FLAG_INPUT_SIGNAL|CIRCUIT_FLAG_OUTPUT_SIGNAL
/obj/item/circuit_component/arithmetic/populate_options()
@@ -25,13 +28,14 @@
COMP_ARITHMETIC_MIN,
COMP_ARITHMETIC_MAX,
)
options = component_options
arithmetic_option = add_option_port("Arithmetic Option", component_options)
/obj/item/circuit_component/arithmetic/Initialize()
. = ..()
arithmetic_ports = list()
for(var/port_id in 1 to input_port_amount)
var/letter = ascii2text(text2ascii("A") + (port_id-1))
add_input_port(letter, PORT_TYPE_NUMBER)
arithmetic_ports += add_input_port(letter, PORT_TYPE_NUMBER)
output = add_output_port("Output", PORT_TYPE_NUMBER)
@@ -40,10 +44,8 @@
if(.)
return
var/list/ports = input_ports.Copy()
var/datum/port/input/first_port = ports[1]
ports -= first_port
ports -= trigger_input
var/list/ports = arithmetic_ports.Copy()
var/datum/port/input/first_port = popleft(ports)
var/result = first_port.input_value
for(var/datum/port/input/input_port as anything in ports)
@@ -51,7 +53,7 @@
if(isnull(value))
continue
switch(current_option)
switch(arithmetic_option.input_value)
if(COMP_ARITHMETIC_ADD)
result += value
if(COMP_ARITHMETIC_SUBTRACT)
@@ -7,6 +7,8 @@
display_name = "Comparison"
desc = "A component that compares two objects."
var/datum/port/input/option/comparison_option
input_port_amount = 2
var/current_type = PORT_TYPE_ANY
@@ -19,20 +21,20 @@
COMP_COMPARISON_GREATER_THAN_OR_EQUAL,
COMP_COMPARISON_LESS_THAN_OR_EQUAL,
)
options = component_options
comparison_option = add_option_port("Comparison Option", component_options)
/obj/item/circuit_component/compare/comparison/input_received(datum/port/input/port)
switch(current_option)
switch(comparison_option.input_value)
if(COMP_COMPARISON_EQUAL, COMP_COMPARISON_NOT_EQUAL)
if(current_type != PORT_TYPE_ANY)
current_type = PORT_TYPE_ANY
input_ports[1].set_datatype(PORT_TYPE_ANY)
input_ports[2].set_datatype(PORT_TYPE_ANY)
compare_ports[1].set_datatype(PORT_TYPE_ANY)
compare_ports[2].set_datatype(PORT_TYPE_ANY)
else
if(current_type != PORT_TYPE_NUMBER)
current_type = PORT_TYPE_NUMBER
input_ports[1].set_datatype(PORT_TYPE_NUMBER)
input_ports[2].set_datatype(PORT_TYPE_NUMBER)
compare_ports[1].set_datatype(PORT_TYPE_NUMBER)
compare_ports[2].set_datatype(PORT_TYPE_NUMBER)
return ..()
@@ -41,8 +43,9 @@
return FALSE
// Comparison component only compares the first two ports
var/input1 = input_ports[1].input_value
var/input2 = input_ports[2].input_value
var/input1 = compare_ports[1].input_value
var/input2 = compare_ports[2].input_value
var/current_option = comparison_option.input_value
switch(current_option)
if(COMP_COMPARISON_EQUAL)
@@ -7,16 +7,20 @@
display_name = "Logic"
desc = "A component with 'and' and 'or' capabilities."
var/datum/port/input/option/logic_options
/obj/item/circuit_component/compare/logic/populate_options()
var/static/component_options = list(
COMP_LOGIC_AND,
COMP_LOGIC_OR,
COMP_LOGIC_XOR,
)
options = component_options
logic_options = add_option_port("Logic Options", component_options)
/obj/item/circuit_component/compare/logic/do_comparisons(list/ports)
. = FALSE
var/current_option = logic_options.input_value
// Used by XOR
var/total_ports = 0
var/total_true_ports = 0
@@ -7,6 +7,8 @@
display_name = "Text Case"
desc = "A component that makes its input uppercase or lowercase."
var/datum/port/input/option/textcase_options
/// The input port
var/datum/port/input/input_port
@@ -20,7 +22,7 @@
COMP_TEXT_LOWER,
COMP_TEXT_UPPER,
)
options = component_options
textcase_options = add_option_port("Textcase Options", component_options)
/obj/item/circuit_component/textcase/Initialize()
. = ..()
@@ -37,7 +39,7 @@
return
var/result
switch(current_option)
switch(textcase_options.input_value)
if(COMP_TEXT_LOWER)
result = lowertext(value)
if(COMP_TEXT_UPPER)
@@ -9,9 +9,11 @@
/// The amount of input ports to have
var/input_port_amount = 4
var/datum/port/input/option/combiner_options
var/datum/port/output/output_port
var/list/combiner_ports = list()
var/current_type
/obj/item/circuit_component/combiner/populate_options()
@@ -23,21 +25,21 @@
PORT_TYPE_ATOM,
PORT_TYPE_SIGNAL,
)
options = component_options
combiner_options = add_option_port("Combiner Options", component_options)
/obj/item/circuit_component/combiner/Initialize()
. = ..()
current_type = current_option
current_type = combiner_options.input_value
for(var/port_id in 1 to input_port_amount)
var/letter = ascii2text(text2ascii("A") + (port_id-1))
add_input_port(letter, current_option)
output_port = add_output_port("Output", current_option)
combiner_ports += add_input_port(letter, current_type)
output_port = add_output_port("Output", current_type)
/obj/item/circuit_component/combiner/input_received(datum/port/input/port)
. = ..()
if(current_type != current_option)
current_type = current_option
for(var/datum/port/input/input_port as anything in input_ports)
if(current_type != combiner_options.input_value)
current_type = combiner_options.input_value
for(var/datum/port/input/input_port as anything in combiner_ports)
input_port.set_datatype(current_type)
output_port.set_datatype(current_type)
@@ -10,6 +10,8 @@
desc = "A component that retains a variable."
circuit_flags = CIRCUIT_FLAG_OUTPUT_SIGNAL
var/datum/port/input/option/ram_options
/// The input to store
var/datum/port/input/input_port
/// The trigger to store the current value of the input
@@ -31,16 +33,15 @@
PORT_TYPE_ATOM,
PORT_TYPE_SIGNAL,
)
options = component_options
ram_options = add_option_port("RAM Options", component_options)
/obj/item/circuit_component/ram/Initialize()
. = ..()
current_type = current_option
input_port = add_input_port("Input", current_type)
input_port = add_input_port("Input", PORT_TYPE_ANY)
trigger = add_input_port("Store", PORT_TYPE_SIGNAL)
clear = add_input_port("Clear", PORT_TYPE_SIGNAL)
output = add_output_port("Stored Value", current_type)
output = add_output_port("Stored Value", PORT_TYPE_ANY)
/obj/item/circuit_component/ram/Destroy()
input_port = null
@@ -51,8 +52,8 @@
/obj/item/circuit_component/ram/input_received(datum/port/input/port)
. = ..()
if(current_type != current_option)
current_type = current_option
if(current_type != ram_options.input_value)
current_type = ram_options.input_value
input_port.set_datatype(current_type)
output.set_datatype(current_type)
@@ -8,6 +8,8 @@
desc = "Copies the input chosen by \"Input Selector\" to the output chosen by \"Output Selector\"."
circuit_flags = CIRCUIT_FLAG_INPUT_SIGNAL|CIRCUIT_FLAG_OUTPUT_SIGNAL
var/datum/port/input/option/router_options
/// Which ports to connect.
var/datum/port/input/input_selector
var/datum/port/input/output_selector
@@ -31,11 +33,11 @@
PORT_TYPE_LIST,
PORT_TYPE_ATOM,
)
options = component_options
router_options = add_option_port("Router Options", component_options)
/obj/item/circuit_component/router/Initialize()
. = ..()
current_type = current_option
current_type = router_options.input_value
if(input_port_amount > 1)
input_selector = add_input_port("Input Selector", PORT_TYPE_NUMBER, default = 1)
if(output_port_amount > 1)
@@ -61,6 +63,7 @@
#define WRAPACCESS(L, I) L[(((I||1)-1)%length(L)+length(L))%length(L)+1]
/obj/item/circuit_component/router/input_received(datum/port/input/port)
. = ..()
var/current_option = router_options.input_value
if(current_type != current_option)
current_type = current_option
for(var/datum/port/input/input as anything in ins)
@@ -8,6 +8,8 @@
desc = "A component that casts a value to a type if it matches or outputs null."
circuit_flags = CIRCUIT_FLAG_INPUT_SIGNAL|CIRCUIT_FLAG_OUTPUT_SIGNAL
var/datum/port/input/option/typecast_options
var/datum/port/input/input_value
var/datum/port/output/output_value
@@ -16,21 +18,22 @@
/obj/item/circuit_component/typecast/Initialize()
. = ..()
current_type = current_option
current_type = typecast_options.input_value
input_value = add_input_port("Input", PORT_TYPE_ANY)
output_value = add_output_port("Output", current_option)
output_value = add_output_port("Output", current_type)
/obj/item/circuit_component/typecast/populate_options()
var/static/component_options = list(
var/static/list/component_options = list(
PORT_TYPE_STRING,
PORT_TYPE_NUMBER,
PORT_TYPE_LIST,
PORT_TYPE_ATOM,
)
options = component_options
typecast_options = add_option_port("Typecast Options", component_options)
/obj/item/circuit_component/typecast/input_received(datum/port/input/port)
. = ..()
var/current_option = typecast_options.input_value
if(current_type != current_option)
current_type = current_option
output_value.set_datatype(current_type)
@@ -8,6 +8,7 @@
desc = "A component that checks the type of its input."
input_port_amount = 1
var/datum/port/input/option/typecheck_options
/obj/item/circuit_component/compare/typecheck/populate_options()
var/static/component_options = list(
@@ -18,7 +19,7 @@
COMP_TYPECHECK_MOB,
COMP_TYPECHECK_HUMAN,
)
options = component_options
typecheck_options = add_option_port("Typecheck Options", component_options)
/obj/item/circuit_component/compare/typecheck/do_comparisons(list/ports)
if(!length(ports))
@@ -28,7 +29,7 @@
// We're only comparing the first port/value. There shouldn't be any more.
var/datum/port/input/input_port = ports[1]
var/input_val = input_port.input_value
switch(current_option)
switch(typecheck_options.input_value)
if(PORT_TYPE_STRING)
return istext(input_val)
if(PORT_TYPE_NUMBER)