Integrated the component printer into the integrated circuit UI. You can now link integrated circuits to component printers (#62287)

Co-authored-by: Watermelon914 <3052169-Watermelon914@users.noreply.gitlab.com>
This commit is contained in:
Watermelon914
2021-10-28 11:42:57 -07:00
committed by GitHub
co-authored by Watermelon914
parent bfe0fcc601
commit 44a2af780d
86 changed files with 571 additions and 34 deletions
+40
View File
@@ -0,0 +1,40 @@
/datum/asset/json/circuit_components
name = "circuit_components"
/datum/asset/json/circuit_components/generate()
var/list/circuit_data = list()
for (var/component_type in subtypesof(/obj/item/circuit_component))
var/obj/item/circuit_component/circuit_info = new component_type()
var/list/component_data = list()
var/list/input_info = list()
for(var/datum/port/input/port as anything in circuit_info.input_ports)
input_info += list(list(
"name" = port.name,
"type" = port.datatype,
"color" = port.color,
"datatype_data" = port.datatype_ui_data(),
))
var/list/output_info = list()
for(var/datum/port/output/port as anything in circuit_info.output_ports)
output_info += list(list(
"name" = port.name,
"type" = port.datatype,
"color" = port.color,
"datatype_data" = port.datatype_ui_data(),
))
component_data["name"] = circuit_info.display_name
component_data["description"] = circuit_info.desc
component_data["category"] = circuit_info.category
component_data["color"] = circuit_info.ui_color
component_data["type"] = component_type
component_data["input_ports"] = input_info
component_data["output_ports"] = output_info
circuit_data += list(component_data)
qdel(circuit_info)
return circuit_data
+3
View File
@@ -16,6 +16,9 @@
/// The name of the component shown on the UI
var/display_name = "Generic"
/// The category of the component in the UI
var/category = COMPONENT_DEFAULT_CATEGORY
/// The colour this circuit component appears in the UI
var/ui_color = "blue"
@@ -14,11 +14,24 @@
/// The techweb the printer will get researched designs from
var/datum/techweb/techweb
/// The current unlocked circuit component designs. Used by integrated circuits to print off circuit components remotely.
var/list/current_unlocked_designs = list()
/obj/machinery/component_printer/Initialize(mapload)
. = ..()
techweb = SSresearch.science_tech
for (var/researched_design_id in techweb.researched_designs)
var/datum/design/design = SSresearch.techweb_design_by_id(researched_design_id)
if (!(design.build_type & COMPONENT_PRINTER) || !ispath(design.build_path, /obj/item/circuit_component))
continue
current_unlocked_designs[design.build_path] = design.id
RegisterSignal(techweb, COMSIG_TECHWEB_ADD_DESIGN, .proc/on_research)
RegisterSignal(techweb, COMSIG_TECHWEB_REMOVE_DESIGN, .proc/on_removed)
materials = AddComponent( \
/datum/component/remote_materials, \
"component_printer", \
@@ -26,6 +39,19 @@
mat_container_flags = BREAKDOWN_FLAGS_LATHE, \
)
/obj/machinery/component_printer/proc/on_research(datum/source, datum/design/added_design, custom)
SIGNAL_HANDLER
if (!(added_design.build_type & COMPONENT_PRINTER) || !ispath(added_design.build_path, /obj/item/circuit_component))
return
current_unlocked_designs[added_design.build_path] = added_design.id
/obj/machinery/component_printer/proc/on_removed(datum/source, datum/design/added_design, custom)
SIGNAL_HANDLER
if (!(added_design.build_type & COMPONENT_PRINTER) || !ispath(added_design.build_path, /obj/item/circuit_component))
return
current_unlocked_designs -= added_design.build_path
/obj/machinery/component_printer/ui_interact(mob/user, datum/tgui/ui)
ui = SStgui.try_update_ui(user, src, ui)
if(!ui)
@@ -37,6 +63,23 @@
get_asset_datum(/datum/asset/spritesheet/sheetmaterials)
)
/obj/machinery/component_printer/proc/print_component(typepath)
var/design_id = current_unlocked_designs[typepath]
var/datum/design/design = SSresearch.techweb_design_by_id(design_id)
if (!(design.build_type & COMPONENT_PRINTER))
return
if (materials.on_hold())
return
if (!materials.mat_container?.has_materials(design.materials))
return
materials.mat_container.use_materials(design.materials)
materials.silo_log(src, "printed", -1, design.name, design.materials)
return new design.build_path(drop_location())
/obj/machinery/component_printer/ui_act(action, list/params)
. = ..()
if (.)
@@ -105,6 +148,14 @@
return data
/obj/machinery/component_printer/attackby(obj/item/weapon, mob/living/user, params)
if(istype(weapon, /obj/item/integrated_circuit) && !user.combat_mode)
var/obj/item/integrated_circuit/circuit = weapon
circuit.linked_component_printer = WEAKREF(src)
balloon_alert(user, "successfully linked to the integrated circuit")
return
return ..()
/obj/machinery/component_printer/crowbar_act(mob/living/user, obj/item/tool)
if(..())
return TRUE
@@ -72,6 +72,9 @@ GLOBAL_LIST_EMPTY_TYPED(integrated_circuits, /obj/item/integrated_circuit)
/// The current size of the circuit.
var/current_size = 0
/// The current linked component printer. Lets you remotely print off circuit components and places them in the integrated circuit.
var/datum/weakref/linked_component_printer
/obj/item/integrated_circuit/Initialize(mapload)
. = ..()
@@ -272,7 +275,8 @@ GLOBAL_LIST_EMPTY_TYPED(integrated_circuits, /obj/item/integrated_circuit)
/obj/item/integrated_circuit/ui_assets(mob/user)
return list(
get_asset_datum(/datum/asset/simple/circuit_assets)
get_asset_datum(/datum/asset/simple/circuit_assets),
get_asset_datum(/datum/asset/json/circuit_components)
)
/obj/item/integrated_circuit/ui_static_data(mob/user)
@@ -281,6 +285,11 @@ GLOBAL_LIST_EMPTY_TYPED(integrated_circuits, /obj/item/integrated_circuit)
.["screen_x"] = screen_x
.["screen_y"] = screen_y
var/obj/machinery/component_printer/printer = linked_component_printer?.resolve()
if(!printer)
return
.["stored_designs"] = printer.current_unlocked_designs
/obj/item/integrated_circuit/ui_data(mob/user)
. = list()
.["components"] = list()
@@ -592,7 +601,28 @@ GLOBAL_LIST_EMPTY_TYPED(integrated_circuits, /obj/item/integrated_circuit)
return
var/obj/item/circuit_component/component = attached_components[component_id]
component.ui_perform_action(ui.user, params["action_name"])
if("print_component")
var/component_path = text2path(params["component_to_print"])
var/obj/item/circuit_component/component
if(!check_rights_for(ui.user.client, R_SPAWN))
var/obj/machinery/component_printer/printer = linked_component_printer?.resolve()
if(!printer)
balloon_alert(ui.user, "linked printer not found!")
return
component = printer.print_component(component_path)
if(!component)
balloon_alert(ui.user, "failed to make the component!")
return
else
if(!ispath(component_path, /obj/item/circuit_component))
return
component = new component_path(drop_location())
component.datum_flags |= DF_VAR_EDITED
if(!add_component(component))
return
component.rel_x = text2num(params["rel_x"])
component.rel_y = text2num(params["rel_y"])
return TRUE
#undef WITHIN_RANGE
+1 -1
View File
@@ -109,7 +109,7 @@
/**
* Returns the data from the datatype
*/
/datum/port/proc/datatype_ui_data()
/datum/port/proc/datatype_ui_data(mob/user)
return datatype_handler.datatype_ui_data(src)
/**