From fe6818a8568fff2b07fb52befc86315a630fcc61 Mon Sep 17 00:00:00 2001 From: Matt Atlas Date: Thu, 19 Mar 2020 18:54:01 +0100 Subject: [PATCH] Ports the decl repository. (#8460) --- aurorastation.dme | 1 + code/datums/repositories/decls.dm | 51 +++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 code/datums/repositories/decls.dm diff --git a/aurorastation.dme b/aurorastation.dme index 69d8cc3af74..193c2625d64 100644 --- a/aurorastation.dme +++ b/aurorastation.dme @@ -337,6 +337,7 @@ #include "code\datums\radio\signal.dm" #include "code\datums\repositories\cameras.dm" #include "code\datums\repositories\crew.dm" +#include "code\datums\repositories\decls.dm" #include "code\datums\repositories\repository.dm" #include "code\datums\trading\_trading_defines.dm" #include "code\datums\trading\ai.dm" diff --git a/code/datums/repositories/decls.dm b/code/datums/repositories/decls.dm new file mode 100644 index 00000000000..a6c27d5c605 --- /dev/null +++ b/code/datums/repositories/decls.dm @@ -0,0 +1,51 @@ +/var/repository/decls/decls_repository = new() + +/repository/decls + var/list/fetched_decls + var/list/fetched_decl_types + var/list/fetched_decl_subtypes + +/repository/decls/New() + ..() + fetched_decls = list() + fetched_decl_types = list() + fetched_decl_subtypes = list() + +/repository/decls/proc/get_decl(var/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) + +/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() + return + +/decl/Destroy() + SHOULD_CALL_PARENT(FALSE) + return QDEL_HINT_LETMELIVE // Prevents Decl destruction