Skip to content

Commit

Permalink
[MIRROR] [NO GBP] Debug chem synthesizer works & related code cleanup…
Browse files Browse the repository at this point in the history
… [MDB IGNORE] (#713)

* [NO GBP] Debug chem synthesizer works & related code cleanup (#79616)

---------

Co-authored-by: SkyratBot <[email protected]>
Co-authored-by: SyncIt21 <[email protected]>
  • Loading branch information
3 people authored Nov 19, 2023
1 parent 18332b4 commit 9605798
Show file tree
Hide file tree
Showing 9 changed files with 126 additions and 181 deletions.
2 changes: 1 addition & 1 deletion code/modules/reagents/chemistry/holder.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 10 additions & 1 deletion code/modules/reagents/chemistry/machinery/chem_dispenser.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
47 changes: 20 additions & 27 deletions code/modules/reagents/chemistry/machinery/chem_synthesizer.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tgstation.dme
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
49 changes: 7 additions & 42 deletions tgui/packages/tgui/interfaces/ChemDebugSynthesizer.tsx
Original file line number Diff line number Diff line change
@@ -1,46 +1,31 @@
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<Data>(context);
const {
amount,
purity,
beakerCurrentVolume,
beakerMaxVolume,
isBeakerLoaded,
beakerContents = [],
} = data;
const { amount, purity, beaker } = data;

return (
<Window width={390} height={330}>
<Window.Content scrollable>
<Section
title="Recipient"
buttons={
isBeakerLoaded ? (
beaker ? (
<>
<Button
icon="eject"
content="Eject"
onClick={() => act('ejectBeaker')}
/>
<NumberInput
value={amount}
unit="u"
minValue={1}
maxValue={beakerMaxVolume}
maxValue={beaker.maxVolume}
step={1}
stepPixelSize={2}
onChange={(e, value) =>
Expand Down Expand Up @@ -76,27 +61,7 @@ export const ChemDebugSynthesizer = (props, context) => {
/>
)
}>
{isBeakerLoaded ? (
<>
<Box>
<AnimatedNumber value={beakerCurrentVolume} />
{' / ' + beakerMaxVolume + ' u'}
</Box>
{beakerContents.length > 0 ? (
<LabeledList>
{beakerContents.map((chem) => (
<LabeledList.Item key={chem.name} label={chem.name}>
{chem.volume} u
</LabeledList.Item>
))}
</LabeledList>
) : (
<Box color="bad">Recipient Empty</Box>
)}
</>
) : (
<Box color="average">No Recipient</Box>
)}
<BeakerDisplay beaker={beaker} showpH />
</Section>
</Window.Content>
</Window>
Expand Down
78 changes: 15 additions & 63 deletions tgui/packages/tgui/interfaces/ChemDispenser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 (
<Window width={565} height={620}>
<Window.Content scrollable>
Expand Down Expand Up @@ -210,46 +196,12 @@ export const ChemDispenser = (props, context) => {
onClick={() => act('remove', { amount })}
/>
))}>
<LabeledList>
<LabeledList.Item
label="Beaker"
buttons={
!!beaker && (
<Button
icon="eject"
content="Eject"
onClick={() => act('eject')}
/>
)
}>
{(recording && 'Virtual beaker') ||
(!!beaker && (
<>
<AnimatedNumber initial={0} value={beaker.currentVolume} />/
{beaker.maxVolume} units
</>
)) ||
'No beaker'}
</LabeledList.Item>
<LabeledList.Item label="Contents">
<Box color="label">
{(!beaker && !recording && 'N/A') ||
(beakerContents.length === 0 && 'Nothing')}
</Box>
{beakerContents.map((chemical) => (
<Box key={chemical.name} color="label">
<AnimatedNumber initial={0} value={chemical.volume} /> units
of {chemical.name}
</Box>
))}
{beakerContents.length > 0 && !!data.showpH && (
<Box>
pH:
<AnimatedNumber value={beaker.pH} />
</Box>
)}
</LabeledList.Item>
</LabeledList>
<BeakerDisplay
beaker={beaker}
title_label={recording && 'Virtual beaker'}
replace_contents={recordedContents}
showpH={data.showpH}
/>
</Section>
</Window.Content>
</Window>
Expand Down
45 changes: 3 additions & 42 deletions tgui/packages/tgui/interfaces/PortableChemMixer.tsx
Original file line number Diff line number Diff line change
@@ -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 = {
Expand All @@ -21,7 +21,6 @@ export const PortableChemMixer = (props, context) => {
const { act, data } = useBackend<Data>(context);
const { beaker } = data;
const beakerTransferAmounts = beaker ? beaker.transferAmounts : [];
const beakerContents = beaker ? beaker.contents : [];
const chemicals = sortBy((chem: DispensableReagent) => chem.id)(
data.chemicals
);
Expand Down Expand Up @@ -71,45 +70,7 @@ export const PortableChemMixer = (props, context) => {
onClick={() => act('remove', { amount })}
/>
))}>
<LabeledList>
<LabeledList.Item
label="Beaker"
buttons={
!!beaker && (
<Button
icon="eject"
content="Eject"
onClick={() => act('eject')}
/>
)
}>
{(!!beaker && (
<>
<AnimatedNumber initial={0} value={beaker.currentVolume} />/
{beaker.maxVolume} units
</>
)) ||
'No beaker'}
</LabeledList.Item>
<LabeledList.Item label="Contents">
<Box color="label">
{(!beaker && 'N/A') ||
(beakerContents.length === 0 && 'Nothing')}
</Box>
{beakerContents.map((chemical) => (
<Box key={chemical.name} color="label">
<AnimatedNumber initial={0} value={chemical.volume} /> units
of {chemical.name}
</Box>
))}
{beakerContents.length > 0 && (
<Box>
pH:
<AnimatedNumber value={beaker.pH} />
</Box>
)}
</LabeledList.Item>
</LabeledList>
<BeakerDisplay beaker={beaker} showpH />
</Section>
</Window.Content>
</Window>
Expand Down
Loading

0 comments on commit 9605798

Please sign in to comment.