mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-08-22 12:41:09 +01:00
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:
@@ -726,10 +726,22 @@
|
||||
COMSIG_ATOM_AFTER_SUCCESSFUL_INITIALIZED_ON = PROC_REF(on_atom_initialized_on),
|
||||
)
|
||||
var/datum/component/connect_loc_behalf/connector
|
||||
var/datum/component/material_container/container
|
||||
|
||||
/obj/item/mod/module/recycler/Initialize(mapload)
|
||||
. = ..()
|
||||
AddComponent(/datum/component/material_container, accepted_mats, 50 * SHEET_MATERIAL_AMOUNT, MATCONTAINER_EXAMINE|MATCONTAINER_NO_INSERT, _after_retrieve=CALLBACK(src, PROC_REF(attempt_insert_storage)))
|
||||
container = AddComponent( \
|
||||
/datum/component/material_container, \
|
||||
accepted_mats, 50 * SHEET_MATERIAL_AMOUNT, \
|
||||
MATCONTAINER_EXAMINE|MATCONTAINER_NO_INSERT, \
|
||||
container_signals = list( \
|
||||
COMSIG_MATCONTAINER_SHEETS_RETRIVED = TYPE_PROC_REF(/obj/item/mod/module/recycler, InsertSheets) \
|
||||
) \
|
||||
)
|
||||
|
||||
/obj/item/mod/module/recycler/Destroy()
|
||||
container = null
|
||||
return ..()
|
||||
|
||||
/obj/item/mod/module/recycler/on_activation()
|
||||
. = ..()
|
||||
@@ -747,6 +759,7 @@
|
||||
|
||||
/obj/item/mod/module/recycler/proc/on_wearer_moved(datum/source, atom/old_loc, dir, forced)
|
||||
SIGNAL_HANDLER
|
||||
|
||||
for(var/obj/item/item in mod.wearer.loc)
|
||||
if(!is_type_in_list(item, allowed_item_types))
|
||||
return
|
||||
@@ -754,12 +767,14 @@
|
||||
|
||||
/obj/item/mod/module/recycler/proc/on_obj_entered(atom/new_loc, atom/movable/arrived, atom/old_loc)
|
||||
SIGNAL_HANDLER
|
||||
|
||||
if(!is_type_in_list(arrived, allowed_item_types))
|
||||
return
|
||||
insert_trash(arrived)
|
||||
|
||||
/obj/item/mod/module/recycler/proc/on_atom_initialized_on(atom/loc, atom/new_atom)
|
||||
SIGNAL_HANDLER
|
||||
|
||||
if(!is_type_in_list(new_atom, allowed_item_types))
|
||||
return
|
||||
//Give the new atom the time to fully initialize and maybe live if the wearer moves away.
|
||||
@@ -770,7 +785,6 @@
|
||||
insert_trash(new_atom)
|
||||
|
||||
/obj/item/mod/module/recycler/proc/insert_trash(obj/item/item)
|
||||
var/datum/component/material_container/container = GetComponent(/datum/component/material_container)
|
||||
var/retrieved = container.insert_item(item, multiplier = efficiency, breakdown_flags = BREAKDOWN_FLAGS_RECYCLER)
|
||||
if(retrieved == MATERIAL_INSERT_ITEM_NO_MATS) //even if it doesn't have any material to give, trash is trash.
|
||||
qdel(item)
|
||||
@@ -787,7 +801,6 @@
|
||||
dispense(target)
|
||||
|
||||
/obj/item/mod/module/recycler/proc/dispense(atom/target)
|
||||
var/datum/component/material_container/container = GetComponent(/datum/component/material_container)
|
||||
if(container.retrieve_all(target))
|
||||
balloon_alert(mod.wearer, "material dispensed")
|
||||
playsound(src, 'sound/machines/microwave/microwave-end.ogg', 50, TRUE)
|
||||
@@ -795,6 +808,11 @@
|
||||
balloon_alert(mod.wearer, "not enough material")
|
||||
playsound(src, 'sound/machines/buzz-sigh.ogg', 50, TRUE)
|
||||
|
||||
/obj/item/mod/module/recycler/proc/InsertSheets(obj/item/recycler, obj/item/stack/sheets)
|
||||
SIGNAL_HANDLER
|
||||
|
||||
attempt_insert_storage(sheets)
|
||||
|
||||
/obj/item/mod/module/recycler/proc/attempt_insert_storage(obj/item/to_drop)
|
||||
if(!isturf(to_drop.loc) && !to_drop.loc.atom_storage?.attempt_insert(to_drop, mod.wearer, override = TRUE))
|
||||
to_drop.forceMove(to_drop.loc.drop_location())
|
||||
@@ -815,7 +833,6 @@
|
||||
var/required_amount = SHEET_MATERIAL_AMOUNT*12.5
|
||||
|
||||
/obj/item/mod/module/recycler/donk/dispense(atom/target)
|
||||
var/datum/component/material_container/container = GetComponent(/datum/component/material_container)
|
||||
if(!container.use_amount_mat(required_amount, /datum/material/iron))
|
||||
balloon_alert(mod.wearer, "not enough material")
|
||||
playsound(src, 'sound/machines/buzz-sigh.ogg', 50, TRUE)
|
||||
|
||||
Reference in New Issue
Block a user