mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-08-25 14:08:31 +01:00
Refactor for storage initialization & organization (#89543)
## About The Pull Request A Huge chunk of changes just comes from moving existing storage code into new files & seperating `atom_storage` code into its own subtype under the already existing `storage/subtypes` folder. With that the changes in this PR can be organized into 3 categories. **1. Refactors how `/obj/item/storage/PopulateContents()` initializes storages** - Fixes #88747 and every other storage item that has a similar variant of this problem The problem with `PopulateContents()` is that it allows you to create atoms directly inside the storage via `new(src)` thus bypassing all the access restrictions enforced by `/datum/storage/can_insert()` resulting in storages holding stuff they shouldn't be able to hold. Now how this proc works has been changed. It must now only return a list of items(each item in the list can either be a typepath or a solid atom or a mix of them in any order) that should be inserted into the storage. Each item is then passed into `can_insert()` to check if it can fit in the storage. If your list contains solid atoms they must be first moved to/Initialized in nullspace so `can_insert()` won't count it as already inserted. `can_insert()` has now also been refactored to throw stack traces but explaining exactly why the item could not fit in the storage thus giving you more debugging details to fix your stuff. A large majority of changes is refactoring `PopulateContents()` to return a list instead of simply creating the item in place so simple 1 line changes & with that we have fixed all broken storages(medical toolbox. electrical toolbox, cruisader armor boxes & many more) that hold more items they can handle **2. Organizes initialization of `atom_storage` for storage subtypes.** All subtypes of `/obj/item/storage` should(not enforced) create their own `/datum/storage/` subtype under the folder `storage/subtypes` if the default values are not sufficient. This is the 2nd change done across all existing storages Not only does this bring code cleanliness & organization (separating storage code from item code like how `/datum/wire` code is separated into its own sub folder) but it also makes storage initialization slightly faster (because you are not modifying default values after `atom_storage` is initialized but you are directly setting the default value in place). You now cannot & should not modify `atom_storage` values inside `PopulateContents()`. This will make that proc as pure as possible so less side effects. Of course this principle is not enforced and you can still modify the storage value after `Initialize()` but this should not be encouraged in the future **3. Adds support for automatic storage computations** Most people don't understand how `atom_storage` values work. The comment here clearly states that https://github.com/tgstation/tgstation/blob/55bbfef0da70d87455ca8d6fd5c95107eb8dbefb/code/game/objects/items/storage/toolbox.dm#L327-L329 Because of that the linked issue occurs not just for medical toolbox but for a lot of other items as well. Which is why if you do not know what you doing, `PopulateContents()` now comes with a new storage parameter i.e. `/datum/storage_config` This datum allows you to compute storage values that will perfectly fit with the initial contents of your storage. It allows you to do stuff like computing `max_slots`, `max_item_weight`, `max_total_weight` etc based on your storage initial contents so that all the contents can fit perfectly leaving no space for excess. ## Changelog 🆑 fix: storages are no longer initialized with items that can't be put back in after taking them out refactor: storage initialization has been refactored. Please report bugs on github /🆑
This commit is contained in:
@@ -112,4 +112,4 @@
|
||||
inhand_icon_state = "sec-case"
|
||||
|
||||
/obj/item/storage/briefcase/secure/digital_storage/PopulateContents()
|
||||
return
|
||||
return NONE
|
||||
|
||||
@@ -110,11 +110,13 @@
|
||||
illustration = "beaker"
|
||||
|
||||
/obj/item/storage/box/alchemist_basic_chems/PopulateContents()
|
||||
. = list()
|
||||
|
||||
for(var/i in 1 to 7)
|
||||
if(prob(1))
|
||||
new /obj/item/reagent_containers/cup/glass/coffee(src)
|
||||
. += /obj/item/reagent_containers/cup/glass/coffee
|
||||
continue
|
||||
new /obj/item/reagent_containers/cup/bottle/alchemist_basic(src)
|
||||
. += /obj/item/reagent_containers/cup/bottle/alchemist_basic
|
||||
|
||||
/obj/item/storage/box/alchemist_random_chems
|
||||
name = "box of potions"
|
||||
@@ -123,25 +125,28 @@
|
||||
illustration = "beaker"
|
||||
|
||||
/obj/item/storage/box/alchemist_random_chems/PopulateContents()
|
||||
. = list()
|
||||
|
||||
for(var/i in 1 to 7)
|
||||
if(prob(1))
|
||||
new /obj/item/reagent_containers/cup/glass/coffee(src)
|
||||
. += /obj/item/reagent_containers/cup/glass/coffee
|
||||
continue
|
||||
new /obj/item/reagent_containers/cup/bottle/alchemist_random(src)
|
||||
. += /obj/item/reagent_containers/cup/bottle/alchemist_random
|
||||
|
||||
/obj/item/storage/box/alchemist_chemistry_kit
|
||||
name = "box of alchemy tools"
|
||||
desc = "Contains everything needed for the up and coming chemistry student to enact hazardous chemical mishaps in the comfort of their own home."
|
||||
|
||||
/obj/item/storage/box/alchemist_chemistry_kit/PopulateContents()
|
||||
new /obj/item/reagent_containers/cup/mortar(src)
|
||||
new /obj/item/pestle(src)
|
||||
new /obj/item/lighter/skull(src)
|
||||
new /obj/item/ph_booklet(src)
|
||||
new /obj/item/thermometer(src)
|
||||
new /obj/item/storage/test_tube_rack/full(src)
|
||||
new /obj/item/reagent_containers/cup/glass/coffee(src)
|
||||
|
||||
return list(
|
||||
/obj/item/reagent_containers/cup/mortar,
|
||||
/obj/item/pestle,
|
||||
/obj/item/lighter/skull,
|
||||
/obj/item/ph_booklet,
|
||||
/obj/item/thermometer,
|
||||
/obj/item/storage/test_tube_rack/full,
|
||||
/obj/item/reagent_containers/cup/glass/coffee,
|
||||
)
|
||||
|
||||
/datum/bitrunning_gimmick/rogue
|
||||
name = "Rogue"
|
||||
@@ -173,10 +178,11 @@
|
||||
name = "fannypack of ULTIMATE DESPAIR"
|
||||
|
||||
/obj/item/storage/belt/fannypack/black/rogue/PopulateContents()
|
||||
new /obj/item/food/drug/saturnx(src)
|
||||
new /obj/item/reagent_containers/cup/blastoff_ampoule(src)
|
||||
new /obj/item/reagent_containers/hypospray/medipen/methamphetamine(src)
|
||||
|
||||
return list(
|
||||
/obj/item/food/drug/saturnx,
|
||||
/obj/item/reagent_containers/cup/blastoff_ampoule,
|
||||
/obj/item/reagent_containers/hypospray/medipen/methamphetamine,
|
||||
)
|
||||
|
||||
/datum/bitrunning_gimmick/healer
|
||||
name = "Healer"
|
||||
|
||||
@@ -50,13 +50,13 @@
|
||||
/obj/item/reagent_containers/cup/soda_cans/space_mountain_wind = 50,
|
||||
/obj/item/reagent_containers/cup/soda_cans/monkey_energy = 30,
|
||||
/obj/item/reagent_containers/cup/soda_cans/volt_energy = 15,
|
||||
/obj/item/reagent_containers/cup/soda_cans/thirteenloko = 5,
|
||||
/obj/item/reagent_containers/cup/soda_cans/thirteenloko = 5,
|
||||
)
|
||||
|
||||
/obj/item/storage/cans/sixenergydrink/PopulateContents()
|
||||
. = list()
|
||||
for(var/i in 1 to 6)
|
||||
var/obj/item/chosen_energy_drink = pick_weight(energy_drink_options)
|
||||
new chosen_energy_drink(src)
|
||||
. += pick_weight(energy_drink_options)
|
||||
|
||||
|
||||
/datum/bitrunning_gimmick/archer
|
||||
@@ -70,23 +70,6 @@
|
||||
/obj/item/ammo_casing/arrow/holy/blazing,
|
||||
)
|
||||
|
||||
/obj/item/storage/bag/quiver/endless
|
||||
name = "endless quiver"
|
||||
desc = "Holds arrows for your bow. A deep digital void is contained within."
|
||||
max_slots = 1
|
||||
|
||||
/obj/item/storage/bag/quiver/endless/Initialize(mapload)
|
||||
. = ..()
|
||||
RegisterSignal(src, COMSIG_ATOM_EXITED, PROC_REF(handle_removed))
|
||||
|
||||
/obj/item/storage/bag/quiver/endless/PopulateContents()
|
||||
. = ..()
|
||||
new arrow_path(src)
|
||||
|
||||
/obj/item/storage/bag/quiver/endless/proc/handle_removed(datum/source, obj/item/gone)
|
||||
new arrow_path(src)
|
||||
|
||||
|
||||
/datum/bitrunning_gimmick/fisher
|
||||
name = "Fisher"
|
||||
|
||||
@@ -125,13 +108,13 @@
|
||||
/obj/item/reagent_containers/cup/soda_cans/space_mountain_wind = 15,
|
||||
/obj/item/reagent_containers/cup/soda_cans/monkey_energy = 15,
|
||||
/obj/item/reagent_containers/cup/soda_cans/volt_energy = 10,
|
||||
/obj/item/reagent_containers/cup/soda_cans/thirteenloko = 5,
|
||||
/obj/item/reagent_containers/cup/soda_cans/thirteenloko = 5,
|
||||
)
|
||||
|
||||
/obj/item/storage/cans/sixgamerdrink/PopulateContents()
|
||||
. = list()
|
||||
for(var/i in 1 to 6)
|
||||
var/obj/item/chosen_gamer_drink = pick_weight(gamer_drink_options)
|
||||
new chosen_gamer_drink(src)
|
||||
. += pick_weight(gamer_drink_options)
|
||||
|
||||
/obj/item/modular_computer/laptop/gamer
|
||||
desc = "A high-end laptop often used for metagaming."
|
||||
|
||||
@@ -23,6 +23,8 @@
|
||||
/obj/item/storage/lockbox/bitrunning/decrypted
|
||||
name = "decrypted curiosity"
|
||||
desc = "Compiled from the virtual domain. An extra reward of a successful bitrunner."
|
||||
storage_type = /datum/storage/lockbox/bitrunning
|
||||
|
||||
/// What virtual domain did we come from.
|
||||
var/datum/lazy_template/virtual_domain/source_domain
|
||||
|
||||
@@ -42,13 +44,8 @@
|
||||
source_domain = completed_domain
|
||||
|
||||
. = ..()
|
||||
atom_storage.max_specific_storage = WEIGHT_CLASS_NORMAL
|
||||
atom_storage.max_slots = 1
|
||||
atom_storage.max_total_storage = 3
|
||||
atom_storage.locked = STORAGE_NOT_LOCKED
|
||||
icon_state = icon_closed
|
||||
|
||||
playsound(src, 'sound/effects/magic/blink.ogg', 50, TRUE)
|
||||
|
||||
/obj/item/storage/lockbox/bitrunning/decrypted/PopulateContents()
|
||||
var/choice = SSbitrunning.pick_secondary_loot(source_domain)
|
||||
new choice(src)
|
||||
return SSbitrunning.pick_secondary_loot(source_domain)
|
||||
|
||||
Reference in New Issue
Block a user