Files
SyncIt21 f640a0e972 Enhances algorithm for finding an atom mount (#94076)
## About The Pull Request
Depends on #94064 for the unit test but offers a better method for
finding an atom to mount on
- Finding a mount now takes into consideration the objects pixel x & y
offsets meaning diagonal mounting is now supported. Gives great
flexibility for mappers
- If you don't want to use pixel offsets but default back to using the
objects direction that behaviour is still preserved. Useful if your
object uses directional icon states(lights & cameras for now) AND don't
use offsets
- If no direction could be specified then as the last resort it defaults
back to the objects local turf for mounting

## Changelog
🆑
fix: all mounted objects on tables, fences, windows & walls should fall
of correctly when the atom it is placed on is destroyed
fix: security telescreen now falls off when their mounted wall is
destroyed
fix: defib wall mount falls off when their mounted wall is destroyed
fix: floor lights are mounted to the ground/catwalk/tram floor they are
sitting on meaning destroying it will destroy the light
fix: wall mounted plaques now fall off when their mounted wall is
destroyed
/🆑
2025-12-12 12:23:22 -05:00

30 lines
1.6 KiB
Plaintext

/// Ensures wallmouted objects prioritize walls over other mountable objects like tables
/datum/unit_test/wallmount
/datum/unit_test/wallmount/Run()
//Test 1 light must priotize wall and not table
var/obj/structure/table/test_table = EASY_ALLOCATE()
var/obj/machinery/light/directional/south/test_light = EASY_ALLOCATE()
test_light.find_and_mount_on_atom()
var/datum/component/atom_mounted/wallmount_component = test_light.GetComponent(/datum/component/atom_mounted)
TEST_ASSERT_NOTNULL(wallmount_component, "[test_light.type] failed to mount")
TEST_ASSERT_NOTEQUAL(wallmount_component.hanging_support_atom, test_table, "[test_light.type] failed to mount on wall!")
//Test 2 button must mount on table not wall
var/obj/machinery/button/test_button = EASY_ALLOCATE()
test_button.find_and_mount_on_atom()
wallmount_component = test_button.GetComponent(/datum/component/atom_mounted)
TEST_ASSERT_NOTNULL(wallmount_component, "[test_button.type] 0 offsets failed to mount!")
TEST_ASSERT_EQUAL(wallmount_component.hanging_support_atom, test_table, "[test_button.type] 0 offsets failed to mount on table!")
//Test 3 button must mount on wall not table because it now uses offsets
test_button = allocate(/obj/machinery/button, run_loc_floor_top_right)
test_button.pixel_y = 24
test_button.find_and_mount_on_atom()
wallmount_component = test_button.GetComponent(/datum/component/atom_mounted)
TEST_ASSERT_NOTNULL(wallmount_component, "[test_button.type] 24y offsets failed to mount!")
TEST_ASSERT(isindestructiblewall(wallmount_component.hanging_support_atom), "[test_button.type] 24y offsets failed to mount on wall!")