mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-07-20 20:45:28 +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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user