splits up the biogen (#19356)

* splits up the biogen

* ugh

---------

Co-authored-by: Cameron Lennox <killer65311@gmail.com>
This commit is contained in:
Kashargul
2026-04-05 16:19:09 -04:00
committed by GitHub
co-authored by Cameron Lennox
parent 17afaef058
commit 522c4f3290
10 changed files with 357 additions and 301 deletions
+57 -55
View File
@@ -1,14 +1,14 @@
// Use this define to register something as a creatable!
// * n - The proper name of the purchasable
// * o - The object type path of the purchasable to spawn
// * r - The amount to dispense
// * r - The maximum amount to dispense
// * p - The price of the purchasable in biomass
#define BIOGEN_ITEM(n, o, r, p) n = new /datum/data/biogenerator_item(n, o, r, p)
// Use this define to register something as dispensable
// * n - The proper name of the purchasable
// * o - The reagent ID
// * r - The amount of reagent to dispense
// * r - The maximum amount to dispense
// * p - The price of the purchasable in biomass
#define BIOGEN_REAGENT(n, o, r, p) n = new /datum/data/biogenerator_reagent(n, o, r, p)
@@ -64,26 +64,19 @@
item_list = list()
item_list["Food Items"] = list(
BIOGEN_REAGENT("Milk x10", REAGENT_ID_MILK, 10, 20),
BIOGEN_REAGENT("Milk x50", REAGENT_ID_MILK, 50, 95),
BIOGEN_REAGENT("Cream x10", REAGENT_ID_CREAM, 10, 30),
BIOGEN_REAGENT("Cream x50", REAGENT_ID_CREAM, 50, 120),
BIOGEN_ITEM("Slab of meat", /obj/item/reagent_containers/food/snacks/meat, 1, 50),
BIOGEN_ITEM("Slabs of meat x5", /obj/item/reagent_containers/food/snacks/meat, 5, 250),
BIOGEN_REAGENT("Milk", REAGENT_ID_MILK, 50, 20),
BIOGEN_REAGENT("Cream", REAGENT_ID_CREAM, 50, 30),
BIOGEN_ITEM("Slab of meat", /obj/item/reagent_containers/food/snacks/meat, 5, 50),
BIOGEN_ITEM("Algae Sheets", /obj/item/stack/material/algae, 50, 100),
)
item_list["Cooking Ingredients"] = list(
BIOGEN_REAGENT("Universal Enzyme x10", REAGENT_ID_ENZYME, 10, 30),
BIOGEN_REAGENT("Universal Enzyme x50", REAGENT_ID_ENZYME, 50, 120),
BIOGEN_ITEM("Nutri-spread", /obj/item/reagent_containers/food/snacks/spreads, 1, 30),
BIOGEN_ITEM("Nutri-spread x5", /obj/item/reagent_containers/food/snacks/spreads, 5, 120),
BIOGEN_REAGENT("Universal Enzyme", REAGENT_ID_ENZYME, 50, 30),
BIOGEN_ITEM("Nutri-spread", /obj/item/reagent_containers/food/snacks/spreads, 5, 30),
)
item_list["Gardening Nutrients"] = list(
BIOGEN_ITEM("E-Z-Nutrient", /obj/item/reagent_containers/glass/bottle/eznutrient, 1, 60),
BIOGEN_ITEM("E-Z-Nutrient x5", /obj/item/reagent_containers/glass/bottle/eznutrient, 5, 300),
BIOGEN_ITEM("Left 4 Zed", /obj/item/reagent_containers/glass/bottle/left4zed, 1, 120),
BIOGEN_ITEM("Left 4 Zed x5", /obj/item/reagent_containers/glass/bottle/left4zed, 5, 600),
BIOGEN_ITEM("Robust Harvest", /obj/item/reagent_containers/glass/bottle/robustharvest, 1, 150),
BIOGEN_ITEM("Robust Harvest x5", /obj/item/reagent_containers/glass/bottle/robustharvest, 5, 750),
BIOGEN_ITEM("E-Z-Nutrient", /obj/item/reagent_containers/glass/bottle/eznutrient, 5, 60),
BIOGEN_ITEM("Left 4 Zed", /obj/item/reagent_containers/glass/bottle/left4zed, 5, 120),
BIOGEN_ITEM("Robust Harvest", /obj/item/reagent_containers/glass/bottle/robustharvest, 5, 150),
)
item_list["Leather Products"] = list(
BIOGEN_ITEM("Wallet", /obj/item/storage/wallet, 1, 100),
@@ -99,21 +92,23 @@
BIOGEN_ITEM("Leather Coat", /obj/item/clothing/suit/leathercoat, 1, 500),
BIOGEN_ITEM("Leather Jacket", /obj/item/clothing/suit/storage/toggle/brown_jacket, 1, 500),
BIOGEN_ITEM("Winter Coat", /obj/item/clothing/suit/storage/hooded/wintercoat, 1, 500),
//VOREStation Edit - Algae for oxygen generator
BIOGEN_ITEM("Algae Sheets x4", /obj/item/stack/material/algae, 4, 400),
BIOGEN_ITEM("Algae Sheets x50", /obj/item/stack/material/algae, 50, 5000),
)
/obj/machinery/biogenerator/tgui_static_data(mob/user)
var/list/static_data[0]
var/list/static_data = list()
// Available items - in static data because we don't wanna compute this list every time! It hardly changes.
static_data["items"] = list()
for(var/cat in item_list)
var/list/cat_items = list()
for(var/prize_name in item_list[cat])
var/datum/data/biogenerator_reagent/prize = item_list[cat][prize_name]
cat_items[prize_name] = list("name" = prize_name, "price" = prize.cost, "reagent" = istype(prize))
for(var/prize_name, value in item_list[cat])
if(istype(value, /datum/data/biogenerator_item))
var/datum/data/biogenerator_item/cat_item = value
cat_items[prize_name] = list("name" = prize_name, "price" = cat_item.cost, "max_amount" = cat_item.equipment_amt)
continue
var/datum/data/biogenerator_reagent/cat_reag = value
cat_items[prize_name] = list("name" = prize_name, "price" = cat_reag.cost, "max_amount" = cat_reag.reagent_amt, "reagent" = TRUE)
static_data["items"][cat] = cat_items
return static_data
@@ -136,13 +131,13 @@
ui.open()
/obj/machinery/biogenerator/tgui_act(action, params, datum/tgui/ui)
if(..())
. = ..()
if(.)
return
. = TRUE
switch(action)
if("activate")
INVOKE_ASYNC(src, PROC_REF(activate), ui.user)
activate(ui.user)
return TRUE
if("detach")
if(beaker)
@@ -153,47 +148,52 @@
if("purchase")
var/category = params["cat"] // meow
var/name = params["name"]
var/amount = params["amount"]
if(!(category in item_list) || !(name in item_list[category])) // Not trying something that's not in the list, are you?
return
if(!(category in item_list) || !(name in item_list[category]) || !isnum(amount)) // Not trying something that's not in the list, are you?
return FALSE
var/datum/data/biogenerator_item/bi = item_list[category][name]
if(!istype(bi))
var/datum/data/biogenerator_reagent/br = item_list[category][name]
if(!istype(br))
return
return FALSE
if(!beaker)
return
var/cost = round(br.cost / build_eff)
return FALSE
if(amount <= 0 || amount > br.reagent_amt)
return FALSE
var/cost = round(br.cost / build_eff) * amount
if(cost > points)
to_chat(ui.user, span_danger("Insufficient biomass."))
return
var/amt_to_actually_dispense = round(min(beaker.reagents.get_free_space(), br.reagent_amt))
return FALSE
var/amt_to_actually_dispense = round(min(beaker.reagents.get_free_space(), br.reagent_amt)) * amount
if(amt_to_actually_dispense <= 0)
to_chat(ui.user, span_danger("The loaded beaker is full!"))
return
return FALSE
points -= (cost * (amt_to_actually_dispense / br.reagent_amt))
beaker.reagents.add_reagent(br.reagent_id, amt_to_actually_dispense)
playsound(src, 'sound/machines/reagent_dispense.ogg', 25, 1)
return
return FALSE
if(amount <= 0 || amount > bi.equipment_amt)
return FALSE
var/cost = round(bi.cost / build_eff)
if(cost > points)
to_chat(ui.user, span_danger("Insufficient biomass."))
return
return FALSE
points -= cost
points -= cost * amount
if(ispath(bi.equipment_path, /obj/item/stack))
new bi.equipment_path(loc, bi.equipment_amt)
new bi.equipment_path(loc, amount)
playsound(src, 'sound/machines/vending/vending_drop.ogg', 100, 1)
return TRUE
for(var/i in 1 to bi.equipment_amt)
for(var/i in 1 to amount)
new bi.equipment_path(loc)
playsound(src, 'sound/machines/vending/vending_drop.ogg', 100, 1)
return TRUE
else
return FALSE
/obj/machinery/biogenerator/on_reagent_change() //When the reagents change, change the icon as well.
update_icon()
@@ -277,19 +277,21 @@
points += 1
else points += I.reagents.get_reagent_amount(REAGENT_ID_NUTRIMENT) * 10 * eat_eff
qdel(I)
if(S)
processing = 1
update_icon()
playsound(src, 'sound/machines/blender.ogg', 40, 1)
use_power(S * 30)
sleep((S + 15) / eat_eff)
processing = 0
SStgui.update_uis(src)
playsound(src, 'sound/machines/biogenerator_end.ogg', 40, 1)
update_icon()
else
if(!S)
to_chat(user, span_warning("Error: No growns inside. Please insert growns."))
return
return
processing = 1
update_icon()
playsound(src, 'sound/machines/blender.ogg', 40, 1)
use_power(S * 30)
addtimer(CALLBACK(src, PROC_REF(finish_processing)), (S + 15) / eat_eff, TIMER_DELETE_ME)
/obj/machinery/biogenerator/proc/finish_processing()
processing = 0
SStgui.update_uis(src)
playsound(src, 'sound/machines/biogenerator_end.ogg', 40, 1)
update_icon()
/obj/machinery/biogenerator/RefreshParts()
..()
@@ -1,246 +0,0 @@
import { useState } from 'react';
import { useBackend } from 'tgui/backend';
import { Window } from 'tgui/layouts';
import {
Box,
Button,
Collapsible,
Dropdown,
Input,
Section,
Stack,
} from 'tgui-core/components';
import type { BooleanLike } from 'tgui-core/react';
import { createSearch } from 'tgui-core/string';
type Sortable = {
name: string;
affordable: number;
price: number;
reagent: BooleanLike;
};
type Data = {
items: Record<string, Sortable[]>;
build_eff: number;
points: number;
processing: BooleanLike;
beaker: boolean;
};
const sortTypes = {
Alphabetical: (a: Sortable, b: Sortable) => a.name.localeCompare(b.name),
'By availability': (a: Sortable, b: Sortable) =>
-(a.affordable - b.affordable),
'By price': (a: Sortable, b: Sortable) => a.price - b.price,
};
export const Biogenerator = (props) => {
const { act, data } = useBackend<Data>();
const { processing, points, beaker } = data;
const [searchText, setSearchText] = useState<string>('');
const [sortOrder, setSortOrder] = useState<string>('Alphabetical');
const [descending, setDescending] = useState<boolean>(false);
return (
<Window width={400} height={450}>
<Window.Content className="Layout__content--flexColumn" scrollable>
{(processing && (
<Section title="Processing">
The biogenerator is processing reagents!
</Section>
)) || (
<>
<Section>
{points} points available.
<Button ml={1} icon="blender" onClick={() => act('activate')}>
Activate
</Button>
<Button
ml={1}
icon="eject"
disabled={!beaker}
onClick={() => act('detach')}
>
Eject Beaker
</Button>
</Section>
<BiogeneratorSearch
searchText={searchText}
sortOrder={sortOrder}
descending={descending}
onSearchText={setSearchText}
onSortOrder={setSortOrder}
onDescending={setDescending}
/>
<BiogeneratorItems
searchText={searchText}
sortOrder={sortOrder}
descending={descending}
/>
</>
)}
</Window.Content>
</Window>
);
};
const BiogeneratorItems = (props: {
searchText: string;
sortOrder: string;
descending: boolean;
}) => {
const { act, data } = useBackend<Data>();
const { points, items = [], build_eff, beaker } = data;
// Search thingies
const searcher = createSearch<[string, Sortable]>(
props.searchText,
(item) => {
return item[0];
},
);
let has_contents = false;
const contents = Object.entries(items).map((kv) => {
let items_in_cat = Object.entries(kv[1])
.filter(searcher)
.map((kv2) => {
kv2[1].affordable = +(points >= kv2[1].price / build_eff);
return kv2[1];
})
.sort(sortTypes[props.sortOrder]);
if (items_in_cat.length === 0) {
return undefined;
}
if (props.descending) {
items_in_cat = items_in_cat.reverse();
}
has_contents = true;
return (
<BiogeneratorItemsCategory
key={kv[0]}
title={kv[0]}
items={items_in_cat}
build_eff={build_eff}
beaker={beaker}
/>
);
});
return (
<Stack.Item grow overflow="auto">
<Section>
{has_contents ? (
contents
) : (
<Box color="label">No items matching your criteria was found!</Box>
)}
</Section>
</Stack.Item>
);
};
const BiogeneratorSearch = (props: {
searchText: string;
sortOrder: string;
descending: boolean;
onSearchText: React.Dispatch<React.SetStateAction<string>>;
onSortOrder: React.Dispatch<React.SetStateAction<string>>;
onDescending: React.Dispatch<React.SetStateAction<boolean>>;
}) => {
return (
<Box mb="0.5rem">
<Stack width="100%">
<Stack.Item grow mr="0.5rem">
<Input
placeholder="Search by item name.."
value={props.searchText}
width="100%"
onChange={(value: string) => props.onSearchText(value)}
/>
</Stack.Item>
<Stack.Item basis="30%">
<Dropdown
autoScroll={false}
selected={props.sortOrder}
options={Object.keys(sortTypes)}
width="100%"
lineHeight="19px"
onSelected={(v) => props.onSortOrder(v)}
/>
</Stack.Item>
<Stack.Item>
<Button
icon={props.descending ? 'arrow-down' : 'arrow-up'}
height="19px"
tooltip={props.descending ? 'Descending order' : 'Ascending order'}
tooltipPosition="bottom-end"
ml="0.5rem"
onClick={() => props.onDescending(!props.descending)}
/>
</Stack.Item>
</Stack>
</Box>
);
};
const canBuyItem = (item: Sortable, beaker: BooleanLike) => {
if (!item.affordable) {
return false;
}
if (item.reagent && !beaker) {
return false;
}
return true;
};
const BiogeneratorItemsCategory = (props: {
key: string;
title: string;
items: Sortable[];
build_eff: number;
beaker: BooleanLike;
}) => {
const { act, data } = useBackend();
const { title, items, build_eff, beaker, ...rest } = props;
return (
<Collapsible open title={title} {...rest}>
{items.map((item) => (
<Box key={item.name}>
<Box
inline
verticalAlign="middle"
lineHeight="20px"
style={{
float: 'left',
}}
>
{item.name}
</Box>
<Button
disabled={!canBuyItem(item, beaker)}
width="15%"
textAlign="center"
style={{
float: 'right',
}}
onClick={() =>
act('purchase', {
cat: title,
name: item.name,
})
}
>
{(item.price / build_eff).toLocaleString('en-US')}
</Button>
<Box
style={{
clear: 'both',
}}
/>
</Box>
))}
</Collapsible>
);
};
@@ -0,0 +1,49 @@
import { useBackend } from 'tgui/backend';
import { Section } from 'tgui-core/components';
import { createSearch } from 'tgui-core/string';
import { BiogeneratorItemsCategory } from './BiogeneratorItemsCategory';
import { sortTypes } from './constants';
import type { Data, Sortable } from './types';
export const BiogeneratorItems = (props: {
searchText: string;
sortOrder: string;
descending: boolean;
}) => {
const { act, data } = useBackend<Data>();
const { points, items = [], build_eff, beaker } = data;
// Search thingies
const searcher = createSearch<[string, Sortable]>(
props.searchText,
(item) => {
return item[0];
},
);
const contents = Object.entries(items).map((kv) => {
let items_in_cat = Object.entries(kv[1])
.filter(searcher)
.map((kv2) => {
kv2[1].affordable = +(points >= kv2[1].price / build_eff);
return kv2[1];
})
.sort(sortTypes[props.sortOrder]);
if (items_in_cat.length === 0) {
return undefined;
}
if (props.descending) {
items_in_cat = items_in_cat.reverse();
}
return (
<BiogeneratorItemsCategory
key={kv[0]}
title={kv[0]}
items={items_in_cat}
build_eff={build_eff}
beaker={beaker}
/>
);
});
return <Section fill>{contents}</Section>;
};
@@ -0,0 +1,98 @@
import { useState } from 'react';
import { useBackend } from 'tgui/backend';
import {
Button,
Collapsible,
Slider,
Stack,
Table,
} from 'tgui-core/components';
import type { BooleanLike } from 'tgui-core/react';
import { canBuyItem } from './functions';
import type { Data, Sortable } from './types';
export const BiogeneratorItemsCategory = (props: {
title: string;
items: Sortable[];
build_eff: number;
beaker: BooleanLike;
}) => {
const { title, items, build_eff, beaker } = props;
return (
<Collapsible open title={title} color="transparent">
<Table>
{items.map((item) => (
<BiogeneratorItemsEntry
key={item.name}
title={title}
item={item}
build_eff={build_eff}
beaker={beaker}
/>
))}
</Table>
</Collapsible>
);
};
const BiogeneratorItemsEntry = (props: {
title: string;
item: Sortable;
build_eff: number;
beaker: BooleanLike;
}) => {
const { act, data } = useBackend<Data>();
const [amount, setAmount] = useState(1);
const { title, item, build_eff, beaker } = props;
const { points } = data;
return (
<Table.Row className="candystripe" key={item.name}>
<Table.Cell>{item.name}</Table.Cell>
<Table.Cell collapsing>
<Stack>
{item.max_amount > 1 && (
<Stack.Item>
<Slider
width="50px"
maxValue={item.max_amount}
minValue={1}
value={amount}
format={(val) => `${val}x`}
onChange={(_, val) => setAmount(val)}
/>
</Stack.Item>
)}
<Stack.Item grow>
<Button
fluid
width="69px"
iconPosition="right"
icon="basket-shopping"
disabled={
!canBuyItem(item, beaker) &&
(item.price / build_eff) * amount > points
}
textAlign="right"
onClick={() =>
act('purchase', {
cat: title,
name: item.name,
amount: amount,
})
}
>
{`${((item.price * amount) / build_eff).toFixed()}`}
</Button>
</Stack.Item>
</Stack>
</Table.Cell>
<Table.Cell collapsing color="label">
Price:
</Table.Cell>
<Table.Cell collapsing color="label" textAlign="right" width="30px">
{`${(item.price / build_eff).toFixed()}`}
</Table.Cell>
</Table.Row>
);
};
@@ -0,0 +1,46 @@
import { Box, Button, Dropdown, Input, Stack } from 'tgui-core/components';
import { sortTypes } from './constants';
export const BiogeneratorSearch = (props: {
searchText: string;
sortOrder: string;
descending: boolean;
onSearchText: React.Dispatch<React.SetStateAction<string>>;
onSortOrder: React.Dispatch<React.SetStateAction<string>>;
onDescending: React.Dispatch<React.SetStateAction<boolean>>;
}) => {
return (
<Box mb="0.5rem">
<Stack width="100%">
<Stack.Item grow mr="0.5rem">
<Input
placeholder="Search by item name.."
value={props.searchText}
width="100%"
onChange={(value: string) => props.onSearchText(value)}
/>
</Stack.Item>
<Stack.Item basis="30%">
<Dropdown
autoScroll={false}
selected={props.sortOrder}
options={Object.keys(sortTypes)}
width="100%"
lineHeight="19px"
onSelected={(v) => props.onSortOrder(v)}
/>
</Stack.Item>
<Stack.Item>
<Button
icon={props.descending ? 'arrow-down' : 'arrow-up'}
height="19px"
tooltip={props.descending ? 'Descending order' : 'Ascending order'}
tooltipPosition="bottom-end"
ml="0.5rem"
onClick={() => props.onDescending(!props.descending)}
/>
</Stack.Item>
</Stack>
</Box>
);
};
@@ -0,0 +1,10 @@
import type { Sortable } from './types';
export const sortTypes = {
Alphabetical: (a: Sortable, b: Sortable) => a.name.localeCompare(b.name),
'By availability': (a: Sortable, b: Sortable) =>
-(a.affordable - b.affordable),
'By price': (a: Sortable, b: Sortable) => {
return a.price - b.price;
},
};
@@ -0,0 +1,12 @@
import type { BooleanLike } from 'tgui-core/react';
import type { Sortable } from './types';
export function canBuyItem(item: Sortable, beaker: BooleanLike) {
if (!item.affordable) {
return false;
}
if (item.reagent && !beaker) {
return false;
}
return true;
}
@@ -0,0 +1,65 @@
import { useState } from 'react';
import { useBackend } from 'tgui/backend';
import { Window } from 'tgui/layouts';
import { Button, Section, Stack } from 'tgui-core/components';
import { BiogeneratorItems } from './BiogeneratorItems';
import { BiogeneratorSearch } from './BiogeneratorSearch';
import type { Data } from './types';
export const Biogenerator = (props) => {
const { act, data } = useBackend<Data>();
const { processing, points, beaker } = data;
const [searchText, setSearchText] = useState<string>('');
const [sortOrder, setSortOrder] = useState<string>('Alphabetical');
const [descending, setDescending] = useState<boolean>(false);
return (
<Window width={520} height={600}>
<Window.Content className="Layout__content--flexColumn" scrollable>
{(processing && (
<Section fill title="Processing">
The biogenerator is processing reagents!
</Section>
)) || (
<Stack fill vertical>
<Stack.Item>
<Section>
{points} points available.
<Button ml={1} icon="blender" onClick={() => act('activate')}>
Activate
</Button>
<Button
ml={1}
icon="eject"
disabled={!beaker}
onClick={() => act('detach')}
>
Eject Beaker
</Button>
</Section>
</Stack.Item>
<Stack.Item>
<BiogeneratorSearch
searchText={searchText}
sortOrder={sortOrder}
descending={descending}
onSearchText={setSearchText}
onSortOrder={setSortOrder}
onDescending={setDescending}
/>
</Stack.Item>
<Stack.Item grow>
<BiogeneratorItems
searchText={searchText}
sortOrder={sortOrder}
descending={descending}
/>
</Stack.Item>
</Stack>
)}
</Window.Content>
</Window>
);
};
@@ -0,0 +1,17 @@
import type { BooleanLike } from 'tgui-core/react';
export type Sortable = {
name: string;
affordable: number;
price: number;
max_amount: number;
reagent?: BooleanLike;
};
export type Data = {
items: Record<string, Sortable[]>;
build_eff: number;
points: number;
processing: BooleanLike;
beaker: boolean;
};
@@ -126,6 +126,9 @@ export function CreateObject(props: CreateObjectProps) {
if (storedShowIcons !== undefined) setshowIcons(storedShowIcons);
if (storedShowPreview !== undefined) setshowPreview(storedShowPreview);
if (storedSelectedObj && allObjects[storedSelectedObj]) {
act('selected-atom-changed', {
newObj: storedSelectedObj,
});
setSelectedObj(storedSelectedObj);
props.onIconSettingsChange?.({
icon: allObjects[storedSelectedObj].icon,