Material container & related stuff ui refactors & clean-up (#76220)

## About The Pull Request

**1. Material container clean-up & refactor**
- Replaced `total_amount` var with `total_amount()` proc, this var can
be easily computed by summing up all material amounts rather than
storing it as a var which is tedious to update & keep track of when
materials are added/removed
- Removed unused procs `transer_amt_to()`, `can_insert_amount_mat()`,
and `get_categories()`. These procs are not used anywhere in the
codebase so let's remove them & make some space.
- Callbacks are replaced with signals, the callbacks don't need to be
explicitly garbage collected & having macros & procs marked with
`SIGNAL_HANDLER` makes your intentions more readable & explicit.
- Fixes #76151 
All material adding, removal, checking operations are "Integer"
operations, i.e. the final value is rounded & them made 1 if the final
value is 0 using the macro `OPTIMIZE_COST`[coudn't come up with a better
name]. No more dealing with decimal value materials
The problem was after the protolathe was upgraded with better parts all
the design costs were multiplied with a decimal `efficiency_coeff`
value, this means even though in the UI the cost was displayed as 60
bluespace crystals its actual cost was `60.0001` something in the
backend causing this check for materials to fail & print the error
message.
- Replaced `GetComponent(/datum/component_material_container)` with just
a simple ref to the material container when adding the component, so we
can save some overhead from calling this proc
- Gave all procs a ton of documentation with documentation having
documentation
- Fixes #76506 RCD and other devices that uses the silo link upgrade now
have the correct material usages
- Fixes #72096. It wasn't just a problem with ancient protolathe but
with all machines that used `datum/component/remote_materials` the
problem was remote materials would add an instance of
`datum/remote/material_container` if it wanted to use local storage but
this component would get added before `datum/component/remote_materials`
could be registered i.e. it comes before remote_materials in the
component list. So when the machine is destroyed it will first destroy
`material_container` & then `remote_materials` therefore destroying the
materials before they could get ejected
- Silo link is established when parent is registered with remote
materials raher than adding an external timer which is faster
- Everything that uses a material container will auto eject their sheets
when destroyed
- Moved this & remote materials into its own folder for better
organization


**2. Material UI Changes**
- Removed the x25 & x50 print buttons from the autolathe, now they just
have x5 & x10 buttons like the protolathe, These buttons were of no use
since you could just type the exact amount you want to print in the
`[Max: <some amount>]` side bar. The code to compute these buttons was
just plain right nasty & some of it unused in the UI.
- The material eject button in the material bar does not gray out when
you can eject exactly one sheet
- All material cost are integer values rounded
- Fixes #76253 Exosuit Fabricator sends the material container static
data to the UI so its material bar is not greyed out when there are
sufficient materials to eject
- Component printer material bar sends the material container static
data to the UI so its material bar is not greyed out when there are
sufficient materials to eject
- Autolathe Material bars now display number of sheets available
- Max printable amount of items are now computed & updated correctly in
the UI. They were displaying wrong values & now get updated when items
are printed, materials are removed
- Silo hold actually works now. When a machine is put on hold it calls
this proc

https://github.com/tgstation/tgstation/blob/e929cf39cded5207d63df1fa8521f41f2816b383/code/datums/components/remote_materials.dm#L78-L87
Notice how the key is `src` so we should be consistent during checking
if a machine is on hold using the same `src` var. But for some reason we
did dumb shit like this

https://github.com/tgstation/tgstation/blob/e929cf39cded5207d63df1fa8521f41f2816b383/code/datums/components/remote_materials.dm#L150-L153
What is category? Why do we care for the area the machine is in? None of
it made sense so i removed all that junk and just made it check for
`src` like it should
- Removed redundant `removable` & `sheets` var from the material
container ui_data. These vars are unused in the UI
- If an item does not have the required materials then upon clicking
that item you will not get any error message but instead nothing happens

## Changelog
🆑
fix: items can be printed from autolathe & protolathe when the exact
material amounts are present in them after upgrading
fix: max printable amount now shows the correct value & updates when
items are printed, materials are removed in the autolathe & protolathe
fix: component printer material bar is not greyed out when there are
sufficient materials to eject
fix: rcd and other devices that uses the silo link upgrade now have the
correct material usages
fix: silo hold actually works
fix: machines using local storage to hold materials will eject it's
materials as sheets when deconstructed/destroyed
refactor: Autolathe Material bars now display number of sheets available
refactor: printing an item that does not have enough materials will fail
silently with no error messages
refactor: Drone dispenser will eject sheets upon deconstruction
refactor: all things that store materials will auto ejects its sheets(if
there is sufficient material) when destroyed
refactor: inserting an item into the material container will display the
units consumed as sheets not absolute units
refactor: removed x25 & x50 print buttons from the autolathe
This commit is contained in:
SyncIt21
2023-07-24 19:47:14 -04:00
committed by GitHub
parent e04c1a3245
commit e92ae5b75b
32 changed files with 861 additions and 789 deletions
+45 -47
View File
@@ -17,6 +17,9 @@
/// The current unlocked circuit component designs. Used by integrated circuits to print off circuit components remotely.
var/list/current_unlocked_designs = list()
/// The efficiency of this machine
var/efficiency_coeff = 1
/obj/machinery/component_printer/Initialize(mapload)
. = ..()
if(!CONFIG_GET(flag/no_default_techweb_link) && !techweb)
@@ -24,7 +27,6 @@
materials = AddComponent( \
/datum/component/remote_materials, \
"component_printer", \
mapload, \
mat_container_flags = BREAKDOWN_FLAGS_LATHE, \
)
@@ -74,18 +76,9 @@
get_asset_datum(/datum/asset/spritesheet/sheetmaterials)
)
/obj/machinery/component_printer/proc/calculate_efficiency()
var/rating = 0
/obj/machinery/component_printer/RefreshParts()
. = ..()
for(var/datum/stock_part/servo/servo in component_parts)
///we do -1 because normal manipulators rating of 1 gives us 1-1=0 i.e no decrement in cost
rating += servo.tier-1
///linear interpolation between full cost i.e 1 & 1/8th the cost i.e 0.125
///we do it in 6 steps because maximum rating of 2 manipulators is 8 but -1 gives us 6
var/coff = 1.0+((0.125-1.0)*(rating/6))
///copied from production.dm calculate_efficiency() proc
if(materials)
var/total_storage = 0
@@ -94,7 +87,17 @@
materials.set_local_size(total_storage)
return coff
efficiency_coeff = 0
for(var/datum/stock_part/servo/servo in component_parts)
///we do -1 because normal manipulators rating of 1 gives us 1-1=0 i.e no decrement in cost
efficiency_coeff += servo.tier-1
///linear interpolation between full cost i.e 1 & 1/8th the cost i.e 0.125
///we do it in 6 steps because maximum rating of 2 manipulators is 8 but -1 gives us 6
efficiency_coeff = 1.0+((0.125-1.0)*(efficiency_coeff / 6))
update_static_data_for_all_viewers()
/obj/machinery/component_printer/proc/print_component(typepath)
var/design_id = current_unlocked_designs[typepath]
@@ -106,8 +109,7 @@
if (materials.on_hold())
return
var/efficiency_coeff = calculate_efficiency()
if (!materials.mat_container?.has_materials(design.materials, efficiency_coeff))
if (!materials.mat_container.has_materials(design.materials, efficiency_coeff))
return
materials.mat_container.use_materials(design.materials, efficiency_coeff)
@@ -133,14 +135,12 @@
say("Mineral access is on hold, please contact the quartermaster.")
return TRUE
var/efficiency_coeff = calculate_efficiency()
if (!materials.mat_container?.has_materials(design.materials, efficiency_coeff))
if (!materials.mat_container.has_materials(design.materials, efficiency_coeff))
say("Not enough materials.")
return TRUE
balloon_alert_to_viewers("printed [design.name]")
materials.mat_container?.use_materials(design.materials, efficiency_coeff)
materials.mat_container.use_materials(design.materials, efficiency_coeff)
materials.silo_log(src, "printed", -1, design.name, design.materials)
var/atom/printed_design = new design.build_path(drop_location())
printed_design.pixel_x = printed_design.base_pixel_x + rand(-5, 5)
@@ -163,12 +163,12 @@
return data
/obj/machinery/component_printer/ui_static_data(mob/user)
var/list/data = list()
var/list/data = materials.mat_container.ui_static_data()
var/list/designs = list()
var/datum/asset/spritesheet/research_designs/spritesheet = get_asset_datum(/datum/asset/spritesheet/research_designs)
var/size32x32 = "[spritesheet.name]32x32"
var/efficiency_coeff = calculate_efficiency()
// for (var/datum/design/component/component_design_type as anything in subtypesof(/datum/design/component))
for (var/researched_design_id in techweb.researched_designs)
@@ -176,12 +176,15 @@
if (!(design.build_type & COMPONENT_PRINTER))
continue
var/icon_size = spritesheet.icon_size_id(design.id)
var/list/cost = list()
for(var/datum/material/mat in design.materials)
cost[mat.name] = OPTIMAL_COST(design.materials[mat] * efficiency_coeff)
var/icon_size = spritesheet.icon_size_id(design.id)
designs[researched_design_id] = list(
"name" = design.name,
"desc" = design.desc,
"cost" = get_material_cost_data(design.materials, efficiency_coeff),
"cost" = cost,
"id" = researched_design_id,
"categories" = design.category,
"icon" = "[icon_size == size32x32 ? "" : "[icon_size] "][design.id]",
@@ -315,12 +318,13 @@
var/cost_per_component = 1000
var/efficiency_coeff = 1
/obj/machinery/module_duplicator/Initialize(mapload)
. = ..()
materials = AddComponent( \
/datum/component/remote_materials, \
"module_duplicator", \
mapload, \
mat_container_flags = BREAKDOWN_FLAGS_LATHE, \
)
@@ -337,8 +341,9 @@
get_asset_datum(/datum/asset/spritesheet/research_designs)
)
/obj/machinery/module_duplicator/proc/calculate_efficiency()
///copied from production.dm calculate_efficiency() proc
/obj/machinery/module_duplicator/RefreshParts()
. = ..()
if(materials)
var/total_storage = 0
@@ -347,17 +352,17 @@
materials.set_local_size(total_storage)
var/rating = 0
efficiency_coeff = 0
for(var/datum/stock_part/servo/servo in component_parts)
///we do -1 because normal manipulators rating of 1 gives us 1-1=0 i.e no decrement in cost
rating += servo.tier - 1
efficiency_coeff += servo.tier - 1
///linear interpolation between full cost i.e 1 & 1/8th the cost i.e 0.125
///we do it in 6 steps because maximum rating of 2 manipulators is 8 but -1 gives us 6
var/coff = 1.0 + ((0.125 - 1.0) * (rating/6))
efficiency_coeff = 1.0 + ((0.125 - 1.0) * (efficiency_coeff / 6))
return coff
update_static_data_for_all_viewers()
/obj/machinery/module_duplicator/ui_act(action, list/params)
. = ..()
@@ -377,14 +382,12 @@
say("Mineral access is on hold, please contact the quartermaster.")
return TRUE
var/efficiency_coeff = calculate_efficiency()
if (!materials.mat_container?.has_materials(design["materials"], efficiency_coeff))
if (!materials.mat_container.has_materials(design["materials"], efficiency_coeff))
say("Not enough materials.")
return TRUE
balloon_alert_to_viewers("printed [design["name"]]")
materials.mat_container?.use_materials(design["materials"], efficiency_coeff)
materials.mat_container.use_materials(design["materials"], efficiency_coeff)
materials.silo_log(src, "printed", -1, design["name"], design["materials"])
print_module(design)
if ("remove_mat")
@@ -481,19 +484,22 @@
return data
/obj/machinery/module_duplicator/ui_static_data(mob/user)
var/list/data = list()
var/list/data = materials.mat_container.ui_static_data()
var/list/designs = list()
var/index = 1
var/efficiency_coeff = calculate_efficiency()
for (var/list/design as anything in scanned_designs)
var/list/cost = list()
var/list/materials = design["materials"]
for(var/datum/material/mat in materials)
cost[mat.name] = OPTIMAL_COST(materials[mat] * efficiency_coeff)
designs["[index]"] = list(
"name" = design["name"],
"desc" = design["desc"],
"cost" = get_material_cost_data(design["materials"], efficiency_coeff),
"cost" = cost,
"id" = "[index]",
"icon" = "integrated_circuit",
"categories" = list("/Saved Circuits"),
@@ -513,11 +519,3 @@
if(..())
return TRUE
return default_deconstruction_screwdriver(user, "module-fab-o", "module-fab-idle", tool)
/obj/machinery/module_duplicator/proc/get_material_cost_data(list/materials, efficiency_coeff)
var/list/data = list()
for (var/datum/material/material_type as anything in materials)
data[initial(material_type.name)] = materials[material_type] * efficiency_coeff
return data