From 960579853a2ff651c6c8b767c76496b83d5f4178 Mon Sep 17 00:00:00 2001 From: Iajret Creature <122297233+Steals-The-PRs@users.noreply.github.com> Date: Sun, 19 Nov 2023 20:25:58 +0300 Subject: [PATCH] [MIRROR] [NO GBP] Debug chem synthesizer works & related code cleanup [MDB IGNORE] (#713) * [NO GBP] Debug chem synthesizer works & related code cleanup (#79616) --------- Co-authored-by: SkyratBot <59378654+SkyratBot@users.noreply.github.com> Co-authored-by: SyncIt21 <110812394+SyncIt21@users.noreply.github.com> --- code/modules/reagents/chemistry/holder.dm | 2 +- .../chemistry/machinery/chem_dispenser.dm | 11 ++- .../chemistry/machinery/chem_synthesizer.dm | 47 +++++------ .../machinery}/portable_chem_mixer.dm | 6 +- tgstation.dme | 2 +- .../tgui/interfaces/ChemDebugSynthesizer.tsx | 49 ++---------- .../tgui/interfaces/ChemDispenser.tsx | 78 ++++--------------- .../tgui/interfaces/PortableChemMixer.tsx | 45 +---------- .../tgui/interfaces/common/BeakerDisplay.tsx | 67 ++++++++++++++++ 9 files changed, 126 insertions(+), 181 deletions(-) rename code/{game/objects/items/devices => modules/reagents/chemistry/machinery}/portable_chem_mixer.dm (97%) create mode 100644 tgui/packages/tgui/interfaces/common/BeakerDisplay.tsx diff --git a/code/modules/reagents/chemistry/holder.dm b/code/modules/reagents/chemistry/holder.dm index 8dfe1dbcf5e..8236a17fb58 100644 --- a/code/modules/reagents/chemistry/holder.dm +++ b/code/modules/reagents/chemistry/holder.dm @@ -521,7 +521,7 @@ // Prevents small amount problems, as well as zero and below zero amounts. amount = round(min(amount, total_volume, target_holder.maximum_volume - target_holder.total_volume), CHEMICAL_QUANTISATION_LEVEL) if(amount <= 0) - return + return FALSE //Set up new reagents to inherit the old ongoing reactions if(!no_react) diff --git a/code/modules/reagents/chemistry/machinery/chem_dispenser.dm b/code/modules/reagents/chemistry/machinery/chem_dispenser.dm index b677a8c02c9..a4d31849cda 100644 --- a/code/modules/reagents/chemistry/machinery/chem_dispenser.dm +++ b/code/modules/reagents/chemistry/machinery/chem_dispenser.dm @@ -304,7 +304,7 @@ beaker_data["pH"] = round(beaker.reagents.ph, 0.01) beaker_data["currentVolume"] = round(beaker.reagents.total_volume, 0.01) var/list/beakerContents = list() - if(beaker && beaker.reagents && beaker.reagents.reagent_list.len) + if(length(beaker.reagents.reagent_list)) for(var/datum/reagent/reagent in beaker.reagents.reagent_list) beakerContents += list(list("name" = reagent.name, "volume" = round(reagent.volume, 0.01))) // list in a list because Byond merges the first list... beaker_data["contents"] = beakerContents @@ -437,6 +437,15 @@ if(beaker) beaker.reagents.ui_interact(ui.user) + var/result = handle_ui_act(action, params, ui, state) + if(isnull(result)) + result = FALSE + return result + +/// Same as ui_act() but to be used by subtypes exclusively +/obj/machinery/chem_dispenser/proc/handle_ui_act(action, params, datum/tgui/ui, datum/ui_state/state) + return null + /obj/machinery/chem_dispenser/wrench_act(mob/living/user, obj/item/tool) . = ..() if(default_unfasten_wrench(user, tool) == SUCCESSFUL_UNFASTEN) diff --git a/code/modules/reagents/chemistry/machinery/chem_synthesizer.dm b/code/modules/reagents/chemistry/machinery/chem_synthesizer.dm index 6de441c6fc7..89c720da0d4 100644 --- a/code/modules/reagents/chemistry/machinery/chem_synthesizer.dm +++ b/code/modules/reagents/chemistry/machinery/chem_synthesizer.dm @@ -20,41 +20,42 @@ ui = new(user, src, "ChemDebugSynthesizer", name) ui.open() -/obj/machinery/chem_dispenser/chem_synthesizer/ui_act(action, params) - . = ..() - if(.) - return +/obj/machinery/chem_dispenser/chem_synthesizer/handle_ui_act(action, params, datum/tgui/ui, datum/ui_state/state) switch(action) - if("ejectBeaker") - if(beaker) - try_put_in_hand(beaker, usr) - beaker = null - . = TRUE if("input") - var/input_reagent = (input("Enter the name of any reagent", "Input") as text|null) - input_reagent = get_reagent_type_from_product_string(input_reagent) //from string to type + if(QDELETED(beaker)) + return FALSE + + var/selected_reagent = tgui_input_list(ui.user, "Select reagent", "Reagent", GLOB.name2reagent) + if(!selected_reagent) + return FALSE + + var/datum/reagent/input_reagent = GLOB.name2reagent[selected_reagent] if(!input_reagent) - say("REAGENT NOT FOUND") - return - else - if(!beaker) - return - else if(!beaker.reagents && !QDELETED(beaker)) - beaker.create_reagents(beaker.volume) - beaker.reagents.add_reagent(input_reagent, amount, added_purity = (purity/100)) + return FALSE + + beaker.reagents.add_reagent(input_reagent, amount, added_purity = (purity / 100)) + return TRUE + if("makecup") if(beaker) return beaker = new /obj/item/reagent_containers/cup/beaker/bluespace(src) visible_message(span_notice("[src] dispenses a bluespace beaker.")) + return TRUE + if("amount") var/input = text2num(params["amount"]) if(input) amount = input + return FALSE + if("purity") var/input = text2num(params["amount"]) if(input) purity = input + return FALSE + update_appearance() /obj/machinery/chem_dispenser/chem_synthesizer/Destroy() @@ -64,11 +65,3 @@ /obj/machinery/chem_dispenser/chem_synthesizer/ui_data(mob/user) . = ..() .["purity"] = purity - return . - -/obj/machinery/chem_dispenser/chem_synthesizer/proc/find_reagent(input) - . = FALSE - if(GLOB.chemical_reagents_list[input]) //prefer IDs! - return input - else - return get_chem_id(input) diff --git a/code/game/objects/items/devices/portable_chem_mixer.dm b/code/modules/reagents/chemistry/machinery/portable_chem_mixer.dm similarity index 97% rename from code/game/objects/items/devices/portable_chem_mixer.dm rename to code/modules/reagents/chemistry/machinery/portable_chem_mixer.dm index 7d8aa808df9..bdc008ce336 100644 --- a/code/game/objects/items/devices/portable_chem_mixer.dm +++ b/code/modules/reagents/chemistry/machinery/portable_chem_mixer.dm @@ -235,11 +235,9 @@ if(!QDELETED(beaker)) var/datum/reagents/container = beaker.reagents - var/actual = min(amount, 1000, container.maximum_volume - container.total_volume) + var/actual = min(amount, container.maximum_volume - container.total_volume) for (var/datum/reagents/source in dispensable_reagents[reagent]["reagents"]) - var/to_transfer = min(source.total_volume, actual) - source.trans_to(beaker, to_transfer, transferred_by = ui.user) - actual -= to_transfer + actual -= source.trans_to(beaker, min(source.total_volume, actual), transferred_by = ui.user) if (actual <= 0) break return TRUE diff --git a/tgstation.dme b/tgstation.dme index 0a2c9b25578..b907f2b4752 100644 --- a/tgstation.dme +++ b/tgstation.dme @@ -2392,7 +2392,6 @@ #include "code\game\objects\items\devices\multitool.dm" #include "code\game\objects\items\devices\pipe_painter.dm" #include "code\game\objects\items\devices\polycircuit.dm" -#include "code\game\objects\items\devices\portable_chem_mixer.dm" #include "code\game\objects\items\devices\powersink.dm" #include "code\game\objects\items\devices\pressureplates.dm" #include "code\game\objects\items\devices\quantum_keycard.dm" @@ -5374,6 +5373,7 @@ #include "code\modules\reagents\chemistry\machinery\chem_separator.dm" #include "code\modules\reagents\chemistry\machinery\chem_synthesizer.dm" #include "code\modules\reagents\chemistry\machinery\pandemic.dm" +#include "code\modules\reagents\chemistry\machinery\portable_chem_mixer.dm" #include "code\modules\reagents\chemistry\machinery\reagentgrinder.dm" #include "code\modules\reagents\chemistry\machinery\smoke_machine.dm" #include "code\modules\reagents\chemistry\reagents\atmos_gas_reagents.dm" diff --git a/tgui/packages/tgui/interfaces/ChemDebugSynthesizer.tsx b/tgui/packages/tgui/interfaces/ChemDebugSynthesizer.tsx index d8516d1e000..2c4b58395a7 100644 --- a/tgui/packages/tgui/interfaces/ChemDebugSynthesizer.tsx +++ b/tgui/packages/tgui/interfaces/ChemDebugSynthesizer.tsx @@ -1,27 +1,17 @@ -import { BooleanLike } from 'common/react'; +import { Beaker, BeakerDisplay } from './common/BeakerDisplay'; import { useBackend } from '../backend'; -import { AnimatedNumber, Box, Button, LabeledList, NumberInput, Section } from '../components'; +import { Button, NumberInput, Section } from '../components'; import { Window } from '../layouts'; type Data = { amount: number; purity: number; - beakerCurrentVolume: number; - beakerMaxVolume: number; - isBeakerLoaded: BooleanLike; - beakerContents: { name: string; volume: number }[]; + beaker: Beaker; }; export const ChemDebugSynthesizer = (props, context) => { const { act, data } = useBackend(context); - const { - amount, - purity, - beakerCurrentVolume, - beakerMaxVolume, - isBeakerLoaded, - beakerContents = [], - } = data; + const { amount, purity, beaker } = data; return ( @@ -29,18 +19,13 @@ export const ChemDebugSynthesizer = (props, context) => {
-
diff --git a/tgui/packages/tgui/interfaces/ChemDispenser.tsx b/tgui/packages/tgui/interfaces/ChemDispenser.tsx index c8dc25e943f..b873100332e 100644 --- a/tgui/packages/tgui/interfaces/ChemDispenser.tsx +++ b/tgui/packages/tgui/interfaces/ChemDispenser.tsx @@ -2,21 +2,9 @@ import { toFixed } from 'common/math'; import { BooleanLike } from 'common/react'; import { toTitleCase } from 'common/string'; import { useBackend, useLocalState } from '../backend'; -import { AnimatedNumber, Box, Button, Icon, LabeledList, ProgressBar, Section } from '../components'; +import { Box, Button, Icon, LabeledList, ProgressBar, Section } from '../components'; import { Window } from '../layouts'; - -export type BeakerReagent = { - name: string; - volume: number; -}; - -export type Beaker = { - maxVolume: number; - transferAmounts: number[]; - pH: number; - currentVolume: number; - contents: BeakerReagent[]; -}; +import { Beaker, BeakerDisplay } from './common/BeakerDisplay'; type DispensableReagent = { title: string; @@ -44,15 +32,13 @@ export const ChemDispenser = (props, context) => { const [hasCol, setHasCol] = useLocalState(context, 'has_col', false); const beakerTransferAmounts = beaker ? beaker.transferAmounts : []; - const beakerContents = - (recording && - Object.keys(data.recordingRecipe).map((id) => ({ - id, - name: toTitleCase(id.replace(/_/, ' ')), - volume: data.recordingRecipe[id], - }))) || - beaker?.contents || - []; + const recordedContents = + recording && + Object.keys(data.recordingRecipe).map((id) => ({ + id, + name: toTitleCase(id.replace(/_/, ' ')), + volume: data.recordingRecipe[id], + })); return ( @@ -210,46 +196,12 @@ export const ChemDispenser = (props, context) => { onClick={() => act('remove', { amount })} /> ))}> - - act('eject')} - /> - ) - }> - {(recording && 'Virtual beaker') || - (!!beaker && ( - <> - / - {beaker.maxVolume} units - - )) || - 'No beaker'} - - - - {(!beaker && !recording && 'N/A') || - (beakerContents.length === 0 && 'Nothing')} - - {beakerContents.map((chemical) => ( - - units - of {chemical.name} - - ))} - {beakerContents.length > 0 && !!data.showpH && ( - - pH: - - - )} - - + diff --git a/tgui/packages/tgui/interfaces/PortableChemMixer.tsx b/tgui/packages/tgui/interfaces/PortableChemMixer.tsx index aea59d95dd7..99861ea7db7 100644 --- a/tgui/packages/tgui/interfaces/PortableChemMixer.tsx +++ b/tgui/packages/tgui/interfaces/PortableChemMixer.tsx @@ -1,7 +1,7 @@ import { sortBy } from 'common/collections'; -import { Beaker } from './ChemDispenser'; +import { Beaker, BeakerDisplay } from './common/BeakerDisplay'; import { useBackend } from '../backend'; -import { AnimatedNumber, Box, Button, LabeledList, Section } from '../components'; +import { Box, Button, Section } from '../components'; import { Window } from '../layouts'; type DispensableReagent = { @@ -21,7 +21,6 @@ export const PortableChemMixer = (props, context) => { const { act, data } = useBackend(context); const { beaker } = data; const beakerTransferAmounts = beaker ? beaker.transferAmounts : []; - const beakerContents = beaker ? beaker.contents : []; const chemicals = sortBy((chem: DispensableReagent) => chem.id)( data.chemicals ); @@ -71,45 +70,7 @@ export const PortableChemMixer = (props, context) => { onClick={() => act('remove', { amount })} /> ))}> - - act('eject')} - /> - ) - }> - {(!!beaker && ( - <> - / - {beaker.maxVolume} units - - )) || - 'No beaker'} - - - - {(!beaker && 'N/A') || - (beakerContents.length === 0 && 'Nothing')} - - {beakerContents.map((chemical) => ( - - units - of {chemical.name} - - ))} - {beakerContents.length > 0 && ( - - pH: - - - )} - - + diff --git a/tgui/packages/tgui/interfaces/common/BeakerDisplay.tsx b/tgui/packages/tgui/interfaces/common/BeakerDisplay.tsx new file mode 100644 index 00000000000..8665712acf3 --- /dev/null +++ b/tgui/packages/tgui/interfaces/common/BeakerDisplay.tsx @@ -0,0 +1,67 @@ +import { BooleanLike } from 'common/react'; +import { AnimatedNumber, Box, Button, LabeledList } from '../../components'; +import { useBackend } from '../../backend'; + +type BeakerReagent = { + name: string; + volume: number; +}; + +export type Beaker = { + maxVolume: number; + transferAmounts: number[]; + pH: number; + currentVolume: number; + contents: BeakerReagent[]; +}; + +type BeakerProps = { + beaker: Beaker; + replace_contents?: BeakerReagent[]; + title_label?: string; + showpH?: BooleanLike; +}; + +export const BeakerDisplay = (props: BeakerProps, context) => { + const { act } = useBackend(context); + const { beaker, replace_contents, title_label, showpH } = props; + const beakerContents = replace_contents || beaker?.contents || []; + + return ( + + act('eject')} /> + ) + }> + {title_label || + (!!beaker && ( + <> + / + {beaker.maxVolume} units + + )) || + 'No beaker'} + + + + {(!beaker && 'N/A') || (beakerContents.length === 0 && 'Nothing')} + + {beakerContents.map((chemical) => ( + + units of{' '} + {chemical.name} + + ))} + {beakerContents.length > 0 && !!showpH && ( + + pH: + + + )} + + + ); +};