mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-07-15 01:54:52 +01:00
Clean up some cruft in mass var edit (#89548)
## About The Pull Request just cleaning out the cobwebs Mixed usr/src, using set on a proc /datum/o casting atom but taking datums ## Changelog 🆑 code: cleaned up some mass var edit code /🆑 --------- Co-authored-by: TiviPlus <572233640+TiviPlus@users.noreply.com>
This commit is contained in:
@@ -1,44 +1,40 @@
|
||||
/client/proc/cmd_mass_modify_object_variables(atom/A, var_name)
|
||||
set category = "Debug"
|
||||
set name = "Mass Edit Variables"
|
||||
set desc="(target) Edit all instances of a target item's variables"
|
||||
|
||||
var/method = 0 //0 means strict type detection while 1 means this type and all subtypes (IE: /obj/item with this set to 1 will set it to ALL items)
|
||||
|
||||
if(tgui_alert(usr, "Are you sure you'd like to mass-modify every instance of the [var_name] variable? This can break everything if you do not know what you are doing.", "Slow down, chief!", list("Yes", "No"), 60 SECONDS) != "Yes")
|
||||
/client/proc/cmd_mass_modify_object_variables(datum/target, var_name)
|
||||
if(tgui_alert(src, "Are you sure you'd like to mass-modify every instance of the [var_name] variable? This can break everything if you do not know what you are doing.", "Slow down, chief!", list("Yes", "No"), 60 SECONDS) != "Yes")
|
||||
return
|
||||
|
||||
if(!check_rights(R_VAREDIT))
|
||||
return
|
||||
|
||||
if(A?.type)
|
||||
method = vv_subtype_prompt(A.type)
|
||||
/// if false get only the strict type, get all subtypes too otherwise
|
||||
var/strict_type = FALSE
|
||||
if(target?.type)
|
||||
strict_type = vv_subtype_prompt(target.type)
|
||||
|
||||
src.massmodify_variables(A, var_name, method)
|
||||
massmodify_variables(target, var_name, strict_type)
|
||||
BLACKBOX_LOG_ADMIN_VERB("Mass Edit Variables")
|
||||
|
||||
/client/proc/massmodify_variables(datum/O, var_name = "", method = 0)
|
||||
/client/proc/massmodify_variables(datum/target, var_name = "", strict_type = FALSE)
|
||||
if(!check_rights(R_VAREDIT))
|
||||
return
|
||||
if(!istype(O))
|
||||
if(!istype(target))
|
||||
return
|
||||
|
||||
var/variable = ""
|
||||
if(!var_name)
|
||||
var/list/names = list()
|
||||
for (var/V in O.vars)
|
||||
for (var/V in target.vars)
|
||||
names += V
|
||||
|
||||
names = sort_list(names)
|
||||
|
||||
variable = input("Which var?", "Var") as null|anything in names
|
||||
variable = input(src, "Which var?", "Var") as null|anything in names
|
||||
else
|
||||
variable = var_name
|
||||
|
||||
if(!variable || !O.can_vv_get(variable))
|
||||
if(!variable || !target.can_vv_get(variable))
|
||||
return
|
||||
var/default
|
||||
var/var_value = O.vars[variable]
|
||||
var/var_value = target.vars[variable]
|
||||
|
||||
if(variable in GLOB.VVckey_edit)
|
||||
to_chat(src, "It's forbidden to mass-modify ckeys. It'll crash everyone's client you dummy.", confidential = TRUE)
|
||||
@@ -52,7 +48,7 @@
|
||||
if(variable in GLOB.VVpixelmovement)
|
||||
if(!check_rights(R_DEBUG))
|
||||
return
|
||||
var/prompt = tgui_alert(usr, "Editing this var may irreparably break tile gliding for the rest of the round. THIS CAN'T BE UNDONE", "DANGER", list("ABORT ", "Continue", " ABORT"))
|
||||
var/prompt = tgui_alert(src, "Editing this var may irreparably break tile gliding for the rest of the round. THIS CAN'T BE UNDONE", "DANGER", list("ABORT ", "Continue", " ABORT"))
|
||||
if (prompt != "Continue")
|
||||
return
|
||||
|
||||
@@ -93,7 +89,7 @@
|
||||
if (value["type"])
|
||||
class = VV_NEW_TYPE
|
||||
|
||||
var/original_name = "[O]"
|
||||
var/original_name = "[target]"
|
||||
|
||||
var/rejected = 0
|
||||
var/accepted = 0
|
||||
@@ -101,7 +97,7 @@
|
||||
switch(class)
|
||||
if(VV_RESTORE_DEFAULT)
|
||||
to_chat(src, "Finding items...", confidential = TRUE)
|
||||
var/list/items = get_all_of_type(O.type, method)
|
||||
var/list/items = get_all_of_type(target.type, strict_type)
|
||||
to_chat(src, "Changing [items.len] items...", confidential = TRUE)
|
||||
for(var/thing in items)
|
||||
if (!thing)
|
||||
@@ -114,20 +110,20 @@
|
||||
CHECK_TICK
|
||||
|
||||
if(VV_TEXT)
|
||||
var/list/varsvars = vv_parse_text(O, new_value)
|
||||
var/list/varsvars = vv_parse_text(target, new_value)
|
||||
var/pre_processing = new_value
|
||||
var/unique
|
||||
if (varsvars?.len)
|
||||
unique = tgui_alert(usr, "Process vars unique to each instance, or same for all?", "Variable Association", list("Unique", "Same"))
|
||||
unique = tgui_alert(src, "Process vars unique to each instance, or same for all?", "Variable Association", list("Unique", "Same"))
|
||||
if(unique == "Unique")
|
||||
unique = TRUE
|
||||
else
|
||||
unique = FALSE
|
||||
for(var/V in varsvars)
|
||||
new_value = replacetext(new_value,"\[[V]]","[O.vars[V]]")
|
||||
new_value = replacetext(new_value,"\[[V]]","[target.vars[V]]")
|
||||
|
||||
to_chat(src, "Finding items...", confidential = TRUE)
|
||||
var/list/items = get_all_of_type(O.type, method)
|
||||
var/list/items = get_all_of_type(target.type, strict_type)
|
||||
to_chat(src, "Changing [items.len] items...", confidential = TRUE)
|
||||
for(var/thing in items)
|
||||
if (!thing)
|
||||
@@ -145,7 +141,7 @@
|
||||
CHECK_TICK
|
||||
|
||||
if (VV_NEW_TYPE)
|
||||
var/many = tgui_alert(usr, "Create only one [value["type"]] and assign each or a new one for each thing", "How Many", list("One", "Many", "Cancel"))
|
||||
var/many = tgui_alert(src, "Create only one [value["type"]] and assign each or a new one for each thing", "How Many", list("One", "Many", "Cancel"))
|
||||
if (many == "Cancel")
|
||||
return
|
||||
if (many == "Many")
|
||||
@@ -155,7 +151,7 @@
|
||||
|
||||
var/type = value["type"]
|
||||
to_chat(src, "Finding items...", confidential = TRUE)
|
||||
var/list/items = get_all_of_type(O.type, method)
|
||||
var/list/items = get_all_of_type(target.type, strict_type)
|
||||
to_chat(src, "Changing [items.len] items...", confidential = TRUE)
|
||||
for(var/thing in items)
|
||||
if (!thing)
|
||||
@@ -173,7 +169,7 @@
|
||||
|
||||
else
|
||||
to_chat(src, "Finding items...", confidential = TRUE)
|
||||
var/list/items = get_all_of_type(O.type, method)
|
||||
var/list/items = get_all_of_type(target.type, strict_type)
|
||||
to_chat(src, "Changing [items.len] items...", confidential = TRUE)
|
||||
for(var/thing in items)
|
||||
if (!thing)
|
||||
@@ -196,9 +192,9 @@
|
||||
if (rejected)
|
||||
to_chat(src, "[rejected] out of [count] objects rejected your edit", confidential = TRUE)
|
||||
|
||||
log_world("### MassVarEdit by [src]: [O.type] (A/R [accepted]/[rejected]) [variable]=[html_encode("[O.vars[variable]]")]([list2params(value)])")
|
||||
log_admin("[key_name(src)] mass modified [original_name]'s [variable] to [O.vars[variable]] ([accepted] objects modified)")
|
||||
message_admins("[key_name_admin(src)] mass modified [original_name]'s [variable] to [O.vars[variable]] ([accepted] objects modified)")
|
||||
log_world("### MassVarEdit by [src]: [target.type] (A/R [accepted]/[rejected]) [variable]=[html_encode("[target.vars[variable]]")]([list2params(value)])")
|
||||
log_admin("[key_name(src)] mass modified [original_name]'s [variable] to [target.vars[variable]] ([accepted] objects modified)")
|
||||
message_admins("[key_name_admin(src)] mass modified [original_name]'s [variable] to [target.vars[variable]] ([accepted] objects modified)")
|
||||
|
||||
//not using global lists as vv is a debug function and debug functions should rely on as less things as possible.
|
||||
/proc/get_all_of_type(T, subtypes = TRUE)
|
||||
|
||||
Reference in New Issue
Block a user