Tsu's Brand Spanking New Storage: or, How I Learned To Pass Github Copilot As My Own Code (#67478)

Currently, storage works as a subtype of /datum/component, utilizing GetComponent() and signals to operate. While this is a pretty good idea in theory, the execution was pretty trash, and we end up with alot of GetComponent() snowflake code (something that shouldn't even need to be used frankly), and a heaping load of scattered procs that lead into one another, and procs that don't get utilized properly.

Instead, this PR adds atom_storage and proc/create_storage(. . .) to every atom, allowing for the possibility of storage on quite frankly anything. Not only does this entirely remove the need for signals, but it heavily squashes down the number of needed procs in total (removing snowflake signal procs that just lead to one another), reducing overall proc overhead and improving performance.
This commit is contained in:
magatsuchi
2022-07-08 18:13:18 -07:00
committed by GitHub
parent 944eb14541
commit 7d0f393f5d
133 changed files with 2056 additions and 2358 deletions
+2 -2
View File
@@ -450,7 +450,7 @@
old_size = null
if(!mod.loc)
return
var/datum/component/storage/holding_storage = mod.loc.GetComponent(/datum/component/storage)
if(!holding_storage || holding_storage.max_w_class >= mod.w_class)
var/datum/storage/holding_storage = mod.loc.atom_storage
if(!holding_storage || holding_storage.max_specific_storage >= mod.w_class)
return
mod.forceMove(drop_location())
+11 -20
View File
@@ -8,8 +8,6 @@
icon_state = "storage"
complexity = 3
incompatible_modules = list(/obj/item/mod/module/storage, /obj/item/mod/module/plate_compression)
/// The storage component of the module.
var/datum/component/storage/concrete/storage
/// Max weight class of items in the storage.
var/max_w_class = WEIGHT_CLASS_NORMAL
/// Max combined weight of all items in the storage.
@@ -19,35 +17,28 @@
/obj/item/mod/module/storage/Initialize(mapload)
. = ..()
storage = AddComponent(/datum/component/storage/concrete)
storage.max_w_class = max_w_class
storage.max_combined_w_class = max_combined_w_class
storage.max_items = max_items
storage.allow_big_nesting = TRUE
SEND_SIGNAL(src, COMSIG_TRY_STORAGE_SET_LOCKSTATE, TRUE)
create_storage(max_specific_storage = max_w_class, max_total_storage = max_combined_w_class, max_slots = max_items)
atom_storage.allow_big_nesting = TRUE
atom_storage.locked = TRUE
/obj/item/mod/module/storage/on_install()
var/datum/component/storage/modstorage = mod.AddComponent(/datum/component/storage, storage)
modstorage.max_w_class = max_w_class
modstorage.max_combined_w_class = max_combined_w_class
modstorage.max_items = max_items
SEND_SIGNAL(src, COMSIG_TRY_STORAGE_SET_LOCKSTATE, FALSE)
RegisterSignal(mod.chestplate, COMSIG_ITEM_PRE_UNEQUIP, .proc/on_chestplate_unequip)
var/datum/storage/modstorage = mod.create_storage(max_specific_storage = max_w_class, max_total_storage = max_combined_w_class, max_slots = max_items)
modstorage.set_real_location(src)
atom_storage.locked = FALSE
/obj/item/mod/module/storage/on_uninstall(deleting = FALSE)
var/datum/component/storage/modstorage = mod.GetComponent(/datum/component/storage)
storage.slaves -= modstorage
var/datum/storage/modstorage = mod.atom_storage
atom_storage.locked = TRUE
qdel(modstorage)
UnregisterSignal(mod.chestplate, COMSIG_ITEM_PRE_UNEQUIP)
if(!deleting)
SEND_SIGNAL(src, COMSIG_TRY_STORAGE_QUICK_EMPTY, drop_location())
SEND_SIGNAL(src, COMSIG_TRY_STORAGE_SET_LOCKSTATE, TRUE)
atom_storage.remove_all(get_turf(src))
UnregisterSignal(mod.chestplate, COMSIG_ITEM_PRE_UNEQUIP)
/obj/item/mod/module/storage/proc/on_chestplate_unequip(obj/item/source, force, atom/newloc, no_move, invdrop, silent)
if(QDELETED(source) || !mod.wearer || newloc == mod.wearer || !mod.wearer.s_store)
return
to_chat(mod.wearer, span_notice("[src] tries to store [mod.wearer.s_store] inside itself."))
SEND_SIGNAL(src, COMSIG_TRY_STORAGE_INSERT, mod.wearer.s_store, mod.wearer, TRUE)
atom_storage?.attempt_insert(src, mod.wearer.s_store, mod.wearer, TRUE)
/obj/item/mod/module/storage/large_capacity
name = "MOD expanded storage module"