Files
Bubberstation/code/modules/unit_tests/holder_loving.dm
SyncIt21 fd7c75b590 Refactor for drone holder loving component (#87239)
## About The Pull Request
Refactors `/datum/component/holderloving` as a whole. It was registering
a lot of unnecessary signals and was doing too much in general(vars like
`can_transfer` simply isn't required)

Fixes
https://github.com/tgstation/tgstation/pull/87131#issuecomment-2403284265
properly by adding an extra `newloc` argument to
`temporarilyRemoveItemFromInventory()` which simply hints where we want
to move the object without actually removing it from the player.

Using this argument we can fix camera assembly construction code because
we now hint we want to move the gas analyzer into the camera and the
signal handler code for drones can correctly check for locs

## Changelog
🆑
refactor: cleaned up how drone holds their tools from the toolbox.
report bugs on github
/🆑
2024-10-25 01:57:48 +02:00

32 lines
1.9 KiB
Plaintext

/datum/unit_test/holder_loving
/datum/unit_test/holder_loving/Run()
var/mob/living/carbon/human/consistent/person = allocate(/mob/living/carbon/human/consistent)
var/obj/item/storage/backpack/duffelbag/bag = allocate(/obj/item/storage/backpack/duffelbag)
var/obj/item/storage/backpack/duffelbag/testbag = allocate(/obj/item/storage/backpack/duffelbag)
var/obj/item/wrench/tool = allocate(/obj/item/wrench)
//put wrench in bag & equip bag on human
tool.AddComponent(/datum/component/holderloving, bag)
bag.atom_storage.attempt_insert(tool, person, messages = FALSE)
person.equip_to_slot_if_possible(bag, ITEM_SLOT_BACK)
//Test 1: Should be able to move wrench from bag to hand
person.putItemFromInventoryInHandIfPossible(tool, 1)
TEST_ASSERT_EQUAL(person.get_item_for_held_index(1), tool, "Holder loving component blocked equiping wrench from storage into hand!")
//Test 2: Should be able to swap the item between hands
person.swap_hand(2, silent = TRUE)
tool.attempt_pickup(person)
TEST_ASSERT_EQUAL(person.get_item_for_held_index(2), tool, "Holder loving component blocked swapping the wrench into the other hand!")
//Test 3: Upon dropping the item onto the ground it should move back into the bag
person.dropItemToGround(tool, silent = TRUE)
TEST_ASSERT_NOTNULL(locate(/obj/item/wrench) in bag, "Holder loving component did not move the wrench back into storage upon dropping!")
//Test 4: Should not be able to move the wrench into any other atom besides its holder
TEST_ASSERT(!person.transferItemToLoc(tool, testbag), "Holder loving component failed to block moving the wrench into another atom that isn't the holder!")
//Test 5: Should fail at the signal checks
TEST_ASSERT(!person.temporarilyRemoveItemFromInventory(tool, newloc = testbag), "Holder loving component failed to block temporarily removing wrench and moving it into another atom that isn't the holder!")