Files
Bubberstation/code/datums/elements/mirage_border.dm
T
LucyandGitHub 2ee02682f7 Converts most other usages of block() to x/y/z format (#89290)
## About The Pull Request

The sequel to https://github.com/tgstation/tgstation/pull/89234

> someone should do the rest at some point

guess what, I'm that someone :3

## Why It's Good For The Game

Same reasoning as the previous PR:

> less cluttered code is nice, and it should in theory be more optimized
as we avoid the need to run min, max, and locate.

## Changelog

No user-facing changes
2025-02-07 02:44:10 +01:00

43 lines
1.5 KiB
Plaintext

/**
* Creates a mirage effect allowing you to see around the world border, by adding the opposite side to its vis_contents.
*/
/datum/element/mirage_border
/datum/element/mirage_border/Attach(datum/target, turf/target_turf, direction, range=world.view)
. = ..()
if(!isturf(target))
return ELEMENT_INCOMPATIBLE
#ifdef TESTING
// This is a highly used proc, and these error states never occur, so limit it to testing.
// If something goes wrong it will runtime anyway.
if(!target_turf || !istype(target_turf) || !direction)
stack_trace("[type] improperly attached with the following args: target=\[[target_turf]\], direction=\[[direction]\], range=\[[range]\]")
return ELEMENT_INCOMPATIBLE
#endif
var/atom/movable/mirage_holder/holder = new(target)
var/x = target_turf.x
var/y = target_turf.y
var/z = clamp(target_turf.z, 1, world.maxz)
holder.vis_contents += block(
x - (direction & WEST ? range : 0), y - (direction & SOUTH ? range : 0), z,
x + (direction & EAST ? range : 0), y + (direction & NORTH ? range : 0), z
)
if(direction & SOUTH)
holder.pixel_y -= ICON_SIZE_Y * range
if(direction & WEST)
holder.pixel_x -= ICON_SIZE_X * range
/datum/element/mirage_border/Detach(atom/movable/target)
. = ..()
var/atom/movable/mirage_holder/held = locate() in target.contents
if(held)
qdel(held)
INITIALIZE_IMMEDIATE(/atom/movable/mirage_holder)
// Using /atom/movable because this is a heavily used path
/atom/movable/mirage_holder
name = "Mirage holder"
mouse_opacity = MOUSE_OPACITY_TRANSPARENT