From 45d85d569dfb45b57e8742c95f3a0e9e2ebfa515 Mon Sep 17 00:00:00 2001 From: SkyratBot <59378654+SkyratBot@users.noreply.github.com> Date: Thu, 15 Aug 2024 17:26:22 +0200 Subject: [PATCH] [MIRROR] Circuit components can now be recycles in circuit printers, and automatically do so upon being removed if a circuit has a linked printer (#29316) * Circuit components can now be recycles in circuit printers, and automatically do so upon being removed if a circuit has a linked printer (#85648) ## About The Pull Request Added support for remote material insertion type whitelists and utilized it to allow circuit printers to recycle components. Removing a component from UI while the circuit has a linked printer will automatically recycle it. Also fixed a rogue space appearing when recycling a single item ## Why It's Good For The Game You literally cannot do anything with components you remove/do not need anymore so usually they end up littering circuit lab's floors. This should make developing circuits slightly less annoying. ## Changelog :cl: qol: Circuit components can now be recycles in circuit printers, and automatically do so upon being removed if a circuit has a linked printer spellcheck: Recycling a single item no longer outputs a line with a rogue space infront of it /:cl: * Circuit components can now be recycles in circuit printers, and automatically do so upon being removed if a circuit has a linked printer --------- Co-authored-by: SmArtKar <44720187+SmArtKar@users.noreply.github.com> --- code/datums/components/material/material_container.dm | 8 ++++---- code/datums/components/material/remote_materials.dm | 11 +++++++++-- code/modules/research/designs/wiremod_designs.dm | 2 +- code/modules/wiremod/core/component.dm | 1 + code/modules/wiremod/core/component_printer.dm | 2 +- code/modules/wiremod/core/integrated_circuit.dm | 3 +++ 6 files changed, 19 insertions(+), 8 deletions(-) diff --git a/code/datums/components/material/material_container.dm b/code/datums/components/material/material_container.dm index 6ee50f5d78c..7b3753cc71d 100644 --- a/code/datums/components/material/material_container.dm +++ b/code/datums/components/material/material_container.dm @@ -259,7 +259,7 @@ * * user - the mob inserting this item * * context - the atom performing the operation, this is the last argument sent in COMSIG_MATCONTAINER_ITEM_CONSUMED and is used mostly for silo logging */ -/datum/component/material_container/proc/user_insert(obj/item/held_item, mob/living/user, atom/context = parent) +/datum/component/material_container/proc/user_insert(obj/item/held_item, mob/living/user, atom/context = parent, forced_type = FALSE) set waitfor = FALSE . = 0 @@ -297,7 +297,7 @@ if(SEND_SIGNAL(src, COMSIG_MATCONTAINER_PRE_USER_INSERT, target_item, user) & MATCONTAINER_BLOCK_INSERT) continue //item is either indestructible, not allowed for redemption or not in the allowed types - if((target_item.resistance_flags & INDESTRUCTIBLE) || (target_item.item_flags & NO_MAT_REDEMPTION) || (allowed_item_typecache && !is_type_in_typecache(target_item, allowed_item_typecache))) + if((target_item.resistance_flags & INDESTRUCTIBLE) || (target_item.item_flags & NO_MAT_REDEMPTION) || (allowed_item_typecache && !is_type_in_typecache(target_item, allowed_item_typecache) && !forced_type)) if(!(mat_container_flags & MATCONTAINER_SILENT)) var/list/status_data = chat_msgs["[MATERIAL_INSERT_ITEM_FAILURE]"] || list() var/list/item_data = status_data[target_item.name] || list() @@ -455,9 +455,9 @@ if(MATERIAL_INSERT_ITEM_SUCCESS) //no problems full item was consumed if(chat_data["stack"]) var/sheets = min(count, amount) //minimum between sheets inserted vs sheets consumed(values differ for alloys) - to_chat(user, span_notice("[sheets > 1 ? sheets : ""] [item_name][sheets > 1 ? "s were" : " was"] added to [parent].")) + to_chat(user, span_notice("[sheets > 1 ? "[sheets] " : ""][item_name][sheets > 1 ? "s were" : " was"] added to [parent].")) else - to_chat(user, span_notice("[count > 1 ? count : ""] [item_name][count > 1 ? "s" : ""], worth [amount] sheets, [count > 1 ? "were" : "was"] added to [parent].")) + to_chat(user, span_notice("[count > 1 ? "[count] " : ""][item_name][count > 1 ? "s" : ""], worth [amount] sheets, [count > 1 ? "were" : "was"] added to [parent].")) if(MATERIAL_INSERT_ITEM_NO_SPACE) //no space to_chat(user, span_warning("[parent] has no space to accept [item_name]!")) if(MATERIAL_INSERT_ITEM_NO_MATS) //no materials inside these items diff --git a/code/datums/components/material/remote_materials.dm b/code/datums/components/material/remote_materials.dm index d630ce8e77f..8ae52069c1b 100644 --- a/code/datums/components/material/remote_materials.dm +++ b/code/datums/components/material/remote_materials.dm @@ -23,13 +23,16 @@ handles linking back and forth. var/mat_container_flags = NONE ///List of signals to hook onto the local container var/list/mat_container_signals + ///Typecache for items that the silo will accept through this remote no matter what + var/list/whitelist_typecache /datum/component/remote_materials/Initialize( mapload, allow_standalone = TRUE, force_connect = FALSE, mat_container_flags = NONE, - list/mat_container_signals = null + list/mat_container_signals = null, + list/whitelist_typecache = null ) if (!isatom(parent)) return COMPONENT_INCOMPATIBLE @@ -37,6 +40,7 @@ handles linking back and forth. src.allow_standalone = allow_standalone src.mat_container_flags = mat_container_flags src.mat_container_signals = mat_container_signals + src.whitelist_typecache = whitelist_typecache RegisterSignal(parent, COMSIG_ATOM_TOOL_ACT(TOOL_MULTITOOL), PROC_REF(OnMultitool)) @@ -93,6 +97,9 @@ handles linking back and forth. allowed_items = /obj/item/stack \ ) + if (whitelist_typecache) + mat_container.allowed_item_typecache |= whitelist_typecache + /datum/component/remote_materials/proc/toggle_holding(force_hold = FALSE) if(isnull(silo)) return @@ -140,7 +147,7 @@ handles linking back and forth. return if(silo) - mat_container.user_insert(target, user, parent) + mat_container.user_insert(target, user, parent, (whitelist_typecache && is_type_in_typecache(target, whitelist_typecache))) return COMPONENT_NO_AFTERATTACK diff --git a/code/modules/research/designs/wiremod_designs.dm b/code/modules/research/designs/wiremod_designs.dm index dbcd7416594..e848356359d 100644 --- a/code/modules/research/designs/wiremod_designs.dm +++ b/code/modules/research/designs/wiremod_designs.dm @@ -39,7 +39,7 @@ name = "Component ( NULL ENTRY )" desc = "A component that goes into an integrated circuit." build_type = COMPONENT_PRINTER - materials = list(/datum/material/glass =HALF_SHEET_MATERIAL_AMOUNT) + materials = list(/datum/material/glass = HALF_SHEET_MATERIAL_AMOUNT) departmental_flags = DEPARTMENT_BITFLAG_SCIENCE category = list( RND_CATEGORY_CIRCUITRY + RND_SUBCATEGORY_CIRCUITRY_COMPONENTS diff --git a/code/modules/wiremod/core/component.dm b/code/modules/wiremod/core/component.dm index ff0e64cd9a4..02e88e53c23 100644 --- a/code/modules/wiremod/core/component.dm +++ b/code/modules/wiremod/core/component.dm @@ -14,6 +14,7 @@ inhand_icon_state = "electronic" lefthand_file = 'icons/mob/inhands/items/devices_lefthand.dmi' righthand_file = 'icons/mob/inhands/items/devices_righthand.dmi' + custom_materials = list(/datum/material/glass = HALF_SHEET_MATERIAL_AMOUNT) /// The name of the component shown on the UI var/display_name = "Generic" diff --git a/code/modules/wiremod/core/component_printer.dm b/code/modules/wiremod/core/component_printer.dm index 9011313397a..45f71ceb617 100644 --- a/code/modules/wiremod/core/component_printer.dm +++ b/code/modules/wiremod/core/component_printer.dm @@ -22,7 +22,7 @@ /obj/machinery/component_printer/Initialize(mapload) . = ..() - materials = AddComponent(/datum/component/remote_materials, mapload) + materials = AddComponent(/datum/component/remote_materials, mapload, whitelist_typecache = typecacheof(/obj/item/circuit_component)) /obj/machinery/component_printer/post_machine_initialize() . = ..() diff --git a/code/modules/wiremod/core/integrated_circuit.dm b/code/modules/wiremod/core/integrated_circuit.dm index c295dc8ad79..29f8d42b489 100644 --- a/code/modules/wiremod/core/integrated_circuit.dm +++ b/code/modules/wiremod/core/integrated_circuit.dm @@ -509,6 +509,9 @@ GLOBAL_LIST_EMPTY_TYPED(integrated_circuits, /obj/item/integrated_circuit) remove_component(component) if(component.loc == src) usr.put_in_hands(component) + var/obj/machinery/component_printer/printer = linked_component_printer?.resolve() + if (!isnull(printer)) + printer.attackby(component, usr) . = TRUE if("set_component_coordinates") var/component_id = text2num(params["component_id"])