Skip to content

Commit

Permalink
Improves /datum/component/sticky code (ParadiseSS13#21836)
Browse files Browse the repository at this point in the history
* sticky code improvements

* we want it like this

* steel review

* Update code/datums/components/sticky.dm

Co-authored-by: Henri215 <[email protected]>

---------

Co-authored-by: SteelSlayer <[email protected]>
Co-authored-by: Henri215 <[email protected]>
  • Loading branch information
3 people authored Jul 31, 2023
1 parent fce54de commit aa655db
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions code/datums/components/sticky.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -59,19 +72,19 @@
/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)

var/obj/item/I = parent
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>")


Expand All @@ -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
Expand All @@ -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)

0 comments on commit aa655db

Please sign in to comment.