Skip to content

Commit

Permalink
Partially revert reaction chamber (#57855)
Browse files Browse the repository at this point in the history
  • Loading branch information
Time-Green committed Mar 26, 2021
1 parent aae397b commit 599e7db
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 39 deletions.
27 changes: 17 additions & 10 deletions code/datums/components/plumbing/reaction_chamber.dm
Expand Up @@ -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
Expand Down
25 changes: 20 additions & 5 deletions code/modules/plumbing/plumbers/reaction_chamber.dm
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -96,15 +103,23 @@
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)
target = text2num(target)
. = 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")
Expand Down
82 changes: 58 additions & 24 deletions tgui/packages/tgui/interfaces/ChemReactionChamber.js
Expand Up @@ -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 (
<Window
width={250}
width={290}
height={280}>
<Window.Content scrollable>
<Section
Expand Down Expand Up @@ -105,28 +114,6 @@ export const ChemReactionChamber = (props, context) => {
)
)}>
<LabeledList>
<tr className="LabledList__row">
<LabeledList.Item label="Reaction Volume">
<td
className={classes([
"LabeledList__buttons",
"LabeledList__cell",
])}>
<NumberInput
value={reagentQuantity}
minValue={1}
maxValue={200}
step={1}
stepPixelSize={3}
width="39px"
onDrag={(e, value) => act('volume', {
target: value,
})} />

<Box inline mr={1} />
</td>
</LabeledList.Item>
</tr>
<tr className="LabledList__row">
<LabeledList.Item label="Acidic pH limit">
<td
Expand Down Expand Up @@ -169,6 +156,53 @@ export const ChemReactionChamber = (props, context) => {
</td>
</LabeledList.Item>
</tr>
<tr className="LabledList__row">
<td
colSpan="2"
className="LabeledList__cell">
<Input
fluid
value=""
placeholder="Reagent Name"
onInput={(e, value) => setReagentName(value)} />
</td>
<td
className={classes([
"LabeledList__buttons",
"LabeledList__cell",
])}>
<NumberInput
value={reagentQuantity}
minValue={1}
maxValue={100}
step={1}
stepPixelSize={3}
width="39px"
onDrag={(e, value) => setReagentQuantity(value)} />
<Box inline mr={1} />
<Button
icon="plus"
onClick={() => act('add', {
chem: reagentName,
amount: reagentQuantity,
})} />
</td>
</tr>
{map((amount, reagent) => (
<LabeledList.Item
key={reagent}
label={reagent}
buttons={(
<Button
icon="minus"
color="bad"
onClick={() => act('remove', {
chem: reagent,
})} />
)}>
{amount}
</LabeledList.Item>
))(reagents)}
</LabeledList>
</Section>
</Window.Content>
Expand Down

0 comments on commit 599e7db

Please sign in to comment.