mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2025-12-10 17:52:36 +00:00
* Del The World: Unit testing for hard deletes (#59612) Co-authored-by: SteelSlayer <42044220+SteelSlayer@ users.noreply.github.com> * Del The World: Unit testing for hard deletes Co-authored-by: LemonInTheDark <58055496+LemonInTheDark@users.noreply.github.com> Co-authored-by: SteelSlayer <42044220+SteelSlayer@ users.noreply.github.com>
32 lines
1.1 KiB
Plaintext
32 lines
1.1 KiB
Plaintext
/// Movables with this component will automatically return to their original turf if moved outside their initial area
|
|
/datum/component/areabound
|
|
var/area/bound_area
|
|
var/turf/reset_turf
|
|
var/datum/movement_detector/move_tracker
|
|
var/moving = FALSE //Used to prevent infinite recursion if your reset turf places you somewhere on enter or something
|
|
|
|
/datum/component/areabound/Initialize()
|
|
if(!ismovable(parent))
|
|
return COMPONENT_INCOMPATIBLE
|
|
bound_area = get_area(parent)
|
|
reset_turf = get_turf(parent)
|
|
move_tracker = new(parent,CALLBACK(src,.proc/check_bounds))
|
|
|
|
/datum/component/areabound/proc/check_bounds()
|
|
var/atom/movable/AM = parent
|
|
var/area/current = get_area(AM)
|
|
if(current != bound_area)
|
|
if(!reset_turf || reset_turf.loc != bound_area)
|
|
stack_trace("Invalid areabound configuration") //qdel(src)
|
|
return
|
|
if(moving)
|
|
stack_trace("Moved during a reset move, giving up to prevent infinite recursion. Turf: [reset_turf.type] at [reset_turf.x], [reset_turf.y], [reset_turf.z]")
|
|
return
|
|
moving = TRUE
|
|
AM.forceMove(reset_turf)
|
|
moving = FALSE
|
|
|
|
/datum/component/areabound/Destroy(force, silent)
|
|
QDEL_NULL(move_tracker)
|
|
. = ..()
|