From 599e7db6e639ac6eebb981b905dcae5cc21649c2 Mon Sep 17 00:00:00 2001 From: Time-Green Date: Fri, 26 Mar 2021 11:00:43 +0100 Subject: [PATCH] Partially revert reaction chamber (#57855) --- .../components/plumbing/reaction_chamber.dm | 27 +++--- .../plumbing/plumbers/reaction_chamber.dm | 25 ++++-- .../tgui/interfaces/ChemReactionChamber.js | 82 +++++++++++++------ 3 files changed, 95 insertions(+), 39 deletions(-) diff --git a/code/datums/components/plumbing/reaction_chamber.dm b/code/datums/components/plumbing/reaction_chamber.dm index d270fbee7a3c60..7e08cb34125262 100644 --- a/code/datums/components/plumbing/reaction_chamber.dm +++ b/code/datums/components/plumbing/reaction_chamber.dm @@ -9,26 +9,33 @@ /datum/component/plumbing/reaction_chamber/can_give(amount, reagent, datum/ductnet/net) . = ..() - var/obj/machinery/plumbing/reaction_chamber/RC = parent - if(!. || !RC.emptying || reagents.is_reacting == TRUE) + var/obj/machinery/plumbing/reaction_chamber/reaction_chamber = parent + if(!. || !reaction_chamber.emptying || reagents.is_reacting == TRUE) return FALSE /datum/component/plumbing/reaction_chamber/send_request(dir) - var/obj/machinery/plumbing/reaction_chamber/RC = parent - if(RC.emptying) + var/obj/machinery/plumbing/reaction_chamber/chamber = parent + if(chamber.emptying) return - process_request(amount = min(MACHINE_REAGENT_TRANSFER, RC.target_volume - reagents.total_volume), dir = dir) - - if(RC.target_volume > round(reagents.total_volume, CHEMICAL_VOLUME_ROUNDING)) //not enough yet - return + for(var/required_reagent in chamber.required_reagents) + var/has_reagent = FALSE + for(var/datum/reagent/containg_reagent as anything in reagents.reagent_list) + if(required_reagent == containg_reagent.type) + has_reagent = TRUE + if(containg_reagent.volume < chamber.required_reagents[required_reagent]) + process_request(min(chamber.required_reagents[required_reagent] - containg_reagent.volume, MACHINE_REAGENT_TRANSFER) , required_reagent, dir) + return + if(!has_reagent) + process_request(min(chamber.required_reagents[required_reagent], MACHINE_REAGENT_TRANSFER), required_reagent, dir) + return reagents.flags &= ~NO_REACT reagents.handle_reactions() - RC.emptying = TRUE //If we move this up, it'll instantly get turned off since any reaction always sets the reagent_total to zero. Other option is make the reaction update + chamber.emptying = TRUE //If we move this up, it'll instantly get turned off since any reaction always sets the reagent_total to zero. Other option is make the reaction update //everything for every chemical removed, wich isn't a good option either. - RC.on_reagent_change(reagents) //We need to check it now, because some reactions leave nothing left. + chamber.on_reagent_change(reagents) //We need to check it now, because some reactions leave nothing left. ///Special connect that we currently use for reaction chambers. Being used so we can keep certain inputs seperate, like into a special internal acid container /datum/component/plumbing/acidic_input diff --git a/code/modules/plumbing/plumbers/reaction_chamber.dm b/code/modules/plumbing/plumbers/reaction_chamber.dm index 64cd694a515297..5fb124d8d7cdb1 100644 --- a/code/modules/plumbing/plumbers/reaction_chamber.dm +++ b/code/modules/plumbing/plumbers/reaction_chamber.dm @@ -6,8 +6,11 @@ buffer = 200 reagent_flags = TRANSPARENT | NO_REACT - ///At what volume do we start reacting? - var/target_volume = 200 + /** + * list of set reagents that the reaction_chamber allows in, and must all be present before mixing is enabled. + * example: list(/datum/reagent/water = 20, /datum/reagent/fuel/oil = 50) + */ + var/list/required_reagents = list() ///If above this pH, we start dumping buffer into it var/acidic_limit = 9 ///If below this pH, we start dumping buffer into it @@ -80,12 +83,16 @@ /obj/machinery/plumbing/reaction_chamber/ui_data(mob/user) var/list/data = list() + var/list/text_reagents = list() + for(var/datum/reagent/required_reagent as anything in required_reagents) //make a list where the key is text, because that looks alot better in the ui than a typepath + text_reagents[initial(required_reagent.name)] = required_reagents[required_reagent] + + data["reagents"] = text_reagents data["emptying"] = emptying data["temperature"] = round(reagents.chem_temp, 0.1) data["ph"] = round(reagents.ph, 0.01) data["targetTemp"] = target_temperature data["isReacting"] = reagents.is_reacting - data["reagentQuantity"] = target_volume data["reagentAcidic"] = acidic_limit data["reagentAlkaline"] = alkaline_limit return data @@ -96,6 +103,16 @@ return . = TRUE switch(action) + if("remove") + var/reagent = get_chem_id(params["chem"]) + if(reagent) + required_reagents.Remove(reagent) + if("add") + var/input_reagent = get_chem_id(params["chem"]) + if(input_reagent && !required_reagents.Find(input_reagent)) + var/input_amount = text2num(params["amount"]) + if(input_amount) + required_reagents[input_reagent] = input_amount if("temperature") var/target = params["target"] if(text2num(target) != null) @@ -103,8 +120,6 @@ . = TRUE if(.) target_temperature = clamp(target, 0, 1000) - if("volume") - target_volume = round(text2num(params["target"])) if("acidic") acidic_limit = round(text2num(params["target"])) if("alkaline") diff --git a/tgui/packages/tgui/interfaces/ChemReactionChamber.js b/tgui/packages/tgui/interfaces/ChemReactionChamber.js index a63341b5d5175a..0105b803358a7d 100644 --- a/tgui/packages/tgui/interfaces/ChemReactionChamber.js +++ b/tgui/packages/tgui/interfaces/ChemReactionChamber.js @@ -8,19 +8,28 @@ import { round, toFixed } from 'common/math'; export const ChemReactionChamber = (props, context) => { const { act, data } = useBackend(context); + const [ + reagentName, + setReagentName, + ] = useLocalState(context, 'reagentName', ''); + const [ + reagentQuantity, + setReagentQuantity, + ] = useLocalState(context, 'reagentQuantity', 1); + const { emptying, temperature, ph, targetTemp, isReacting, - reagentQuantity, reagentAcidic, reagentAlkaline, } = data; + const reagents = data.reagents || []; return (
{ ) )}> - - - - act('volume', { - target: value, - })} /> - - - - - { + + + setReagentName(value)} /> + + + setReagentQuantity(value)} /> + +