[MIRROR] Refactored fundamental circuit components that have varying inputs. Improvements to the integrated circuit UI. Improves and rebalances the drone shell [MDB IGNORE] (#15264)

* Refactored fundamental circuit components that have varying inputs. Improvements to the integrated circuit UI. Improves and rebalances the drone shell (#68586)

* Refactored fundamental circuit components that have varying inputs. Made the integrated circuit UI slightly better.

* Fixes with UI

* Removes logger

* Ran prettier

* Fixed documentation

* Rebalances drone circuit

* Drones can now charge in chargers

Co-authored-by: Watermelon914 <hidden@ hidden.com>

* Refactored fundamental circuit components that have varying inputs. Improvements to the integrated circuit UI. Improves and rebalances the drone shell

Co-authored-by: Watermelon914 <37270891+Watermelon914@users.noreply.github.com>
Co-authored-by: Watermelon914 <hidden@ hidden.com>
This commit is contained in:
SkyratBot
2022-07-30 17:22:46 +02:00
committed by GitHub
parent e2c4318f29
commit 856ea9c79a
25 changed files with 533 additions and 336 deletions
@@ -16,9 +16,6 @@
desc = "General arithmetic component with arithmetic capabilities."
category = "Math"
/// The amount of input ports to have
var/input_port_amount = 4
var/datum/port/input/option/arithmetic_option
/// The result from the output
@@ -26,6 +23,10 @@
var/list/arithmetic_ports
circuit_flags = CIRCUIT_FLAG_INPUT_SIGNAL|CIRCUIT_FLAG_OUTPUT_SIGNAL
ui_buttons = list(
"plus" = "add",
"minus" = "remove"
)
/obj/item/circuit_component/arithmetic/populate_options()
var/static/component_options = list(
@@ -40,11 +41,15 @@
/obj/item/circuit_component/arithmetic/populate_ports()
arithmetic_ports = list()
for(var/port_id in 1 to input_port_amount)
var/letter = ascii2text(text2ascii("A") + (port_id-1))
arithmetic_ports += add_input_port(letter, PORT_TYPE_NUMBER)
output = add_output_port("Output", PORT_TYPE_NUMBER)
AddComponent(/datum/component/circuit_component_add_port, \
port_list = arithmetic_ports, \
add_action = "add", \
remove_action = "remove", \
port_type = PORT_TYPE_NUMBER, \
prefix = "Port", \
minimum_amount = 2 \
)
output = add_output_port("Output", PORT_TYPE_NUMBER, order = 1.1)
/obj/item/circuit_component/arithmetic/input_received(datum/port/input/port)
@@ -3,25 +3,40 @@
*
* Return an array of binary digits from a number input.
*/
/obj/item/circuit_component/binary_decimal/binary_conversion
/obj/item/circuit_component/binary_conversion
display_name = "Binary Conversion"
desc = "Splits a decimal number into an array of binary digits, or bits, represented as 1 or 0 and often used in boolean or binary operations like AND, OR and XOR."
category = "Math"
/obj/item/circuit_component/binary_decimal/binary_conversion/populate_ports()
. = ..()
number = add_input_port("Number", PORT_TYPE_NUMBER)
/// One number
var/datum/port/input/number
/obj/item/circuit_component/binary_decimal/binary_conversion/add_bit_port(index)
return add_output_port("Bit [index]", PORT_TYPE_NUMBER)
/// Many binary digits
var/list/datum/port/bit_array = list()
/obj/item/circuit_component/binary_decimal/binary_conversion/remove_bit_port(datum/port/to_remove)
return remove_output_port(to_remove)
ui_buttons = list(
"plus" = "add",
"minus" = "remove"
)
/obj/item/circuit_component/binary_decimal/binary_conversion/input_received(datum/port/input/port)
if(!array_size)
/obj/item/circuit_component/binary_conversion/populate_ports()
AddComponent(/datum/component/circuit_component_add_port, \
port_list = bit_array, \
add_action = "add", \
remove_action = "remove", \
is_output = TRUE, \
port_type = PORT_TYPE_NUMBER, \
prefix = "Bit", \
minimum_amount = 1, \
maximum_amount = MAX_BITFIELD_SIZE \
)
number = add_input_port("Number", PORT_TYPE_NUMBER, order = 1.1)
/obj/item/circuit_component/binary_conversion/input_received(datum/port/input/port)
if(!length(bit_array))
return
for(var/iteration in 1 to array_size)
for(var/iteration in 1 to length(bit_array))
var/datum/port/output/bit = bit_array[iteration]
bit.set_output(number.value & (2 ** (iteration - 1)))
@@ -10,7 +10,11 @@
var/datum/port/input/option/comparison_option
input_port_amount = 2
/// First value to compare with the second value
var/datum/port/input/first_port
/// Second value to compare with the first value
var/datum/port/input/second_port
var/current_type = PORT_TYPE_ANY
/obj/item/circuit_component/compare/comparison/populate_options()
@@ -24,27 +28,27 @@
)
comparison_option = add_option_port("Comparison Option", component_options)
/obj/item/circuit_component/compare/comparison/populate_custom_ports()
first_port = add_input_port("A", PORT_TYPE_ANY)
second_port = add_input_port("B", PORT_TYPE_ANY)
/obj/item/circuit_component/compare/comparison/pre_input_received(datum/port/input/port)
switch(comparison_option.value)
if(COMP_COMPARISON_EQUAL, COMP_COMPARISON_NOT_EQUAL)
if(current_type != PORT_TYPE_ANY)
current_type = PORT_TYPE_ANY
compare_ports[1].set_datatype(PORT_TYPE_ANY)
compare_ports[2].set_datatype(PORT_TYPE_ANY)
first_port.set_datatype(PORT_TYPE_ANY)
second_port.set_datatype(PORT_TYPE_ANY)
else
if(current_type != PORT_TYPE_NUMBER)
current_type = PORT_TYPE_NUMBER
compare_ports[1].set_datatype(PORT_TYPE_NUMBER)
compare_ports[2].set_datatype(PORT_TYPE_NUMBER)
first_port.set_datatype(PORT_TYPE_NUMBER)
second_port.set_datatype(PORT_TYPE_NUMBER)
/obj/item/circuit_component/compare/comparison/do_comparisons(list/ports)
if(length(ports) < input_port_amount)
return FALSE
// Comparison component only compares the first two ports
var/input1 = compare_ports[1].value
var/input2 = compare_ports[2].value
/obj/item/circuit_component/compare/comparison/do_comparisons()
var/input1 = first_port.value
var/input2 = second_port.value
var/current_option = comparison_option.value
switch(current_option)
@@ -3,27 +3,40 @@
*
* Return a number from an array of binary inputs.
*/
/obj/item/circuit_component/binary_decimal/decimal_conversion
/obj/item/circuit_component/decimal_conversion
display_name = "Decimal Conversion"
desc = "Merges an array of binary digits, or bits, represented as 1 or 0 and often used in boolean or binary operations, into a decimal number."
category = "Math"
/obj/item/circuit_component/binary_decimal/decimal_conversion/populate_ports()
. = ..()
number = add_output_port("Number", PORT_TYPE_NUMBER)
/// One number
var/datum/port/output/number
/obj/item/circuit_component/binary_decimal/decimal_conversion/add_bit_port(index)
return add_input_port("Bit [index]", PORT_TYPE_NUMBER)
/// Many binary digits
var/list/datum/port/bit_array = list()
/obj/item/circuit_component/binary_decimal/decimal_conversion/remove_bit_port(datum/port/to_remove)
return remove_input_port(to_remove)
ui_buttons = list(
"plus" = "add",
"minus" = "remove"
)
/obj/item/circuit_component/binary_decimal/decimal_conversion/input_received(datum/port/input/port)
if(!array_size)
/obj/item/circuit_component/decimal_conversion/populate_ports()
AddComponent(/datum/component/circuit_component_add_port, \
port_list = bit_array, \
add_action = "add", \
remove_action = "remove", \
port_type = PORT_TYPE_NUMBER, \
prefix = "Bit", \
minimum_amount = 1, \
maximum_amount = MAX_BITFIELD_SIZE \
)
number = add_output_port("Number", PORT_TYPE_NUMBER, order = 1.1)
/obj/item/circuit_component/decimal_conversion/input_received(datum/port/input/port)
if(!length(bit_array))
return
var/result = 0
for(var/iteration in 1 to array_size)
for(var/iteration in 1 to length(bit_array))
var/datum/port/input/bit = bit_array[iteration]
if(bit.value)
result += (2 ** (iteration-1))
+22 -5
View File
@@ -14,6 +14,14 @@
var/datum/port/input/option/logic_options
/// Ports to do comparisons with
var/list/comparison_ports = list()
ui_buttons = list(
"plus" = "add",
"minus" = "remove"
)
/obj/item/circuit_component/compare/logic/populate_options()
var/static/component_options = list(
COMP_LOGIC_AND,
@@ -22,17 +30,25 @@
)
logic_options = add_option_port("Logic Options", component_options)
/obj/item/circuit_component/compare/logic/do_comparisons(list/ports)
/obj/item/circuit_component/compare/logic/populate_custom_ports()
AddComponent(/datum/component/circuit_component_add_port, \
port_list = comparison_ports, \
add_action = "add", \
remove_action = "remove", \
port_type = PORT_TYPE_ANY, \
prefix = "Port", \
order = 0.9, \
minimum_amount = 2 \
)
/obj/item/circuit_component/compare/logic/do_comparisons()
. = FALSE
var/current_option = logic_options.value
// Used by XOR
var/total_ports = 0
var/total_true_ports = 0
for(var/datum/port/input/port as anything in ports)
if(isnull(port.value) && length(port.connected_ports) == 0)
continue
for(var/datum/port/input/port as anything in comparison_ports)
total_ports += 1
switch(current_option)
if(COMP_LOGIC_AND)
@@ -52,6 +68,7 @@
return FALSE
if(.)
return TRUE
return .
#undef COMP_LOGIC_AND
#undef COMP_LOGIC_OR