mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-02-07 14:59:13 +00:00
ELEMENT_DETACH is **not** a requirement to having `Detach` called. Detach is always called when the element itself is destroyed. ELEMENT_DETACH is a flag that when set, makes sure Detach is called when the atom destroys. Sometimes you want this, for instance: ```dm /datum/element/point_of_interest/Detach(datum/target) SSpoints_of_interest.on_poi_element_removed(target) return ..() ``` This Detach cleans up a reference that would have hung if target was destroyed without this being called. However, most uses of Detach are cleaning up signals. Signals are automatically cleaned up when something is destroyed. You do not need ELEMENT_DETACH in this case, and it slows down init. This also includes somewhat more complex stuff, like removing overlays on the source object. It's getting deleted anyway, you don't care! I have removed all uses of ELEMENT_DETACH that seemed superfluous. I have also renamed it to `ELEMENT_DETACH_ON_HOST_DESTROY` to make its purpose more clear, as me and a lot of other maintainers misunderstood what it did, --- An update to this, ELEMENT_DETACH *is* needed for anything that can register to a turf, as turfs do not clear their signals on destroy.
43 lines
1.3 KiB
Plaintext
43 lines
1.3 KiB
Plaintext
#define SHORT 5/7
|
|
#define TALL 7/5
|
|
|
|
/**
|
|
* squish.dm
|
|
*
|
|
* It's an element that squishes things. After the duration passes, it reverses the transformation it squished with, taking into account if they are a different orientation than they started (read: rotationally-fluid)
|
|
*
|
|
* Normal squishes apply vertically, as if the target is being squished from above, but you can set reverse to TRUE if you want to squish them from the sides, like if they pancake into a wall from the East or West
|
|
*/
|
|
/datum/element/squish
|
|
element_flags = ELEMENT_DETACH_ON_HOST_DESTROY
|
|
|
|
/datum/element/squish/Attach(datum/target, duration=20 SECONDS, reverse=FALSE)
|
|
. = ..()
|
|
if(!iscarbon(target))
|
|
return ELEMENT_INCOMPATIBLE
|
|
|
|
var/mob/living/carbon/C = target
|
|
var/was_lying = C.body_position == LYING_DOWN
|
|
addtimer(CALLBACK(src, .proc/Detach, C, was_lying, reverse), duration)
|
|
|
|
if(reverse)
|
|
C.transform = C.transform.Scale(SHORT, TALL)
|
|
else
|
|
C.transform = C.transform.Scale(TALL, SHORT)
|
|
|
|
/datum/element/squish/Detach(mob/living/carbon/C, was_lying, reverse)
|
|
. = ..()
|
|
if(istype(C))
|
|
var/is_lying = C.body_position == LYING_DOWN
|
|
|
|
if(reverse)
|
|
is_lying = !is_lying
|
|
|
|
if(was_lying == is_lying)
|
|
C.transform = C.transform.Scale(SHORT, TALL)
|
|
else
|
|
C.transform = C.transform.Scale(TALL, SHORT)
|
|
|
|
#undef SHORT
|
|
#undef TALL
|