Makes RemoveComponent more sane (#26877)

* Makes RemoveComponent more sane

* An even better wrapper

* Update code/datums/components/surgery_initiator.dm

Co-authored-by: Contrabang <91113370+Contrabang@users.noreply.github.com>
Signed-off-by: DGamerL <108773801+DGamerL@users.noreply.github.com>

* Update code/datums/components/_component.dm

Co-authored-by: Contrabang <91113370+Contrabang@users.noreply.github.com>
Signed-off-by: DGamerL <108773801+DGamerL@users.noreply.github.com>

* Update code/datums/components/_component.dm

Signed-off-by: DGamerL <108773801+DGamerL@users.noreply.github.com>

* Update code/datums/components/_component.dm

Co-authored-by: Contrabang <91113370+Contrabang@users.noreply.github.com>
Signed-off-by: DGamerL <108773801+DGamerL@users.noreply.github.com>

* Update code/datums/components/_component.dm

Co-authored-by: Contrabang <91113370+Contrabang@users.noreply.github.com>
Signed-off-by: DGamerL <108773801+DGamerL@users.noreply.github.com>

---------

Signed-off-by: DGamerL <108773801+DGamerL@users.noreply.github.com>
Co-authored-by: Contrabang <91113370+Contrabang@users.noreply.github.com>
This commit is contained in:
DGamerL
2024-10-09 18:46:04 +00:00
committed by GitHub
co-authored by Contrabang
parent 3e640bd2c0
commit 89796a055b
20 changed files with 45 additions and 32 deletions
+1 -1
View File
@@ -8,7 +8,7 @@
/// when a component is added to a datum: (/datum/component)
#define COMSIG_COMPONENT_ADDED "component_added"
/// before a component is removed from a datum because of RemoveComponent: (/datum/component)
/// before a component is removed from a datum because of UnlinkComponent: (/datum/component)
#define COMSIG_COMPONENT_REMOVING "component_removing"
/// before a datum's Destroy() is called: (force), returning a nonzero value will cancel the qdel operation
#define COMSIG_PARENT_PREQDELETED "parent_preqdeleted"
+1 -1
View File
@@ -294,7 +294,7 @@ SUBSYSTEM_DEF(statpanels)
actively_tracking = TRUE
/datum/object_window_info/proc/stop_turf_tracking()
qdel(GetComponent(/datum/component/connect_mob_behalf))
DeleteComponent(/datum/component/connect_mob_behalf)
actively_tracking = FALSE
/datum/object_window_info/proc/on_mob_move(mob/source)
+17 -2
View File
@@ -441,6 +441,14 @@
return new_comp
return old_comp
/**
* Removes the component from the datum
*/
/datum/proc/DeleteComponent(component_to_nuke)
var/datum/component/removing = GetComponent(component_to_nuke)
if(istype(removing, component_to_nuke) && !QDELETED(removing))
qdel(removing)
/**
* Get existing component of type, or create it and return a reference to it
*
@@ -458,7 +466,7 @@
/**
* Removes the component from parent, ends up with a null parent
*/
/datum/component/proc/RemoveComponent()
/datum/component/proc/UnlinkComponent()
if(!parent)
return
var/datum/old_parent = parent
@@ -467,6 +475,13 @@
parent = null
SEND_SIGNAL(old_parent, COMSIG_COMPONENT_REMOVING, src)
/**
* Deletes the component and removes it from parent.
*/
/datum/component/proc/RemoveComponent() // This really is just a wrapper to pretend that we're using sane procs to fully remove a component
if(!QDELETED(src))
qdel(src)
/**
* Transfer this component to another parent
*
@@ -479,7 +494,7 @@
if(!target || target.parent == src)
return
if(target.parent)
target.RemoveComponent()
target.UnlinkComponent()
target.parent = src
var/result = target.PostTransfer()
switch(result)
+1 -1
View File
@@ -67,8 +67,8 @@
SIGNAL_HANDLER // COMSIG_ATOM_UPDATE_SHARPNESS
var/obj/item/P = parent
if(!P.sharp)
UnlinkComponent()
RemoveComponent()
qdel(src)
/// Does the surgery initiation.
/datum/component/surgery_initiator/proc/initiate_surgery_moment(datum/source, atom/target, mob/user)
+1 -1
View File
@@ -148,7 +148,7 @@
/datum/disease/zombie/cure()
affected_mob.mind?.remove_antag_datum(/datum/antagonist/zombie)
REMOVE_TRAIT(affected_mob, TRAIT_I_WANT_BRAINS, ZOMBIE_TRAIT)
qdel(affected_mob.GetComponent(/datum/component/zombie_regen))
affected_mob.DeleteComponent(/datum/component/zombie_regen)
affected_mob.med_hud_set_health()
affected_mob.med_hud_set_status()
return ..()
+2 -1
View File
@@ -1572,7 +1572,8 @@
if(istype(I))
apply_to_card(I, H, list(ACCESS_MAINT_TUNNELS), "Solar Federation Infilitrator", "lifetimeid")
qdel(H.GetComponent(/datum/component/footstep)) // they're literally stealth
H.DeleteComponent(/datum/component/footstep)
var/datum/martial_art/cqc/CQC = new()
CQC.teach(H)
+1 -1
View File
@@ -1002,7 +1002,7 @@ GLOBAL_LIST_EMPTY(blood_splatter_icons)
if(!QDELETED(healthy_green_glow))
healthy_green_glow.strength = max(0, (healthy_green_glow.strength - (RAD_BACKGROUND_RADIATION * clean_factor)))
if(healthy_green_glow.strength <= RAD_BACKGROUND_RADIATION)
qdel(healthy_green_glow)
healthy_green_glow.RemoveComponent()
/obj/effect/decal/cleanable/blood/clean_blood(radiation_clean = FALSE)
return // While this seems nonsensical, clean_blood isn't supposed to be used like this on a blood decal.
+1 -3
View File
@@ -677,9 +677,7 @@
/// Easy way to remove the component when the fun has been played out
/atom/movable/proc/stop_deadchat_plays()
var/datum/component/deadchat_control/comp = GetComponent(/datum/component/deadchat_control)
if(!QDELETED(comp))
qdel(comp)
DeleteComponent(/datum/component/deadchat_control)
/atom/movable/vv_get_dropdown()
. = ..()
+1 -1
View File
@@ -473,7 +473,7 @@
if(visualsOnly)
return
qdel(H.GetComponent(/datum/component/footstep))
H.DeleteComponent(/datum/component/footstep)
/datum/outfit/job/mime/on_mind_initialize(mob/living/carbon/human/H)
. = ..()
@@ -479,10 +479,9 @@
/obj/item/kinetic_crusher/mecha/Initialize(mapload)
. = ..()
var/datum/component/unwanted = GetComponent(/datum/component/parry)
unwanted?.RemoveComponent()
unwanted = GetComponent(/datum/component/two_handed)
unwanted?.RemoveComponent()
DeleteComponent(/datum/component/parry)
DeleteComponent(/datum/component/two_handed)
/// This is only for the sake of internal checks in the crusher itself.
ADD_TRAIT(src, TRAIT_WIELDED, "mech[UID()]")
@@ -29,7 +29,7 @@
. += "<span class='notice'>The fuze is set to [det_time / 10] second\s.</span>"
else
. += "<span class='warning'>[src] is set for instant detonation.</span>"
if(modifiable_timer)
. += "<span class='notice'>Use a screwdriver to modify the time on the fuze.</span>"
else
@@ -125,8 +125,4 @@
if(!HAS_TRAIT(src, TRAIT_CMAGGED))
return
REMOVE_TRAIT(src, TRAIT_CMAGGED, "cmagged grenade")
var/datum/component/bomberang = GetComponent(/datum/component/boomerang)
if(!bomberang)
return
bomberang.RemoveComponent()
qdel(bomberang)
DeleteComponent(/datum/component/boomerang)
+2 -1
View File
@@ -524,7 +524,8 @@
icon_state = "egg_hatched"
flick("egg_opening", src)
status = BURSTING
qdel(GetComponent(/datum/component/proximity_monitor))
DeleteComponent(/datum/component/proximity_monitor)
addtimer(CALLBACK(src, PROC_REF(hatch)), 1.5 SECONDS)
///We now check HOW the hugger is hatching, kill carried from Burst() and obj_break()
@@ -430,7 +430,8 @@ GLOBAL_LIST_EMPTY(telecomms_trap_tank)
/obj/structure/environmental_storytelling_holopad/proc/start_message(mob/living/carbon/human/H)
activated = TRUE
qdel(GetComponent(/datum/component/proximity_monitor))
DeleteComponent(/datum/component/proximity_monitor)
icon_state = "holopad1"
update_icon(UPDATE_OVERLAYS)
var/obj/effect/overlay/hologram = new(get_turf(src))
+2 -1
View File
@@ -90,7 +90,8 @@
saved.shoot_inventory = FALSE
saved.aggressive = FALSE
if(saved.tiltable)
qdel(saved.GetComponent(/datum/component/proximity_monitor))
saved.DeleteComponent(/datum/component/proximity_monitor)
if(originMachine)
originMachine.speak("I am... vanquished. My people will remem...ber...meeee.")
originMachine.visible_message("[originMachine] beeps and seems lifeless.")
@@ -203,7 +203,7 @@
icon_state = "[initial(icon_state)]_dead"
item_state = "facehugger_inactive"
stat = DEAD
qdel(GetComponent(/datum/component/proximity_monitor))
DeleteComponent(/datum/component/proximity_monitor)
visible_message("<span class='danger'>[src] curls up into a ball!</span>")
@@ -21,7 +21,7 @@
if(!mind)
return FALSE
if(mind.miming)
qdel(GetComponent(/datum/component/footstep))
DeleteComponent(/datum/component/footstep)
return TRUE
/**
@@ -413,7 +413,7 @@ While using this makes the system rely on OnFire, it still gives options for tim
text += "<span class='warning'>If teleported to the Station by jaunter, you are allowed to attack people on Station, until you get killed.</span>"
to_chat(mychild, text.Join(" "))
qdel(GetComponent(/datum/component/proximity_monitor))
DeleteComponent(/datum/component/proximity_monitor)
/obj/item/tumor_shard
name = "tumor shard"
+2 -2
View File
@@ -506,7 +506,7 @@
/obj/item/mod/module/energy_shield/on_suit_deactivation(deleting = FALSE)
var/datum/component/shielded/shield = mod.GetComponent(/datum/component/shielded)
charges = shield.current_charges
qdel(shield)
shield.RemoveComponent()
UnregisterSignal(mod.wearer, COMSIG_HUMAN_CHECK_SHIELDS)
/obj/item/mod/module/energy_shield/proc/shield_reaction(mob/living/carbon/human/owner,
@@ -581,7 +581,7 @@
return FALSE
var/datum/component/shielded/shield = mod.GetComponent(/datum/component/shielded)
charges = shield.current_charges
qdel(shield)
shield.RemoveComponent()
UnregisterSignal(mod.wearer, COMSIG_HUMAN_CHECK_SHIELDS)
REMOVE_TRAIT(mod.wearer, TRAIT_SHOCKIMMUNE, UNIQUE_TRAIT_SOURCE(src))
+2 -1
View File
@@ -38,7 +38,8 @@
/obj/item/mod/module/waddle/on_suit_deactivation(deleting = FALSE)
if(!deleting)
qdel(mod.boots.GetComponent(/datum/component/squeak))
mod.boots.DeleteComponent(/datum/component/squeak)
mod.wearer.RemoveElement(/datum/element/waddling)
//Boot heating - dries floors like galoshes/dry
@@ -514,8 +514,8 @@
if(M.mind?.assigned_role != "Clown")
REMOVE_TRAIT(M, TRAIT_COMIC_SANS, id)
M.RemoveElement(/datum/element/waddling)
qdel(M.GetComponent(/datum/component/squeak))
M.DeleteComponent(/datum/component/squeak)
/datum/reagent/royal_bee_jelly
name = "Royal bee jelly"