Files
Bubberstation/code/modules/unit_tests/storage.dm
MrMelbert 0dc6b71a87 Change setting item weight class to a setter to patch some weight class related shenanigans (#82494)
## About The Pull Request

Fixes #81052 
Fixes #58008

Setting weight class of items is now done via `update_weight_class`.

I updated as many occurrences of manually setting `w_class` as I could
find but I may have missed some. Let me know if you know of any I
missed.

This is done to allow datums to react to an item having its weight class
changed.

Humans and atom storage are two such datums which now react to having an
item in its contents change weight class, to allow it to expel items
that grow to a weight class beyond what is normally allowed.

## Changelog

🆑 Melbert
fix: You can't fit items which are normally too large for a storage by
fitting it in the storage when it is small, then growing it to a larger
size.
/🆑
2024-04-08 19:01:30 -06:00

23 lines
1.1 KiB
Plaintext

/// Test storage datums
/datum/unit_test/storage
/datum/unit_test/storage/Run()
var/obj/item/big_thing = allocate(__IMPLIED_TYPE__, run_loc_floor_bottom_left)
big_thing.w_class = WEIGHT_CLASS_BULKY
var/obj/item/small_thing = allocate(__IMPLIED_TYPE__, run_loc_floor_bottom_left)
small_thing.w_class = WEIGHT_CLASS_SMALL
var/obj/item/storage/backpack/storage_item = allocate(__IMPLIED_TYPE__, run_loc_floor_bottom_left)
storage_item.atom_storage.attempt_insert(big_thing)
TEST_ASSERT_NOTEQUAL(big_thing.loc, storage_item, "A bulky item should have failed to insert into a backpack")
storage_item.atom_storage.attempt_insert(small_thing)
TEST_ASSERT_EQUAL(small_thing.loc, storage_item, "A small item should have successfully inserted into a backpack")
small_thing.update_weight_class(WEIGHT_CLASS_NORMAL)
TEST_ASSERT_EQUAL(small_thing.loc, storage_item, "A small item changed into normal size should not have ejected from the backpack")
small_thing.update_weight_class(WEIGHT_CLASS_BULKY)
TEST_ASSERT_NOTEQUAL(small_thing.loc, storage_item, "A small item changed back into bulky size should have ejected from the backpack")