Skip to content

Commit

Permalink
Chemical press can now make patches and bottles (tgstation#51000)
Browse files Browse the repository at this point in the history
* Pill press can now make patches

* Add bottles to Chem Press
  • Loading branch information
antropod authored May 11, 2020
1 parent 21e85b7 commit 1a7c7ae
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 67 deletions.
109 changes: 68 additions & 41 deletions code/modules/plumbing/plumbers/pill_press.dm
Original file line number Diff line number Diff line change
@@ -1,31 +1,39 @@
///We take a constant input of reagents, and produce a pill once a set volume is reached
/obj/machinery/plumbing/pill_press
name = "pill press"
desc = "A press that presses pills."
name = "chemical press"
desc = "A press that makes pills, patches and bottles."
icon_state = "pill_press"
///the minimum size a pill can be
var/minimum_pill = 5
///the maximum size a pill can be
var/maximum_pill = 50
///the size of the pill
var/pill_size = 10
///pill name
var/pill_name = "factory pill"
///maximum size of a pill
var/max_pill_volume = 50
///maximum size of a patch
var/max_patch_volume = 40
///maximum size of a bottle
var/max_bottle_volume = 30
///current operating product (pills or patches)
var/product = "pill"
///the minimum size a pill or patch can be
var/min_volume = 5
///the maximum size a pill or patch can be
var/max_volume = 50
///selected size of the product
var/current_volume = 10
///prefix for the product name
var/product_name = "factory"
///the icon_state number for the pill.
var/pill_number = RANDOM_PILL_STYLE
///list of id's and icons for the pill selection of the ui
var/list/pill_styles
///list of pills stored in the machine, so we dont have 610 pills on one tile
var/list/stored_pills = list()
///list of products stored in the machine, so we dont have 610 pills on one tile
var/list/stored_products = list()
///max amount of pills allowed on our tile before we start storing them instead
var/max_floor_pills = 10
var/max_floor_products = 10

ui_x = 300
ui_y = 199
ui_y = 227

/obj/machinery/plumbing/pill_press/examine(mob/user)
. = ..()
. += "<span class='notice'>The [name] currently has [stored_pills.len] stored. There needs to be less than [max_floor_pills] on the floor to continue dispensing.</span>"
. += "<span class='notice'>The [name] currently has [stored_products.len] stored. There needs to be less than [max_floor_products] on the floor to continue dispensing.</span>"

/obj/machinery/plumbing/pill_press/Initialize(mapload, bolt)
. = ..()
Expand All @@ -43,26 +51,37 @@
/obj/machinery/plumbing/pill_press/process()
if(machine_stat & NOPOWER)
return
if(reagents.total_volume >= pill_size)
var/obj/item/reagent_containers/pill/P = new(src)
reagents.trans_to(P, pill_size)
P.name = pill_name
stored_pills += P
if(pill_number == RANDOM_PILL_STYLE)
P.icon_state = "pill[rand(1,21)]"
else
P.icon_state = "pill[pill_number]"
if(P.icon_state == "pill4") //mirrored from chem masters
P.desc = "A tablet or capsule, but not just any, a red one, one taken by the ones not scared of knowledge, freedom, uncertainty and the brutal truths of reality."
if(stored_pills.len)
if(reagents.total_volume >= current_volume)
if (product == "pill")
var/obj/item/reagent_containers/pill/P = new(src)
reagents.trans_to(P, current_volume)
P.name = trim("[product_name] pill")
stored_products += P
if(pill_number == RANDOM_PILL_STYLE)
P.icon_state = "pill[rand(1,21)]"
else
P.icon_state = "pill[pill_number]"
if(P.icon_state == "pill4") //mirrored from chem masters
P.desc = "A tablet or capsule, but not just any, a red one, one taken by the ones not scared of knowledge, freedom, uncertainty and the brutal truths of reality."
else if (product == "patch")
var/obj/item/reagent_containers/pill/patch/P = new(src)
reagents.trans_to(P, current_volume)
P.name = trim("[product_name] patch")
stored_products += P
else if (product == "bottle")
var/obj/item/reagent_containers/glass/bottle/P = new(src)
reagents.trans_to(P, current_volume)
P.name = trim("[product_name] bottle")
stored_products += P
if(stored_products.len)
var/pill_amount = 0
for(var/obj/item/reagent_containers/pill/P in loc)
pill_amount++
if(pill_amount >= max_floor_pills) //too much so just stop
if(pill_amount >= max_floor_products) //too much so just stop
break
if(pill_amount < max_floor_pills)
var/atom/movable/AM = stored_pills[1] //AM because forceMove is all we need
stored_pills -= AM
if(pill_amount < max_floor_products)
var/atom/movable/AM = stored_products[1] //AM because forceMove is all we need
stored_products -= AM
AM.forceMove(drop_location())


Expand All @@ -81,9 +100,12 @@
/obj/machinery/plumbing/pill_press/ui_data(mob/user)
var/list/data = list()
data["pill_style"] = pill_number
data["pill_size"] = pill_size
data["pill_name"] = pill_name
data["current_volume"] = current_volume
data["product_name"] = product_name
data["pill_styles"] = pill_styles
data["product"] = product
data["min_volume"] = min_volume
data["max_volume"] = max_volume
return data

/obj/machinery/plumbing/pill_press/ui_act(action, params)
Expand All @@ -93,11 +115,16 @@
switch(action)
if("change_pill_style")
pill_number = clamp(text2num(params["id"]), 1 , PILL_STYLE_COUNT)
if("change_pill_size")
pill_size = clamp(text2num(params["volume"]), minimum_pill, maximum_pill)
if("change_pill_name")
var/new_name = html_encode(params["name"])
if(findtext(new_name, "pill")) //names like pillatron and Pilliam are thus valid
pill_name = new_name
else
pill_name = new_name + " pill"
if("change_current_volume")
current_volume = clamp(text2num(params["volume"]), min_volume, max_volume)
if("change_product_name")
product_name = html_encode(params["name"])
if("change_product")
product = params["product"]
if (product == "pill")
max_volume = max_pill_volume
else if (product == "patch")
max_volume = max_patch_volume
else if (product == "bottle")
max_volume = max_bottle_volume
current_volume = clamp(current_volume, min_volume, max_volume)
82 changes: 57 additions & 25 deletions tgui/packages/tgui/interfaces/ChemPress.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,51 +5,83 @@ import { Window } from '../layouts';
export const ChemPress = (props, context) => {
const { act, data } = useBackend(context);
const {
pill_size,
pill_name,
current_volume,
product_name,
pill_style,
pill_styles = [],
product,
min_volume,
max_volume,
} = data;
return (
<Window>
<Window.Content>
<Section>
<LabeledList>
<LabeledList.Item label="Pill Volume">
<LabeledList.Item label="Product">
<Button.Checkbox
content="Pills"
checked={product === "pill"}
onClick={() => act('change_product', {
product: "pill",
})}
/>
<Button.Checkbox
content="Patches"
checked={product === "patch"}
onClick={() => act('change_product', {
product: "patch",
})}
/>
<Button.Checkbox
content="Bottles"
checked={product === "bottle"}
onClick={() => act('change_product', {
product: "bottle",
})}
/>
</LabeledList.Item>
<LabeledList.Item label="Volume">
<NumberInput
value={pill_size}
value={current_volume}
unit="u"
width="43px"
minValue={5}
maxValue={50}
minValue={min_volume}
maxValue={max_volume}
step={1}
stepPixelSize={2}
onChange={(e, value) => act('change_pill_size', {
onChange={(e, value) => act('change_current_volume', {
volume: value,
})} />
</LabeledList.Item>
<LabeledList.Item label="Pill Name">
<LabeledList.Item label="Name">
<Input
value={pill_name}
onChange={(e, value) => act('change_pill_name', {
value={product_name}
placeholder={product_name}
onChange={(e, value) => act('change_product_name', {
name: value,
})} />
<Box as="span">
{product}
</Box>
</LabeledList.Item>
<LabeledList.Item label="Pill Style">
{pill_styles.map(pill => (
<Button
key={pill.id}
width="30px"
selected={pill.id === pill_style}
textAlign="center"
color="transparent"
onClick={() => act('change_pill_style', {
id: pill.id,
})}>
<Box mx={-1} className={pill.class_name} />
</Button>
))}
</LabeledList.Item>
{product === "pill" && (
<LabeledList.Item label="Style">
{pill_styles.map(pill => (
<Button
key={pill.id}
width="30px"
selected={pill.id === pill_style}
textAlign="center"
color="transparent"
onClick={() => act('change_pill_style', {
id: pill.id,
})}>
<Box mx={-1} className={pill.class_name} />
</Button>
))}
</LabeledList.Item>
)}
</LabeledList>
</Section>
</Window.Content>
Expand Down
2 changes: 1 addition & 1 deletion tgui/packages/tgui/public/tgui.bundle.js

Large diffs are not rendered by default.

0 comments on commit 1a7c7ae

Please sign in to comment.