Files
Bubberstation/code/datums/elements/openspace_item_click_handler.dm
SkyratBot a55591a09a [MIRROR] Makes it easier to place tiles on multi-z holes [MDB IGNORE] (#23381)
* Makes it easier to place tiles on multi-z holes (#77935)

## About The Pull Request
Adds the "open space click handler" to tile stacks, which makes it so
you don't have to pixel hunt for a turf on the BELOW z level in order to
fix a hole.
This exists on rods and rpds since they're often used to fix holes.
But wasn't added to tiles when they were made to be able to fix holes
directly, without rods.

Additionally, closes #77540 by having the open space click handler loop
up z levels so that it works if you're clicking on items from multiple z
levels away.
## Why It's Good For The Game
The current behavior can be very frustrating to work around, and appears
to not be intended.
## Changelog
🆑
fix: Made it easier to place tiles on multi z level holes
/🆑

* Makes it easier to place tiles on multi-z holes

---------

Co-authored-by: FlufflesTheDog <piecopresident@gmail.com>
2023-08-28 01:57:23 -04:00

30 lines
1.1 KiB
Plaintext

/**
* allow players to easily use items such as iron rods, rcds on open space without
* having to pixelhunt for portions not occupied by object or mob visuals.
*/
/datum/element/openspace_item_click_handler
/datum/element/openspace_item_click_handler/Attach(datum/target)
. = ..()
if(!isitem(target))
return ELEMENT_INCOMPATIBLE
RegisterSignal(target, COMSIG_ITEM_AFTERATTACK, PROC_REF(on_afterattack))
/datum/element/openspace_item_click_handler/Detach(datum/source)
UnregisterSignal(source, COMSIG_ITEM_AFTERATTACK)
return ..()
//Invokes the proctype with a turf above as target.
/datum/element/openspace_item_click_handler/proc/on_afterattack(obj/item/source, atom/target, mob/user, proximity_flag, click_parameters)
SIGNAL_HANDLER
if(target.z == user.z)
return
var/turf/checked_turf = get_turf(target)
while(!isnull(checked_turf))
checked_turf = checked_turf.above()
if(checked_turf?.z == user.z)
INVOKE_ASYNC(source, TYPE_PROC_REF(/obj/item, handle_openspace_click), checked_turf, user, user.CanReach(checked_turf, source), click_parameters)
break
return COMPONENT_AFTERATTACK_PROCESSED_ITEM