From 34d98d3619f29fcb1bd403c9312fe062a6cf77cb Mon Sep 17 00:00:00 2001 From: NovaBot <154629622+NovaBot13@users.noreply.github.com> Date: Thu, 1 Feb 2024 11:57:25 -0500 Subject: [PATCH] [MIRROR] Bit of reference handling for custom food holders (#728) * Bit of reference handling for custom food holders (#81195) ## About The Pull Request `ingredients` seems to hold a reference to all the food in our atom's contents that are used to make up our custom food, but it doesn't clear it anywhere. So I implemented `Exited`, as well as cutting the list on component `Destroy`. * Bit of reference handling for custom food holders --------- Co-authored-by: MrMelbert <51863163+MrMelbert@users.noreply.github.com> --- .../components/customizable_reagent_holder.dm | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/code/datums/components/customizable_reagent_holder.dm b/code/datums/components/customizable_reagent_holder.dm index 7bffb3d9ada..bd88508bec0 100644 --- a/code/datums/components/customizable_reagent_holder.dm +++ b/code/datums/components/customizable_reagent_holder.dm @@ -57,6 +57,7 @@ /datum/component/customizable_reagent_holder/Destroy(force) QDEL_NULL(top_overlay) + LAZYCLEARLIST(ingredients) return ..() @@ -64,6 +65,7 @@ . = ..() RegisterSignal(parent, COMSIG_ATOM_ATTACKBY, PROC_REF(customizable_attack)) RegisterSignal(parent, COMSIG_ATOM_EXAMINE, PROC_REF(on_examine)) + RegisterSignal(parent, COMSIG_ATOM_EXITED, PROC_REF(food_exited)) RegisterSignal(parent, COMSIG_ATOM_PROCESSED, PROC_REF(on_processed)) RegisterSignal(parent, COMSIG_ATOM_REQUESTING_CONTEXT_FROM_ITEM, PROC_REF(on_requesting_context_from_item)) ADD_TRAIT(parent, TRAIT_CUSTOMIZABLE_REAGENT_HOLDER, REF(src)) @@ -74,6 +76,7 @@ UnregisterSignal(parent, list( COMSIG_ATOM_ATTACKBY, COMSIG_ATOM_EXAMINE, + COMSIG_ATOM_EXITED, COMSIG_ATOM_PROCESSED, COMSIG_ATOM_REQUESTING_CONTEXT_FROM_ITEM, )) @@ -91,20 +94,13 @@ SIGNAL_HANDLER var/atom/atom_parent = parent - var/ingredients_listed = "" - if (LAZYLEN(ingredients)) - for (var/i in 1 to ingredients.len) - var/obj/item/ingredient = ingredients[i] - var/ending = ", " - switch(length(ingredients)) - if (2) - if (i == 1) - ending = " and " - if (3 to INFINITY) - if (i == ingredients.len - 1) - ending = ", and " - ingredients_listed += "\a [ingredient.name][ending]" - examine_list += "It [LAZYLEN(ingredients) ? "contains [ingredients_listed]making a [custom_adjective()]-sized [initial(atom_parent.name)]" : "does not contain any ingredients"]." + var/list/ingredients_listed = list() + for(var/obj/item/ingredient as anything in ingredients) + ingredients_listed += "\a [ingredient.name]" + + examine_list += "It [LAZYLEN(ingredients) \ + ? "contains [english_list(ingredients_listed)] making a [custom_adjective()]-sized [initial(atom_parent.name)]" \ + : "does not contain any ingredients"]." //// Proc that checks if an ingredient is valid or not, returning false if it isnt and true if it is. /datum/component/customizable_reagent_holder/proc/valid_ingredient(obj/ingredient) @@ -289,3 +285,8 @@ context[SCREENTIP_CONTEXT_LMB] = "[screentip_verb] [held_item]" return CONTEXTUAL_SCREENTIP_SET + +/// Clear refs if our food "goes away" somehow +/datum/component/customizable_reagent_holder/proc/food_exited(datum/source, atom/movable/gone) + SIGNAL_HANDLER + LAZYREMOVE(ingredients, gone)