mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-07-22 05:25:15 +01:00
Refactors the list datatype to support composite lists. Adapts a lot of circuits to be able to properly use composite lists. Adds the dispenser shell (#61856)
Co-authored-by: Watermelon914 <3052169-Watermelon914@users.noreply.gitlab.com> Co-authored-by: Colovorat <35225170+Colovorat@users.noreply.github.com>
This commit is contained in:
@@ -75,9 +75,9 @@
|
||||
name = "[lowertext(display_name)] [COMPONENT_DEFAULT_NAME]"
|
||||
populate_options()
|
||||
populate_ports()
|
||||
if(circuit_flags & CIRCUIT_FLAG_INPUT_SIGNAL)
|
||||
if((circuit_flags & CIRCUIT_FLAG_INPUT_SIGNAL) && !trigger_input)
|
||||
trigger_input = add_input_port("Trigger", PORT_TYPE_SIGNAL, order = 2)
|
||||
if(circuit_flags & CIRCUIT_FLAG_OUTPUT_SIGNAL)
|
||||
if((circuit_flags & CIRCUIT_FLAG_OUTPUT_SIGNAL) && !trigger_output)
|
||||
trigger_output = add_output_port("Triggered", PORT_TYPE_SIGNAL, order = 2)
|
||||
if(circuit_flags & CIRCUIT_FLAG_INSTANT)
|
||||
ui_color = "orange"
|
||||
@@ -252,7 +252,7 @@
|
||||
if(!cell?.use(power_usage_per_input))
|
||||
return FALSE
|
||||
|
||||
if((circuit_flags & CIRCUIT_FLAG_INPUT_SIGNAL) && !COMPONENT_TRIGGERED_BY(trigger_input, port))
|
||||
if((!port || port.trigger == .proc/input_received) && (circuit_flags & CIRCUIT_FLAG_INPUT_SIGNAL) && !COMPONENT_TRIGGERED_BY(trigger_input, port))
|
||||
return FALSE
|
||||
|
||||
return TRUE
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
// An assoc list of all the possible datatypes.
|
||||
GLOBAL_LIST_INIT(circuit_datatypes, generate_circuit_datatypes())
|
||||
GLOBAL_LIST_INIT_TYPED(circuit_datatypes, /datum/circuit_datatype, generate_circuit_datatypes())
|
||||
|
||||
/proc/generate_circuit_datatypes()
|
||||
var/list/datatypes_by_key = list()
|
||||
for(var/datum/circuit_datatype/type as anything in subtypesof(/datum/circuit_datatype))
|
||||
if(!initial(type.datatype))
|
||||
if(!initial(type.datatype) || initial(type.abstract))
|
||||
continue
|
||||
datatypes_by_key[initial(type.datatype)] = new type()
|
||||
return datatypes_by_key
|
||||
@@ -22,6 +22,9 @@ GLOBAL_LIST_INIT(circuit_datatypes, generate_circuit_datatypes())
|
||||
/// The flags of the circuit datatype
|
||||
var/datatype_flags = 0
|
||||
|
||||
/// Whether this datatype should be loaded into the global circuit_datatypes list.
|
||||
var/abstract = FALSE
|
||||
|
||||
/**
|
||||
* Returns the value to be set for the port
|
||||
*
|
||||
@@ -89,3 +92,9 @@ GLOBAL_LIST_INIT(circuit_datatypes, generate_circuit_datatypes())
|
||||
*/
|
||||
/datum/circuit_datatype/proc/handle_manual_input(datum/port/input/port, mob/user, user_input)
|
||||
return user_input
|
||||
|
||||
/**
|
||||
* Used by composite datatypes. Returns all the datatypes that build this datatype up.
|
||||
*/
|
||||
/datum/circuit_datatype/proc/get_datatypes()
|
||||
return list()
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
GLOBAL_LIST_INIT(circuit_dupe_whitelisted_types, list(
|
||||
PORT_TYPE_NUMBER,
|
||||
PORT_TYPE_STRING,
|
||||
PORT_TYPE_LIST,
|
||||
PORT_TYPE_ANY,
|
||||
PORT_TYPE_OPTION,
|
||||
))
|
||||
|
||||
@@ -314,6 +314,7 @@ GLOBAL_LIST_EMPTY_TYPED(integrated_circuits, /obj/item/integrated_circuit)
|
||||
"type" = port.datatype,
|
||||
"ref" = REF(port),
|
||||
"color" = port.color,
|
||||
"datatype_data" = port.datatype_ui_data(user)
|
||||
))
|
||||
|
||||
component_data["name"] = component.display_name
|
||||
@@ -551,7 +552,8 @@ GLOBAL_LIST_EMPTY_TYPED(integrated_circuits, /obj/item/integrated_circuit)
|
||||
var/variable_datatype = params["variable_datatype"]
|
||||
if(!(variable_datatype in GLOB.wiremod_basic_types))
|
||||
return
|
||||
|
||||
if(params["is_list"])
|
||||
variable_datatype = PORT_TYPE_LIST(variable_datatype)
|
||||
circuit_variables[variable_identifier] = new /datum/circuit_variable(variable_identifier, variable_datatype)
|
||||
. = TRUE
|
||||
if("remove_variable")
|
||||
@@ -568,19 +570,14 @@ GLOBAL_LIST_EMPTY_TYPED(integrated_circuits, /obj/item/integrated_circuit)
|
||||
if(setter_and_getter_count >= max_setters_and_getters)
|
||||
balloon_alert(usr, "setter and getter count at maximum capacity")
|
||||
return
|
||||
var/designated_type = /obj/item/circuit_component/getter
|
||||
var/designated_type = /obj/item/circuit_component/variable/getter
|
||||
if(params["is_setter"])
|
||||
designated_type = /obj/item/circuit_component/setter
|
||||
var/obj/item/circuit_component/component = new designated_type(src)
|
||||
designated_type = /obj/item/circuit_component/variable/setter
|
||||
var/obj/item/circuit_component/variable/component = new designated_type(src)
|
||||
if(!add_component(component, usr))
|
||||
qdel(component)
|
||||
return
|
||||
if(params["is_setter"])
|
||||
var/obj/item/circuit_component/setter/setter = component
|
||||
setter.variable_name.set_input(params["variable"])
|
||||
else
|
||||
var/obj/item/circuit_component/getter/getter = component
|
||||
getter.variable_name.set_input(params["variable"])
|
||||
component.variable_name.set_input(params["variable"])
|
||||
component.rel_x = text2num(params["rel_x"])
|
||||
component.rel_y = text2num(params["rel_y"])
|
||||
RegisterSignal(component, COMSIG_CIRCUIT_COMPONENT_REMOVED, .proc/clear_setter_or_getter)
|
||||
|
||||
@@ -92,7 +92,7 @@
|
||||
datatype_handler = handler
|
||||
color = datatype_handler.color
|
||||
datatype_handler.on_gain(src)
|
||||
src.value = datatype_handler.convert_value(src, value)
|
||||
src.value = null
|
||||
SEND_SIGNAL(src, COMSIG_PORT_SET_TYPE, type_to_set)
|
||||
if(connected_component?.parent)
|
||||
SStgui.update_uis(connected_component.parent)
|
||||
@@ -124,6 +124,7 @@
|
||||
* an integrated circuit
|
||||
*/
|
||||
/datum/port/proc/disconnect_all()
|
||||
value = null
|
||||
SEND_SIGNAL(src, COMSIG_PORT_DISCONNECT)
|
||||
|
||||
/datum/port/input/disconnect_all()
|
||||
@@ -184,6 +185,11 @@
|
||||
if(!(datatype_handler.datatype_flags & DATATYPE_FLAG_AVOID_VALUE_UPDATE))
|
||||
set_input(output.value)
|
||||
|
||||
/datum/port/input/set_datatype(new_type)
|
||||
. = ..()
|
||||
for(var/datum/port/output/port as anything in connected_ports)
|
||||
check_type(port)
|
||||
|
||||
/**
|
||||
* Determines if a datatype is compatible with another port of a different type.
|
||||
*
|
||||
|
||||
@@ -10,6 +10,9 @@
|
||||
/// The datatype of the circuit variable. Used by the setter and getter circuit components
|
||||
var/datatype
|
||||
|
||||
/// The datatype handler for the circuit variable.
|
||||
var/datum/circuit_datatype/datatype_handler
|
||||
|
||||
/// The colour that appears in the UI. The value is set to the datatype's matching colour
|
||||
var/color
|
||||
|
||||
@@ -24,16 +27,11 @@
|
||||
src.name = name
|
||||
src.datatype = datatype
|
||||
|
||||
var/datum/circuit_datatype/circuit_datatype = GLOB.circuit_datatypes[datatype]
|
||||
|
||||
src.datatype_handler = GLOB.circuit_datatypes[datatype]
|
||||
src.listeners = list()
|
||||
src.color = circuit_datatype.color
|
||||
src.color = datatype_handler.color
|
||||
|
||||
|
||||
/datum/circuit_variable/Destroy(force, ...)
|
||||
listeners = null
|
||||
return ..()
|
||||
|
||||
/// Sets the value of the circuit component and triggers the appropriate listeners
|
||||
/datum/circuit_variable/proc/set_value(new_value)
|
||||
value = new_value
|
||||
|
||||
Reference in New Issue
Block a user