From 1b477db9049fa70824ccb6194020c14b83acebbf Mon Sep 17 00:00:00 2001 From: Tigercat2000 Date: Mon, 16 Nov 2015 14:21:05 -0800 Subject: [PATCH] Global DatumRefLists cleanup x1 Changelog: - Switched surgeries to use init_subtypes() - Updated init_subtypes() - Made the species race_key handling a bit less line-taking (uses pre-increment now) - Added new proc, init_datum_subtypes, which takes 4 arguments- init_datum_subtypes(prototype, list/L, list/pexempt, assocvar) prototype is a path which will be run through subtypesof list/L is the list that new datums will be added to pexempt is subtracted from the 'subtypesof(prototype)' (exempting them) assocvar is the var to associate by in the list- uses vars[] lookup Jobs, superheroes, and languages now use this proc. --- code/__HELPERS/global_lists.dm | 55 ++++++++++++++-------------------- 1 file changed, 22 insertions(+), 33 deletions(-) diff --git a/code/__HELPERS/global_lists.dm b/code/__HELPERS/global_lists.dm index 00faf1864f9..3773d69f3a2 100644 --- a/code/__HELPERS/global_lists.dm +++ b/code/__HELPERS/global_lists.dm @@ -15,32 +15,12 @@ //socks init_sprite_accessory_subtypes(/datum/sprite_accessory/socks, socks_list, socks_m, socks_f) - - - var/list/paths - //Surgery Steps - Initialize all /datum/surgery_step into a list - paths = subtypesof(/datum/surgery_step) - for(var/T in paths) - var/datum/surgery_step/S = new T - surgery_steps += S + init_subtypes(/datum/surgery_step, surgery_steps) sort_surgeries() - //List of job. I can't believe this was calculated multiple times per tick! - paths = subtypesof(/datum/job) -list(/datum/job/ai,/datum/job/cyborg) - for(var/T in paths) - var/datum/job/J = new T - joblist[J.title] = J - - paths = subtypesof(/datum/superheroes) - for(var/T in paths) - var/datum/superheroes/S = new T - all_superheroes[S.name] = S - - //Languages and species. - paths = subtypesof(/datum/language) - for(var/T in paths) - var/datum/language/L = new T - all_languages[L.name] = L + init_datum_subtypes(/datum/job, joblist, list(/datum/job/ai, /datum/job/cyborg), "title") + init_datum_subtypes(/datum/superheroes, all_superheroes, null, "name") + init_datum_subtypes(/datum/language, all_languages, null, "name") for (var/language_name in all_languages) var/datum/language/L = all_languages[language_name] @@ -49,19 +29,17 @@ language_keys[".[lowertext(L.key)]"] = L language_keys["#[lowertext(L.key)]"] = L + var/list/paths = subtypesof(/datum/species) var/rkey = 0 - paths = subtypesof(/datum/species) for(var/T in paths) - rkey++ var/datum/species/S = new T - S.race_key = rkey //Used in mob icon caching. + S.race_key = ++rkey //Used in mob icon caching. all_species[S.name] = S if(S.flags & IS_WHITELISTED) whitelisted_species += S.name init_subtypes(/datum/table_recipe, table_recipes) - return 1 /* // Uncomment to debug chemical reaction list. @@ -80,8 +58,19 @@ //creates every subtype of prototype (excluding prototype) and adds it to list L. //if no list/L is provided, one is created. /proc/init_subtypes(prototype, list/L) - if(!istype(L)) L = list() - for(var/path in typesof(prototype)) - if(path == prototype) continue - L += new path() - return L + if(!istype(L)) L = list() + for(var/path in subtypesof(prototype)) + L += new path() + return L + +/proc/init_datum_subtypes(prototype, list/L, list/pexempt, assocvar) + if(!istype(L)) L = list() + for(var/path in subtypesof(prototype) - pexempt) + var/datum/D = new path() + if(istype(D)) + var/assoc + if(D.vars["[assocvar]"]) //has the var + assoc = D.vars["[assocvar]"] //access value of var + if(assoc) //value gotten + L["[assoc]"] = D //put in association + return L \ No newline at end of file