From 5e671acf046a2bb35a08ee72d56fd106615d2816 Mon Sep 17 00:00:00 2001 From: ShadowLarkens Date: Fri, 21 May 2021 20:05:25 -0700 Subject: [PATCH] Build all vending machine inventories on startup (cursed) --- code/modules/asset_cache/asset_list_items.dm | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/code/modules/asset_cache/asset_list_items.dm b/code/modules/asset_cache/asset_list_items.dm index 815d250dcc7..9bd72d824e1 100644 --- a/code/modules/asset_cache/asset_list_items.dm +++ b/code/modules/asset_cache/asset_list_items.dm @@ -359,6 +359,7 @@ name = "vending" /datum/asset/spritesheet/vending/register() + populate_vending_products() for(var/k in GLOB.vending_products) var/atom/item = k if(!ispath(item, /atom)) @@ -406,6 +407,22 @@ Insert(imgid, I) return ..() +// this is cursed but necessary or else vending product icons can be missing +// basically, if there's any vending machines that aren't already mapped in, our register() will not know +// that they exist, and therefore can't generate the entries in the spritesheet for them +// and since assets are unique and can't be reloaded later, we have to make sure that GLOB.vending_products +// is populated with every single type of vending machine +// As this is only done at runtime, we have to create all the vending machines in existence and force them +// to register their products when this asset initializes. +/datum/asset/spritesheet/vending/proc/populate_vending_products() + SSatoms.map_loader_begin() + for(var/path in subtypesof(/obj/machinery/vending)) + var/obj/machinery/vending/x = new path(null) + // force an inventory build; with map_loader_begin active, init isn't called + x.build_inventory() + qdel(x) + SSatoms.map_loader_stop() + // /datum/asset/simple/genetics // assets = list( // "dna_discovered.gif" = 'html/dna_discovered.gif',