Skip to content

Commit

Permalink
[MIRROR] Bit of reference handling for custom food holders (#1789)
Browse files Browse the repository at this point in the history
* Bit of reference handling for custom food holders (#81195)

---------

Co-authored-by: NovaBot <[email protected]>
Co-authored-by: MrMelbert <[email protected]>
  • Loading branch information
3 people authored Feb 6, 2024
1 parent 3bb5f53 commit a44203e
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions code/datums/components/customizable_reagent_holder.dm
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,15 @@

/datum/component/customizable_reagent_holder/Destroy(force)
QDEL_NULL(top_overlay)
LAZYCLEARLIST(ingredients)
return ..()


/datum/component/customizable_reagent_holder/RegisterWithParent()
. = ..()
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))
Expand All @@ -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,
))
Expand All @@ -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)
Expand Down Expand Up @@ -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)

0 comments on commit a44203e

Please sign in to comment.