mirror of
https://github.com/CHOMPStation2/CHOMPStation2.git
synced 2025-12-11 02:34:00 +00:00
[MIRROR] Add recipe macro recording to reagent dispenser (#8769)
Co-authored-by: ShadowLarkens <shadowlarkens@gmail.com> Co-authored-by: Kashargul <144968721+Kashargul@users.noreply.github.com>
This commit is contained in:
@@ -21,6 +21,11 @@
|
||||
anchored = TRUE
|
||||
unacidable = TRUE
|
||||
|
||||
/// Records the reagents dispensed by the user if this list is not null
|
||||
var/list/recording_recipe
|
||||
/// Saves all the recipes recorded by the machine
|
||||
var/list/saved_recipes = list()
|
||||
|
||||
/obj/machinery/chemical_dispenser/Initialize()
|
||||
. = ..()
|
||||
if(spawn_cartridges)
|
||||
@@ -154,25 +159,38 @@
|
||||
var/obj/item/weapon/reagent_containers/chem_disp_cartridge/C = cartridges[label]
|
||||
chemicals.Add(list(list("name" = label, "id" = label, "volume" = C.reagents.total_volume))) // list in a list because Byond merges the first list...
|
||||
data["chemicals"] = chemicals
|
||||
|
||||
data["recipes"] = saved_recipes
|
||||
data["recordingRecipe"] = recording_recipe
|
||||
return data
|
||||
|
||||
/obj/machinery/chemical_dispenser/tgui_act(action, params)
|
||||
if(..())
|
||||
return TRUE
|
||||
/obj/machinery/chemical_dispenser/tgui_act(action, list/params, datum/tgui/ui, datum/tgui_state/state)
|
||||
. = ..()
|
||||
if(.)
|
||||
return
|
||||
if(stat & BROKEN)
|
||||
return FALSE
|
||||
|
||||
add_fingerprint(ui.user)
|
||||
|
||||
. = TRUE
|
||||
switch(action)
|
||||
if("amount")
|
||||
amount = clamp(round(text2num(params["amount"]), 1), 0, 120) // round to nearest 1 and clamp 0 - 120
|
||||
. = TRUE
|
||||
|
||||
if("dispense")
|
||||
var/label = params["reagent"]
|
||||
if(cartridges[label] && container && container.is_open_container())
|
||||
if(recording_recipe)
|
||||
recording_recipe += list(list("id" = label, "amount" = amount))
|
||||
else if(cartridges[label] && container && container.is_open_container())
|
||||
var/obj/item/weapon/reagent_containers/chem_disp_cartridge/C = cartridges[label]
|
||||
playsound(src, 'sound/machines/reagent_dispense.ogg', 25, 1)
|
||||
C.reagents.trans_to(container, amount)
|
||||
. = TRUE
|
||||
|
||||
if("remove")
|
||||
var/amount = text2num(params["amount"])
|
||||
if(!container || !amount)
|
||||
if(!container || !amount || recording_recipe)
|
||||
return
|
||||
var/datum/reagents/R = container.reagents
|
||||
var/id = params["reagent"]
|
||||
@@ -180,18 +198,82 @@
|
||||
R.remove_reagent(id, amount)
|
||||
else if(amount == -1) // Isolate
|
||||
R.isolate_reagent(id)
|
||||
. = TRUE
|
||||
|
||||
if("ejectBeaker")
|
||||
if(container)
|
||||
container.forceMove(get_turf(src))
|
||||
|
||||
if(Adjacent(usr)) // So the AI doesn't get a beaker somehow.
|
||||
usr.put_in_hands(container)
|
||||
|
||||
if(Adjacent(ui.user)) // So the AI doesn't get a beaker somehow.
|
||||
ui.user.put_in_hands(container)
|
||||
container = null
|
||||
else
|
||||
return FALSE
|
||||
. = TRUE
|
||||
|
||||
if("record_recipe")
|
||||
recording_recipe = list()
|
||||
. = TRUE
|
||||
|
||||
if("cancel_recording")
|
||||
recording_recipe = null
|
||||
. = TRUE
|
||||
|
||||
if("clear_recipes")
|
||||
if(tgui_alert(ui.user, "Clear all recipes?", "Clear?", list("No", "Yes")) == "Yes")
|
||||
saved_recipes = list()
|
||||
. = TRUE
|
||||
|
||||
if("save_recording")
|
||||
var/name = tgui_input_text(ui.user, "What do you want to name this recipe?", "Recipe Name?", "Recipe Name", MAX_NAME_LEN)
|
||||
if(tgui_status(ui.user, state) != STATUS_INTERACTIVE)
|
||||
return
|
||||
if(saved_recipes[name] && tgui_alert(ui.user, "\"[name]\" already exists, do you want to overwrite it?",, list("No", "Yes")) != "Yes")
|
||||
return
|
||||
if(name && recording_recipe)
|
||||
for(var/list/L in recording_recipe)
|
||||
var/label = L["id"]
|
||||
// Verify this dispenser can dispense every chemical
|
||||
if(!cartridges[label])
|
||||
visible_message(span_warning("[src] buzzes."), span_warning("You hear a faint buzz."))
|
||||
to_chat(ui.user, span_warning("[src] cannot find <b>[label]</b>!"))
|
||||
playsound(src, 'sound/machines/buzz-two.ogg', 50, TRUE)
|
||||
return
|
||||
saved_recipes[name] = recording_recipe
|
||||
recording_recipe = null
|
||||
. = TRUE
|
||||
|
||||
if("dispense_recipe")
|
||||
var/list/chemicals_to_dispense = saved_recipes[params["recipe"]]
|
||||
if(!LAZYLEN(chemicals_to_dispense))
|
||||
return
|
||||
|
||||
if(!recording_recipe)
|
||||
if(!container)
|
||||
to_chat(ui.user, span_warning("There is no beaker in [src]."))
|
||||
return
|
||||
|
||||
for(var/list/L in chemicals_to_dispense)
|
||||
var/label = L["id"]
|
||||
var/dispense_amount = L["amount"]
|
||||
|
||||
var/obj/item/weapon/reagent_containers/chem_disp_cartridge/C = cartridges[label]
|
||||
if(!C)
|
||||
visible_message(span_warning("[src] buzzes."), span_warning("You hear a faint buzz."))
|
||||
to_chat(ui.user, span_warning("[src] cannot find <b>[label]</b>!"))
|
||||
playsound(src, 'sound/machines/buzz-two.ogg', 50, TRUE)
|
||||
break
|
||||
|
||||
// Allows copying recipes
|
||||
playsound(src, 'sound/machines/reagent_dispense.ogg', 25, 1)
|
||||
var/amount_actually_dispensed = C.reagents.trans_to(container, dispense_amount)
|
||||
if(dispense_amount != amount_actually_dispensed)
|
||||
visible_message(span_warning("[src] buzzes."), span_warning("You hear a faint buzz."))
|
||||
to_chat(ui.user, span_warning("[src] was only able to dispense [amount_actually_dispensed]u out of [dispense_amount]u requested of <b>[label]</b>!"))
|
||||
playsound(src, 'sound/machines/buzz-two.ogg', 50, TRUE)
|
||||
break
|
||||
else
|
||||
recording_recipe += chemicals_to_dispense
|
||||
|
||||
. = TRUE
|
||||
|
||||
add_fingerprint(usr)
|
||||
|
||||
/obj/machinery/chemical_dispenser/attack_ghost(mob/user)
|
||||
if(stat & BROKEN)
|
||||
|
||||
Reference in New Issue
Block a user