Ported updated decls repository from Neb.

This commit is contained in:
MistakeNot4892
2021-03-26 10:44:30 +11:00
parent dfd0844701
commit cccb2a159f
4 changed files with 58 additions and 23 deletions
+3 -1
View File
@@ -492,4 +492,6 @@ GLOBAL_LIST_INIT(all_volume_channels, list(
#define NTOS_EMAIL_NONEWMESSAGES 0
#define NTOS_EMAIL_NOTIFALREADY 1
#define NTOS_EMAIL_NEWMESSAGE 2
#define NTOS_EMAIL_NEWMESSAGE 2
#define GET_DECL(D) (ispath(D, /decl) ? (decls_repository.fetched_decls[D] || decls_repository.get_decl(D)) : null)
+48 -16
View File
@@ -1,4 +1,20 @@
/var/repository/decls/decls_repository = new()
// /decl is a subtype used for singletons that should never have more than one instance
// in existence at a time. If you want to use a /decl you should use a pattern like:
// var/decl/somedecl/mydecl = GET_DECL(/decl/somedecl)
// /decls are created the first time they are fetched from decls_repository and will
// automatically call Initialize() and such when created in this way.
// decls_repository.get_decls_of_type() and decls_repository.get_decls_of_subtype()
// can be used similarly to typesof() and subtypesof(), returning assoc instance lists.
// The /decl commandments:
// I. Thou shalt not create a /decl with new().
// II. Thou shalt not del() or qdel() a /decl.
// III. Thou shalt not write a decl that relies on arguments supplied to New().
// IV. Thou shalt not call Initialize() on a /decl.
var/repository/decls/decls_repository = new()
/repository/decls
var/list/fetched_decls
@@ -11,29 +27,45 @@
fetched_decl_types = list()
fetched_decl_subtypes = list()
/repository/decls/proc/decls_of_type(var/decl_prototype)
. = fetched_decl_types[decl_prototype]
if(!.)
. = get_decls(typesof(decl_prototype))
fetched_decl_types[decl_prototype] = .
/repository/decls/proc/decls_of_subtype(var/decl_prototype)
. = fetched_decl_subtypes[decl_prototype]
if(!.)
. = get_decls(subtypesof(decl_prototype))
fetched_decl_subtypes[decl_prototype] = .
/repository/decls/proc/get_decl(var/decl_type)
ASSERT(ispath(decl_type))
. = fetched_decls[decl_type]
if(!.)
. = new decl_type()
fetched_decls[decl_type] = .
var/decl/decl = .
if(istype(decl))
decl.Initialize()
/repository/decls/proc/get_decls(var/list/decl_types)
. = list()
for(var/decl_type in decl_types)
.[decl_type] = get_decl(decl_type)
.[decl_type] = get_decl(decl_type)
/decls/Destroy()
/repository/decls/proc/get_decls_unassociated(var/list/decl_types)
. = list()
for(var/decl_type in decl_types)
. += get_decl(decl_type)
/repository/decls/proc/get_decls_of_type(var/decl_prototype)
. = fetched_decl_types[decl_prototype]
if(!.)
. = get_decls(typesof(decl_prototype))
fetched_decl_types[decl_prototype] = .
/repository/decls/proc/get_decls_of_subtype(var/decl_prototype)
. = fetched_decl_subtypes[decl_prototype]
if(!.)
. = get_decls(subtypesof(decl_prototype))
fetched_decl_subtypes[decl_prototype] = .
/decl/proc/Initialize()
//SHOULD_CALL_PARENT(TRUE)
//SHOULD_NOT_SLEEP(TRUE)
return
/decl/Destroy()
//SHOULD_CALL_PARENT(FALSE)
crash_with("Prevented attempt to delete a decl instance: [log_info_line(src)]")
return QDEL_HINT_LETMELIVE // Prevents Decl destruction
return QDEL_HINT_LETMELIVE // Prevents decl destruction
+1 -1
View File
@@ -92,7 +92,7 @@ var/global/datum/controller/plants/plant_controller // Set in New().
S.update_seed()
//Might as well mask the gene types while we're at it.
var/list/gene_datums = decls_repository.decls_of_subtype(/decl/plantgene)
var/list/gene_datums = decls_repository.get_decls_of_subtype(/decl/plantgene)
var/list/used_masks = list()
var/list/plant_traits = ALL_GENES
while(plant_traits && plant_traits.len)
@@ -3,8 +3,9 @@
/datum/unit_test/integrated_circuit_prefabs_shall_respect_complexity_and_size_contraints/start_test()
var/list/failed_prefabs = list()
for(var/prefab_type in subtypesof(/decl/prefab/ic_assembly))
var/decl/prefab/ic_assembly/prefab = decls_repository.get_decl(prefab_type)
var/list/prefab_types = decls_repository.get_decls_of_subtype(/decl/prefab/ic_assembly)
for(var/prefab_type in prefab_types)
var/decl/prefab/ic_assembly/prefab = prefab_types[prefab_type]
var/obj/item/device/electronic_assembly/assembly = prefab.assembly_type
var/available_size = initial(assembly.max_components)
@@ -33,9 +34,9 @@
/datum/unit_test/integrated_circuit_prefabs_shall_not_fail_to_create/start_test()
var/list/failed_prefabs = list()
for(var/prefab_type in subtypesof(/decl/prefab/ic_assembly))
var/decl/prefab/ic_assembly/prefab = decls_repository.get_decl(prefab_type)
var/list/prefab_types = decls_repository.get_decls_of_subtype(/decl/prefab/ic_assembly)
for(var/prefab_type in prefab_types)
var/decl/prefab/ic_assembly/prefab = prefab_types[prefab_type]
try
var/built_item = prefab.create(get_standard_turf())
if(built_item)