diff --git a/code/controllers/subsystems/chemistry.dm b/code/controllers/subsystems/chemistry.dm index f0a6b07eabd..fa5b0393648 100644 --- a/code/controllers/subsystems/chemistry.dm +++ b/code/controllers/subsystems/chemistry.dm @@ -2,7 +2,6 @@ var/datum/controller/subsystem/chemistry/SSchemistry /datum/controller/subsystem/chemistry name = "Chemistry" - flags = SS_NO_INIT priority = SS_PRIORITY_CHEMISTRY var/list/active_holders @@ -19,7 +18,11 @@ var/datum/controller/subsystem/chemistry/SSchemistry active_holders = list() chemical_reactions = chemical_reactions_list chemical_reagents = chemical_reagents_list - + +/datum/controller/subsystem/chemistry/Initialize() + load_secret_chemicals() + . = ..() + /datum/controller/subsystem/chemistry/fire(resumed = FALSE) if (!resumed) processing_holders = active_holders.Copy() @@ -53,3 +56,38 @@ var/datum/controller/subsystem/chemistry/SSchemistry src.active_holders = SSchemistry.active_holders src.chemical_reactions = SSchemistry.chemical_reactions src.chemical_reagents = SSchemistry.chemical_reagents + +/datum/controller/subsystem/chemistry/proc/load_secret_chemicals() + var/list/chemconfig = list() + try + chemconfig = json_decode(return_file_text("config/secretchem.json")) + catch(var/exception/e) + log_debug("SSchemistry: Warning: Could not load config, as secretchem.json is missing - [e]") + return + + chemconfig = chemconfig["chemicals"] + for (var/chemical in chemconfig) + log_debug("SSchemistry: Loading chemical: [chemical]") + var/datum/chemical_reaction/cc = new() + cc.name = chemconfig[chemical]["name"] + cc.id = chemconfig[chemical]["id"] + cc.result = chemconfig[chemical]["result"] + cc.result_amount = chemconfig[chemical]["resultamount"] + cc.required_reagents = chemconfig[chemical]["required_reagents"] + if(!cc.result in chemical_reagents_list) + log_debug("SSchemistry: Warning: Invalid result [cc.result] in [cc.name] reactions list.") + qdel(cc) + + for(var/A in cc.required_reagents) + if(!(A in chemical_reagents_list)) + log_debug("SSchemistry: Warning: Invalid chemical [A] in [cc.name] required reagents list.") + break + qdel(cc) + + if(LAZYLEN(cc.required_reagents)) + var/reagent_id = cc.required_reagents[1] + LAZYINITLIST(chemical_reactions_list[reagent_id]) + chemical_reactions_list[reagent_id] += cc + + chemical_reactions = chemical_reactions_list + diff --git a/config/example/secretchem.json b/config/example/secretchem.json new file mode 100644 index 00000000000..a43bd9975fd --- /dev/null +++ b/config/example/secretchem.json @@ -0,0 +1,14 @@ +{ + "chemicals": { + "superrine": { + "name": "super rine", + "id": "superrine", + "result": "water", + "resultamount": 60, + "required_reagents": { + "water": 1, + "sugar": 1 + } + } + } +} \ No newline at end of file