Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autolathe 2.1 - Fucking Performance Edition #8770

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 9 additions & 23 deletions code/game/machinery/autolathe.dm
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
var/shock_wire
var/prod_coeff = 1
var/datum/techweb/stored_research
var/screen = 1
var/base_price = 25
var/hacked_price = 50
var/datum/research/files
Expand All @@ -39,9 +38,7 @@
var/processing_line
var/printdirection = 0
var/queuelength = 0
var/selected_category = "Tools"

var/list/categories = list("Tools","Electronics","Construction","T-Comm","Security","Machinery","Medical","Misc","Dinnerware","Imported")
var/list/categories = list("Tools","Electronics","Construction","T-Comm","Security","Machinery","Medical","Misc","Dinnerware","Imported", "Search")

/obj/machinery/autolathe/Initialize()
AddComponent(/datum/component/material_container, list(MAT_METAL, MAT_GLASS), 0, TRUE, null, null, CALLBACK(src, .proc/AfterMaterialInsert))
Expand Down Expand Up @@ -74,21 +71,21 @@
/obj/machinery/autolathe/ui_data(mob/user) // All the data the ui will need
var/list/data = list()
var/list/designs = list()

var/datum/component/material_container/materials = GetComponent(/datum/component/material_container)
data["screen"] = screen
data["total_amount"] = materials.total_amount
data["max_amount"] = materials.max_amount
data["metal_amount"] = materials.amount(MAT_METAL)
data["glass_amount"] = materials.amount(MAT_GLASS)
data["categories"] = categories
data["selected_category"] = selected_category

data["rightwall"] = wallcheck(4) // Wall data for ui
data["leftwall"] = wallcheck(8)
data["abovewall"] = wallcheck(1)
data["belowwall"] = wallcheck(2)

processing_line = being_built.len ? get_processing_line() : null
data["processing"] = processing_line
data["printdir"] = printdirection
data["isprocessing"] = processing_queue
data["queuelength"] = queuelength
data["categories"] = categories
for(var/v in stored_research.researched_designs)
var/datum/design/D = SSresearch.techweb_design_by_id(v)
var/list/design = list()
Expand All @@ -113,15 +110,7 @@
design["materials_metal"] = get_design_cost_metal(D)
design["materials_glass"] = get_design_cost_glass(D)
designs += list(design)

data["designs"] = designs
processing_line = being_built.len ? get_processing_line() : null
data["processing"] = processing_line

data["printdir"] = printdirection

data["isprocessing"] = processing_queue
data["queuelength"] = queuelength
if(istype(autoqueue) && autoqueue.len)
var/list/uidata = list()
var/index = 1
Expand All @@ -140,9 +129,6 @@
return

switch(action)
if("set_category")
selected_category = params["category"]

if("make") // Lets try make the item supplied via the UI
request = stored_research.isDesignResearchedID(params["item_id"])
if(!request)
Expand All @@ -153,7 +139,6 @@
add_to_queue(request, multiplier) // Add item to queue for processing
else
to_chat(usr, "<span class='warning'>The autolathe queue is full!</span>")

if("eject")
request = stored_research.isDesignResearchedID(params["item_id"])
if(processing_queue)
Expand Down Expand Up @@ -195,6 +180,7 @@
if(printdirection > 8) // Simple Sanity Check
printdirection = 0

ui_interact(usr)
update_icon()

/obj/machinery/autolathe/on_deconstruction()
Expand Down Expand Up @@ -421,7 +407,7 @@
say("Queue processing halted.")
processing_queue = FALSE
return
if(stat&(NOPOWER|BROKEN))
if(stat&(NOPOWER|BROKEN) || panel_open)
processing_queue = FALSE
return
if(!can_build(D,multiplier))
Expand Down
33 changes: 26 additions & 7 deletions tgui-next/packages/tgui/interfaces/Autolathe.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ export class Autolathe extends Component {

constructor() {
super();
this.state = { searchterms: '', sheetnumberglass: 0, sheetnumbermetal: 0 };
this.state = {
searchterms: '', sheetnumberglass: 0, sheetnumbermetal: 0, setcategory: 'Tools',
};
}

setSearchText(searchterms) {
Expand All @@ -29,12 +31,18 @@ export class Autolathe extends Component {
sheetnumberglass,
});
}

setCategory(setcategory) {
this.setState({
setcategory,
});
}

render() {
const { state } = this.props;
const { config, data } = state;
const { ref } = config;
const { searchterms, sheetnumberglass, sheetnumbermetal } = this.state;
const { searchterms, sheetnumberglass, sheetnumbermetal, setcategory } = this.state;
return (
<Section
title={("Autolathe")}
Expand Down Expand Up @@ -181,26 +189,37 @@ export class Autolathe extends Component {
key={categoryName}
fluid
mr={2}
selected={data.selected_category === categoryName}
selected={
(searchterms.length > 1 ? (
(categoryName === 'Search' ? 1 : 0)
):(
setcategory === categoryName
))
}
color="transparent"
content={categoryName}
onClick={(!searchterms ? (
() => act(ref, 'set_category', { category: categoryName })
() => this.setCategory(categoryName)
):(
() => this.setSearchText("")))}
/>
))}
</Section>
</Flex.Item>
<Flex.Item>
{searchterms.length > 0 ? (
{searchterms.length > 1 ? (
<Section fluid title="Search Results" width={100}>
<div>
<Flex.Item>
{data.designs.filter(design => {
const searchTerm = searchterms.toLowerCase();
const searchableString = String(design.name).toLowerCase();
return (searchableString.startsWith(searchterms));
// this.setCategory('Search');
return (searchterms.length < 2 ? (
null
) : (
(searchableString.match(new RegExp(searchterms, "i")))
));
}).map(design => (
<div key={data.designs}>
<Grid>
Expand Down Expand Up @@ -275,7 +294,7 @@ export class Autolathe extends Component {
<div>
<Flex.Item>
{data.designs.filter(design => {
return (design.category.includes(data.selected_category));
return (design.category.includes(setcategory));
}).map(design => (
<div key={data.designs}>
<Grid>
Expand Down
2 changes: 1 addition & 1 deletion tgui-next/packages/tgui/public/tgui.bundle.js

Large diffs are not rendered by default.