Files
Bubberstation/code/datums/components/temporary_body.dm
LemonInTheDark ae5a4f955d Pulls apart the vestiges of components still hanging onto signals (#75914)
## About The Pull Request

Signals were initially only usable with component listeners, which while
no longer the case has lead to outdated documentation, names, and a
similar location in code.

This pr pulls the two apart. Partially because mso thinks we should, but
also because they really aren't directly linked anymore, and having them
in this midstate just confuses people.

[Renames comp_lookup to listen_lookup, since that's what it
does](102b79694f)

[Moves signal procs over to their own
file](33d07d01fd)

[Renames the PREQDELETING and QDELETING comsigs to drop the parent bit
since they can hook to more then just comps
now](335ea4ad08)

[Does something similar to the attackby comsigs (PARENT ->
ATOM)](210e57051d)

[And finally passes over the examine
signals](65917658fb)

## Why It's Good For The Game

Code makes more sense, things are better teased apart, s just good imo

## Changelog
🆑
refactor: Pulled apart the last vestiges of names/docs directly linking
signals to components
/🆑
2023-06-09 06:14:31 +00:00

56 lines
1.9 KiB
Plaintext

/**
* ##temporary_body
*
* Used on living mobs when they are meant to be a 'temporary body'
* Holds a reference to an old mind & body, to put them back in
* once the body this component is attached to, is being deleted.
*/
/datum/component/temporary_body
///The old mind we will be put back into when parent is being deleted.
var/datum/weakref/old_mind_ref
///The old body we will be put back into when parent is being deleted.
var/datum/weakref/old_body_ref
/datum/component/temporary_body/Initialize(datum/mind/old_mind, mob/living/old_body)
if(!isliving(parent) || !isliving(old_body))
return COMPONENT_INCOMPATIBLE
ADD_TRAIT(old_body, TRAIT_MIND_TEMPORARILY_GONE, REF(src))
src.old_mind_ref = WEAKREF(old_mind)
src.old_body_ref = WEAKREF(old_body)
/datum/component/temporary_body/RegisterWithParent()
RegisterSignal(parent, COMSIG_QDELETING, PROC_REF(on_parent_destroy))
/datum/component/temporary_body/UnregisterFromParent()
UnregisterSignal(parent, COMSIG_QDELETING)
/**
* Sends the mind of the temporary body back into their previous host
* If the previous host is alive, we'll force them into the body.
* Otherwise we'll let them hang out as a ghost still.
*/
/datum/component/temporary_body/proc/on_parent_destroy()
SIGNAL_HANDLER
var/datum/mind/old_mind = old_mind_ref?.resolve()
var/mob/living/old_body = old_body_ref?.resolve()
if(!old_mind || !old_body)
return
var/mob/living/living_parent = parent
var/mob/dead/observer/ghost = living_parent.ghostize()
if(!ghost)
ghost = living_parent.get_ghost()
if(!ghost)
CRASH("[src] belonging to [parent] was completely unable to find a ghost to put back into a body!")
ghost.mind = old_mind
if(old_body.stat != DEAD)
old_mind.transfer_to(old_body, force_key_move = TRUE)
else
old_mind.set_current(old_body)
REMOVE_TRAIT(old_body, TRAIT_MIND_TEMPORARILY_GONE, REF(src))
old_mind = null
old_body = null