mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-07-19 12:05:59 +01: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:
@@ -1,72 +0,0 @@
|
||||
/**
|
||||
* # Binary Decimal Component
|
||||
*
|
||||
* Has a bit array on one side and a decimal number on the other.
|
||||
*/
|
||||
/obj/item/circuit_component/binary_decimal
|
||||
display_name = "Decimal - Bit Array"
|
||||
desc = "Splits a decimal number into an array of binary digits and vicecersa."
|
||||
circuit_flags = CIRCUIT_FLAG_INPUT_SIGNAL|CIRCUIT_FLAG_OUTPUT_SIGNAL
|
||||
|
||||
/// One number
|
||||
var/datum/port/output/number
|
||||
|
||||
/// Many binary digits
|
||||
var/list/datum/port/bit_array = list()
|
||||
|
||||
var/array_size = 0
|
||||
|
||||
var/default_array_size = 8
|
||||
|
||||
var/min_size = 1 //Who in their right mind would use a 1-bit array for circuits anyway?
|
||||
var/max_size = MAX_BITFIELD_SIZE
|
||||
|
||||
ui_buttons = list(
|
||||
"plus" = "increase",
|
||||
"minus" = "decrease"
|
||||
)
|
||||
|
||||
/obj/item/circuit_component/binary_decimal/save_data_to_list(list/component_data)
|
||||
. = ..()
|
||||
component_data["array_size"] = array_size
|
||||
|
||||
/obj/item/circuit_component/binary_decimal/load_data_from_list(list/component_data)
|
||||
set_array_size(component_data["array_size"])
|
||||
return ..()
|
||||
|
||||
/obj/item/circuit_component/binary_decimal/proc/set_array_size(new_size)
|
||||
if(new_size <= 0)
|
||||
for(var/datum/port/port in bit_array)
|
||||
remove_bit_port(port)
|
||||
bit_array = list()
|
||||
array_size = 0
|
||||
return
|
||||
|
||||
while(array_size > new_size)
|
||||
var/index = length(bit_array)
|
||||
var/datum/port/output = bit_array[index]
|
||||
bit_array -= output
|
||||
remove_bit_port(output)
|
||||
array_size--
|
||||
|
||||
while(array_size < new_size)
|
||||
array_size++
|
||||
var/index = length(bit_array)
|
||||
bit_array += add_bit_port(index)
|
||||
|
||||
/obj/item/circuit_component/binary_decimal/proc/add_bit_port(index)
|
||||
return
|
||||
|
||||
/obj/item/circuit_component/binary_decimal/proc/remove_bit_port(datum/port/to_remove)
|
||||
return
|
||||
|
||||
/obj/item/circuit_component/binary_decimal/populate_ports()
|
||||
set_array_size(default_array_size)
|
||||
|
||||
// Increase or decrease the array size
|
||||
/obj/item/circuit_component/binary_decimal/ui_perform_action(mob/user, action)
|
||||
switch(action)
|
||||
if("increase")
|
||||
set_array_size(min(array_size + 1, max_size))
|
||||
if("decrease")
|
||||
set_array_size(max(array_size - 1, min_size))
|
||||
@@ -6,9 +6,6 @@
|
||||
/obj/item/circuit_component/compare
|
||||
display_name = "Compare"
|
||||
|
||||
/// The amount of input ports to have
|
||||
var/input_port_amount = 4
|
||||
|
||||
/// The trigger for the true/false signals
|
||||
var/datum/port/input/compare
|
||||
|
||||
@@ -19,13 +16,7 @@
|
||||
/// The result from the output
|
||||
var/datum/port/output/result
|
||||
|
||||
var/list/datum/port/input/compare_ports = list()
|
||||
|
||||
/obj/item/circuit_component/compare/populate_ports()
|
||||
for(var/port_id in 1 to input_port_amount)
|
||||
var/letter = ascii2text(text2ascii("A") + (port_id-1))
|
||||
compare_ports += add_input_port(letter, PORT_TYPE_ANY)
|
||||
|
||||
populate_custom_ports()
|
||||
compare = add_input_port("Compare", PORT_TYPE_SIGNAL)
|
||||
|
||||
@@ -41,7 +32,7 @@
|
||||
|
||||
/obj/item/circuit_component/compare/input_received(datum/port/input/port)
|
||||
|
||||
var/logic_result = do_comparisons(compare_ports)
|
||||
var/logic_result = do_comparisons()
|
||||
if(COMPONENT_TRIGGERED_BY(compare, port))
|
||||
if(logic_result)
|
||||
true.set_output(COMPONENT_SIGNAL)
|
||||
@@ -50,5 +41,5 @@
|
||||
result.set_output(logic_result)
|
||||
|
||||
/// Do the comparisons and return a result
|
||||
/obj/item/circuit_component/compare/proc/do_comparisons(list/ports)
|
||||
/obj/item/circuit_component/compare/proc/do_comparisons()
|
||||
return FALSE
|
||||
|
||||
@@ -3,8 +3,6 @@
|
||||
desc = "Performs a basic comparison between two lists of strings, with additional functions that help in using it to check access on IDs."
|
||||
category = "ID"
|
||||
|
||||
input_port_amount = 0 //Uses custom ports for its comparisons
|
||||
|
||||
/// A list of the accesses to check
|
||||
var/datum/port/input/subject_accesses
|
||||
|
||||
@@ -14,7 +12,9 @@
|
||||
/// Whether to check for all or any of the required accesses
|
||||
var/datum/port/input/check_any
|
||||
|
||||
ui_buttons = list("id-card" = "access")
|
||||
ui_buttons = list(
|
||||
"id-card" = "access",
|
||||
)
|
||||
|
||||
/obj/item/circuit_component/compare/access/Initialize(mapload)
|
||||
. = ..()
|
||||
@@ -57,7 +57,7 @@
|
||||
LAZYCLEARLIST(req_one_access)
|
||||
req_access = required_accesses_list.Copy()
|
||||
|
||||
/obj/item/circuit_component/compare/access/do_comparisons(list/ports)
|
||||
/obj/item/circuit_component/compare/access/do_comparisons()
|
||||
return check_access_list(subject_accesses.value)
|
||||
|
||||
/obj/item/circuit_component/compare/access/ui_perform_action(mob/user, action)
|
||||
|
||||
@@ -3,55 +3,66 @@
|
||||
*
|
||||
* Return an associative list literal.
|
||||
*/
|
||||
/obj/item/circuit_component/list_literal/assoc_literal
|
||||
/obj/item/circuit_component/assoc_literal
|
||||
display_name = "Associative List Literal"
|
||||
desc = "A component that returns an associative list consisting of the inputs."
|
||||
category = "List"
|
||||
circuit_flags = CIRCUIT_FLAG_INPUT_SIGNAL|CIRCUIT_FLAG_OUTPUT_SIGNAL
|
||||
|
||||
/// The list type
|
||||
var/datum/port/input/option/list_options
|
||||
|
||||
/// The inputs used to create the list
|
||||
var/list/datum/port/input/entry_ports = list()
|
||||
/// The inputs used to create the list
|
||||
var/list/datum/port/input/key_ports = list()
|
||||
|
||||
/obj/item/circuit_component/list_literal/assoc_literal/clear_lists()
|
||||
for(var/datum/port/input/port as anything in key_ports)
|
||||
remove_input_port(port)
|
||||
for(var/datum/port/input/port as anything in entry_ports)
|
||||
remove_input_port(port)
|
||||
key_ports = list()
|
||||
entry_ports = list()
|
||||
length = 0
|
||||
/// The result from the output
|
||||
var/datum/port/output/list_output
|
||||
|
||||
/obj/item/circuit_component/list_literal/assoc_literal/remove_one_entry()
|
||||
var/index = length(entry_ports)
|
||||
var/key_port = key_ports[index]
|
||||
key_ports -= key_port
|
||||
remove_input_port(key_port)
|
||||
var/value_port = entry_ports[index]
|
||||
entry_ports -= value_port
|
||||
remove_input_port(value_port)
|
||||
length--
|
||||
ui_buttons = list(
|
||||
"plus" = "add",
|
||||
"minus" = "remove"
|
||||
)
|
||||
|
||||
/obj/item/circuit_component/list_literal/assoc_literal/pre_input_received(datum/port/input/port)
|
||||
var/max_list_count = 100
|
||||
|
||||
/obj/item/circuit_component/assoc_literal/pre_input_received(datum/port/input/port)
|
||||
if(port == list_options)
|
||||
var/new_datatype = list_options.value
|
||||
list_output.set_datatype(PORT_TYPE_ASSOC_LIST(PORT_TYPE_STRING, new_datatype))
|
||||
for(var/datum/port/input/port_to_set as anything in entry_ports)
|
||||
port_to_set.set_datatype(new_datatype)
|
||||
|
||||
/obj/item/circuit_component/list_literal/assoc_literal/add_one_entry()
|
||||
length++
|
||||
key_ports += add_input_port("Key [length]", PORT_TYPE_STRING)
|
||||
entry_ports += add_input_port("Index [length]", PORT_TYPE_ANY)
|
||||
/obj/item/circuit_component/assoc_literal/populate_options()
|
||||
list_options = add_option_port("List Type", GLOB.wiremod_basic_types)
|
||||
|
||||
/obj/item/circuit_component/list_literal/assoc_literal/populate_ports()
|
||||
set_list_size(default_list_size)
|
||||
list_output = add_output_port("Value", PORT_TYPE_ASSOC_LIST(PORT_TYPE_STRING, PORT_TYPE_ANY))
|
||||
/obj/item/circuit_component/assoc_literal/populate_ports()
|
||||
AddComponent(/datum/component/circuit_component_add_port, \
|
||||
port_list = entry_ports, \
|
||||
add_action = "add", \
|
||||
remove_action = "remove", \
|
||||
port_type = PORT_TYPE_ANY, \
|
||||
prefix = "Index", \
|
||||
minimum_amount = 1, \
|
||||
maximum_amount = 20 \
|
||||
)
|
||||
AddComponent(/datum/component/circuit_component_add_port, \
|
||||
port_list = key_ports, \
|
||||
add_action = "add", \
|
||||
remove_action = "remove", \
|
||||
port_type = PORT_TYPE_STRING, \
|
||||
prefix = "Key", \
|
||||
minimum_amount = 1, \
|
||||
maximum_amount = 20 \
|
||||
)
|
||||
list_output = add_output_port("Value", PORT_TYPE_ASSOC_LIST(PORT_TYPE_STRING, PORT_TYPE_ANY), order = 1.1)
|
||||
|
||||
/obj/item/circuit_component/list_literal/assoc_literal/input_received(datum/port/input/port)
|
||||
/obj/item/circuit_component/assoc_literal/input_received(datum/port/input/port)
|
||||
var/list/new_literal = list()
|
||||
var/datum/circuit_datatype/value_handler = GLOB.circuit_datatypes[list_options.value]
|
||||
var/datum/circuit_datatype/key_handler = GLOB.circuit_datatypes[PORT_TYPE_STRING]
|
||||
for(var/index in 1 to length)
|
||||
for(var/index in 1 to length(entry_ports))
|
||||
// To prevent people from infinitely making lists to crash the server
|
||||
if(islist(entry_ports[index].value) && get_list_count(entry_ports[index].value, max_list_count) >= max_list_count)
|
||||
visible_message("[src] begins to overheat!")
|
||||
|
||||
@@ -17,16 +17,9 @@
|
||||
/// The result from the output
|
||||
var/datum/port/output/list_output
|
||||
|
||||
var/length = 0
|
||||
|
||||
var/default_list_size = 2
|
||||
|
||||
var/min_size = 1
|
||||
var/max_size = 20
|
||||
|
||||
ui_buttons = list(
|
||||
"plus" = "increase",
|
||||
"minus" = "decrease"
|
||||
"plus" = "add",
|
||||
"minus" = "remove"
|
||||
)
|
||||
|
||||
var/max_list_count = 100
|
||||
@@ -34,43 +27,6 @@
|
||||
/obj/item/circuit_component/list_literal/populate_options()
|
||||
list_options = add_option_port("List Type", GLOB.wiremod_basic_types)
|
||||
|
||||
/obj/item/circuit_component/list_literal/save_data_to_list(list/component_data)
|
||||
. = ..()
|
||||
component_data["length"] = length
|
||||
|
||||
/obj/item/circuit_component/list_literal/load_data_from_list(list/component_data)
|
||||
set_list_size(component_data["length"])
|
||||
|
||||
return ..()
|
||||
|
||||
/obj/item/circuit_component/list_literal/proc/clear_lists()
|
||||
for(var/datum/port/input/port as anything in entry_ports)
|
||||
remove_input_port(port)
|
||||
entry_ports.Cut()
|
||||
length = 0
|
||||
|
||||
/obj/item/circuit_component/list_literal/proc/remove_one_entry()
|
||||
var/index = length(entry_ports)
|
||||
var/entry_port = entry_ports[index]
|
||||
entry_ports -= entry_port
|
||||
remove_input_port(entry_port)
|
||||
length--
|
||||
|
||||
/obj/item/circuit_component/list_literal/proc/add_one_entry()
|
||||
length++
|
||||
entry_ports += add_input_port("Index [length]", list_options.value || PORT_TYPE_ANY)
|
||||
|
||||
/obj/item/circuit_component/list_literal/proc/set_list_size(new_size)
|
||||
if(new_size <= 0)
|
||||
clear_lists()
|
||||
return
|
||||
|
||||
while(length > new_size)
|
||||
remove_one_entry()
|
||||
|
||||
while(length < new_size)
|
||||
add_one_entry()
|
||||
|
||||
/obj/item/circuit_component/list_literal/pre_input_received(datum/port/input/port)
|
||||
if(port == list_options)
|
||||
var/new_datatype = list_options.value
|
||||
@@ -79,23 +35,18 @@
|
||||
port_to_set.set_datatype(new_datatype)
|
||||
|
||||
/obj/item/circuit_component/list_literal/populate_ports()
|
||||
set_list_size(default_list_size)
|
||||
list_output = add_output_port("Value", PORT_TYPE_LIST(PORT_TYPE_ANY))
|
||||
|
||||
/obj/item/circuit_component/list_literal/Destroy()
|
||||
list_output = null
|
||||
return ..()
|
||||
|
||||
// Increases list length
|
||||
/obj/item/circuit_component/list_literal/ui_perform_action(mob/user, action)
|
||||
switch(action)
|
||||
if("increase")
|
||||
set_list_size(min(length + 1, max_size))
|
||||
if("decrease")
|
||||
set_list_size(max(length - 1, min_size))
|
||||
AddComponent(/datum/component/circuit_component_add_port, \
|
||||
port_list = entry_ports, \
|
||||
add_action = "add", \
|
||||
remove_action = "remove", \
|
||||
port_type = PORT_TYPE_ANY, \
|
||||
prefix = "Index", \
|
||||
minimum_amount = 1, \
|
||||
maximum_amount = 20 \
|
||||
)
|
||||
list_output = add_output_port("Value", PORT_TYPE_LIST(PORT_TYPE_ANY), order = 1.1)
|
||||
|
||||
/obj/item/circuit_component/list_literal/input_received(datum/port/input/port)
|
||||
|
||||
var/list/new_literal = list()
|
||||
var/datum/circuit_datatype/handler = GLOB.circuit_datatypes[list_options.value]
|
||||
for(var/datum/port/input/entry_port as anything in entry_ports)
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -8,21 +8,28 @@
|
||||
desc = "A component that combines strings."
|
||||
category = "String"
|
||||
|
||||
/// The amount of input ports to have
|
||||
var/input_port_amount = 4
|
||||
|
||||
var/list/datum/port/input/concat_ports = list()
|
||||
|
||||
/// The result from the output
|
||||
var/datum/port/output/output
|
||||
circuit_flags = CIRCUIT_FLAG_INPUT_SIGNAL|CIRCUIT_FLAG_OUTPUT_SIGNAL
|
||||
|
||||
/obj/item/circuit_component/concat/populate_ports()
|
||||
for(var/port_id in 1 to input_port_amount)
|
||||
var/letter = ascii2text(text2ascii("A") + (port_id-1))
|
||||
concat_ports += add_input_port(letter, PORT_TYPE_STRING)
|
||||
ui_buttons = list(
|
||||
"plus" = "add",
|
||||
"minus" = "remove"
|
||||
)
|
||||
|
||||
output = add_output_port("Output", PORT_TYPE_STRING)
|
||||
/obj/item/circuit_component/concat/populate_ports()
|
||||
AddComponent(/datum/component/circuit_component_add_port, \
|
||||
port_list = concat_ports, \
|
||||
add_action = "add", \
|
||||
remove_action = "remove", \
|
||||
port_type = PORT_TYPE_STRING, \
|
||||
prefix = "Port", \
|
||||
minimum_amount = 2 \
|
||||
)
|
||||
|
||||
output = add_output_port("Output", PORT_TYPE_STRING, order = 1.1)
|
||||
|
||||
/obj/item/circuit_component/concat/input_received(datum/port/input/port)
|
||||
|
||||
|
||||
@@ -8,8 +8,6 @@
|
||||
desc = "Checks if a string contains a word/letter"
|
||||
category = "String"
|
||||
|
||||
input_port_amount = 0
|
||||
|
||||
var/datum/port/input/needle
|
||||
var/datum/port/input/haystack
|
||||
|
||||
@@ -22,11 +20,7 @@
|
||||
haystack = null
|
||||
return ..()
|
||||
|
||||
|
||||
/obj/item/circuit_component/compare/contains/do_comparisons(list/ports)
|
||||
if(length(ports) < input_port_amount)
|
||||
return
|
||||
|
||||
/obj/item/circuit_component/compare/contains/do_comparisons()
|
||||
var/to_find = needle.value
|
||||
var/to_search = haystack.value
|
||||
|
||||
|
||||
@@ -11,9 +11,11 @@
|
||||
desc = "A component that checks the type of its input."
|
||||
category = "Utility"
|
||||
|
||||
input_port_amount = 1
|
||||
var/datum/port/input/option/typecheck_options
|
||||
|
||||
/// Object to typecheck
|
||||
var/datum/port/input/thing_to_check
|
||||
|
||||
/obj/item/circuit_component/compare/typecheck/populate_options()
|
||||
var/static/component_options = list(
|
||||
PORT_TYPE_STRING,
|
||||
@@ -25,14 +27,11 @@
|
||||
)
|
||||
typecheck_options = add_option_port("Typecheck Options", component_options)
|
||||
|
||||
/obj/item/circuit_component/compare/typecheck/do_comparisons(list/ports)
|
||||
if(!length(ports))
|
||||
return
|
||||
. = FALSE
|
||||
/obj/item/circuit_component/compare/typecheck/populate_custom_ports()
|
||||
thing_to_check = add_input_port("Value", PORT_TYPE_ANY)
|
||||
|
||||
// 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.value
|
||||
/obj/item/circuit_component/compare/typecheck/do_comparisons()
|
||||
var/input_val = thing_to_check.value
|
||||
switch(typecheck_options.value)
|
||||
if(PORT_TYPE_STRING)
|
||||
return istext(input_val)
|
||||
@@ -46,7 +45,7 @@
|
||||
return ismob(input_val)
|
||||
if(COMP_TYPECHECK_HUMAN)
|
||||
return ishuman(input_val)
|
||||
|
||||
return FALSE
|
||||
|
||||
#undef COMP_TYPECHECK_MOB
|
||||
#undef COMP_TYPECHECK_HUMAN
|
||||
|
||||
@@ -188,6 +188,8 @@
|
||||
var/datum/port/output/output_port = new(arglist(arguments))
|
||||
output_ports += output_port
|
||||
sortTim(output_ports, /proc/cmp_port_order_asc)
|
||||
if(parent)
|
||||
SStgui.update_uis(parent)
|
||||
return output_port
|
||||
|
||||
/**
|
||||
|
||||
@@ -43,6 +43,7 @@ GLOBAL_LIST_INIT(circuit_dupe_whitelisted_types, list(
|
||||
var/obj/item/circuit_component/component = load_component(type)
|
||||
identifiers_to_circuit[identifier] = component
|
||||
component.load_data_from_list(component_data)
|
||||
SEND_SIGNAL(component, COMSIG_CIRCUIT_COMPONENT_LOAD_DATA, component_data)
|
||||
|
||||
var/list/input_ports_data = component_data["input_ports_stored_data"]
|
||||
for(var/port_name in input_ports_data)
|
||||
@@ -167,6 +168,7 @@ GLOBAL_LIST_INIT(circuit_dupe_whitelisted_types, list(
|
||||
component_data["connections"] = connections
|
||||
component_data["input_ports_stored_data"] = input_ports_stored_data
|
||||
|
||||
SEND_SIGNAL(component, COMSIG_CIRCUIT_COMPONENT_SAVE_DATA, component_data)
|
||||
component.save_data_to_list(component_data)
|
||||
circuit_data[identifier] = component_data
|
||||
|
||||
|
||||
@@ -614,6 +614,7 @@ GLOBAL_LIST_EMPTY_TYPED(integrated_circuits, /obj/item/integrated_circuit)
|
||||
if(!WITHIN_RANGE(component_id, attached_components))
|
||||
return
|
||||
var/obj/item/circuit_component/component = attached_components[component_id]
|
||||
SEND_SIGNAL(component, COMSIG_CIRCUIT_COMPONENT_PERFORM_ACTION, ui.user, params["action_name"])
|
||||
component.ui_perform_action(ui.user, params["action_name"])
|
||||
if("print_component")
|
||||
var/component_path = text2path(params["component_to_print"])
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
/// Helper component that handles users adding/removing ports from a circuit component.
|
||||
/datum/component/circuit_component_add_port
|
||||
dupe_mode = COMPONENT_DUPE_ALLOWED
|
||||
|
||||
/// The list to add the ports to when created
|
||||
var/list/datum/port/port_list
|
||||
/// The action to add a port on
|
||||
var/add_action
|
||||
/// The action to remove a port on
|
||||
var/remove_action
|
||||
/// The type of port
|
||||
var/port_type = PORT_TYPE_ANY
|
||||
/// Whether we are adding output ports or not
|
||||
var/is_output = FALSE
|
||||
/// The prefix of the new ports
|
||||
var/prefix = "Port"
|
||||
/// The order of the new ports
|
||||
var/order = 1
|
||||
/// The minimum amount of ports required
|
||||
var/minimum_amount = 1
|
||||
/// The maximum amount of ports allowed
|
||||
var/maximum_amount = 10
|
||||
|
||||
/datum/component/circuit_component_add_port/Initialize(list/port_list, add_action, remove_action, port_type, is_output = FALSE, prefix = "Port", order = 1, minimum_amount = 1, maximum_amount = 10)
|
||||
. = ..()
|
||||
if(!istype(parent, /obj/item/circuit_component))
|
||||
return COMPONENT_INCOMPATIBLE
|
||||
src.port_list = port_list
|
||||
src.add_action = add_action
|
||||
src.remove_action = remove_action
|
||||
src.port_type = port_type
|
||||
src.is_output = is_output
|
||||
src.prefix = prefix
|
||||
src.order = order
|
||||
src.minimum_amount = minimum_amount
|
||||
src.maximum_amount = maximum_amount
|
||||
|
||||
if(minimum_amount > 0)
|
||||
for(var/i in 1 to minimum_amount)
|
||||
port_list += add_port()
|
||||
|
||||
/datum/component/circuit_component_add_port/RegisterWithParent()
|
||||
RegisterSignal(parent, COMSIG_CIRCUIT_COMPONENT_PERFORM_ACTION, .proc/on_action)
|
||||
RegisterSignal(parent, COMSIG_CIRCUIT_COMPONENT_SAVE_DATA, .proc/on_data_saved)
|
||||
RegisterSignal(parent, COMSIG_CIRCUIT_COMPONENT_LOAD_DATA, .proc/on_data_loaded)
|
||||
|
||||
/datum/component/circuit_component_add_port/UnregisterFromParent()
|
||||
UnregisterSignal(parent, list(
|
||||
COMSIG_CIRCUIT_COMPONENT_PERFORM_ACTION,
|
||||
COMSIG_CIRCUIT_COMPONENT_SAVE_DATA,
|
||||
COMSIG_CIRCUIT_COMPONENT_LOAD_DATA,
|
||||
))
|
||||
|
||||
/datum/component/circuit_component_add_port/proc/on_action(obj/item/circuit_component/component, mob/user, action)
|
||||
SIGNAL_HANDLER
|
||||
if(length(port_list))
|
||||
/// Take the port type of the first stored list element, useful if the types of the ports change
|
||||
port_type = port_list[1].datatype
|
||||
|
||||
if(action == add_action)
|
||||
if(length(port_list) >= maximum_amount)
|
||||
return
|
||||
port_list += add_port()
|
||||
else if(action == remove_action)
|
||||
if(length(port_list) <= minimum_amount)
|
||||
return
|
||||
if(is_output)
|
||||
component.remove_output_port(pop(port_list))
|
||||
else
|
||||
component.remove_input_port(pop(port_list))
|
||||
|
||||
/datum/component/circuit_component_add_port/proc/add_port()
|
||||
var/obj/item/circuit_component/component = parent
|
||||
var/list/arguments = list("[prefix] [length(port_list) + 1]", port_type, order = src.order + (length(port_list) + 1) * 0.001)
|
||||
if(is_output)
|
||||
return component.add_output_port(arglist(arguments))
|
||||
else
|
||||
return component.add_input_port(arglist(arguments))
|
||||
|
||||
/datum/component/circuit_component_add_port/proc/on_data_saved(datum/source, list/data)
|
||||
SIGNAL_HANDLER
|
||||
data["port_count"] = length(port_list)
|
||||
|
||||
/datum/component/circuit_component_add_port/proc/on_data_loaded(datum/source, list/data)
|
||||
SIGNAL_HANDLER
|
||||
var/count = data["port_count"]
|
||||
|
||||
if(!count || count <= length(port_list))
|
||||
return
|
||||
|
||||
while(length(port_list) < count)
|
||||
port_list += add_port()
|
||||
@@ -7,6 +7,8 @@
|
||||
name = "drone"
|
||||
icon = 'icons/obj/wiremod.dmi'
|
||||
icon_state = "setup_medium_med"
|
||||
maxHealth = 300
|
||||
health = 300
|
||||
living_flags = 0
|
||||
light_system = MOVABLE_LIGHT_DIRECTIONAL
|
||||
light_on = FALSE
|
||||
@@ -17,11 +19,30 @@
|
||||
new /obj/item/circuit_component/bot_circuit()
|
||||
), SHELL_CAPACITY_LARGE)
|
||||
|
||||
/mob/living/circuit_drone/examine(mob/user)
|
||||
. = ..()
|
||||
if(health < maxHealth)
|
||||
if(health > maxHealth/3)
|
||||
. += "[src]'s parts look loose."
|
||||
else
|
||||
. += "[src]'s parts look very loose!"
|
||||
else
|
||||
. += "[src] is in pristine condition."
|
||||
|
||||
/mob/living/circuit_drone/updatehealth()
|
||||
. = ..()
|
||||
if(health < 0)
|
||||
gib(no_brain = TRUE, no_organs = TRUE, no_bodyparts = TRUE)
|
||||
|
||||
/mob/living/circuit_drone/welder_act(mob/living/user, obj/item/tool)
|
||||
. = ..()
|
||||
if(health == maxHealth)
|
||||
balloon_alert(user, "already at maximum integrity!")
|
||||
return TRUE
|
||||
if(tool.use_tool(src, user, 1 SECONDS, volume = 50))
|
||||
heal_overall_damage(50, 50)
|
||||
return TRUE
|
||||
|
||||
/mob/living/circuit_drone/spawn_gibs()
|
||||
new /obj/effect/gibspawner/robot(drop_location(), src, get_static_viruses())
|
||||
|
||||
@@ -44,6 +65,21 @@
|
||||
/// Delay between each movement
|
||||
var/move_delay = 0.2 SECONDS
|
||||
|
||||
/obj/item/circuit_component/bot_circuit/register_shell(atom/movable/shell)
|
||||
. = ..()
|
||||
if(ismob(shell))
|
||||
RegisterSignal(shell, COMSIG_PROCESS_BORGCHARGER_OCCUPANT, .proc/on_borg_charge)
|
||||
|
||||
/obj/item/circuit_component/bot_circuit/unregister_shell(atom/movable/shell)
|
||||
UnregisterSignal(shell, COMSIG_PROCESS_BORGCHARGER_OCCUPANT)
|
||||
return ..()
|
||||
|
||||
/obj/item/circuit_component/bot_circuit/proc/on_borg_charge(datum/source, amount)
|
||||
SIGNAL_HANDLER
|
||||
if (isnull(parent.cell))
|
||||
return
|
||||
parent.cell.give(amount)
|
||||
|
||||
/obj/item/circuit_component/bot_circuit/populate_ports()
|
||||
north = add_input_port("Move North", PORT_TYPE_SIGNAL)
|
||||
east = add_input_port("Move East", PORT_TYPE_SIGNAL)
|
||||
|
||||
Reference in New Issue
Block a user