Improves /datum/component/sticky code (#21836)

* sticky code improvements

* we want it like this

* steel review

* Update code/datums/components/sticky.dm

Co-authored-by: Henri215 <77684085+Henri215@users.noreply.github.com>

---------

Co-authored-by: SteelSlayer <42044220+SteelSlayer@users.noreply.github.com>
Co-authored-by: Henri215 <77684085+Henri215@users.noreply.github.com>
This commit is contained in:
Contrabang
2023-07-31 15:36:46 -04:00
committed by GitHub
parent fce54deb01
commit aa655db473
+21 -7
View File
@@ -9,12 +9,25 @@
/datum/component/sticky/Initialize(_drop_on_attached_destroy = FALSE)
if(!isitem(parent))
stack_trace("/datum/component/sticky's parent is not an item, its [parent.type]")
return COMPONENT_INCOMPATIBLE
drop_on_attached_destroy = _drop_on_attached_destroy
/datum/component/sticky/Destroy(force, silent)
// we dont want the falling off visible message if this component is getting destroyed because parent is getting destroyed
if(!QDELETED(parent) && isitem(parent) && attached_to)
var/obj/item/I = parent
I.visible_message("<span class='notice'>[parent] falls off of [attached_to].</span>")
pick_up(parent)
move_to_the_thing(parent, get_turf(parent))
return ..()
/datum/component/sticky/RegisterWithParent()
RegisterSignal(parent, COMSIG_ITEM_PRE_ATTACK, PROC_REF(stick_to_it))
/datum/component/sticky/UnregisterFromParent()
UnregisterSignal(parent, COMSIG_ITEM_PRE_ATTACK)
/datum/component/sticky/proc/stick_to_it(obj/item/I, atom/target, mob/user, params)
SIGNAL_HANDLER
if(!in_range(I, target))
@@ -59,10 +72,10 @@
/datum/component/sticky/proc/pick_up(atom/A, mob/living/carbon/human/user)
SIGNAL_HANDLER
if(!attached_to)
CRASH("/datum/component/sticky/proc/pick_up was called, but without an attached atom")
if(user && user.a_intent != INTENT_GRAB)
return
if(user.a_intent != INTENT_GRAB)
return
if(user.get_active_hand())
if(user && user.get_active_hand())
return
attached_to.cut_overlay(overlay, priority = TRUE)
@@ -70,8 +83,8 @@
I.pixel_x = initial(I.pixel_x)
I.pixel_y = initial(I.pixel_y)
move_to_the_thing(parent)
INVOKE_ASYNC(user, TYPE_PROC_REF(/mob, put_in_hands), I)
if(user)
INVOKE_ASYNC(user, TYPE_PROC_REF(/mob, put_in_hands), I)
to_chat(user, "<span class='notice'>You take [parent] off of [attached_to].</span>")
@@ -90,8 +103,7 @@
/datum/component/sticky/proc/on_move(datum/source, oldloc, move_dir)
SIGNAL_HANDLER
if(!attached_to)
stack_trace("/datum/component/sticky was called on_move, but without an attached atom")
return
CRASH("/datum/component/sticky/proc/on_move was called, but without an attached atom")
move_to_the_thing(parent)
/datum/component/sticky/process() // because sometimes the item can move inside something, like a crate
@@ -118,4 +130,6 @@
return // only items should be able to have the sticky component
if(!target)
target = get_turf(attached_to)
if(!target)
CRASH("/datum/component/sticky/proc/move_to_the_thing was called without a viable target")
INVOKE_ASYNC(I, TYPE_PROC_REF(/atom/movable, forceMove), target)