mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-01-03 13:32:17 +00:00
[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:
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user